/* app.css — Family Calendar */
@import url('https://fonts.googleapis.com/css2?family=Work+Sans:wght@300;400;500;600&display=swap');

/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  --font: 'Work Sans', 'Helvetica Neue', sans-serif;
  --radius: 8px;
  --transition: 0.15s ease;
}

body.dark {
  --bg:          #0a0a0a;
  --bg2:         #111111;
  --bg3:         #161616;
  --border:      #1e1e1e;
  --border2:     #2a2a2a;
  --text:        #e8e4de;
  --text2:       #888;
  --text3:       #444;
  --accent:      #C9A96E;
  --conflict-bg: #8B202022;
  --conflict-bd: #8B2020;
  --conflict-tx: #ffaaaa;
  --modal-bg:    rgba(0,0,0,0.78);
  --shadow:      0 40px 80px rgba(0,0,0,0.6);
}

body.light {
  --bg:          #f4f2ee;
  --bg2:         #ffffff;
  --bg3:         #ece9e3;
  --border:      #ddd8cf;
  --border2:     #ccc6bb;
  --text:        #1a1814;
  --text2:       #666;
  --text3:       #aaa;
  --accent:      #b08d4e;
  --conflict-bg: #fff0f0;
  --conflict-bd: #e06060;
  --conflict-tx: #a02020;
  --modal-bg:    rgba(0,0,0,0.4);
  --shadow:      0 20px 60px rgba(0,0,0,0.15);
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow-x: hidden; }
html { overscroll-behavior: none; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}
button { cursor: pointer; font-family: var(--font); }
input, textarea, select { font-family: var(--font); }
::selection { background: var(--accent); color: var(--bg); }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ── Screens ─────────────────────────────────────────────────────────────  */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ── Auth ────────────────────────────────────────────────────────────────  */
.auth-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}
.auth-logo {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 48px;
}
.auth-pane {
  display: none;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 360px;
}
.auth-pane.active { display: flex; }
.auth-pane h2 { font-size: 20px; font-weight: 500; letter-spacing: -0.02em; }
.auth-sub { font-size: 13px; color: var(--text2); }
.auth-switch { font-size: 12px; color: var(--text3); text-align: center; }
.auth-switch a { color: var(--accent); text-decoration: none; }
#pane-sent { align-items: center; text-align: center; }

.color-row, .notify-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.color-swatches { display: flex; gap: 8px; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid transparent;
  transition: border-color var(--transition);
}
.swatch.active { border-color: var(--text); }
.notify-checks { display: flex; gap: 16px; }
.notify-checks label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
}

/* ── App header ──────────────────────────────────────────────────────────  */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}
.header-left { display: flex; align-items: center; gap: 6px; }
.app-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.header-right { display: flex; align-items: center; gap: 10px; }

.cal-switcher {
  background: none;
  border: 1px solid var(--border2);
  border-radius: 4px;
  color: var(--text3);
  font-size: 10px;
  padding: 2px 6px;
  transition: all var(--transition);
}
.cal-switcher:hover { color: var(--text); border-color: var(--text3); }

/* user pills */
#user-pills { display: flex; gap: 7px; flex-wrap: wrap; }
.user-pill {
  padding: 4px 13px;
  border-radius: 100px;
  border: 1px solid var(--border2);
  background: transparent;
  color: var(--text3);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: all var(--transition);
}
.user-pill.on { border-color: var(--pill-color); background: var(--pill-light); color: var(--pill-color); }

/* view toggle */
.view-toggle {
  display: flex;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}
.view-btn {
  padding: 6px 14px;
  background: transparent;
  color: var(--text3);
  border: none;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: all var(--transition);
}
.view-btn.active { background: var(--bg2); color: var(--text); }
.icon-btn {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 18px;
  padding: 4px 6px;
  transition: color var(--transition);
  line-height: 1;
}
.icon-btn:hover { color: var(--text); }

/* ── Nav bar ─────────────────────────────────────────────────────────────  */
#cal-nav {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 24px 14px;
}
#cal-title { flex: 1; font-size: 22px; font-weight: 500; letter-spacing: -0.02em; }
.nav-arrow {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 22px;
  line-height: 1;
  padding: 2px 4px;
  transition: color var(--transition);
}
.nav-arrow:hover { color: var(--text); }
.btn-today {
  padding: 5px 13px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text3);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-today:hover { color: var(--text); border-color: var(--border2); }

/* ── Calendar body ───────────────────────────────────────────────────────  */
#cal-body {
  flex: 1;
  padding: 0 12px 24px;
  display: flex;
  flex-direction: column;
}

