/* Coffre — design tokens and layout.
   All styling lives here: the Content-Security-Policy forbids inline styles, which also
   keeps an injected script from restyling the UI into something that looks trustworthy. */

:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --surface-3: #f0f0f4;
  --border: #e2e2e9;
  --border-strong: #cdcdd8;
  --text: #17171c;
  --text-2: #5c5c6b;
  --text-3: #8b8b9a;
  --accent: #6b4dff;
  --accent-soft: #efeaff;
  --personal: #7c5cff;
  --company: #0e9f6e;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --warn: #d97706;
  --warn-soft: #fdf3e3;
  --ok: #067647;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 40, 0.06), 0 8px 24px rgba(20, 20, 40, 0.07);
  --shadow-lg: 0 12px 48px rgba(20, 20, 40, 0.18);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d11;
    --surface: #16161c;
    --surface-2: #1b1b22;
    --surface-3: #23232c;
    --border: #2a2a34;
    --border-strong: #3a3a47;
    --text: #f0f0f4;
    --text-2: #a1a1b0;
    --text-3: #75758a;
    --accent: #8b6dff;
    --accent-soft: #241d45;
    --personal: #9d84ff;
    --company: #34d399;
    --danger: #f97066;
    --danger-soft: #3a1b1a;
    --warn: #fdb022;
    --warn-soft: #3a2a10;
    --ok: #47cd89;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute is a UA rule (`display: none`), and any author rule that sets
   `display` beats it — `.field { display: grid }` was enough to keep hidden elements on
   screen. This restores the attribute's meaning for every component. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ── boot ─────────────────────────────────────────────────────────────────── */

.boot {
  height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  color: var(--text-3);
}

.boot-mark {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── auth screens ─────────────────────────────────────────────────────────── */

.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  padding: 32px 20px;
}

@media (min-width: 1000px) {
  .auth { grid-template-columns: 1.05fr 1fr; gap: 48px; padding: 0 8vw; }
}

.auth-pitch { max-width: 460px; display: none; }
@media (min-width: 1000px) { .auth-pitch { display: block; } }

.auth-pitch h1 { font-size: 40px; line-height: 1.1; margin: 0 0 12px; letter-spacing: -0.02em; }
.auth-pitch .lede { font-size: 17px; color: var(--text-2); margin: 0 0 28px; }
.auth-pitch ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.auth-pitch li { display: grid; grid-template-columns: 26px 1fr; gap: 10px; color: var(--text-2); }
.auth-pitch li b { color: var(--text); display: block; font-weight: 600; }

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-card h2 { margin: 0 0 4px; font-size: 21px; letter-spacing: -0.01em; }
.auth-card .sub { color: var(--text-2); margin: 0 0 22px; }

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(140deg, var(--accent), #b98bff);
  display: grid; place-content: center; color: #fff; font-size: 15px;
}
.brand-name { font-weight: 650; letter-spacing: -0.01em; font-size: 16px; }

/* ── forms ────────────────────────────────────────────────────────────────── */

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { resize: vertical; min-height: 72px; font-family: var(--mono); font-size: 13px; }
input.mono, .mono { font-family: var(--mono); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 550;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.block { width: 100%; }
.btn.small { padding: 5px 9px; font-size: 12.5px; }
.btn.ghost { background: none; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-3); }

.linkish {
  background: none; border: none; padding: 0; color: var(--accent);
  cursor: pointer; font-weight: 550;
}
.linkish:hover { text-decoration: underline; }

.form-error {
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
  padding: 9px 11px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 13px;
}

.notice {
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  padding: 11px 13px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  margin-bottom: 16px;
}
.notice.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }

/* strength meter */
.meter { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.meter > i { display: block; height: 100%; width: 0; transition: width 0.25s, background 0.25s; }
.meter-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-3); margin-top: 5px; }

/* ── app shell ────────────────────────────────────────────────────────────── */

.shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 252px minmax(280px, 380px) 1fr;
  background: var(--bg);
}

/* Hidden on the three-column layout, where the tree is always visible beside the detail. */
.back-to-tree { display: none; font-size: 18px; line-height: 1; padding: 2px 10px; }
.mobile-bar { display: none; }
.drawer-scrim { display: none; }

/* Responsive and touch rules live at the END of this file — see the closing section.
   Media queries add no specificity, so they must come after the component rules they
   override or the desktop values silently win. */

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head { padding: 16px 14px 10px; }
.sidebar-scroll { overflow-y: auto; flex: 1; padding: 0 8px 8px; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 8px; }

.nav-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-3); font-weight: 700;
  padding: 14px 8px 6px;
  display: flex; align-items: center; justify-content: space-between;
}

.nav-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  padding: 7px 9px;
  border-radius: 8px;
  border: none; background: none; cursor: pointer;
  text-align: left;
  color: var(--text-2);
}
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.nav-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--company); flex: none; }
.nav-item .dot.personal { background: var(--personal); }
.nav-item .count { margin-left: auto; color: var(--text-3); font-size: 12px; }
.nav-item .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item.locked .label { opacity: 0.55; }

/* ── tree navigator ───────────────────────────────────────────────────────── */

/* Denser than the card list: a tree is scanned vertically, so rows earn their height. */
.list-scroll.tree { padding: 4px 6px 12px; }
.list-scroll.tree.drop-root {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  outline: 2px dashed color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: -4px; border-radius: var(--radius);
}

.tree-row {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 6px 3px 8px;
  border-radius: 6px;
  cursor: default;
  user-select: none;
  min-height: 26px;
  position: relative;
}
.tree-row:hover { background: var(--surface-3); }
.tree-row.selected { background: var(--accent-soft); }
.tree-row.selected .tree-name { font-weight: 600; }
.tree-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tree-row[draggable="true"]:active { opacity: 0.55; }

/* The drop target is outlined rather than filled, so the row underneath stays readable. */
.tree-row.drop-into {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.tree-row .chev {
  width: 14px; flex: none; text-align: center;
  color: var(--text-2); font-size: 11px; line-height: 1;
  transition: transform 0.12s ease;
  cursor: pointer;
}
.tree-row .chev.open { transform: rotate(90deg); }
/* "leaf", not "empty" — the generic .empty utility carries 40px of padding. */
.tree-row .chev.leaf { cursor: default; }
.tree-row .chev:hover:not(.leaf) { color: var(--text); }

.tree-row .tree-icon { flex: none; font-size: 14px; line-height: 1; width: 18px; text-align: center; }
.tree-row .tree-name {
  flex: none; max-width: 60%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tree-row.folder .tree-name { font-weight: 550; }
.tree-row .tree-sub {
  color: var(--text-3); font-size: 12px; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tree-row .tree-count {
  margin-left: auto; color: var(--text-3); font-size: 11px;
  background: var(--surface-3); border-radius: 999px; padding: 0 6px;
}

/* Row actions stay hidden until the row is touched, so the tree reads cleanly. */
.tree-row .tree-more {
  margin-left: auto; opacity: 0; flex: none;
  background: none; border: none; cursor: pointer;
  color: var(--text-3); padding: 0 4px; border-radius: 5px;
}
.tree-row:hover .tree-more,
.tree-row:focus-within .tree-more { opacity: 1; }
.tree-row .tree-more:hover { background: var(--surface); color: var(--text); }
.tree-row .tree-count + .tree-more { margin-left: 4px; }

.list-pane {
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}

.list-head { padding: 14px 14px 10px; display: grid; gap: 10px; }
.list-title { display: flex; align-items: center; gap: 8px; }
.list-title h2 { margin: 0; font-size: 16px; letter-spacing: -0.01em; }
.list-actions { margin-left: auto; display: flex; gap: 6px; }

.search-wrap { position: relative; }
.search-wrap input { padding-left: 30px; }
.search-wrap::before {
  content: "⌕"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); font-size: 15px;
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 12px; cursor: pointer; color: var(--text-2);
}
.chip.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); color: var(--text); font-weight: 600; }

