/* ════════════════════════════════════════════════════════════════════════
   main.css: the one stylesheet. Same design system as my-portfolio, so every
   project shares the same look and class names. The reference page
   (app/templates/index.html) shows every component.

   Sections: font · tokens · reset · navbar · dark-mode switch · layout ·
   typography · buttons · cards · forms · alerts · badges · tables · tabs ·
   collapsible sections · icons · footer · login · utilities · responsive
   ════════════════════════════════════════════════════════════════════════ */

/* ─── Font: Inter (variable, self-hosted; SIL Open Font License, see
   app/static/fonts/inter/OFL.txt). No Google Fonts: visitor IPs stay here. */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url('/static/fonts/inter/inter-latin-ext-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url('/static/fonts/inter/inter-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ─── Tokens: change these to re-theme the whole app ──────────────────── */
:root {
  --font-body: 'Inter', -apple-system, system-ui, sans-serif;   /* one font for everything, code included */

  --max-w: 860px;          /* .page width */
  --max-w-narrow: 420px;   /* .page-narrow width (forms) */
  --nav-h: 58px;
  --radius-sm: 12px;
  --radius: 18px;
  --radius-lg: 24px;
  --pill: 980px;
  --ease: 150ms ease;
  --ease-md: 280ms ease;
}

:root, [data-theme="light"] {
  --bg:          #ffffff;
  --bg-alt:      #f5f5f7;
  --bg-card:     #ffffff;
  --bg-hover:    #f5f5f7;
  --border:      #e5e5ea;
  --border-hi:   #d2d2d7;
  --text:        #1d1d1f;
  --text-2:      #6e6e73;
  --text-3:      #86868b;
  --nav-bg:      rgba(255,255,255,0.72);
  --shadow-sm:   0 1px 2px rgba(0,0,0,0.04);
  --shadow:      0 2px 12px rgba(0,0,0,0.05);
  --shadow-lg:   0 12px 40px rgba(0,0,0,0.10);
  --tag-bg:      #f5f5f7;
  --tag-text:    #6e6e73;
  --ok:          #30a46c;
  --ok-bg:       #e9f7f0;
  --err:         #d93025;
  --err-bg:      #fdecea;
  --accent:      #0071e3;               /* links, focus, active states */
  --accent-btn:  #0071e3;               /* filled buttons */
  --accent-hi:   #0077ed;               /* button hover */
  --accent-soft: rgba(0,113,227,0.10);  /* tinted backgrounds */
}

[data-theme="dark"] {
  --bg:          #000000;
  --bg-alt:      #111113;
  --bg-card:     #1d1d1f;
  --bg-hover:    #2a2a2d;
  --border:      #2c2c2e;
  --border-hi:   #424245;
  --text:        #f5f5f7;
  --text-2:      #a1a1a6;
  --text-3:      #6e6e73;
  --nav-bg:      rgba(0,0,0,0.72);
  --shadow-sm:   0 1px 2px rgba(0,0,0,0.40);
  --shadow:      0 2px 12px rgba(0,0,0,0.35);
  --shadow-lg:   0 12px 40px rgba(0,0,0,0.55);
  --tag-bg:      #2a2a2d;
  --tag-text:    #a1a1a6;
  --ok:          #5bbf8e;
  --ok-bg:       #12251c;
  --err:         #ff6b5e;
  --err-bg:      #2a1412;
  --accent:      #2997ff;
  --accent-btn:  #0a84ff;
  --accent-hi:   #409cff;
  --accent-soft: rgba(41,151,255,0.16);
}

/* ─── Reset ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  min-height: 100vh;
  display: flex; flex-direction: column;
  font-family: var(--font-body);
  background: var(--bg-alt);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  transition: background var(--ease-md), color var(--ease-md);
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; }
ul { list-style: none; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─── Navbar (app/templates/_nav.html) ───────────────────────────────── */
.nav {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 200;
  transition: background var(--ease-md), border-color var(--ease-md);
}
.nav-bar { height: 100%; display: flex; align-items: center; gap: 1.5rem; padding: 0 1.5rem; }
.nav-brand {
  font-size: .9rem; font-weight: 600; color: var(--text); letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color var(--ease);
}
.nav-brand:hover { color: var(--accent); }
.nav-menu { display: flex; align-items: center; gap: 1.75rem; margin-left: auto; }
.nav-links { display: flex; align-items: center; gap: 1.5rem; }
.nav-links a { font-size: .85rem; font-weight: 500; color: var(--text-2); transition: color var(--ease); }
.nav-links a:hover { color: var(--accent); }
.nav-links a.active { color: var(--text); }
.nav-links-extra a { color: var(--text-3); }
.nav-burger {
  display: none;
  width: 2.5rem; height: 2.5rem; margin-right: -.5rem;
  align-items: center; justify-content: center;
  border: none; background: none; color: var(--text-2);
}
.nav-burger .icon { width: 1.25rem; height: 1.25rem; }
.nav-burger:hover { color: var(--accent); }

/* ─── Dark-mode switch (app/templates/_theme_switch.html) ────────────── */
.theme-switch {
  position: relative; display: inline-flex; align-items: center; cursor: pointer; flex-shrink: 0;
  height: 1.15rem; line-height: 0;
  top: .1rem;   /* optical alignment with the link text next to it */
}
.theme-switch-input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.theme-switch-track {
  width: 2.1rem; height: 1.15rem; border-radius: var(--pill);
  background: var(--border); position: relative;
  transition: background var(--ease);
}
.theme-switch-thumb {
  position: absolute; top: .15rem; left: .15rem;
  width: .85rem; height: .85rem; border-radius: 50%;
  background: var(--bg); color: var(--text-3); box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center;
  transition: transform var(--ease);
}
.theme-switch .theme-switch-thumb .icon { width: .6rem; height: .6rem; display: block; }
/* Calm on purpose: same greys in both states, only the knob moves */
/* Position from data-theme on <html> (set in <head> before the first paint), not
   :checked (set by JS later): otherwise the knob slides on every page load in dark mode. */
[data-theme="dark"] .theme-switch-thumb { transform: translateX(.95rem); }
.theme-switch-input:focus-visible + .theme-switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-switch:hover .theme-switch-track { background: var(--border-hi); }
.theme-switch:hover .theme-switch-thumb { color: var(--text-2); }
/* One icon in the knob: sun in light mode, moon in dark mode */
.theme-switch .theme-switch-thumb .theme-switch-moon { display: none; }
[data-theme="dark"] .theme-switch .theme-switch-thumb .theme-switch-sun { display: none; }
[data-theme="dark"] .theme-switch .theme-switch-thumb .theme-switch-moon { display: block; }

/* ─── Layout ──────────────────────────────────────────────────────────── */
main { flex: 1; padding-top: var(--nav-h); }
.page { max-width: var(--max-w); margin: 0 auto; padding: 2.5rem 1.5rem 5rem; }
.page-narrow { max-width: var(--max-w-narrow); margin: 0 auto; padding: 3rem 1.5rem 5rem; }
.page-header { margin-bottom: 2rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; align-items: start; }

/* ─── Typography ──────────────────────────────────────────────────────── */
h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); font-weight: 600; letter-spacing: -.025em; line-height: 1.2; }
h2 { font-size: 1.05rem; font-weight: 600; letter-spacing: -.01em; }
h3 { font-size: .95rem; font-weight: 600; }
.lede { font-size: 1rem; color: var(--text-2); margin-top: .5rem; max-width: 560px; }
.label { display: block; font-size: .8rem; font-weight: 600; color: var(--text-3); margin-bottom: .6rem; }
code {
  font-family: var(--font-body);   /* same font as the text */
  font-size: .88em; background: var(--bg-alt); color: var(--text);
  padding: .1rem .4rem; border-radius: 6px;
}
pre {
  font-family: var(--font-body); font-size: .82rem; line-height: 1.6;
  background: var(--bg-alt); border-radius: var(--radius); padding: 1rem 1.25rem;
  overflow-x: auto; white-space: pre;
}
pre code { background: none; padding: 0; font-size: inherit; }
.prose { color: var(--text-2); font-size: .92rem; line-height: 1.75; }
.prose > * + * { margin-top: .9rem; }
.prose h2, .prose h3 { color: var(--text); margin-top: 1.6rem; }
.prose ul { list-style: disc; padding-left: 1.25rem; }
.prose ol { list-style: decimal; padding-left: 1.25rem; }
.prose a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.prose strong { color: var(--text); font-weight: 600; }
.divider { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

/* ─── Buttons ─────────────────────────────────────────────────────────── */
/* .btn-primary / .btn-secondary: pill buttons for actions on public pages */
.btn-primary, .btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .6rem 1.3rem; border-radius: var(--pill);
  font-size: .88rem; font-weight: 500; line-height: 1.2;
  transition: all var(--ease);
}
.btn-primary { background: var(--accent-btn); color: #fff; border: 1px solid var(--accent-btn); }
.btn-primary:hover { background: var(--accent-hi); border-color: var(--accent-hi); }
.btn-secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-secondary:hover { background: var(--accent-soft); }

/* .btn-submit: form buttons; add .secondary for the grey variant */
.btn-submit {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .55rem 1.25rem; line-height: 1.2;
  background: var(--accent-btn); color: #fff;
  border: 1px solid transparent; border-radius: var(--pill);
  font-size: .88rem; font-weight: 500;
  transition: background var(--ease);
}
.btn-submit:hover { background: var(--accent-hi); }
.btn-submit.secondary { background: var(--bg-alt); color: var(--text); border-color: var(--border-hi); box-shadow: var(--shadow-sm); }
.btn-submit.secondary:hover { background: var(--bg-hover); border-color: var(--text-3); }
.btn-submit.danger { background: var(--err); }
.btn-submit.danger:hover { filter: brightness(1.08); }
.btn-full { width: 100%; }

/* .btn-sm: small outlined buttons in tables and card headers */
.btn-sm {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .72rem; padding: .25rem .75rem;
  border: 1px solid var(--border); border-radius: var(--pill);
  background: var(--bg-card); color: var(--text-2);
  white-space: nowrap; transition: all var(--ease);
}
.btn-sm:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm.danger:hover { border-color: var(--err); color: var(--err); }

/* One primary + identical secondary buttons, same height, room to wrap */
.editor-actions { display: flex; align-items: center; gap: 1rem .9rem; flex-wrap: wrap; margin-top: 1.5rem; }

/* ─── Cards ───────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  transition: box-shadow var(--ease-md);
}
.card-title { font-size: .8rem; font-weight: 600; color: var(--text-3); margin-bottom: 1rem; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.card-header .card-title { margin-bottom: 0; }
/* A table that runs edge to edge at the bottom of a .card (form above, list below) */
.card-table { margin: 1.5rem -1.5rem -1.5rem; border-top: 1px solid var(--border); overflow-x: auto; }
.card-table:first-child { margin-top: -1.5rem; border-top: none; }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }

/* ─── Forms ───────────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field-label { font-size: .75rem; font-weight: 500; color: var(--text-2); }
.field-input, .field-textarea, .field-select {
  width: 100%;
  padding: .65rem .9rem;
  background: var(--bg-alt);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .875rem;
  outline: none;
  transition: all var(--ease);
}
.field-input:focus, .field-textarea:focus, .field-select:focus {
  background: var(--bg-card);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.field-input::placeholder, .field-textarea::placeholder { color: var(--text-3); }
.field-textarea { min-height: 110px; resize: vertical; line-height: 1.6; }
.field-input.sm { padding: .35rem .6rem; font-size: .8rem; }
.field-check { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--text-2); cursor: pointer; }
.field-hint { font-size: .72rem; color: var(--text-3); }
.inline-form { display: flex; gap: .4rem; align-items: center; }

/* ─── Alerts and status messages ──────────────────────────────────────── */
.alert {
  font-size: .85rem; padding: .7rem 1rem; margin-bottom: 1rem;
  border-radius: var(--radius-sm); border: 1px solid currentColor;
}
.alert-success { color: var(--ok); background: var(--ok-bg); }
.alert-error { color: var(--err); background: var(--err-bg); }
.alert-info { color: var(--accent); background: var(--accent-soft); }

@keyframes status-pop {
  0%   { opacity: 0; transform: translateY(2px); }
  15%  { opacity: 1; transform: translateY(0); }
  70%  { opacity: 1; }
  100% { opacity: 0; }
}
/* Short "Saved" message next to a button; fades out by itself */
.save-status { font-size: .78rem; animation: status-pop 2.8s ease forwards; }
.save-status.success { color: var(--ok); }
.save-status.error { color: var(--err); }