#day-headers {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
}
.day-header-cell {
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text3);
  padding: 6px 0;
  font-weight: 600;
}

#cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  flex: 1;
}

.day-cell {
  background: var(--bg);
  min-height: 96px;
  padding: 8px 6px;
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
  overflow: hidden;
}
.day-cell:hover { background: var(--bg3); }
.day-cell.today { border-left: 2px solid var(--accent); }
.day-cell.selecting { background: color-mix(in srgb, var(--accent) 12%, var(--bg)); }
.day-cell.range-start, .day-cell.range-end { background: color-mix(in srgb, var(--accent) 18%, var(--bg)); }
.day-cell.in-range { background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }

.day-num {
  font-size: 12px;
  color: var(--text3);
  font-weight: 400;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}
.day-num.is-today { color: var(--accent); font-weight: 600; }

.conflict-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--conflict-bd);
  display: inline-block;
}

.event-chip {
  display: block;
  padding: 2px 6px 2px 7px;
  border-left: 2px solid var(--chip-color, #888);
  background: var(--chip-light, #88888814);
  border-radius: 0 3px 3px 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.5;
  margin-bottom: 3px;
  transition: opacity var(--transition);
  cursor: pointer;
}
.event-chip:hover { opacity: 0.8; }
.event-time { font-size: 10px; margin-right: 4px; font-weight: 600; }
.recur-icon { font-size: 9px; color: var(--text3); margin-left: 2px; }
.more-chip { font-size: 10px; color: var(--text3); padding-left: 4px; }

/* week grid */
#week-grid {
  display: grid;
  grid-template-columns: 52px repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  min-width: 560px;
  overflow: auto;
}
.week-header-cell {
  background: var(--bg);
  padding: 10px 6px;
  text-align: center;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: border-color var(--transition);
}
.week-header-cell.today { border-bottom-color: var(--accent); }
.week-day-label { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text3); margin-bottom: 4px; }
.week-date-num { font-size: 20px; font-weight: 300; color: var(--text2); }
.week-date-num.is-today { color: var(--accent); font-weight: 600; }
.week-dots { display: flex; justify-content: center; gap: 3px; margin-top: 5px; }
.week-dot { width: 5px; height: 5px; border-radius: 50%; }

.hour-label {
  background: var(--bg);
  font-size: 10px;
  color: var(--text3);
  text-align: right;
  padding: 5px 8px 0;
  height: 50px;
  letter-spacing: 0.03em;
}
.hour-cell {
  background: var(--bg);
  height: 50px;
  padding: 3px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.hour-cell:hover { background: var(--bg3); }

/* ── Modals ──────────────────────────────────────────────────────────────  */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-bg);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(5px);
  animation: fadeIn 0.15s ease;
}
.modal-overlay[hidden] { display: none; }

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.modal-label { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text3); margin-bottom: 4px; }
.modal-date { font-size: 18px; font-weight: 500; }
.modal-close {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 22px;
  line-height: 1;
  padding: 0 4px;
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text); }

.conflict-badge {
  display: inline-block;
  font-size: 9px;
  background: var(--conflict-bg);
  border: 1px solid var(--conflict-bd);
  color: var(--conflict-tx);
  padding: 3px 9px;
  border-radius: 4px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 6px;
  cursor: pointer;
}
.conflict-badge[hidden] { display: none !important; }
.conflict-badge:hover { opacity: 0.8; }

/* form fields */
.field-group { display: flex; flex-direction: column; gap: 7px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.label-sm { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text3); }
.label-opt { font-weight: 300; }

select,
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
input[type="time"],
textarea {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  width: 100%;
  transition: border-color var(--transition);
  color-scheme: dark;
}
body.light input, body.light textarea, body.light select { color-scheme: light; }
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: none; line-height: 1.6; }
.check-label { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text2); cursor: pointer; }

