/* Duo Vault: a quiet, dusk-toned look. Muted sage for you, soft plum for them. */
:root {
  --bg: #0e1419;
  --bg2: #131b21;
  --card: #19222a;
  --ink: #e2e6e5;
  --muted: #90a0a7;
  --line: #28343c;
  --accent: #7fb0a4;
  --accent-ink: #0b1815;
  --me: #7fb0a4;
  --them: #b69bbc;
  --warm: #c6a460;
  --danger: #d9827a;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 10px 28px rgb(0 0 0 / 28%);
  --r: 18px;
  --tab-h: 62px;
  --display: "Optima", "Avenir Next", "Gill Sans", "Candara", "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #e8ecee;
  --bg2: #dde4e7;
  --card: #f5f7f7;
  --ink: #1b2a32;
  --muted: #5a6b74;
  --line: #cdd7dc;
  --accent: #3b6e66;
  --accent-ink: #f3f8f7;
  --me: #3b6e66;
  --them: #85658c;
  --warm: #9a7332;
  --danger: #a23d36;
  --shadow: 0 1px 2px rgb(27 42 50 / 8%), 0 8px 24px rgb(27 42 50 / 7%);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: 0.01em; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.04em; }

/* ---------- buttons & fields ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  padding: 0.7rem 1rem;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { display: block; width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }

.field { display: grid; gap: 0.3rem; margin-bottom: 0.9rem; }
.field > span { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.field input, .field textarea, .field select, .input {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--card) 60%, var(--bg));
  min-height: 46px;
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field textarea:focus, .input:focus, .btn:focus-visible, .day:focus-visible, .tile:focus-visible, .tab:focus-visible, .seg button:focus-visible, .ev:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 1px;
}
.check { display: flex; gap: 0.6rem; align-items: center; margin-bottom: 0.9rem; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.row { display: flex; gap: 0.6rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.split > * { flex: 1; min-width: 0; }
.grow { flex: 1; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 1.1rem;
  margin-bottom: 0.9rem;
}
.card h3 { font-size: 1.05rem; margin-bottom: 0.4rem; }
.card p + p, .card p + .btn, .card .row + p { margin-top: 0.6rem; }

/* ---------- onboarding ---------- */
.screen {
  min-height: 100%;
  padding: max(1.5rem, env(safe-area-inset-top)) 1.25rem max(1.5rem, env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.hero { text-align: center; padding: 1.8rem 0 0.6rem; }
.hero img { width: 76px; height: 76px; border-radius: 22px; box-shadow: var(--shadow); }
.hero h1 { font-size: 1.9rem; margin-top: 0.9rem; }
.hero p { margin: 0.5rem auto 0; color: var(--muted); max-width: 32ch; }
.invite-box {
  word-break: break-all;
  padding: 0.8rem;
  border-radius: 14px;
  background: color-mix(in srgb, var(--warm) 12%, var(--card));
  border: 1px dashed color-mix(in srgb, var(--warm) 60%, var(--line));
  font-size: 0.85rem;
  user-select: all;
}
.banner {
  padding: 0.75rem 0.95rem;
  border-radius: 14px;
  background: color-mix(in srgb, var(--warm) 13%, var(--card));
  border: 1px solid color-mix(in srgb, var(--warm) 45%, var(--line));
  font-size: 0.9rem;
}
.banner.err { background: color-mix(in srgb, var(--danger) 10%, var(--card)); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }

/* ---------- shell ---------- */
.shell { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(0.7rem, env(safe-area-inset-top)) 1.1rem 0.4rem;
}
.top h1 { font-size: 1.55rem; }
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0.5rem 0.2rem;
  cursor: pointer;
}
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--me); }
.status.busy::before { background: var(--warm); }
.status.offline { color: var(--danger); }
.status.offline::before { background: var(--danger); }
.who { display: flex; gap: 0.9rem; padding: 0 1.1rem 0.5rem; font-size: 0.82rem; color: var(--muted); }
.who span { display: inline-flex; align-items: center; gap: 0.4rem; }
.who i { width: 10px; height: 10px; border-radius: 3px; background: var(--me); }
.who i.them { background: var(--them); }
.view { flex: 1; overflow-y: auto; padding: 0 1rem calc(var(--tab-h) + 5.5rem); -webkit-overflow-scrolling: touch; }
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg2) 90%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: center;
}
.tabs-inner { display: flex; width: 100%; max-width: 760px; }
.tab {
  flex: 1;
  border: 0;
  background: none;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--muted);
  cursor: pointer;
  position: relative;
}
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"]::after {
  content: "";
  position: absolute;
  top: 0; left: 32%; right: 32%;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
}
.fab {
  position: fixed;
  right: max(1rem, calc(50% - 380px + 1rem));
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 1rem);
  width: 56px; height: 56px;
  border-radius: 20px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.9rem;
  line-height: 1;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); }
