/* ==========================================================================
   Clinical Toolbox — launcher styles
   Vanilla CSS, no build step, no external fonts.
   Palette deliberately matches the existing tools so the whole thing reads as
   one product rather than a wrapper around unrelated pages.
   ========================================================================== */

:root {
  --bg:      #f7f6f2;
  --surface: #ffffff;
  --surface2:#f1efe8;
  --text:    #1a1a18;
  --text2:   #5f5e5a;
  --text3:   #888780;
  --border:  rgba(0, 0, 0, .11);
  --border2: rgba(0, 0, 0, .2);
  --accent:  #0F6E56;
  --accent-t:#085041;
  --accent-bg:#E1F5EE;
  --star:    #BA7517;
  --radius:  10px;
  --radius-s: 7px;
  --shadow:  0 1px 2px rgba(0, 0, 0, .04), 0 4px 12px rgba(0, 0, 0, .04);
  --shadow-h:0 2px 4px rgba(0, 0, 0, .05), 0 8px 24px rgba(0, 0, 0, .07);
  --maxw:    900px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* Dark palette. Applied either by system preference or by an explicit
   data-theme override set from app.js. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:      #1c1c1a;
    --surface: #252523;
    --surface2:#2e2e2b;
    --text:    #e8e6df;
    --text2:   #a8a79f;
    --text3:   #6e6d68;
    --border:  rgba(255, 255, 255, .1);
    --border2: rgba(255, 255, 255, .2);
    --accent:  #4FBF9F;
    --accent-t:#9FE1CB;
    --accent-bg:#04342C;
    --star:    #E0A64A;
    --shadow:  0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
    --shadow-h:0 2px 4px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  --bg:      #1c1c1a;
  --surface: #252523;
  --surface2:#2e2e2b;
  --text:    #e8e6df;
  --text2:   #a8a79f;
  --text3:   #6e6d68;
  --border:  rgba(255, 255, 255, .1);
  --border2: rgba(255, 255, 255, .2);
  --accent:  #4FBF9F;
  --accent-t:#9FE1CB;
  --accent-bg:#04342C;
  --star:    #E0A64A;
  --shadow:  0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
  --shadow-h:0 2px 4px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The `hidden` attribute is only `display: none` in the UA stylesheet, so ANY
   author-level display rule silently defeats it. Several components here set
   display (.toast is flex, .icon-btn is inline-flex, .clear-btn is flex), which
   made them permanently visible no matter what the JS set `hidden` to.
   This override must stay. Do not remove it, and do not rely on `hidden`
   working without it. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* --- accessibility primitives ------------------------------------------- */

.vh {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 200;
  background: var(--accent); color: #fff;
  padding: 10px 16px; border-radius: var(--radius-s);
  font-size: 14px; font-weight: 500; text-decoration: none;
  transition: top .15s;
}
.skip-link:focus { top: 8px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

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

.hdr {
  position: sticky; top: 0; z-index: 100;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: .5px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
@supports not (backdrop-filter: blur(1px)) { .hdr { background: var(--bg); } }

.hdr-inner {
  max-width: var(--maxw); margin: 0 auto;
  padding: 0 1.5rem; height: 56px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}

.brand {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text);
  min-height: 44px;
}
.brand-mark { width: 24px; height: 24px; color: var(--accent); flex-shrink: 0; border-radius: 6px; }
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }

.hdr-actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 44px; min-height: 44px; padding: 0 8px;
  background: none; border: none; border-radius: var(--radius-s);
  color: var(--text2); cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 500;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; flex-shrink: 0; }
.icon-btn.labelled { padding: 0 12px; }

/* Only one of the three theme glyphs is visible at a time. */
#themeBtn .ico-light, #themeBtn .ico-dark { display: none; }
:root[data-theme="light"] #themeBtn .ico-system,
:root[data-theme="dark"]  #themeBtn .ico-system { display: none; }
:root[data-theme="light"] #themeBtn .ico-light { display: block; }
:root[data-theme="dark"]  #themeBtn .ico-dark  { display: block; }

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

