:root {
  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --text: #0F172A;
  --muted: #64748B;
  --border: #E2E8F0;
  --primary: #2563EB;
  --danger: #DC2626;
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #0F172A;
  --surface: #1E293B;
  --text: #F8FAFC;
  --muted: #94A3B8;
  --border: #334155;
  --primary: #3B82F6;
  --danger: #EF4444;
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
  background: #0F172A !important;
  color: #F8FAFC !important;
  border-color: #334155 !important;
}

[data-theme="dark"] .card {
  background: var(--surface) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}

[data-theme="dark"] .ghost-btn,
[data-theme="dark"] .seg-btn:not(.active),
[data-theme="dark"] .chip:not(.active),
[data-theme="dark"] .dow-chip:not(.active) {
  background: #0F172A !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.app-shell {
  max-width: 540px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px 8px;
}

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  flex-shrink: 0;
  white-space: nowrap;
}
.brand-icon { font-size: 18px; flex-shrink: 0; }
.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55vw;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 9px;
  width: 31px;
  height: 31px;
  padding: 0;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

.user-pill {
  border: 1px solid var(--border);
  background: #F8FAFC;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
}
.user-pill.readonly {
  cursor: default;
}

.add-btn {
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: 9px;
  width: 31px;
  height: 31px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

.member-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-top: 8px;
  scrollbar-width: none;
}
.member-chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chip.active {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.main-content {
  flex: 1;
  padding: 12px 14px 86px;
}

.tab-view { display: none; }
.tab-view.active { display: block; }

.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  margin: 14px 0 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
}

.item-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; font-size: 15px; word-break: break-word; }
.item-title.done { text-decoration: line-through; color: var(--muted); }
.item-meta { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: #EFF6FF;
  color: #1D4ED8;
}

.badge.fixed { background: #FEF3C7; color: #92400E; }
.badge.lock { background: #F1F5F9; color: #475569; }

.seg-tabs {
  display: flex;
  background: #E2E8F0;
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 12px;
}

.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.seg-btn.active { background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.cal-nav h2 { margin: 0; font-size: 16px; }

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  background: var(--surface);
  padding: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.month-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  padding-bottom: 4px;
}

.month-cell {
  min-height: 54px;
  border-radius: 8px;
  padding: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.month-cell.today { background: #EFF6FF; border-color: #93C5FD; }
.month-cell.selected { border-color: var(--primary); background: #DBEAFE; }
.month-day-num { font-size: 12px; font-weight: 600; }
.month-dots { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; margin-top: 4px; }

.dow-chips { display: flex; gap: 5px; margin-bottom: 10px; }
.dow-chip {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 0;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.dow-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.chk-box {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
  cursor: pointer;
  margin-top: 2px;
}

.chat-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 190px);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 10px;
}

.chat-msg {
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.chat-msg.mine { align-items: flex-end; }

.chat-sender { font-size: 11px; color: var(--muted); margin-bottom: 2px; display: flex; align-items: center; gap: 4px; }
.chat-bubble {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  word-break: break-word;
  font-size: 14px;
}
.chat-msg.mine .chat-bubble {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.chat-time { font-size: 10px; color: var(--muted); margin-top: 2px; }

.chat-form {
  display: flex;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.chat-form input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 25;
}

.nav-btn {
  position: relative;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 19px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 0;
}
.nav-badge {
  position: absolute;
  top: 2px;
  right: 18%;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.nav-btn small { font-size: 11px; font-weight: 600; }
.nav-btn.active { color: var(--primary); }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.hidden { display: none !important; }

.sheet {
  width: 100%;
  max-width: 540px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.sheet-header h3 { margin: 0; font-size: 17px; }

.login-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 12px 0;
}
.login-card {
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 14px 10px;
  text-align: center;
  background: var(--surface);
  cursor: pointer;
}
.login-card.selected { border-color: var(--primary); background: #EFF6FF; }
.login-emoji { font-size: 28px; display: block; margin-bottom: 4px; }

.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
}

.primary-btn {
  width: 100%;
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 12px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.danger-btn {
  border: 1px solid #FECACA;
  background: #FEF2F2;
  color: var(--danger);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.ghost-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.pin-box input {
  width: 100%;
  padding: 12px;
  font-size: 18px;
  text-align: center;
  letter-spacing: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 8px 0;
}

.hint { font-size: 13px; color: var(--muted); margin: 4px 0 10px; }
.error-text { color: var(--danger); font-size: 13px; margin-bottom: 8px; min-height: 18px; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; font-size: 14px; }
