/* =========================================================================
   Judgment Journal — styles
   A calm, legible legal reference tool. Reading-app feel, restrained palette.
   ========================================================================= */

:root {
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, system-ui, sans-serif;

  /* Light — warm paper & ink */
  --paper: #f6f2ea;
  --surface: #fffdf8;
  --surface-2: #f1ebdf;
  --ink: #211d17;
  --ink-soft: #4a4437;
  --muted: #7c7566;
  --faint: #a49c8c;
  --line: #e6ded0;
  --line-strong: #d8cfbd;
  --accent: #3c4a66;          /* deep ink-blue */
  --accent-soft: #eef0f5;
  --accent-ink: #2c3852;
  --danger: #9a3b32;
  --danger-soft: #f6e7e4;
  --focus: #6b7fa8;
  --shadow: 0 1px 2px rgba(40,33,20,.05), 0 8px 26px rgba(40,33,20,.09);
  --shadow-sm: 0 1px 2px rgba(40,33,20,.06);
  --radius: 12px;
  --radius-sm: 8px;
  --topbar-h: 60px;
  --sidebar-w: 288px;
  --chip-l: 92%;
  --chip-border-l: 80%;
  --chip-text-l: 30%;
  --dot-l: 55%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16130e;
    --surface: #1e1a14;
    --surface-2: #262119;
    --ink: #ece6da;
    --ink-soft: #cdc5b5;
    --muted: #9d9483;
    --faint: #6f6759;
    --line: #322c22;
    --line-strong: #3f382c;
    --accent: #9fb2d8;
    --accent-soft: #262c39;
    --accent-ink: #b9c7e6;
    --danger: #d98a80;
    --danger-soft: #33221f;
    --focus: #7f93bd;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 34px rgba(0,0,0,.45);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
    --chip-l: 22%;
    --chip-border-l: 32%;
    --chip-text-l: 78%;
    --dot-l: 62%;
  }
}

* { box-sizing: border-box; }
/* The [hidden] attribute must always win over component display rules below. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---------- scrollbars ---------- */
.results, .detail, .sheet-body, .taglist { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

/* =========================================================================
   Top bar
   ========================================================================= */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--ink);
  white-space: nowrap;
}
.brand-mark {
  font-family: var(--font-serif);
  font-size: 24px;
  color: var(--accent);
  line-height: 1;
}
.brand-text { font-weight: 600; letter-spacing: .2px; font-size: 16px; }

.search-wrap {
  flex: 1;
  max-width: 560px;
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap .search-icon {
  position: absolute; left: 12px; width: 17px; height: 17px;
  fill: none; stroke: var(--faint); stroke-width: 2; pointer-events: none;
}
#search {
  width: 100%;
  height: 40px;
  padding: 0 34px 0 36px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  outline: none;
}
#search:focus { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 24%, transparent); }
#search::-webkit-search-cancel-button { display: none; }
.clear-search {
  position: absolute; right: 8px;
  border: none; background: transparent; color: var(--muted);
  font-size: 20px; line-height: 1; width: 26px; height: 26px; border-radius: 50%;
}
.clear-search:hover { background: var(--surface-2); }

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* =========================================================================
   Buttons & controls
   ========================================================================= */
.primary-btn {
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14px; font-weight: 600;
  white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .primary-btn { color: #14110c; } }
.primary-btn:hover { filter: brightness(1.06); }
.primary-btn:disabled { opacity: .55; cursor: default; }

.text-btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-soft);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px; font-weight: 500;
}
.text-btn:hover { background: var(--surface-2); }

.link-btn { border: none; background: none; color: var(--accent); font-size: 13px; font-weight: 600; padding: 2px 4px; }
.link-btn:hover { text-decoration: underline; }

.danger-btn {
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--danger); padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 500;
}
.danger-btn:hover { background: var(--danger-soft); border-color: var(--danger); }