.wrap {
  flex: 1 0 auto;
  width: 100%; max-width: var(--maxw);
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* --- search -------------------------------------------------------------- */

.search-row { margin-bottom: 16px; }

.search-box {
  position: relative;
  display: flex; align-items: center;
  background: var(--surface);
  border: .5px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.search-ico {
  width: 19px; height: 19px; margin-left: 14px;
  color: var(--text3); flex-shrink: 0; pointer-events: none;
}

.search-input {
  flex: 1; min-width: 0;
  padding: 14px 12px; border: none; background: none;
  font-family: inherit; font-size: 16px; /* 16px prevents iOS zoom on focus */
  color: var(--text);
}
.search-input:focus { outline: none; }
.search-input::placeholder { color: var(--text3); }
.search-input::-webkit-search-cancel-button { display: none; }

.kbd-hint {
  margin-right: 12px; padding: 2px 7px;
  font-family: inherit; font-size: 11px; color: var(--text3);
  background: var(--surface2); border: .5px solid var(--border);
  border-radius: 5px; flex-shrink: 0;
}
.search-box:focus-within .kbd-hint { display: none; }
@media (max-width: 560px) { .kbd-hint { display: none; } }

.clear-btn {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; margin-right: 4px;
  background: none; border: none; border-radius: var(--radius-s);
  color: var(--text3); cursor: pointer; flex-shrink: 0;
}
.clear-btn:hover { color: var(--text); background: var(--surface2); }
.clear-btn svg { width: 18px; height: 18px; }

/* --- filter chips -------------------------------------------------------- */

.filters {
  display: flex; gap: 7px; flex-wrap: wrap;
  margin-bottom: 18px;
}
@media (max-width: 640px) {
  .filters {
    flex-wrap: nowrap; overflow-x: auto;
    scrollbar-width: none;
    margin-left: -1.5rem; margin-right: -1.5rem;
    padding: 2px 1.5rem 6px;
    scroll-padding: 1.5rem;
  }
  .filters::-webkit-scrollbar { display: none; }
}

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; min-height: 38px;
  background: var(--surface); color: var(--text2);
  border: .5px solid var(--border);
  border-radius: 999px;
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover { color: var(--text); border-color: var(--border2); }
.chip[aria-pressed="true"] {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
:root[data-theme="dark"] .chip[aria-pressed="true"],
.chip[aria-pressed="true"] { color: #fff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chip[aria-pressed="true"] { color: #06231c; }
}
:root[data-theme="dark"] .chip[aria-pressed="true"] { color: #06231c; }

.chip-count {
  font-size: 11px; font-variant-numeric: tabular-nums;
  opacity: .65;
}

.chip-star { width: 13px; height: 13px; }

/* --- status line --------------------------------------------------------- */

.status-line {
  font-size: 12px; color: var(--text3);
  margin-bottom: 14px; min-height: 16px;
}

/* --- sections ------------------------------------------------------------ */

.group { margin-bottom: 34px; }

.group-head {
  display: flex; align-items: baseline; gap: 9px;
  margin-bottom: 12px;
}
.group-title {
  font-size: 11px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--text3);
}
.group-rule { flex: 1; height: .5px; background: var(--border); }

/* --- cards --------------------------------------------------------------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(292px, 1fr));
  gap: 12px;
}
@media (max-width: 660px) { .grid { grid-template-columns: 1fr; } }

.card {
  position: relative;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: .5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.card:hover { box-shadow: var(--shadow-h); border-color: var(--border2); transform: translateY(-1px); }
.card:focus-within { border-color: var(--accent); }

/* The whole card is a link. The favourite button sits above it via z-index so
   it stays independently clickable and independently focusable. */
.card-link {
  display: flex; flex-direction: column; gap: 6px;
  padding: 15px 46px 14px 16px;
  text-decoration: none; color: inherit;
  border-radius: var(--radius);
  flex: 1;
}
.card-link:focus-visible { outline-offset: -2px; }

.card-title {
  font-size: 15px; font-weight: 600; line-height: 1.35;
  letter-spacing: -.01em; color: var(--text);
}
.card-title mark {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: inherit; border-radius: 2px; padding: 0 1px;
}

.card-desc {
  font-size: 13px; color: var(--text2); line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-desc mark {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: inherit; border-radius: 2px; padding: 0 1px;
}

.card-meta {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  margin-top: auto; padding-top: 8px;
  font-size: 11px; color: var(--text3);
}

.tagline { display: flex; gap: 5px; flex-wrap: wrap; }
.tag {
  padding: 2px 7px;
  background: var(--surface2); color: var(--text3);
  border: .5px solid var(--border);
  border-radius: 4px;
  font-size: 10.5px; font-weight: 500;
}

.badge {
  padding: 2px 8px; border-radius: 999px;
  font-size: 10.5px; font-weight: 600;
  letter-spacing: .02em;
}
.badge-draft   { background: #FAEEDA; color: #854F0B; }
.badge-review  { background: #E6F1FB; color: #0C447C; }
.badge-archived{ background: var(--surface2); color: var(--text3); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge-draft  { background: #412402; color: #FAC775; }
  :root:not([data-theme="light"]) .badge-review { background: #042C53; color: #B5D4F4; }
}
:root[data-theme="dark"] .badge-draft  { background: #412402; color: #FAC775; }
:root[data-theme="dark"] .badge-review { background: #042C53; color: #B5D4F4; }

.fav-btn {
  position: absolute; top: 9px; right: 9px; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  background: none; border: none; border-radius: 50%;
  color: var(--text3); cursor: pointer;
  transition: color .15s, background .15s;
}
.fav-btn:hover { background: var(--surface2); color: var(--star); }
.fav-btn svg { width: 17px; height: 17px; }
.fav-btn[aria-pressed="true"] { color: var(--star); }
.fav-btn[aria-pressed="true"] svg { fill: var(--star); }

/* Comfortable touch targets on coarse pointers. */
@media (pointer: coarse) {
  .fav-btn { width: 44px; height: 44px; top: 4px; right: 4px; }
  .card-link { padding-right: 52px; }
}

/* --- empty state --------------------------------------------------------- */

.empty { text-align: center; padding: 56px 20px; }
.empty-title { font-size: 15px; font-weight: 600; margin-bottom: 5px; }
.empty-sub { font-size: 13px; color: var(--text2); margin-bottom: 18px; }

.btn-ghost {
  padding: 9px 16px; min-height: 40px;
  background: var(--surface); color: var(--text);
  border: .5px solid var(--border2); border-radius: var(--radius-s);
  font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
}
.btn-ghost:hover { background: var(--surface2); }

.notice {
  padding: 14px 16px; margin-top: 16px;
  background: var(--surface2); border: .5px solid var(--border);
  border-radius: var(--radius); font-size: 13px; color: var(--text2);
}

/* --- footer -------------------------------------------------------------- */

.ftr {
  flex-shrink: 0;
  border-top: .5px solid var(--border);
  padding: 20px 1.5rem calc(24px + env(safe-area-inset-bottom));
}
.ftr > * { max-width: var(--maxw); margin-left: auto; margin-right: auto; }
.ftr p { font-size: 11.5px; color: var(--text3); line-height: 1.6; }
.ftr strong { color: var(--text2); font-weight: 600; }
.ftr-meta { margin-top: 8px; display: flex; gap: 7px; flex-wrap: wrap; }
.dot { opacity: .5; }

/* --- update toast -------------------------------------------------------- */

.toast {
  position: fixed; z-index: 300;
  left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px;
  max-width: 420px; margin: 0 auto;
  padding: 11px 11px 11px 16px;
  background: var(--text); color: var(--bg);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .25);
  animation: rise .2s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.toast-text { flex: 1; font-size: 13px; font-weight: 500; }

.toast-btn {
  padding: 7px 14px; min-height: 36px;
  background: var(--bg); color: var(--text);
  border: none; border-radius: var(--radius-s);
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.toast-btn:hover { opacity: .88; }

.toast-x {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: none; border: none; border-radius: 50%;
  color: var(--bg); opacity: .6; cursor: pointer;
}
.toast-x:hover { opacity: 1; }
.toast-x svg { width: 16px; height: 16px; }

/* --- print --------------------------------------------------------------- */

@media print {
  .hdr, .filters, .search-row, .toast, .fav-btn, .skip-link { display: none !important; }
  .card { break-inside: avoid; box-shadow: none; }
}
