/* NN Calendar — dark-first, with a light palette for daytime phone use. */

:root {
  --bg: #12151c;
  --bg-raised: #1a1f29;
  --bg-sunken: #0d1015;
  --line: #262d3a;
  --line-soft: #1e242f;
  --text: #e8ecf3;
  --text-dim: #98a3b5;
  --text-faint: #63708a;
  --accent: #5eead4;
  --accent-ink: #062b26;
  --danger: #f87171;
  --danger-bg: #2a1518;
  --info-bg: #14202e;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --bg-raised: #ffffff;
    --bg-sunken: #eceef2;
    --line: #d7dbe2;
    --line-soft: #e5e8ed;
    --text: #161b22;
    --text-dim: #5b6472;
    --text-faint: #8b95a5;
    --accent: #0f766e;
    --accent-ink: #ffffff;
    --danger: #b42318;
    --danger-bg: #fdeceb;
    --info-bg: #eaf2fb;
    --shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

body { overscroll-behavior-y: none; }

button { font: inherit; color: inherit; cursor: pointer; }

/* --- header ---------------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  padding-top: max(0.6rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }

.brand h1 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-mark {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 4px;
  flex: none;
  background: linear-gradient(135deg, var(--accent) 0 50%, #f97316 50% 100%);
}

.viewswitch {
  display: flex;
  gap: 2px;
  margin-left: auto;
  padding: 2px;
  background: var(--bg-sunken);
  border-radius: 8px;
}

.vs-btn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 0.32rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 550;
}

.vs-btn.is-active { background: var(--bg-raised); color: var(--text); }

.header-actions { display: flex; align-items: center; gap: 0.3rem; }

.status { font-size: 0.72rem; color: var(--text-faint); }

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 6px;
  font-size: 0.95rem;
  line-height: 1;
}

.icon-btn:hover { background: var(--bg-sunken); color: var(--text); }

/* --- banners --------------------------------------------------------- */

.banner {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin: 0.6rem 0.9rem 0;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
}

.banner-error { background: var(--danger-bg); color: var(--danger); }
.banner-info { background: var(--info-bg); color: var(--text-dim); }

.link-btn {
  border: 0;
  background: transparent;
  color: inherit;
  text-decoration: underline;
  padding: 0;
  font-weight: 600;
}

/* --- layout ---------------------------------------------------------- */

#main { padding: 0.9rem; padding-bottom: max(2rem, env(safe-area-inset-bottom)); }

.view { max-width: 1180px; margin: 0 auto; }

.empty {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.9rem;
}

.muted { color: var(--text-faint); }

.swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 3px;
  display: inline-block;
  flex: none;
}

.swatch-sm { width: 0.55rem; height: 0.55rem; border-radius: 2px; }

.badge {
  font-size: 0.68rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.16rem 0.4rem;
  border-radius: 4px;
}

.badge-apart { background: #7c2d12; color: #fed7aa; }
.badge-together { background: #134e4a; color: #99f6e4; }
.badge-today { background: var(--accent); color: var(--accent-ink); }

.hint {
  font-size: 0.66rem;
  color: var(--text-faint);
  border: 1px dashed var(--line);
  border-radius: 3px;
  padding: 0 0.25rem;
}

/* --- now view -------------------------------------------------------- */

.now-date { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.9rem; }
.now-date h2 { margin: 0; font-size: 1.15rem; font-weight: 650; letter-spacing: -0.02em; }

.now-people {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.7rem;
}

.person-card {
  position: relative;
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 0.85rem 0.9rem 0.9rem;
  overflow: hidden;
}

.person-card::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--place, var(--line));
}

.person-head { display: flex; align-items: center; gap: 0.45rem; margin-bottom: 0.4rem; }

.person-name {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
}

.place-line { display: flex; align-items: center; gap: 0.4rem; }
.place-label { font-size: 1.05rem; font-weight: 620; letter-spacing: -0.01em; }