.icon-btn {
  border: 1px solid transparent; background: transparent; color: var(--ink-soft);
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.control {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}
textarea.control { height: auto; padding: 10px 12px; line-height: 1.55; resize: vertical; font-family: var(--font-serif); font-size: 15.5px; }
.control:focus { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.control-sm { height: 34px; font-size: 13.5px; padding: 0 8px; width: auto; }
select.control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%237c7566' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px; }

/* =========================================================================
   Layout
   ========================================================================= */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top));
}
.sidebar, .results, .detail { min-height: 0; }
.results { overflow-y: auto; }
.detail { overflow-y: auto; }
.sidebar { overflow-y: auto; }

/* ---------- Chips (tags) — deterministic muted hue via --h ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; line-height: 1;
  padding: 5px 9px; border-radius: 999px;
  background: hsl(var(--h) 34% var(--chip-l));
  color: hsl(var(--h) 45% var(--chip-text-l));
  border: 1px solid hsl(var(--h) 30% var(--chip-border-l));
  white-space: nowrap;
}
.chip-btn { cursor: pointer; }
.chip-btn:hover { filter: brightness(.97) saturate(1.1); }
.chip-lg { font-size: 13px; padding: 7px 12px; }
.chip-count { opacity: .7; font-weight: 700; }
.chip-removable { padding-right: 5px; }
.chip-x { border: none; background: transparent; color: inherit; font-size: 12px; cursor: pointer; padding: 2px 3px; opacity: .7; border-radius: 50%; }
.chip-x:hover { opacity: 1; }

/* =========================================================================
   Sidebar (filters + tags)
   ========================================================================= */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 16px 14px 24px;
  display: flex; flex-direction: column; gap: 18px;
}
.viewnav { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.viewnav-btn {
  flex: 1; border: none; background: transparent; color: var(--muted);
  padding: 8px; border-radius: 7px; font-size: 13.5px; font-weight: 600;
}
.viewnav-btn.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.filters { display: flex; flex-direction: column; gap: 14px; }
.filter-group { display: flex; flex-direction: column; gap: 6px; }
.filter-label { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.date-range { display: flex; align-items: center; gap: 6px; }
.date-range .control { padding: 0 8px; font-size: 13px; }
.date-sep { color: var(--faint); }
.clear-filters { align-self: flex-start; border: none; background: none; color: var(--danger); font-size: 13px; font-weight: 600; padding: 2px 0; }
.clear-filters:hover { text-decoration: underline; }

.tagpanel { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1; }
.tagpanel-head { display: flex; align-items: baseline; justify-content: space-between; }
.tagpanel-head h2 { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.tag-search { height: 34px; font-size: 13.5px; }
.taglist { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.tagitem {
  width: 100%; display: flex; align-items: center; gap: 9px;
  border: 1px solid transparent; background: transparent;
  padding: 7px 9px; border-radius: 8px; text-align: left; color: var(--ink-soft); font-size: 14px;
}
.tagitem:hover { background: var(--surface-2); }
.tagitem.active { background: hsl(var(--h) 34% var(--chip-l)); border-color: hsl(var(--h) 30% var(--chip-border-l)); color: hsl(var(--h) 45% var(--chip-text-l)); font-weight: 600; }
.tagdot { width: 9px; height: 9px; border-radius: 50%; background: hsl(var(--h) 50% var(--dot-l)); flex: none; }
.tagitem-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tagitem-count { font-size: 12px; color: var(--faint); font-weight: 600; font-variant-numeric: tabular-nums; }
.taglist-empty { color: var(--faint); font-size: 13px; padding: 8px 9px; }

/* =========================================================================
   Results list
   ========================================================================= */
.results { background: var(--paper); }
.results-head {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px 10px;
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(6px);
}
.results-count { font-size: 14px; color: var(--muted); }
.results-count strong { color: var(--ink); font-weight: 700; }
.sort-wrap { display: flex; align-items: center; gap: 6px; }
.sort-label { font-size: 12px; color: var(--faint); }

.active-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 20px 8px; }
.afilter {
  border: 1px solid hsl(var(--h,220) 30% var(--chip-border-l)); border-radius: 999px;
  background: hsl(var(--h,220) 34% var(--chip-l)); color: hsl(var(--h,220) 45% var(--chip-text-l));
  font-size: 12px; font-weight: 600; padding: 5px 10px;
}
.afilter:hover { filter: brightness(.97); }

.case-list { list-style: none; margin: 0; padding: 4px 14px 40px; display: flex; flex-direction: column; gap: 8px; }
.case-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s, transform .04s;
}
.case-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.case-card:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.case-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.case-name {
  font-family: var(--font-serif); font-size: 17px; font-weight: 600; line-height: 1.3;
  color: var(--ink); letter-spacing: .1px;
}
.case-citation { font-size: 13px; color: var(--accent-ink); margin-top: 3px; font-variant-numeric: tabular-nums; }
.case-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.case-why { font-family: var(--font-serif); font-style: italic; font-size: 14px; color: var(--ink-soft); margin-top: 8px; line-height: 1.45; }
.case-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }

.empty { text-align: center; padding: 60px 24px; }
.empty-title { font-family: var(--font-serif); font-size: 18px; color: var(--ink); margin: 0 0 6px; }
.empty-sub { color: var(--muted); font-size: 14px; margin: 0 0 18px; }

/* =========================================================================
   Detail pane
   ========================================================================= */
.detail { background: var(--surface); border-left: 1px solid var(--line); }
.detail[data-empty="true"] { display: flex; align-items: center; justify-content: center; }
.detail-inner { max-width: 640px; margin: 0 auto; padding: 20px 30px 60px; width: 100%; }
.detail-topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; min-height: 40px; }
.detail-topbar .text-btn { margin-left: auto; }

