/* Reset, app shell and shared components. */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
body.is-demo { --demo-h: 30px; }
h1, h2, h3, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.ico { width: var(--icon); height: var(--icon); flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 1px; }
.view:focus { outline: none; }

/* Demo bar */
.demo-bar {
  position: sticky; top: 0; z-index: 30;
  height: var(--demo-h);
  display: flex; align-items: center; justify-content: center; gap: var(--space-5);
  background: var(--accent-strong); color: var(--on-accent);
  font-size: var(--fs-sm);
}
.demo-bar a { text-decoration: underline; text-underline-offset: 2px; font-weight: 500; }

/* Shell */
.app { display: block; min-height: calc(100dvh - var(--demo-h)); }
.sidebar { display: none; }
.view {
  display: block;
  width: 100%; max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-5) var(--space-5) calc(var(--bottom-h) + env(safe-area-inset-bottom) + var(--space-5));
}
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--bottom-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 10.5px;
}
.bottom-nav .ico { width: var(--icon-nav); height: var(--icon-nav); }
.bottom-nav a.active { color: var(--accent-strong); font-weight: 600; }

/* Page head */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-2) var(--space-5); margin-bottom: var(--space-5); min-height: 28px; }
.page-head h1 { font-family: var(--font-serif); font-size: var(--fs-title); font-weight: 600; line-height: 1.2; }
.page-head .couple { font-family: var(--font-serif); font-size: var(--fs-lg); font-weight: 600; color: var(--gold-text); text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-link { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); font-size: var(--fs-sm); margin-bottom: 2px; }

/* Cards */
.card { display: block; min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: var(--card-pad); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-2); }
.card-title { font-size: var(--fs-md); font-weight: 600; }
.card-link { font-size: var(--fs-sm); color: var(--accent-strong); white-space: nowrap; }
a.card { transition: border-color .15s; }
@media (hover: hover) { a.card:hover { border-color: var(--accent); } }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: var(--ctl-h); padding: 0 var(--space-6);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font-size: var(--fs-control); font-weight: 500; white-space: nowrap; cursor: pointer;
}
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }
.btn-text { border-color: transparent; background: transparent; color: var(--muted); padding: 0 var(--space-3); }

/* Forms */
.field { display: block; min-width: 0; }
.field-label { display: block; margin-bottom: var(--space-1); font-size: var(--fs-sm); font-weight: 500; color: var(--muted); }
.field-hint { margin-top: var(--space-1); font-size: var(--fs-xs); color: var(--muted); }
.field-error { margin-top: var(--space-1); font-size: var(--fs-xs); color: var(--danger); }
.field-error:empty { display: none; }
.input {
  display: block; width: 100%; min-width: 0; height: var(--ctl-h); padding: 0 var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font-size: var(--fs-input);
  -webkit-appearance: none; appearance: none;
}
select.input { -webkit-appearance: auto; appearance: auto; }
/* iPhone centres date and time values and can collapse an empty field. */
.input::-webkit-date-and-time-value { text-align: left; min-height: 1.4em; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input:focus { outline: none; border-color: var(--accent-strong); box-shadow: 0 0 0 1px var(--accent-strong); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-5) var(--space-4); }
.span-2 { grid-column: 1 / -1; }

