/* ---------- Tokens ---------- */
:root {
  --paper: #FBF9F4;
  --paper-line: #E4DDCB;
  --paper-line-soft: #EDE8DA;
  --ink: #2B2B2E;
  --ink-soft: #6B6B70;
  --ink-faint: #A6A29A;
  --surface: #FFFFFF;
  --shadow: rgba(43, 43, 46, 0.14);
  --shadow-soft: rgba(43, 43, 46, 0.08);

  --blue: #3B82C4;
  --coral: #E8604C;
  --gold: #E0A93E;
  --violet: #8E6FC4;
  --teal: #3FA79B;
  --rose: #D65E93;
  --green: #4C9A6A;
  --red: #D9503F;

  --font-display: Verdana, Geneva, "Segoe UI", sans-serif;
  --font-body: Verdana, Geneva, "Segoe UI", sans-serif;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
}

[data-theme="dark"] {
  --paper: #1C1C1E;
  --paper-line: #38383B;
  --paper-line-soft: #2A2A2D;
  --ink: #F0EFEA;
  --ink-soft: #B5B3AE;
  --ink-faint: #7C7A76;
  --surface: #26262A;
  --shadow: rgba(0, 0, 0, 0.5);
  --shadow-soft: rgba(0, 0, 0, 0.3);
}

body {
  transition: background-color 0.15s ease, color 0.15s ease;
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  background-image:
    linear-gradient(var(--paper-line-soft) 1px, transparent 1px);
  background-size: 100% 44px;
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; }
p { margin: 0; }
button { font-family: inherit; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; color: inherit; }
ul { margin: 0; padding: 0; list-style: none; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

#root { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--ink);
  padding: 10px 18px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 0 var(--shadow); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-green { background: var(--green); color: #fff; border-color: var(--green); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--paper-line-soft); box-shadow: none; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- Loading ---------- */
.loading-screen {
  flex: 1; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 20px; color: var(--ink-soft);
}

/* ---------- Setup / Login ---------- */
.centered-screen {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.card-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 30px var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 420px;
}
.card-panel h1 { font-size: 26px; margin-bottom: 6px; }
.card-panel .subtitle { color: var(--ink-soft); font-size: 14px; margin-bottom: 22px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 11px 13px; border-radius: var(--radius-sm);
  border: 2px solid var(--paper-line); background: var(--paper);
}
.field input:focus, .field select:focus { border-color: var(--blue); }
.form-error { color: var(--red); font-size: 13px; margin: 8px 0 4px; min-height: 18px; }

.name-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 14px; }
.name-chip {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: none; border: none; cursor: pointer; padding: 6px;
}
.avatar {
  width: 60px; height: 60px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 22px;
  border: 3px solid var(--ink);
}
.name-chip span { font-size: 13px; font-weight: 600; }

.pin-pad-dots { display: flex; gap: 10px; justify-content: center; margin: 18px 0; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink); }
.pin-dot.filled { background: var(--ink); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-key {
  font-family: var(--font-display); font-size: 22px; font-weight: 600;
  padding: 16px 0; border-radius: var(--radius-sm); border: 2px solid var(--paper-line);
  background: var(--paper); cursor: pointer;
}
.pin-key:active { background: var(--paper-line-soft); }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); margin: 14px 0; }

/* ---------- App header ---------- */
.app-header {
  display: flex; align-items: center; gap: 16px; padding: 14px 20px;
  border-bottom: 2px solid var(--ink); background: var(--surface);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 800; font-size: 18px; }
.brand .magnet-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--coral); }
.month-nav { display: flex; align-items: center; gap: 10px; margin: 0 auto; }
.month-nav h2 { font-size: 19px; min-width: 210px; text-align: center; letter-spacing: -0.01em; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--ink);
  background: var(--surface); cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.icon-btn:hover { background: var(--paper-line-soft); }
.header-actions { display: flex; align-items: center; gap: 8px; }
.badge {
  position: absolute; top: -6px; right: -6px; background: var(--coral); color: #fff;
  font-size: 11px; font-weight: 700; border-radius: 50%; min-width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px; border: 2px solid var(--surface);
}
.rel { position: relative; }
.user-chip {
  display: flex; align-items: center; gap: 8px; border: 2px solid var(--ink); border-radius: 999px;
  padding: 4px 12px 4px 4px; background: var(--surface); cursor: pointer;
}
.user-chip .avatar { width: 30px; height: 30px; font-size: 13px; border-width: 2px; }
.user-chip span { font-size: 13px; font-weight: 600; }

.menu {
  position: absolute; right: 0; top: calc(100% + 8px); background: var(--surface);
  border: 2px solid var(--ink); border-radius: var(--radius-sm); box-shadow: 0 6px 18px var(--shadow);
  min-width: 170px; z-index: 40; overflow: hidden;
}
.menu button {
  display: block; width: 100%; text-align: left; padding: 11px 14px; background: none; border: none;
  font-size: 14px; cursor: pointer; font-family: var(--font-body);
}
.menu button:hover { background: var(--paper-line-soft); }