.detail-header { border-bottom: 1px solid var(--line); padding-bottom: 18px; margin-bottom: 4px; }
.detail-name { font-family: var(--font-serif); font-size: 28px; line-height: 1.2; color: var(--ink); letter-spacing: .2px; }
.detail-citation { font-size: 15px; color: var(--accent-ink); margin-top: 8px; font-weight: 500; font-variant-numeric: tabular-nums; }
.detail-court { font-size: 14px; color: var(--ink-soft); margin-top: 6px; }
.detail-date { font-size: 13px; color: var(--muted); margin-top: 3px; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }

.detail-why {
  font-family: var(--font-serif); font-style: italic; font-size: 16px; line-height: 1.5;
  color: var(--ink-soft);
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding: 14px 16px; border-radius: 0 8px 8px 0; margin: 20px 0;
}
.detail-why-mark { display: block; font-family: var(--font-sans); font-style: normal; font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin-bottom: 5px; }

.detail-field { margin: 20px 0; }
.detail-field-label { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); margin-bottom: 6px; }
.detail-field-body { font-family: var(--font-serif); font-size: 16px; line-height: 1.62; color: var(--ink); }
.detail-field-body a { word-break: break-all; }
.detail-foot { margin-top: 30px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--faint); }

.welcome { text-align: center; color: var(--muted); padding: 40px; }
.welcome-mark { font-family: var(--font-serif); font-size: 52px; color: var(--line-strong); }
.welcome h2 { font-family: var(--font-serif); font-size: 22px; color: var(--ink-soft); margin: 8px 0 6px; }
.welcome p { font-size: 14px; margin: 0 0 20px; }