.list-scroll { overflow-y: auto; flex: 1; padding: 0 8px 12px; }

.item-row {
  display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center;
  width: 100%; padding: 9px; border: none; background: none; cursor: pointer;
  border-radius: 9px; text-align: left; color: inherit;
}
.item-row:hover { background: var(--surface-3); }
.item-row.active { background: var(--accent-soft); }
.item-row .icon {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-content: center;
  background: var(--surface-3); font-size: 15px;
}
.item-row .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row .sub { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row .badges { display: flex; gap: 4px; }

.badge {
  font-size: 10.5px; padding: 2px 6px; border-radius: 999px; font-weight: 700;
  background: var(--surface-3); color: var(--text-2);
}
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.personal { background: color-mix(in srgb, var(--personal) 16%, transparent); color: var(--personal); }
.badge.company { background: color-mix(in srgb, var(--company) 16%, transparent); color: var(--company); }

.empty {
  padding: 40px 24px; text-align: center; color: var(--text-3);
  display: grid; gap: 10px; justify-items: center;
}
.empty .big { font-size: 30px; }

/* ── detail pane ──────────────────────────────────────────────────────────── */

.detail-pane { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }

.detail-head {
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 14px;
  position: sticky; top: 0; background: var(--bg); z-index: 2;
}
.detail-head .icon {
  width: 42px; height: 42px; border-radius: 11px; display: grid; place-content: center;
  background: var(--surface-3); font-size: 21px; flex: none;
}
.detail-head h1 { margin: 0; font-size: 19px; letter-spacing: -0.01em; }
.detail-head .meta { color: var(--text-3); font-size: 12.5px; margin-top: 3px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.detail-head .spacer { flex: 1; }

.detail-body { padding: 18px 24px 60px; display: grid; gap: 18px; max-width: 780px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card > header {
  padding: 11px 14px; border-bottom: 1px solid var(--border);
  font-weight: 650; font-size: 13px; display: flex; align-items: center; gap: 8px;
}
.card > header .spacer { flex: 1; }
.card-body { padding: 14px; display: grid; gap: 12px; }

.kv { display: grid; grid-template-columns: 150px 1fr auto; gap: 10px; align-items: center; }
.kv > .k { color: var(--text-2); font-size: 13px; }
.kv > .v { font-family: var(--mono); font-size: 13px; word-break: break-all; }
.kv > .v.masked { letter-spacing: 2px; color: var(--text-3); }
.kv .row-actions { display: flex; gap: 4px; }

/* Narrow: the label takes its own line, but the value keeps its copy/reveal buttons
   beside it. Dropping the actions to a third line turns every field into 90px of
   scrolling. */
@media (max-width: 720px) {
  .kv { grid-template-columns: 1fr auto; }
  .kv > .k { grid-column: 1 / -1; font-weight: 600; }
}

.totp-code {
  font-family: var(--mono); font-size: 22px; letter-spacing: 3px; font-weight: 600;
}
.totp-ring {
  width: 26px; height: 26px; border-radius: 50%;
  background: conic-gradient(var(--accent) var(--pct, 100%), var(--surface-3) 0);
  flex: none;
}

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 24px; }
.tab {
  padding: 9px 12px; border: none; background: none; cursor: pointer;
  color: var(--text-2); border-bottom: 2px solid transparent; font-weight: 550;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ── attachments ──────────────────────────────────────────────────────────── */

.attachments { display: grid; gap: 6px; }

.attachment-row {
  display: grid; grid-template-columns: 24px 1fr auto; gap: 10px; align-items: center;
  padding: 7px 9px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2);
}
.attachment-row .name { font-weight: 550; word-break: break-all; }
.attachment-row .sub { font-size: 12px; color: var(--text-3); }

.dropzone {
  display: grid; gap: 3px; justify-items: center; text-align: center;
  padding: 16px; margin-top: 4px;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  color: var(--text-2); cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.dropzone .file-input { display: none; }

/* ── tables ───────────────────────────────────────────────────────────────── */

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-3); padding: 8px 12px; border-bottom: 1px solid var(--border); font-weight: 700;
}
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data td.actions { text-align: right; white-space: nowrap; }

.fp { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); }