.person-summary {
  margin: 0.45rem 0 0;
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.person-meta { margin: 0.45rem 0 0; font-size: 0.74rem; color: var(--text-faint); }

.person-next {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.6rem 0 0;
  padding-top: 0.55rem;
  border-top: 1px solid var(--line-soft);
  font-size: 0.8rem;
  color: var(--text-dim);
}

.person-next .arrow { color: var(--text-faint); }

.upcoming { margin-top: 1.5rem; }

.upcoming h3, .legend h4 {
  margin: 0 0 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.upcoming-list { list-style: none; margin: 0; padding: 0; }

.upcoming-list li {
  display: grid;
  grid-template-columns: 6.5rem 1fr auto;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.5rem 0.2rem;
  border-bottom: 1px solid var(--line-soft);
  font-size: 0.85rem;
  cursor: pointer;
}

.upcoming-list li:hover { background: var(--bg-raised); }
.up-when { color: var(--text-faint); font-size: 0.76rem; font-variant-numeric: tabular-nums; }
.up-who { color: var(--text-faint); font-size: 0.72rem; }

/* --- year ribbon ----------------------------------------------------- */

.year-nav {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}

.year-tabs { display: flex; gap: 2px; padding: 2px; background: var(--bg-sunken); border-radius: 8px; }

.year-tab {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.year-tab.is-active { background: var(--bg-raised); color: var(--text); font-weight: 600; }
.year-tab:disabled { color: var(--text-faint); opacity: 0.45; cursor: default; }

.year-key { display: flex; gap: 0.8rem; font-size: 0.72rem; color: var(--text-faint); }
.year-key-item { display: flex; align-items: center; gap: 0.3rem; }

.key-bar {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 2px;
  background: linear-gradient(var(--line) 0 50%, transparent 50% 100%);
}

.key-bar[data-pos="bottom"] { background: linear-gradient(transparent 0 50%, var(--line) 50% 100%); }

.year-scroll { overflow-x: auto; padding-bottom: 0.4rem; }

.year-grid {
  display: grid;
  grid-template-columns: 2.1rem repeat(31, minmax(13px, 1fr));
  gap: 2px;
  min-width: 620px;
}

.yg-corner { }

.yg-daynum {
  font-size: 0.58rem;
  color: var(--text-faint);
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding-bottom: 2px;
}

.yg-month {
  font-size: 0.7rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.35rem;
}

.yg-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 13px;
  display: flex;
  flex-direction: column;
  border-radius: 2px;
  overflow: hidden;
  cursor: pointer;
  background: var(--bg-sunken);
}

.yg-cell:hover { outline: 1.5px solid var(--text-dim); outline-offset: 1px; }
.yg-void { background: transparent; cursor: default; }
.yg-sliver { flex: 1; min-height: 0; }
.yg-sliver.is-inferred { opacity: 0.42; }
.yg-cell.is-apart .yg-sliver:first-child { box-shadow: inset 0 -1px 0 var(--bg); }

.yg-cell.is-today {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  z-index: 2;
}

.legend { margin-top: 1.4rem; }
.legend-items { display: flex; flex-wrap: wrap; gap: 0.35rem 0.8rem; }

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.32rem;
  font-size: 0.76rem;
  color: var(--text-dim);
}

.legend-count { color: var(--text-faint); font-size: 0.68rem; font-variant-numeric: tabular-nums; }

/* --- month grid ------------------------------------------------------ */

.month-nav { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.7rem; }
.month-title { margin: 0; font-size: 1.05rem; font-weight: 650; letter-spacing: -0.02em; }

.nav-btn {
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text-dim);
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
  display: grid;
  place-items: center;
}

.nav-btn:hover { color: var(--text); border-color: var(--text-faint); }

.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }

.mg-dow {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  text-align: center;
  padding-bottom: 0.2rem;
}

.mg-cell {
  position: relative;
  min-height: 4.6rem;
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.35rem;
  overflow: hidden;
  cursor: pointer;
}

.mg-cell:hover { border-color: var(--text-faint); }
.mg-void { background: transparent; border: 0; cursor: default; min-height: 0; }
.mg-cell.is-today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.mg-bars { position: absolute; inset: 0 0 auto 0; display: flex; height: 3px; }
.mg-bar { flex: 1; }
.mg-bar.is-inferred { opacity: 0.42; }

.mg-num {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  margin-top: 0.15rem;
}

.mg-cell.is-today .mg-num { color: var(--accent); }

.mg-note {
  margin-top: 0.15rem;
  font-size: 0.66rem;
  line-height: 1.28;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- agenda ---------------------------------------------------------- */

.view-agenda { max-width: 720px; }

.segment {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--bg-raised);
  margin-bottom: 0.6rem;
  overflow: hidden;
}

.segment.is-now { border-color: var(--accent); }

.segment-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem 0.8rem;
  padding: 0.7rem 0.8rem;
  cursor: pointer;
}

.segment-when { display: flex; align-items: baseline; gap: 0.5rem; }
.segment-range { font-size: 0.92rem; font-weight: 640; letter-spacing: -0.01em; }
.segment-rel { font-size: 0.72rem; color: var(--text-faint); }
.segment-len { font-size: 0.72rem; color: var(--text-faint); text-align: right; }

.segment-places {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  padding: 0.18rem 0.45rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--place) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--place) 40%, transparent);
}

.chip-who { color: var(--text-faint); font-size: 0.68rem; }

.segment-events { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line-soft); }