/* ---------- Dashboard ---------- */
.dashboard { max-width: 640px; }
.dash-title { font-family: var(--font-serif); font-size: 26px; color: var(--ink); margin-bottom: 18px; }
.dash-stats { display: flex; gap: 12px; margin-bottom: 28px; }
.stat { flex: 1; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-num { font-family: var(--font-serif); font-size: 30px; font-weight: 600; color: var(--accent-ink); line-height: 1; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 6px; letter-spacing: .03em; }
.dash-section { margin-bottom: 28px; }
.dash-section h2 { font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); margin-bottom: 12px; }
.dash-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.dash-recent { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.dash-recent-item { width: 100%; text-align: left; border: none; background: transparent; padding: 10px 12px; border-radius: 8px; display: flex; flex-direction: column; gap: 3px; }
.dash-recent-item:hover { background: var(--paper); }
.dash-recent-name { font-family: var(--font-serif); font-size: 15.5px; color: var(--ink); }
.dash-recent-meta { font-size: 12.5px; color: var(--muted); }

/* =========================================================================
   Sheets (editor / settings / tag manager)
   ========================================================================= */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(30,24,14,.42);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
@media (prefers-color-scheme: dark) { .sheet-backdrop { background: rgba(0,0,0,.6); } }
.sheet {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  width: 100%; max-width: 640px;
  max-height: min(88vh, 900px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-family: var(--font-serif); font-size: 19px; }
.sheet-head-actions { display: flex; gap: 8px; align-items: center; }
.sheet-body { padding: 18px 20px; overflow-y: auto; }
.sheet-foot { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface); }
.sheet-foot-spacer { flex: 1; }

.editor-hint { font-size: 13px; color: var(--muted); margin: 0 0 16px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.field label .muted { font-weight: 400; }
.field .req { color: var(--danger); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.tag-input {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 7px 8px; background: var(--surface); min-height: 42px;
}
.tag-input:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.tag-chips { display: contents; }
.tag-input-field { border: none; outline: none; background: transparent; color: var(--ink); font-size: 14px; flex: 1; min-width: 140px; height: 26px; font-family: inherit; }
.tag-suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag-suggest-item {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink-soft);
  padding: 5px 10px; border-radius: 999px;
}
.tag-suggest-item:hover { border-color: var(--focus); }

.more-fields { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.more-fields > summary { cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--accent); padding: 6px 0; list-style: none; }
.more-fields > summary::-webkit-details-marker { display: none; }
.more-fields > summary::before { content: "＋ "; }
.more-fields[open] > summary::before { content: "− "; }

/* PDF import */
.import-pdf-btn {
  width: 100%; display: flex; align-items: center; gap: 10px;
  border: 1px dashed var(--line-strong); background: var(--paper);
  color: var(--ink-soft); padding: 12px 14px; border-radius: var(--radius);
  margin-bottom: 14px; text-align: left; font-family: inherit;
}
.import-pdf-btn:hover { border-color: var(--focus); background: var(--surface-2); }
.import-pdf-btn svg { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--accent); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.import-pdf-btn > span:nth-of-type(1) { font-weight: 600; font-size: 14.5px; }
.import-pdf-sub { margin-left: auto; font-size: 12px; color: var(--faint); }
.import-banner {
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius-sm); padding: 11px 13px; margin-bottom: 14px;
  font-size: 13px; line-height: 1.5; color: var(--ink-soft);
}
.import-banner strong { color: var(--ink); }
.import-banner.warn { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.import-verify { color: var(--muted); font-style: italic; }

.pdf-text-panel { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 10px; }
.pdf-text-panel > summary { cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--accent); padding: 6px 0; list-style: none; }
.pdf-text-panel > summary::-webkit-details-marker { display: none; }
.pdf-text-panel > summary::before { content: "＋ "; }
.pdf-text-panel[open] > summary::before { content: "− "; }
.pdf-text {
  max-height: 320px; overflow: auto; margin: 8px 0 0;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px; font-family: var(--font-serif); font-size: 13px; line-height: 1.6;
  color: var(--ink-soft); white-space: pre-wrap; word-break: break-word;
}
.pdf-holding-suggest { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; margin: 8px 0; }
.holding-suggest-label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); margin-bottom: 6px; }
.holding-suggest-text { margin: 0 0 10px; font-family: var(--font-serif); font-style: italic; font-size: 14px; line-height: 1.5; color: var(--ink); border-left: 3px solid var(--line-strong); padding-left: 10px; }