/* ---------- Legend ---------- */
.legend {
  display: flex; gap: 10px; padding: 12px 20px; overflow-x: auto; background: var(--paper);
  border-bottom: 1px solid var(--paper-line);
}
.legend-chip {
  display: flex; align-items: center; gap: 6px; border: 2px solid var(--paper-line); border-radius: 999px;
  padding: 5px 12px 5px 6px; background: var(--surface); cursor: pointer; white-space: nowrap; flex-shrink: 0;
  font-size: 13px; font-weight: 600; opacity: 0.55; transition: opacity 0.12s, border-color 0.12s;
}
.legend-chip .avatar { width: 22px; height: 22px; font-size: 10px; border-width: 2px; }
.legend-chip.active { opacity: 1; border-color: var(--ink); }

/* ---------- Calendar grid ---------- */
.calendar-wrap { flex: 1; padding: 16px 20px 100px; }
.weekday-row { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 6px; }
.weekday-row div { text-align: center; font-size: 12px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: minmax(96px, 1fr); gap: 6px; }
.day-cell {
  background: var(--surface); border: 1px solid var(--paper-line); border-radius: var(--radius-sm);
  padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; min-width: 0;
  transition: box-shadow 0.12s;
}
.day-cell:hover { box-shadow: 0 4px 12px var(--shadow-soft); }
.day-cell.other-month { opacity: 0.4; }
.day-cell.today { border: 2px solid var(--ink); }
.day-num { font-size: 13px; font-weight: 700; }
.day-cell.today .day-num {
  background: var(--ink); color: #fff; width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.event-chip {
  font-size: 11px; padding: 2px 6px; border-radius: 5px; color: #fff; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.event-more { font-size: 11px; color: var(--ink-soft); font-weight: 600; padding: 0 4px; }

/* ---------- Floating add button (signature magnet element) ---------- */
.fab {
  position: fixed; bottom: 26px; right: 26px; width: 62px; height: 62px; border-radius: 50%;
  background: var(--coral); color: #fff; border: none; font-size: 30px; cursor: pointer;
  box-shadow: 0 8px 20px rgba(217, 80, 55, 0.4); z-index: 30;
  display: flex; align-items: center; justify-content: center; line-height: 1; padding: 0;
  transition: transform 0.15s ease;
}
.fab:hover { transform: scale(1.06); }
.fab:active { transform: scale(0.96); }

/* ---------- Overlay / modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(43, 43, 46, 0.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.15s ease;
}
@media (min-width: 760px) { .overlay { align-items: center; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  background: var(--surface); border-radius: 20px 20px 0 0; width: 100%; max-width: 520px;
  max-height: 88vh; overflow-y: auto; padding: 24px; position: relative;
  animation: pinIn 0.18s cubic-bezier(.2,.8,.3,1.2);
}
@media (min-width: 760px) { .sheet { border-radius: var(--radius-lg); margin: 20px; } }
@keyframes pinIn { from { transform: translateY(16px) rotate(0.6deg); opacity: 0; } to { transform: translateY(0) rotate(0); opacity: 1; } }
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.sheet-header h2 { font-size: 20px; }
.sheet-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--ink-soft); line-height: 1; padding: 4px; }

/* ---------- Day panel event list ---------- */
.day-event-row {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--paper-line); margin-bottom: 10px;
}
.day-event-row .stripe { width: 5px; align-self: stretch; border-radius: 3px; flex-shrink: 0; }
.day-event-row .info { flex: 1; min-width: 0; }
.day-event-row .info .title { font-weight: 700; }
.day-event-row .info .meta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.day-event-row .tags { display: flex; gap: 4px; margin-top: 6px; }
.day-event-row .tags .avatar { width: 20px; height: 20px; font-size: 9px; border-width: 1.5px; }
.row-actions { display: flex; gap: 6px; }