.segment-events li {
  display: grid;
  grid-template-columns: 5.6rem 1fr auto;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.42rem 0.8rem;
  font-size: 0.82rem;
  cursor: pointer;
}

.segment-events li + li { border-top: 1px solid var(--line-soft); }
.segment-events li:hover { background: var(--bg-sunken); }
.ev-when { font-size: 0.72rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.ev-who { font-size: 0.7rem; color: var(--text-faint); }

/* --- sheet / modal --------------------------------------------------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  background: rgba(6, 8, 12, 0.62);
  backdrop-filter: blur(3px);
  padding: 1rem;
  overflow-y: auto;
}

.sheet.is-open { display: flex; align-items: flex-start; justify-content: center; }

.sheet-panel {
  width: 100%;
  max-width: 780px;
  margin: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sheet-narrow { max-width: 480px; }

.sheet-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg-raised);
}

.sheet-title { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0; }
.sheet-title h2 { margin: 0; font-size: 0.98rem; font-weight: 650; letter-spacing: -0.01em; }

.sheet-close {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.sheet-close:hover { background: var(--bg-sunken); color: var(--text); }

.sheet-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1px;
  background: var(--line-soft);
}

.detail-person { background: var(--bg); padding: 0.8rem; }

.detail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line-soft);
}

.detail-body { display: flex; flex-direction: column; gap: 0.5rem; }

.facet-events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; }

.facet-events li {
  font-size: 0.86rem;
  line-height: 1.35;
  padding-left: 0.6rem;
  border-left: 2px solid var(--line);
}

.facet {
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
}

.facet-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  font-weight: 700;
}

.flight-route {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}

.airport { font-weight: 700; font-size: 0.9rem; letter-spacing: 0.02em; }
.flight-time { font-size: 0.74rem; color: var(--text-dim); }
.flight-arrow { color: var(--text-faint); }
.flight-meta { margin-top: 0.2rem; font-size: 0.72rem; color: var(--text-faint); }
.flight-conf { margin-top: 0.3rem; display: flex; align-items: center; gap: 0.35rem; }
.flight-conf code { font-family: var(--mono); font-size: 0.76rem; letter-spacing: 0.04em; }

.facet-stay { border-left: 2px solid var(--accent); }
.stay-name { display: flex; align-items: center; gap: 0.35rem; font-size: 0.86rem; font-weight: 560; }
.facet-icon { color: var(--text-faint); }
.stay-address { margin-top: 0.2rem; font-size: 0.72rem; color: var(--text-faint); line-height: 1.35; }

.facet-cancelled ul { list-style: none; margin: 0.25rem 0 0; padding: 0; }

.facet-cancelled li {
  text-decoration: line-through;
  color: var(--text-faint);
  font-size: 0.8rem;
  line-height: 1.35;
}

.facet-tag {
  font-size: 0.66rem;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  align-self: flex-start;
}

/* --- settings form --------------------------------------------------- */

.settings-body { display: block; background: var(--bg); padding: 0.9rem; }
.form-help { margin: 0 0 0.9rem; font-size: 0.8rem; color: var(--text-dim); line-height: 1.45; }
.field { display: block; margin-bottom: 0.8rem; }

.field-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 0.25rem;
}

.field input {
  width: 100%;
  padding: 0.5rem 0.6rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field-help { display: block; margin-top: 0.25rem; font-size: 0.7rem; color: var(--text-faint); }
.form-error { min-height: 1rem; margin: 0 0 0.5rem; font-size: 0.78rem; color: var(--danger); }
.form-actions { display: flex; gap: 0.5rem; }

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-faint); }

/* --- narrow screens -------------------------------------------------- */

@media (max-width: 640px) {
  .app-header { flex-wrap: wrap; }
  .viewswitch { order: 3; width: 100%; margin-left: 0; justify-content: space-between; }
  .vs-btn { flex: 1; text-align: center; }
  .header-actions { margin-left: auto; }
  #main { padding: 0.7rem; }
  .upcoming-list li { grid-template-columns: 1fr auto; }
  .up-when { grid-column: 1 / -1; }
  .segment-events li { grid-template-columns: 1fr auto; }
  .ev-when { grid-column: 1 / -1; }
  .mg-cell { min-height: 3.4rem; padding: 0.2rem 0.25rem; }
  .mg-note { display: none; }
  .sheet { padding: 0; align-items: flex-end; }
  .sheet.is-open { align-items: flex-end; }

  .sheet-panel {
    max-width: none;
    margin: 0;
    border-radius: 14px 14px 0 0;
    border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .sheet.is-open .sheet-panel { animation: rise 0.18s ease-out; }
  @keyframes rise { from { transform: translateY(8px); opacity: 0.6; } }
}