/* Settings & tag manager */
.settings-section { margin-bottom: 22px; }
.settings-section h3 { font-size: 14px; margin-bottom: 6px; }
.settings-section .muted { font-size: 13px; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.settings-code { display: flex; gap: 8px; margin-top: 10px; }
.settings-code .control { flex: 1; }
.tagmgr-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.tagmgr-item { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.tagmgr-item .tagdot { background: hsl(var(--h) 50% var(--dot-l)); }
.tagmgr-name { flex: 1; height: 36px; }
.tagmgr-count { font-size: 12px; color: var(--faint); font-weight: 600; min-width: 20px; text-align: right; }

/* Confirm dialog — sits above the editor/tag-manager sheets */
.confirm-backdrop { z-index: 150; }
.sheet.confirm { max-width: 380px; border-radius: 16px; }
.confirm-body { padding: 24px 24px 8px; }
.confirm-message { font-family: var(--font-serif); font-size: 16px; line-height: 1.5; color: var(--ink); margin: 0; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 20px 20px; }
.confirm-ok { background: var(--danger); color: #fff; border-color: transparent; }
.confirm-ok:hover { filter: brightness(1.06); background: var(--danger); }
@media (max-width: 720px) {
  .confirm-backdrop { align-items: center; padding: 24px; }
  .sheet.confirm { border-radius: 16px; }
}

/* =========================================================================
   Toast
   ========================================================================= */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 200; background: var(--ink); color: var(--paper);
  padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow); max-width: 90vw;
}
.toast-warn { background: var(--danger); color: #fff; }

/* =========================================================================
   Mobile tab bar + slide-over mechanics
   ========================================================================= */
.tabbar { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(30,24,14,.4); z-index: 45; }
.only-narrow { display: none; }
.only-wide { display: inline-flex; }

/* ---------- WIDE (desktop): 3 columns, everything persistent ---------- */
@media (min-width: 1080px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(340px, 1fr) minmax(380px, 1.15fr); }
  .sidebar { position: static !important; transform: none !important; }
  .detail { position: static !important; transform: none !important; }
}

/* ---------- NARROW (tablet + phone): slide-overs ---------- */
@media (max-width: 1079px) {
  .only-wide { display: none; }
  .only-narrow { display: inline-flex; }

  .layout { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
    width: min(340px, 86vw);
    transform: translateX(-102%);
    transition: transform .24s ease;
    box-shadow: var(--shadow);
    padding-top: calc(16px + env(safe-area-inset-top));
  }
  body.sidebar-open .sidebar { transform: translateX(0); }

  .detail {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 55;
    width: min(560px, 100vw);
    transform: translateX(102%);
    transition: transform .24s ease;
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow);
  }
  body.detail-open .detail { transform: translateX(0); }
  .detail[data-empty="true"] { display: none; }

  .detail-inner { padding-top: calc(16px + env(safe-area-inset-top)); }

  /* Bottom tab bar for primary actions — on iPad and phone alike, so adding an
     entry / searching / browsing tags is always one thumb-tap away. */
  .case-list { padding-bottom: calc(94px + env(safe-area-inset-bottom)); }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tab {
    border: none; background: transparent; color: var(--muted);
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 10px 0 8px; font-size: 11px; font-weight: 600;
    min-height: 56px;
  }
  .tab:active { color: var(--ink); }
  .tab svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .tab-add { color: #fff; }
  .tab-add svg { background: var(--accent); border-radius: 50%; padding: 7px; box-sizing: content-box; width: 22px; height: 22px; margin-top: -16px; box-shadow: var(--shadow-sm); }
}
@media (max-width: 1079px) and (prefers-color-scheme: dark) {
  .tab-add svg { color: #14110c; }
}

/* ---------- PHONE: single column + bottom tab bar ---------- */
@media (max-width: 720px) {
  :root { --topbar-h: 56px; }
  .brand-text { display: none; }
  .topbar { gap: 8px; padding: 0 12px; padding-top: env(safe-area-inset-top); }
  .search-wrap { max-width: none; }

  .case-list { padding-left: 12px; padding-right: 12px; }
  .results-head { padding: 12px 16px 8px; }
  .active-filters { padding: 0 16px 8px; }
  .detail { width: 100vw; }
  .detail-inner { padding: 16px 20px calc(40px + env(safe-area-inset-bottom)); }
  .detail-name { font-size: 24px; }

  .field-row { grid-template-columns: 1fr; }
  .sheet-backdrop { padding: 0; align-items: flex-end; }
  .sheet { max-width: none; max-height: 94vh; border-radius: 18px 18px 0 0; }
  .sheet-body { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* Prevent background scroll when a modal is open on small screens */
body.modal-open { overflow: hidden; }

/* Offline banner hint on the sync indicator */
body.is-offline .brand-mark { color: var(--danger); }