/* Segmented radio group */
.segment { display: flex; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.segment label { flex: 1; position: relative; cursor: pointer; }
.segment label + label { border-left: 1px solid var(--border); }
.segment input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segment span { display: flex; align-items: center; justify-content: center; height: calc(var(--ctl-h) - 2px); font-size: var(--fs-control); color: var(--muted); }
.segment input:checked + span { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.segment input:focus-visible + span { outline: 2px solid var(--accent-strong); outline-offset: -2px; }

/* Theme picker */
.theme-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.theme-opt { position: relative; cursor: pointer; }
.theme-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.theme-opt > span { display: flex; align-items: center; gap: var(--space-3); height: var(--ctl-h); padding: 0 var(--space-4); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: var(--fs-control); }
.theme-opt input:checked + span { border-color: var(--accent-strong); box-shadow: 0 0 0 1px var(--accent-strong); font-weight: 600; }
.theme-opt input:focus-visible + span { outline: 2px solid var(--accent-strong); outline-offset: 1px; }
.swatches { display: inline-flex; }
.swatches i { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .1); }
.swatches i + i { margin-left: -4px; }

/* Lists, pills, bars */
.rows li { display: flex; align-items: center; gap: var(--space-3); min-height: var(--row-h); border-top: 1px solid var(--border); font-size: var(--fs-control); }
.rows li:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { flex: none; font-size: var(--fs-sm); color: var(--muted); white-space: nowrap; }
.pill { display: inline-flex; align-items: center; height: 20px; padding: 0 var(--space-3); border-radius: 10px; background: var(--track); color: var(--muted); font-size: var(--fs-xs); font-weight: 500; white-space: nowrap; }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.bar { display: flex; height: 4px; border-radius: 2px; background: var(--track); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar > span.gold { background: var(--gold); }
.bar > span.over { background: var(--danger); }
.empty-note { padding: var(--space-5) 0; font-size: var(--fs-sm); color: var(--muted); }
.empty-note a { color: var(--accent-strong); }

/* Placeholder section */
.placeholder { padding: var(--space-7) var(--space-6); text-align: center; color: var(--muted); font-size: var(--fs-control); }
.placeholder .ico { width: 24px; height: 24px; margin-bottom: var(--space-3); color: var(--gold); }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom) + var(--space-4));
  padding: var(--space-3) var(--space-6); border-radius: var(--radius);
  background: var(--text); color: var(--surface); font-size: var(--fs-sm); white-space: nowrap;
}

/* Laptop */
@media (min-width: 768px) {
  .only-phone { display: none !important; }
  .app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .bottom-nav { display: none; }
  .sidebar {
    position: sticky; top: var(--demo-h);
    display: flex; flex-direction: column;
    height: calc(100vh - var(--demo-h));
    padding: var(--space-6) var(--space-4) var(--space-5);
    background: var(--surface); border-right: 1px solid var(--border);
  }
  .brand { display: block; padding: 0 var(--space-3) var(--space-5); font-family: var(--font-serif); font-size: 20px; font-weight: 600; }
  .side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; overflow-y: auto; }
  .side-nav a { display: flex; align-items: center; gap: var(--space-3); height: 32px; padding: 0 var(--space-3); border-radius: var(--radius); color: var(--muted); font-size: 13px; }
  .side-nav a.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
  .side-foot { padding: var(--space-4) var(--space-3) 0; border-top: 1px solid var(--border); }
  .side-foot .names { font-family: var(--font-serif); font-size: var(--fs-lg); font-weight: 600; overflow-wrap: anywhere; }
  .side-foot .date { font-size: var(--fs-xs); color: var(--muted); }
  .view { padding: var(--space-6) 20px; }
  .toast { bottom: var(--space-7); }
  .theme-picker { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (hover: hover) and (min-width: 768px) {
  .side-nav a:not(.active):hover { background: var(--bg); color: var(--text); }
}

/* Dialog: centred on laptop, bottom sheet on phone */
.modal {
  width: 100%; max-width: none; margin: auto 0 0; padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--surface); color: var(--text); box-shadow: 0 8px 30px rgba(40, 35, 25, .16);
}
.modal::backdrop { background: rgba(40, 35, 25, .32); }
.modal form { padding: var(--space-6) var(--space-6) calc(var(--space-6) + env(safe-area-inset-bottom)); }
.modal-title { margin-bottom: var(--space-5); font-size: var(--fs-lg); font-weight: 600; }
.modal-title:focus { outline: none; }
.modal-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-top: var(--space-6); }
.modal-buttons { display: flex; gap: var(--space-2); }
.btn-danger { color: var(--danger); padding: 0; }
.link-btn { padding: 0; border: 0; background: none; color: var(--accent-strong); font-size: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* Checkbox */
.check-wrap { display: flex; align-items: center; justify-content: center; flex: none; width: 26px; min-height: var(--row-h); cursor: pointer; }
.check {
  position: relative; width: 16px; height: 16px; margin: 0; cursor: pointer;
  border: 1px solid var(--muted); border-radius: 4px; background: var(--surface);
  -webkit-appearance: none; appearance: none;
}
.check:checked { background: var(--accent-strong); border-color: var(--accent-strong); }
.check:checked::after { content: ""; position: absolute; left: 4.5px; top: 1.5px; width: 4px; height: 8px; border: solid var(--on-accent); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); }

@media (min-width: 768px) {
  .modal { width: 440px; margin: auto; border-radius: var(--radius-lg); }
}