/* ---------- Forms ---------- */
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.chip-select { display: flex; flex-wrap: wrap; gap: 8px; }
.member-toggle {
  display: flex; align-items: center; gap: 6px; border: 2px solid var(--paper-line); border-radius: 999px;
  padding: 6px 12px 6px 6px; background: var(--paper); cursor: pointer; font-size: 13px; font-weight: 600;
}
.member-toggle.active { border-color: var(--ink); background: var(--surface); }
.member-toggle .avatar { width: 22px; height: 22px; font-size: 10px; border-width: 1.5px; }
.toggle-row { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.switch {
  width: 42px; height: 24px; border-radius: 999px; background: var(--paper-line); position: relative;
  cursor: pointer; border: none; flex-shrink: 0;
}
.switch.on { background: var(--green); }
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: left 0.15s;
}
.switch.on::after { left: 21px; }
.scope-prompt { border: 2px dashed var(--paper-line); border-radius: var(--radius-sm); padding: 12px; margin: 14px 0; }
.scope-prompt .options { display: flex; gap: 10px; margin-top: 8px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet-actions .btn { flex: 1; }
.help-text { font-size: 12px; color: var(--ink-soft); margin-top: -8px; margin-bottom: 14px; }

/* ---------- Requests ---------- */
.request-card { border: 1px solid var(--paper-line); border-radius: var(--radius-sm); padding: 14px; margin-bottom: 12px; }
.request-card .top-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.request-card .top-row .avatar { width: 26px; height: 26px; font-size: 11px; }
.type-badge { font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; color: #fff; }
.type-add { background: var(--green); }
.type-edit { background: var(--gold); }
.type-delete { background: var(--red); }
.status-badge { font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; }
.status-pending { background: #FBEBD0; color: #8A5A0E; }
.status-approved { background: #DFF0E4; color: #24603D; }
.status-rejected { background: #F7E0DC; color: #93321F; }
.request-summary { font-size: 14px; margin-bottom: 10px; }
.request-summary b { font-weight: 700; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--ink-soft); }
.empty-state .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- Family admin ---------- */
.member-row {
  display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--paper-line); margin-bottom: 8px;
}
.member-row .info { flex: 1; }
.member-row .info .name-line { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.role-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--ink-soft); border: 1px solid var(--paper-line); border-radius: 6px; padding: 1px 6px; }
.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch { width: 30px; height: 30px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; }
.color-swatch.selected { border-color: var(--ink); }
.section-divider { border: none; border-top: 1px dashed var(--paper-line); margin: 22px 0; }
.import-textarea { width: 100%; min-height: 120px; padding: 10px; border-radius: var(--radius-sm); border: 2px solid var(--paper-line); background: var(--paper); font-family: monospace; font-size: 12px; }
.import-result { font-size: 13px; margin-top: 10px; }
.import-result ul { margin-top: 6px; padding-left: 4px; }
.import-result li { margin-bottom: 4px; color: var(--ink-soft); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px; font-size: 14px;
  font-weight: 600; z-index: 100; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .month-grid { grid-auto-rows: minmax(64px, 1fr); }
  .event-chip { font-size: 10px; }
  .app-header { padding: 10px 14px; }
  .calendar-wrap { padding: 12px 12px 100px; }
  .month-nav h2 { min-width: 152px; font-size: 16px; }
}

/* ---------- View switcher ---------- */
.view-switch {
  display: flex; gap: 4px; background: var(--paper-line-soft); border-radius: 999px; padding: 4px;
  flex-shrink: 0;
}
.view-switch-btn {
  font-family: var(--font-display); font-weight: 600; font-size: 13px; border: none; background: none;
  color: var(--ink-soft); padding: 7px 14px; border-radius: 999px; cursor: pointer; transition: background 0.12s, color 0.12s;
}
.view-switch-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 2px 6px var(--shadow-soft); }

/* ---------- Week view ---------- */
.week-wrap { padding: 16px 20px 100px; }
.week-columns { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: start; }
.week-col {
  background: var(--surface); border: 1px solid var(--paper-line); border-radius: var(--radius-sm);
  display: flex; flex-direction: column; min-height: 260px; min-width: 0;
}
.week-col.today { border: 2px solid var(--ink); }
.week-col-head {
  text-align: center; padding: 10px 4px 8px; border-bottom: 1px solid var(--paper-line); cursor: pointer;
}
.week-col-dow { font-size: 11px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.week-col-num { font-size: 17px; font-weight: 700; margin-top: 2px; }
.week-col.today .week-col-num {
  background: var(--ink); color: var(--surface); width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; margin: 2px auto 0;
}
.week-col-body { flex: 1; padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.week-empty { text-align: center; color: var(--ink-faint); font-size: 12px; padding: 10px 0; }
.week-event {
  border-left: 4px solid; border-radius: 6px; background: var(--paper); padding: 6px 8px; cursor: pointer;
}
.week-event-time { font-size: 10px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; }
.week-event-title { font-size: 12px; font-weight: 700; margin-top: 2px; overflow-wrap: anywhere; }
.week-event-loc { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }

@media (max-width: 900px) {
  .week-columns { grid-template-columns: repeat(7, minmax(96px, 1fr)); overflow-x: auto; }
  .week-wrap { padding: 12px 12px 100px; overflow-x: auto; }
}

/* ---------- Today view (tablet mode) ---------- */
.today-wrap { padding: 20px 24px 110px; max-width: 720px; margin: 0 auto; width: 100%; }
.today-card {
  display: flex; gap: 14px; background: var(--surface); border: 1px solid var(--paper-line);
  border-radius: var(--radius-md); padding: 18px; margin-bottom: 14px; box-shadow: 0 4px 14px var(--shadow-soft);
}
.today-card-stripe { width: 6px; border-radius: 4px; flex-shrink: 0; }
.today-card-body { flex: 1; min-width: 0; }
.today-card-time { font-size: 13px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }
.today-card-title { font-size: 22px; font-weight: 700; margin-top: 4px; font-family: var(--font-display); }
.today-card-meta { font-size: 15px; color: var(--ink-soft); margin-top: 6px; }
.today-card .tags { display: flex; gap: 6px; margin-top: 10px; }
.back-to-month-btn { position: fixed; bottom: 30px; left: 26px; z-index: 30; background: var(--surface); }

@media (min-width: 700px) {
  .today-card-title { font-size: 26px; }
  .today-card-time, .today-card-meta { font-size: 16px; }
}