.seg button { appearance: none; border: 0; background: none; padding: 0.4rem 0.85rem; min-height: 38px; font-weight: 600; font-size: 0.85rem; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 18%, var(--card)); color: var(--ink); }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 0.4rem; margin: 0.4rem 0 0.7rem; }
.cal-head h2 { flex: 1; font-size: 1.35rem; text-align: center; }
.cal-head .btn { min-height: 40px; padding: 0.4rem 0.8rem; }
.cal-tools { display: flex; justify-content: center; margin-bottom: 0.7rem; }
.dows, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.dows span { text-align: center; font-size: 0.75rem; font-weight: 600; color: var(--muted); padding-bottom: 4px; }
.day {
  appearance: none;
  border: 1px solid transparent;
  background: var(--card);
  border-radius: 14px;
  min-height: 62px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.4rem 0.45rem;
  gap: 0.25rem;
  cursor: pointer;
  font-weight: 600;
  text-align: left;
  overflow: hidden;
}
.day.out { background: transparent; color: var(--muted); font-weight: 400; }
.day .num { font-variant-numeric: tabular-nums; font-size: 0.9rem; line-height: 1.4; min-width: 1.6em; text-align: center; }
.day.today .num { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 0.35rem; }
.day.sel { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.dots { display: flex; gap: 3px; height: 8px; align-items: center; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--them); }
.dot.me { background: var(--me); }
.chips { display: none; flex-direction: column; gap: 2px; width: 100%; }
.chip {
  display: block;
  width: 100%;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.35;
  padding: 0 0.35rem;
  border-radius: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: color-mix(in srgb, var(--them) 22%, var(--card));
  color: var(--ink);
  border-left: 3px solid var(--them);
}
.chip.me { background: color-mix(in srgb, var(--me) 22%, var(--card)); border-left-color: var(--me); }
.more { font-size: 0.68rem; color: var(--muted); font-weight: 600; }
@media (min-width: 560px) {
  .day { min-height: 92px; }
  .chips { display: flex; }
  .dots { display: none; }
}
.agenda h3 { margin: 1.2rem 0 0.55rem; font-size: 1.05rem; }
.ev {
  display: block;
  width: 100%;
  text-align: left;
  appearance: none;
  border: 1px solid var(--line);
  border-left: 5px solid var(--them);
  background: var(--card);
  border-radius: 14px;
  padding: 0.7rem 0.95rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
}
.ev.me { border-left-color: var(--me); }
.ev .t { font-weight: 650; }
.ev .m { font-size: 0.85rem; color: var(--muted); }
.ev .n { font-size: 0.85rem; margin-top: 0.25rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { text-align: center; color: var(--muted); padding: 1.6rem 0.5rem; }

/* ---------- photos ---------- */
.photo-head { display: flex; align-items: center; justify-content: space-between; margin: 0.4rem 0 0.4rem; }
.photo-head h2 { font-size: 1.2rem; }
.month { margin-top: 1.3rem; }
.month h3 { font-size: 1rem; color: var(--muted); margin-bottom: 0.55rem; font-weight: 600; }
.photo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; grid-auto-flow: dense; }
@media (min-width: 560px) { .photo-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { appearance: none; border: 0; padding: 0; background: var(--line); aspect-ratio: 1; border-radius: 12px; overflow: hidden; cursor: pointer; position: relative; }
.tile.feature { grid-column: span 2; grid-row: span 2; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .by { position: absolute; left: 6px; bottom: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--them); box-shadow: 0 0 0 2px rgb(0 0 0 / 35%); }
.tile .by.me { background: var(--me); }
.file-btn { position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }

/* ---------- dialogs ---------- */
dialog.sheet {
  border: 0;
  padding: 0;
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  margin: auto auto 0;
  border-radius: 24px 24px 0 0;
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--shadow);
}
dialog.sheet::backdrop { background: rgb(6 10 14 / 58%); }
.sheet-body { padding: 1.2rem 1.15rem calc(1.15rem + env(safe-area-inset-bottom)); overflow-y: auto; max-height: 92dvh; }
.sheet-body h2 { font-size: 1.25rem; margin-bottom: 0.8rem; }
.sheet-body > * + *, .card > .btn + .btn, .card > .banner + *, .card > .invite-box + * { margin-top: 0.7rem; }
.viewer .sheet-body > * + * { margin-top: 0; }
dialog.viewer { max-width: 100%; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; background: #070a0e; color: #e2e6e5; }
.viewer .sheet-body { padding: max(0.8rem, env(safe-area-inset-top)) 0.8rem max(0.8rem, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 0.6rem; height: 100dvh; max-height: 100dvh; }
.viewer-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; touch-action: pan-y; }
.viewer-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 10px; }
.viewer .input { background: #121a21; border-color: #28343c; color: #e2e6e5; }
.viewer .btn { background: #121a21; color: #e2e6e5; border-color: #28343c; }
.viewer .btn.danger { color: #e79a92; }
.viewer .muted { color: #90a0a7; }
.spinner { position: absolute; width: 34px; height: 34px; border: 4px solid #28343c; border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 5rem);
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--bg);
  padding: 0.65rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1000;
  max-width: 90vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.view .who { padding-left: 0.2rem; }