/* ─── Badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; font-size: .65rem; font-weight: 600; letter-spacing: .02em;
  padding: .15rem .6rem; border-radius: var(--pill);
  background: var(--tag-bg); color: var(--text-3);
}
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge-count {
  font-size: .62rem; font-weight: 600;
  background: var(--accent-btn); color: #fff;
  border-radius: var(--pill); padding: .1rem .45rem;
}
.tag {
  font-size: .7rem; font-weight: 500;
  background: var(--tag-bg); color: var(--tag-text);
  padding: .2rem .65rem; border-radius: var(--pill);
}

/* ─── Tables ──────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  font-size: .72rem; font-weight: 600; color: var(--text-3);
  text-align: left; padding: .5rem .75rem;
  border-bottom: 1px solid var(--border);
}
.table td { padding: .75rem; border-bottom: 1px solid var(--border); font-size: .84rem; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
/* Outer columns keep the same breathing room as the card padding */
.table th:first-child, .table td:first-child { padding-left: 1.5rem; }
.table th:last-child, .table td:last-child { padding-right: 1.5rem; }
.table tr.muted td { opacity: .5; }

/* ─── Tabs (data-tab on .tab-btn, id="panel-<name>" on .tab-panel) ────── */
.tabs {
  display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 2rem;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;   /* swipe on mobile */
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  padding: .55rem 1rem;
  font-size: .8rem; font-weight: 500; color: var(--text-3);
  background: transparent; border: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  display: flex; align-items: center; gap: .4rem;
  flex-shrink: 0; white-space: nowrap;
  transition: all var(--ease);
}
.tab-btn:hover { color: var(--text-2); background: var(--bg-hover); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Collapsible sections (.section > .section-header + .section-body) ─ */
.section {
  background: var(--bg-card); border-radius: var(--radius-lg);
  margin-bottom: 1rem; overflow: hidden;
  box-shadow: var(--shadow); transition: box-shadow var(--ease-md);
}
.section.open { box-shadow: var(--shadow-lg); }
.section-header {
  display: flex; align-items: center; gap: .6rem; width: 100%;
  padding: 1.1rem 1.5rem; background: none; border: none; text-align: left;
  font-size: .875rem; font-weight: 600; color: var(--text);
  cursor: pointer; user-select: none; transition: background var(--ease);
}
.section-header:hover { background: var(--bg-hover); }
.section.open .section-header { border-bottom: 1px solid var(--border); }
.section-subtitle { font-size: .72rem; color: var(--text-3); font-weight: 400; }
.section-chevron { display: inline-flex; margin-left: auto; color: var(--text-3); transition: transform var(--ease); }
.section-chevron .icon { width: 1rem; height: 1rem; }
.section.open .section-chevron { transform: rotate(90deg); }
.section-body { display: none; padding: 1.5rem; }
.section.open .section-body { display: block; }

/* ─── Icons (Heroicons via icon() in app/templating.py) ──────────────── */
.icon { display: inline-block; width: 1.05em; height: 1.05em; vertical-align: -.2em; flex-shrink: 0; }

/* ─── Footer ──────────────────────────────────────────────────────────── */
.footer { padding: 1.5rem; border-top: 1px solid var(--border); text-align: center; }
.footer-text { font-size: .72rem; color: var(--text-3); }

/* ─── Login ───────────────────────────────────────────────────────────── */
.login-card {
  max-width: 360px; margin: 4rem auto 0; padding: 2.25rem;
  background: var(--bg-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.login-title { font-size: 1.5rem; font-weight: 600; letter-spacing: -.025em; margin-bottom: .2rem; }
.login-sub { font-size: .85rem; color: var(--text-3); margin-bottom: 1.5rem; }

/* ─── Utilities ───────────────────────────────────────────────────────── */
.text-muted { color: var(--text-2); }
.text-faint { color: var(--text-3); }
.text-sm { font-size: .85rem; }
.text-xs { font-size: .75rem; }
.text-ok { color: var(--ok); }
.text-err { color: var(--err); }
.mt-1 { margin-top: .5rem; }  .mt-2 { margin-top: 1rem; }  .mt-3 { margin-top: 1.5rem; }  .mt-4 { margin-top: 2rem; }
.mb-1 { margin-bottom: .5rem; }  .mb-2 { margin-bottom: 1rem; }  .mb-3 { margin-bottom: 1.5rem; }
.flex { display: flex; }  .items-center { align-items: center; }  .justify-between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }  .gap-1 { gap: .5rem; }  .gap-2 { gap: 1rem; }

/* ─── Small screens: hamburger menu ──────────────────────────────────── */
@media (max-width: 860px) {
  .nav-burger { display: flex; }
  /* menu is folded away: switch sits right, centred next to the hamburger */
  .nav-bar .theme-switch { margin-left: auto; top: 0; }
  .nav-bar .nav-burger { margin-left: -1rem; }   /* hamburger close to the switch */
  .nav-menu {
    display: none;
    position: absolute; top: var(--nav-h); left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: .15rem;
    padding: .5rem .75rem .75rem;   /* link text lines up with the brand */
    background: var(--bg); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-lg);
    max-height: calc(100vh - var(--nav-h)); overflow-y: auto;
  }
  .nav.open .nav-menu { display: flex; }
  /* compact list: no dividers, the current page gets a soft background */
  .nav-links { flex-direction: column; align-items: stretch; gap: .15rem; }
  .nav-links a { display: block; padding: .6rem .75rem; font-size: .9rem; border-radius: var(--radius-sm); }
  .nav-links a:hover { background: var(--bg-hover); }
  .nav-links a.active { background: var(--bg-hover); }
}

@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .page { padding: 2rem 1rem 4rem; }
  .card { padding: 1.25rem; }
  .card-table { margin: 1.25rem -1.25rem -1.25rem; }
  .card-table:first-child { margin-top: -1.25rem; }
  .table th:first-child, .table td:first-child { padding-left: 1.25rem; }
  .table th:last-child, .table td:last-child { padding-right: 1.25rem; }
  .table .hide-sm { display: none; }
  .login-card { margin-top: 2rem; padding: 1.75rem; }
}