/* day event card */
.day-event-card {
  background: var(--chip-light, #88888814);
  border-left: 3px solid var(--chip-color, #888);
  border-radius: 0 8px 8px 0;
  padding: 11px 14px;
  position: relative;
}
.day-event-card + .day-event-card { margin-top: 8px; }
.dec-title { font-size: 14px; font-weight: 500; color: var(--text); }
.dec-meta { font-size: 11px; color: var(--text3); margin-top: 2px; }
.dec-note { font-size: 12px; color: var(--text2); margin-top: 5px; line-height: 1.5; }
.dec-owner { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; margin-top: 6px; }
.card-del {
  position: absolute;
  top: 10px; right: 10px;
  background: none;
  border: none;
  color: var(--text3);
  font-size: 16px;
  line-height: 1;
  transition: color var(--transition);
}
.card-del:hover { color: #e05555; }

/* invite modal extras */
.invite-link-copy {
  display: flex;
  gap: 8px;
}
.invite-link-copy input {
  flex: 1;
  font-size: 12px;
  color: var(--text2);
}
.btn-copy {
  width: auto;
  padding: 9px 16px;
  flex-shrink: 0;
}
.invite-divider {
  text-align: center;
  color: var(--text3);
  font-size: 11px;
  position: relative;
  margin: 4px 0;
}
.invite-divider span {
  background: var(--bg2);
  padding: 0 12px;
  position: relative;
  z-index: 1;
}
.invite-divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
}

/* calendar switcher list */
.cal-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 12px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  transition: all var(--transition);
}
.cal-list-item + .cal-list-item { margin-top: 8px; }
.cal-list-item.active { border-color: var(--accent); }
.cal-list-item:hover { background: var(--bg2); }
.cal-list-name { font-weight: 500; }
.cal-list-role { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.08em; }

/* buttons */
.btn-primary {
  padding: 11px;
  background: var(--bg3);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: all var(--transition);
  width: 100%;
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 12%, var(--bg)); }
.btn-primary:disabled { border-color: var(--border); color: var(--text3); cursor: default; }

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn-secondary {
  padding: 9px;
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text3);
  border-radius: 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: all var(--transition);
  width: 100%;
  cursor: pointer;
}
.btn-secondary:hover { color: var(--text); border-color: var(--text3); }

/* toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 11px 22px;
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow);
  z-index: 200;
  white-space: nowrap;
  pointer-events: none;
  animation: fadeUp 0.2s ease;
}
.toast[hidden] { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ── Mobile ──────────────────────────────────────────────────────────────  */
@media (max-width: 600px) {
  html, body { overflow-x: hidden; width: 100%; max-width: 100vw; height: 100dvh; }
  .screen { overflow-x: hidden; max-width: 100vw; min-height: 100dvh; height: 100dvh; }
  .screen.active { height: 100dvh; }

  .auth-wrap { padding: 32px 20px; }
  .auth-logo { font-size: 20px; margin-bottom: 36px; }
  .auth-pane { max-width: 100%; gap: 12px; }
  .auth-pane h2 { font-size: 18px; }

  #app-header {
    padding: 10px 10px 8px;
    gap: 6px;
    flex-wrap: wrap;
  }
  .header-left { width: auto; }
  .app-title { font-size: 13px; }
  #user-pills { gap: 4px; }
  .user-pill { padding: 3px 9px; font-size: 10px; }
  .header-right { gap: 5px; }
  .view-btn { padding: 4px 9px; font-size: 9px; }
  .icon-btn { font-size: 15px; padding: 4px; }

  #cal-nav { padding: 8px 10px 6px; gap: 8px; }
  #cal-title { font-size: 17px; }
  .nav-arrow { font-size: 20px; padding: 4px 6px; }
  .btn-today { padding: 4px 10px; font-size: 10px; }

  #cal-body { padding: 0; }
  #day-headers { margin-bottom: 0; }
  .day-header-cell { padding: 5px 0; font-size: 9px; letter-spacing: 0.06em; }

  .day-cell { min-height: 0; padding: 3px 2px; }
  .day-num { font-size: 11px; margin-bottom: 2px; }
  .event-chip {
    font-size: 9px;
    padding: 1px 3px 1px 4px;
    line-height: 1.35;
    margin-bottom: 2px;
    border-left-width: 2px;
  }
  .event-time { font-size: 8px; margin-right: 2px; }
  .recur-icon { font-size: 8px; }
  .more-chip { font-size: 8px; }
  .conflict-dot { width: 5px; height: 5px; }

  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }
  .modal-box {
    padding: 20px 16px 24px;
    border-radius: 14px 14px 0 0;
    max-width: 100%;
    max-height: 85vh;
    width: 100%;
  }
  .modal-date { font-size: 16px; }
  .field-row { grid-template-columns: 1fr; gap: 10px; }
  .btn-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .btn-primary { padding: 12px; font-size: 12px; }
  .btn-secondary { padding: 10px; font-size: 11px; }

  .day-event-card { padding: 10px 12px; }
  .dec-title { font-size: 13px; }
  .dec-meta { font-size: 10px; }
  .dec-note { font-size: 11px; }

  .toast { bottom: 16px; font-size: 12px; padding: 9px 18px; }

  select,
  input[type="text"],
  input[type="email"],
  input[type="date"],
  textarea {
    font-size: 16px;
    padding: 10px 12px;
  }
}