/* ── modal ────────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 10, 20, 0.55);
  display: grid; place-items: center; padding: 24px; z-index: 100;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: min(660px, 100%); max-height: 88vh; display: flex; flex-direction: column;
}
.modal.wide { width: min(920px, 100%); }
.modal > header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.modal > header h3 { margin: 0; font-size: 16px; }
.modal > header .spacer { flex: 1; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal > footer {
  padding: 13px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}
.modal > footer .spacer { flex: 1; }

/* ── toasts ───────────────────────────────────────────────────────────────── */

.toast-root {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: grid; gap: 8px; z-index: 200; pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 9px 14px; border-radius: 999px; box-shadow: var(--shadow-lg);
  font-size: 13px; font-weight: 550;
  animation: rise 0.2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ── misc ─────────────────────────────────────────────────────────────────── */

.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.stat .n { font-size: 24px; font-weight: 680; letter-spacing: -0.02em; }
.stat .l { font-size: 12px; color: var(--text-3); }
.stat.danger .n { color: var(--danger); }
.stat.warn .n { color: var(--warn); }
.stat.ok .n { color: var(--ok); }

pre.blob {
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px; overflow-x: auto;
  font-family: var(--mono); font-size: 11.5px; color: var(--text-2);
  white-space: pre-wrap; word-break: break-all; margin: 0; max-height: 200px;
}

/* A white plate behind the symbol: in dark mode the page is nearly black, and a scanner
   pointed at an inverted code will not read it. */
.qr-holder {
  display: flex; justify-content: center;
  padding: 14px; margin-bottom: 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.qr-holder svg { display: block; max-width: 100%; height: auto; image-rendering: pixelated; }

.recovery-kit {
  font-family: var(--mono); font-size: 15px; letter-spacing: 1px; line-height: 2;
  background: var(--surface-3); border: 2px dashed var(--border-strong);
  border-radius: var(--radius); padding: 16px; text-align: center; word-break: break-all;
}

.share-list { display: grid; gap: 8px; }
.share-box {
  font-family: var(--mono); font-size: 11px; background: var(--surface-3);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 9px;
  word-break: break-all;
}

.audit-row td.action { font-family: var(--mono); font-size: 12px; }
.hash { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); }

.lock-timer { font-size: 11.5px; color: var(--text-3); font-family: var(--mono); }

.severity-3 { color: var(--danger); font-weight: 600; }
.severity-2 { color: var(--warn); }
.severity-1 { color: var(--text-3); }

/* ════════════════════════════════════════════════════════════════════════════
   RESPONSIVE — must stay last in the file.

   Media queries carry no extra specificity, so a `@media` rule placed above the
   component it overrides loses on source order alone. Every layout and touch
   override therefore lives here, after everything it modifies.
   ════════════════════════════════════════════════════════════════════════════ */

/* ── tablet: two columns; the detail pane takes over when an item is open ─── */

/* Bounded at both ends on purpose. An open-ended `max-width: 1080px` also matches phone
   widths, and `.shell.detail-open` (two classes) outranks the phone block's `.shell`, so
   the two-column grid would win on a 375px screen and leave the layout collapsed. */
@media (min-width: 721px) and (max-width: 1080px) {
  .shell { grid-template-columns: 220px 1fr; }
  .shell .detail-pane { display: none; }
  .shell.detail-open { grid-template-columns: 0 1fr; }
  .shell.detail-open .sidebar,
  .shell.detail-open .list-pane { display: none; }
  .shell.detail-open .detail-pane { display: flex; }
  .shell.detail-open .back-to-tree { display: inline-flex; }
}

/* ── phone: one column, coffers in a slide-over drawer ────────────────────── */

@media (max-width: 720px) {
  .shell,
  .shell.detail-open,
  .shell.drawer-open {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .back-to-tree { display: inline-flex; }

  .mobile-bar {
    display: flex; align-items: center; gap: 8px;
    grid-row: 1; grid-column: 1;
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 30;
  }
  .mobile-title {
    flex: 1; font-weight: 650; font-size: 15px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }

  /* The sidebar leaves the grid and slides in over everything else. */
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(84vw, 320px); z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-lg);
    padding-top: env(safe-area-inset-top);
  }
  .shell.drawer-open .sidebar { transform: none; }

  .drawer-scrim {
    display: block; position: fixed; inset: 0; z-index: 40;
    background: rgba(10, 10, 20, 0.45);
    opacity: 0; pointer-events: none;
    transition: opacity 0.22s ease;
  }
  .shell.drawer-open .drawer-scrim { opacity: 1; pointer-events: auto; }

  .list-pane,
  .detail-pane { grid-row: 2; grid-column: 1; }
  .list-pane { border-right: none; }
  .shell.detail-open .list-pane { display: none; }
  .shell.detail-open .detail-pane { display: flex; }
  /* The drawer is fixed, so the detail-open rule above must not hide it. */
  .shell.detail-open .sidebar { display: flex; }

  .detail-head { padding: 10px 12px 8px; gap: 8px; }
  .detail-head .icon { width: 32px; height: 32px; font-size: 16px; border-radius: 9px; }
  .detail-head h1 { font-size: 17px; }
  .detail-head .meta { font-size: 11.5px; gap: 6px; }
  .detail-body { padding: 12px 12px 80px; }
  .card-body { padding: 12px; }
  .list-head { padding: 10px 12px 8px; }
  .kv { gap: 4px 8px; }

  /* 16px stops iOS Safari zooming the viewport when a field takes focus. */
  input[type="text"], input[type="email"], input[type="password"], input[type="number"],
  input[type="date"], input[type="search"], select, textarea { font-size: 16px; }

  /* Dialogs become full sheets: a centred box wastes a phone screen.
     `min-height: 0` matters — a grid item defaults to min-height:auto, so a long
     dialog would grow past the viewport instead of scrolling its body. */
  .modal-backdrop { padding: 0; align-items: stretch; justify-items: stretch; }
  .modal, .modal.wide {
    width: 100%; max-width: none;
    height: 100%; max-height: 100%; min-height: 0;
    border-radius: 0; border: none;
  }
  .modal > footer { padding-bottom: calc(13px + env(safe-area-inset-bottom)); }

  .auth { padding: 20px 16px; }
  .auth-card { padding: 20px; }

  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); }
  table.data { font-size: 12.5px; }
  table.data th, table.data td { padding: 7px 8px; }

  .toast-root { bottom: calc(14px + env(safe-area-inset-bottom)); width: max-content; max-width: 92vw; }
}

/* ── touch: bigger targets, no hover-only affordances ─────────────────────── */

@media (pointer: coarse) {
  /* 27px rows are comfortable with a mouse and unusable with a thumb. */
  .tree-row { min-height: 40px; padding-top: 7px; padding-bottom: 7px; }
  .tree-row .chev { width: 26px; font-size: 13px; }
  .nav-item { padding: 10px 9px; }
  .btn.small { padding: 8px 12px; }
  .chip { padding: 6px 12px; }
  .item-row { padding: 11px 9px; }
  .attachment-row { padding: 11px 10px; }

  /* Revealed by hover on a desktop. There is no hover on touch, so a hidden
     control is simply an absent one. */
  .tree-row .tree-more { opacity: 1; }
}