/* ─── Contacts (app-specific) ─────────────────────────────────────────── */
[hidden] { display: none !important; }   /* also for elements with display: flex */
.btn-submit, .btn-sm { gap: .4rem; }
.btn-sm.icon-only { padding: .35rem; }
.btn-sm .icon { width: .95rem; height: .95rem; }
.num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.align-end { align-self: end; padding-bottom: .65rem; }
.narrow-card { max-width: var(--max-w-narrow); }
.back-link { display: inline-flex; align-items: center; gap: .2rem; font-size: .8rem; color: var(--text-3); margin-bottom: .6rem; }
.back-link:hover { color: var(--accent); }
.alert { transition: opacity .6s ease; }
.alert.fade-out { opacity: 0; }
.field-select.sm { padding: .35rem .6rem; font-size: .8rem; width: auto; }
.field-input[type="file"] { padding: .5rem .9rem; }
.form-grid { gap: 1rem; }
.badge.warn { background: color-mix(in srgb, #d97706 14%, transparent); color: #d97706; }

/* Side-by-side cards with the same height */
.grid-equal { align-items: stretch; }
.grid-equal > .card { display: flex; flex-direction: column; }
.grid-equal > .card > .card-bottom { margin-top: auto; }
.grid-2 + .card, .grid-2 + .grid-2 { margin-top: 1rem; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; flex-shrink: 0; border-radius: var(--pill);
  background: none; border: none; color: var(--text-3); transition: all var(--ease);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--accent); }
.icon-btn.sm { width: 1.5rem; height: 1.5rem; }
.icon-btn .icon { width: 1.1rem; height: 1.1rem; }
.link-btn { background: none; border: none; padding: 0; font-size: .85rem; font-weight: 600; color: var(--accent); }
.link-btn:hover { text-decoration: underline; text-underline-offset: 2px; }

/* Sync status */
.sync-status { display: flex; align-items: center; gap: .4rem; }
.sync-dot { display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; background: var(--text-3); vertical-align: .05em; }
.sync-dot.ok { background: var(--ok); }
.sync-dot.error { background: var(--err); }

/* Toolbar above the list: add, search, per page, menu */
.toolbar { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-wrap .field-input { padding-left: 2.3rem; padding-right: 2.3rem; background: var(--bg-card); box-shadow: var(--shadow-sm); }
.search-wrap .field-input::-webkit-search-cancel-button { display: none; }
.search-icon { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search-clear {
  position: absolute; right: .4rem; top: 50%; transform: translateY(-50%);
  display: inline-flex; padding: .3rem; border: none; border-radius: var(--pill);
  background: none; color: var(--text-3);
}
.search-clear:hover { background: var(--bg-hover); color: var(--text); }
.per-page { display: inline-flex; align-items: center; gap: .4rem; }
.toolbar-menu { position: relative; }
.toolbar-dropdown {
  position: absolute; right: 0; top: calc(100% + .4rem); z-index: 20; min-width: 15rem;
  padding: .35rem; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
}
.toolbar-menu-item {
  display: flex; align-items: center; gap: .55rem; width: 100%;
  padding: .55rem .7rem; border: none; border-radius: 8px;
  background: none; color: var(--text); font-size: .85rem; text-align: left;
}
.toolbar-menu-item:hover { background: var(--bg-hover); color: var(--accent); }
.toolbar-menu-item .icon { color: var(--text-3); }

/* Dialogs (vCard, CSV, merge with) */
.app-dialog {
  margin: auto; width: min(32rem, calc(100vw - 2rem)); max-height: calc(100vh - 4rem);
  padding: 1.5rem; border: none; border-radius: var(--radius-lg);
  background: var(--bg-card); color: var(--text); box-shadow: var(--shadow-lg);
}
.app-dialog::backdrop { background: rgba(0, 0, 0, .35); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.app-dialog .divider { margin: 1.25rem 0; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.dialog-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.app-dialog-sm { width: min(24rem, calc(100vw - 2rem)); }
.dialog-title { font-size: 1.1rem; font-weight: 600; letter-spacing: -.01em; }
.dialog-actions-end { justify-content: flex-end; }
.merge-results { margin-top: .75rem; max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.merge-results-empty { padding: .75rem 1rem; }
.merge-result-row { display: flex; align-items: center; gap: .75rem; padding: .6rem .75rem; border-bottom: 1px solid var(--border); }
.merge-result-row:last-child { border-bottom: none; }
.merge-result-row:hover { background: var(--bg-hover); }

/* The contact list: rows that open into details or an edit form */
.contacts-card { padding: .5rem; }
.contacts-empty { padding: 1rem; }
.contact-entry + .contact-entry { border-top: 1px solid var(--border); }
.contact-row-header {
  display: flex; align-items: center; gap: .85rem; padding: .7rem .75rem;
  border-radius: var(--radius-sm); cursor: pointer; transition: background var(--ease);
}
.contact-row-header:hover, .contact-entry.is-open .contact-row-header { background: var(--bg-hover); }
.contact-avatar {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 2.25rem; height: 2.25rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: .9rem;
}
.contact-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.contact-meta .name { font-weight: 600; font-size: .9rem; }
.contact-meta .sub { font-size: .8rem; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-detail-panel, .contact-edit-panel { padding: 1rem .75rem 1.25rem 3.85rem; }
.detail-row { display: grid; grid-template-columns: 9rem 1fr; gap: 1rem; padding: .45rem 0; font-size: .875rem; }
.detail-label { font-size: .75rem; font-weight: 500; color: var(--text-3); padding-top: .1rem; }
.detail-value { min-width: 0; overflow-wrap: anywhere; }
.detail-value a { color: var(--accent); }
.rel-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .3rem; }
.rel-add { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .3rem; }
.detail-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.two-col-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.field > .field-input + .two-col-grid { margin-top: .5rem; }
.list-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem; }

/* Email and phone rows */
.rows { display: flex; flex-direction: column; gap: .5rem; }
.dynamic-row { display: flex; align-items: center; gap: .5rem; }
.dynamic-row .field-select { width: 7.5rem; flex-shrink: 0; }
.dynamic-row .field-input { flex: 1; min-width: 0; }

/* Duplicates and merge */
.dup-grid { gap: 1rem; }
.dup-card { padding: 1rem; border-radius: var(--radius-sm); background: var(--bg-alt); }
.dup-card .contact-avatar, .merge-card .contact-avatar { margin-bottom: .5rem; }
.dup-name { font-weight: 600; }
.dup-reason { flex: 1; }
.card-header .badge { flex-shrink: 0; }
.merge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.merge-grid > .card { margin-bottom: 0; }
.merge-result { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }
.pick-label { display: flex; align-items: center; gap: .75rem; }
.pick { display: inline-flex; gap: .5rem; }
.pick-option { display: inline-flex; align-items: center; gap: .2rem; font-weight: 600; color: var(--text-3); cursor: pointer; }
.pick-option input { accent-color: var(--accent); }

@media (max-width: 640px) {
  .merge-grid, .two-col-grid { grid-template-columns: 1fr; }
  .contact-detail-panel, .contact-edit-panel { padding-left: .75rem; }
  .detail-row { grid-template-columns: 1fr; gap: .1rem; }
  .toolbar .btn-submit { flex: 1; }
  .search-wrap { order: 3; flex-basis: 100%; }
}

/* ─── Reduced motion (keep this last) ─────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
