/* Image Library — light-table palette: cool grey surfaces so photos read true, one accent for actions,
   and each company/folder carries its own color. */

:root {
  --accent: #3346d3;
  --accent-ink: #ffffff;
  --accent-text: var(--accent);
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --surface: #e9ecef;
  --panel: #f7f8f9;
  --raised: #ffffff;
  --stage: #dde1e6;
  --ink: #18202b;
  --ink-2: #566070;
  --ink-3: #848d9a;
  --line: #d2d7de;
  --hover: color-mix(in srgb, var(--ink) 6%, transparent);
  --hover-strong: color-mix(in srgb, var(--ink) 10%, transparent);
  --checker-a: #f3f4f6;
  --checker-b: #dfe2e7;
  --danger: #b42323;
  --ok: #18794e;
  --shadow: 0 24px 60px -16px rgb(15 22 35 / 0.35);
  --row-h: 210px;
  --gap: 10px;
  --top-h: 60px;
  --side-w: 264px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent-text: color-mix(in srgb, var(--accent) 60%, white);
    --accent-soft: color-mix(in srgb, var(--accent) 24%, transparent);
    --surface: #1c1e22; --panel: #24272c; --raised: #2b2f35; --stage: #202227;
    --ink: #e8eaed; --ink-2: #a3abb6; --ink-3: #7b8490; --line: #383c43;
    --checker-a: #34373d; --checker-b: #2a2d32;
    --danger: #f07a7a; --ok: #5fd39a;
    --shadow: 0 24px 60px -16px rgb(0 0 0 / 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --accent-text: color-mix(in srgb, var(--accent) 60%, white);
  --accent-soft: color-mix(in srgb, var(--accent) 24%, transparent);
  --surface: #1c1e22; --panel: #24272c; --raised: #2b2f35; --stage: #202227;
  --ink: #e8eaed; --ink-2: #a3abb6; --ink-3: #7b8490; --line: #383c43;
  --checker-a: #34373d; --checker-b: #2a2d32;
  --danger: #f07a7a; --ok: #5fd39a;
  --shadow: 0 24px 60px -16px rgb(0 0 0 / 0.6);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { margin: 0; font: 400 14px/1.45 var(--font); color: var(--ink); background: var(--surface); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); }
code { font-family: var(--mono); font-size: .92em; }
svg { display: block; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.only-narrow { display: none !important; }
.muted { color: var(--ink-2); }
.noscript { padding: 24px; text-align: center; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row.center { justify-content: center; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--raised); color: var(--ink);
  font-weight: 550; text-decoration: none; white-space: nowrap;
  transition: background-color .12s, border-color .12s, color .12s;
}
.btn:hover { border-color: color-mix(in srgb, var(--ink) 28%, var(--line)); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; gap: 6px; }
.btn-sm svg { width: 16px; height: 16px; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { background: color-mix(in srgb, var(--accent) 86%, black); border-color: color-mix(in srgb, var(--accent) 86%, black); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 86%, black); }
.btn-lg { height: 46px; width: 100%; font-size: 15px; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--hover); border-color: transparent; color: var(--ink); }
.btn-quiet-danger { border-color: transparent; background: transparent; color: var(--danger); }
.btn-quiet-danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: transparent; }
.icon-btn {
  width: 36px; height: 36px; flex: none; display: grid; place-items: center;
  border: 0; border-radius: 8px; background: transparent; color: var(--ink-2);
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn[disabled] { opacity: .35; cursor: default; background: transparent; }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.bordered { border: 1px solid var(--line); background: var(--raised); }
.icon-btn.danger:hover { color: var(--danger); }
.linklike { border: 0; background: none; padding: 0; color: var(--accent-text); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- brand ---------- */
.brand-mark { width: 22px; height: 22px; flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.brand-mark i { border-radius: 2px; background: var(--accent); }
.brand-mark i:nth-child(2) { opacity: .55; }
.brand-mark i:nth-child(3) { opacity: .3; }
.brand-mark i:nth-child(4) { opacity: .8; }
.brand-mark.big { width: 44px; height: 44px; gap: 4px; }
.brand-mark.big i { border-radius: 4px; animation: pulse 1.4s ease-in-out infinite; }
.brand-mark.big i:nth-child(2) { animation-delay: .15s; }
.brand-mark.big i:nth-child(3) { animation-delay: .45s; }
.brand-mark.big i:nth-child(4) { animation-delay: .3s; }
@keyframes pulse { 50% { transform: scale(.82); } }

/* ---------- full-screen states ---------- */
.center-screen { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 14px; padding: 24px 16px; }
.auth-card {
  width: min(420px, calc(100vw - 32px));
  padding: 28px 26px 24px; border: 1px solid var(--line); border-radius: 16px;
  background: var(--panel); box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 650; margin-bottom: 22px; }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; font-weight: 650; letter-spacing: -0.015em; }
.auth-lede { margin: 0 0 20px; color: var(--ink-2); }
.auth-msg { margin: 0 0 16px; padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); }
.auth-error { margin: -4px 0 12px; min-height: 1.2em; color: var(--danger); font-weight: 550; }
.auth-links { margin-top: 14px; text-align: center; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--top-h); display: flex; align-items: center; gap: 12px;
  padding: 0 14px 0 18px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; width: calc(var(--side-w) - 30px); min-width: 0; color: var(--ink); text-decoration: none; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.brand-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-title { margin: 0; flex: 1; min-width: 0; font-size: 16px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { position: relative; flex: 1; max-width: 560px; display: flex; align-items: center; }
.search-icon { position: absolute; left: 11px; color: var(--ink-3); pointer-events: none; }
.search input {
  width: 100%; height: 38px; padding: 0 40px 0 36px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--raised);
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search kbd { position: absolute; right: 9px; padding: 1px 6px; border: 1px solid var(--line); border-radius: 5px; font: 500 11px/1.4 var(--mono); color: var(--ink-3); pointer-events: none; }
.search input:not(:placeholder-shown) ~ kbd, .search input:focus ~ kbd { display: none; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
#uploadBtn { margin-right: 4px; }

/* ---------- layout + sidebar ---------- */
.layout { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }
.sidebar {
  position: sticky; top: var(--top-h); height: calc(100dvh - var(--top-h));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 10px 40px;
  background: var(--panel); border-right: 1px solid var(--line);
}
.nav-quick { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 1px; }
.nav-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px;
  color: var(--ink-2); text-decoration: none; font-weight: 550;
}
.nav-row svg { width: 17px; height: 17px; }
.nav-row:hover { background: var(--hover); color: var(--ink); }
.nav-row.active { background: var(--accent-soft); color: var(--accent-text); }
.nav-label { flex: 1; }
.nav-count, .tree-count { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink-3); }
.side-h-row { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 4px 10px; }
.side-h { margin: 0; font-size: 12px; font-weight: 600; color: var(--ink-3); }
.side-empty { margin: 4px 10px; color: var(--ink-3); }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree-row {
  display: flex; align-items: center; gap: 2px;
  padding-left: calc(var(--depth, 0) * 14px);
  border-radius: 8px;
}
.tree-row:hover { background: var(--hover); }
.tree-row.active { background: var(--accent-soft); }
.tree-row.active .tree-name { color: var(--accent-text); font-weight: 650; }
.tree-row.company { margin-top: 2px; }
.tree-row.company .tree-name { font-weight: 600; color: var(--ink); }
.twisty {
  width: 22px; height: 30px; flex: none; display: grid; place-items: center;
  border: 0; border-radius: 6px; background: transparent; color: var(--ink-3);
  transition: transform .15s;
}
.twisty[disabled] { cursor: default; }
.twisty.open svg { transform: rotate(90deg); }
.twisty svg { transition: transform .15s; }
.tree-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 5px 8px 5px 2px; color: var(--ink-2); text-decoration: none; }
.tree-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drop-over { outline: 2px dashed var(--accent) !important; outline-offset: -2px; background: var(--accent-soft) !important; }

/* avatars + color dots */
.avatar {
  --size: 40px;
  width: var(--size); height: var(--size); flex: none;
  display: grid; place-items: center;
  border-radius: calc(var(--size) * .28);
  background: var(--c, var(--accent)); color: #fff;
  font-weight: 700; font-size: calc(var(--size) * .38); letter-spacing: .01em;
}
.avatar.xs { --size: 20px; border-radius: 5px; font-size: 9.5px; }
.avatar.lg { --size: 52px; }
.sw-dot { width: 18px; height: 18px; flex: none; border-radius: 50%; background: var(--sw, var(--ink-3)); box-shadow: inset 0 0 0 1px rgb(0 0 0 / .12); }
.sw-dot.inherit { background: repeating-linear-gradient(45deg, var(--ink-3) 0 2px, transparent 2px 5px); box-shadow: inset 0 0 0 1.5px var(--ink-3); }

/* ---------- main ---------- */
.main { min-width: 0; padding: 18px 22px 120px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin: -2px 0 10px; font-size: 13px; color: var(--ink-3); }
.crumbs:empty { display: none; }
.crumbs a { color: var(--ink-2); text-decoration: none; padding: 2px 4px; border-radius: 5px; }
.crumbs a:hover { background: var(--hover); color: var(--ink); }
.crumbs span[aria-current] { padding: 2px 4px; color: var(--ink); font-weight: 550; }
.crumb-sep { color: var(--ink-3); display: inline-grid; }
.view-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.vh-icon { flex: none; display: grid; }
.vh-glyph { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 14px; background: var(--raised); border: 1px solid var(--line); color: var(--accent-text); }
.vh-glyph svg { width: 24px; height: 24px; }
.vh-text { flex: 1; min-width: 0; }
.view-head h1 { margin: 0; font-size: 24px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; overflow-wrap: anywhere; }
.vh-sub { margin: 2px 0 0; color: var(--ink-2); }
.vh-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.vh-actions svg { width: 17px; height: 17px; }
.section + .section { margin-top: 26px; }
.sec-h { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--ink-3); }

/* folder + company cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.cards.companies { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.fcard {
  position: relative; display: flex; align-items: center; gap: 12px; min-width: 0;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--raised); color: var(--ink); text-decoration: none;
  border-left: 4px solid var(--c);
  transition: border-color .12s, box-shadow .12s;
}
.fcard:hover { border-color: color-mix(in srgb, var(--c) 55%, var(--line)); border-left-color: var(--c); box-shadow: 0 4px 14px -8px rgb(0 0 0 / .25); }
.fcard-text { min-width: 0; display: grid; }
.fcard-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fcard-sub { font-size: 12.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ccard { flex-wrap: wrap; padding: 14px; border-left-width: 1px; }
.ccard .fcard-text { flex: 1; }
.ccard-strip { flex-basis: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 2px; }
.ccard-strip img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; background: var(--stage); }

/* toolbar */
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; margin-bottom: 12px; }
.toolbar .sec-h { margin: 0; }
.count { margin: 0; color: var(--ink-2); font-variant-numeric: tabular-nums; flex: 1; }
.tools { display: flex; align-items: center; gap: 8px; }
#selectBtn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.select { position: relative; display: block; }
.select select { appearance: none; -webkit-appearance: none; height: 32px; padding: 0 30px 0 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); font-size: 13px; }
.select select:disabled { opacity: .55; }
.select::after { content: ""; position: absolute; right: 12px; top: 50%; width: 6px; height: 6px; border-right: 1.6px solid var(--ink-2); border-bottom: 1.6px solid var(--ink-2); transform: translateY(-70%) rotate(45deg); pointer-events: none; }
.seg { display: inline-flex; padding: 2px; border: 1px solid var(--line); border-radius: 9px; background: var(--raised); }
.seg button { width: 32px; height: 26px; border: 0; border-radius: 6px; display: grid; place-items: center; background: transparent; color: var(--ink-3); }
.seg button svg { width: 17px; height: 17px; }
.seg button[aria-pressed="true"] { background: var(--hover-strong); color: var(--ink); }
.seg.wide { width: 100%; }
.seg-opt { flex: 1; position: relative; }
.seg-opt input { position: absolute; opacity: 0; }
.seg-opt span { display: block; padding: 6px 10px; border-radius: 6px; text-align: center; color: var(--ink-2); font-weight: 550; cursor: pointer; }
.seg-opt input:checked + span { background: var(--hover-strong); color: var(--ink); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--accent); }
.size input { width: 100px; accent-color: var(--accent); }

/* ---------- grid ---------- */
.grid { --h: var(--row-h); gap: var(--gap); }
.grid.rows { display: flex; flex-wrap: wrap; }
.grid.rows::after { content: ""; flex-grow: 999999999; }
.grid.rows .tile { flex: var(--r) 1 calc(var(--r) * var(--h)); max-width: calc(var(--r) * var(--h) * 2.6); }
.grid.rows .tile:only-child { max-width: min(100%, calc(var(--r) * var(--h) * 2)); }
.grid.squares { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--h), 1fr)); }
.tile {
  position: relative; min-width: 0; border-radius: 7px; overflow: hidden;
  background: var(--tile-bg, var(--stage));
  outline: 2px solid transparent; outline-offset: 2px; transition: outline-color .2s;
}
.tile.alpha, #dImg.alpha {
  background-color: var(--checker-a);
  background-image: conic-gradient(var(--checker-b) 25%, transparent 0 50%, var(--checker-b) 0 75%, transparent 0);
  background-size: 16px 16px;
}
.tile-hit { display: block; width: 100%; aspect-ratio: var(--r); padding: 0; border: 0; background: none; cursor: zoom-in; }
.grid.squares .tile-hit { aspect-ratio: 1; }
.grid.squares .tile.alpha .tile-hit img { padding: 12%; }
.tile-hit img { display: block; width: 100%; height: 100%; object-fit: contain; }
.doc-tile { width: 100%; height: 100%; display: grid; place-content: center; justify-items: center; gap: 6px; color: var(--ink-2); font-weight: 650; font-size: 12px; background: var(--raised); }
.tile-meta {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding: 26px 10px 8px; background: linear-gradient(to top, rgb(8 12 18 / .72), transparent);
  color: #fff; font-size: 12px; opacity: 0; transition: opacity .15s; pointer-events: none;
}
.tile-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-dim { flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; font-variant-numeric: tabular-nums; }
.tile-copy, .tile-check {
  position: absolute; top: 8px; width: 32px; height: 32px; display: grid; place-items: center;
  border: 0; border-radius: 8px; background: rgb(255 255 255 / .94); color: #18202b;
  box-shadow: 0 1px 3px rgb(0 0 0 / .25); opacity: 0; transition: opacity .15s, background-color .15s;
}
.tile-copy { right: 8px; }
.tile-check { left: 8px; width: 26px; height: 26px; border-radius: 7px; color: transparent; }
.tile:hover .tile-meta, .tile:focus-within .tile-meta,
.tile:hover .tile-copy, .tile:focus-within .tile-copy, .tile:hover .tile-check { opacity: 1; }
.grid.selecting .tile-check { opacity: 1; }
.grid.selecting .tile-copy { display: none; }
.grid.selecting .tile-hit { cursor: pointer; }
.tile.selected { outline-color: var(--accent); }
.tile.selected .tile-check { background: var(--accent); color: #fff; opacity: 1; }
.tile.selected .tile-hit img { transform: scale(.94); transition: transform .15s; }
.tile.flash { outline-color: var(--accent); }
.tile-star { position: absolute; right: 10px; bottom: 9px; color: #f5b301; filter: drop-shadow(0 1px 2px rgb(0 0 0 / .45)); }
.tile:hover .tile-star { opacity: 0; }
.sentinel { height: 1px; }
@media (hover: none) {
  .tile-copy { opacity: .92; width: 30px; height: 30px; }
  .tile-star { opacity: 1 !important; }
}
.drag-ghost { position: fixed; top: -100px; left: -100px; padding: 6px 12px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 600; font-size: 13px; }

/* ---------- empty states ---------- */
.empty { max-width: 480px; margin: 8vh auto 0; text-align: center; color: var(--ink-2); }
.empty h2 { margin: 0 0 8px; color: var(--ink); font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.empty p { margin: 0 0 18px; }
.empty svg { width: 17px; height: 17px; }

/* ---------- selection bar, FAB, upload tray, drop hint ---------- */
.selbar {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); z-index: 40; translate: -50% 0;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center;
  max-width: calc(100vw - 24px); padding: 8px 8px 8px 16px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow);
}
.sel-count { font-weight: 650; margin-right: 6px; white-space: nowrap; }
.fab {
  position: fixed; right: 18px; bottom: calc(18px + var(--safe-b)); z-index: 35;
  width: 58px; height: 58px; border: 0; border-radius: 18px;
  place-items: center; background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 10px 24px -8px color-mix(in srgb, var(--accent) 70%, black);
}
.fab svg { width: 24px; height: 24px; }
.selbar:not([hidden]) ~ .fab { display: none !important; }
.tray {
  position: fixed; right: 18px; bottom: calc(18px + var(--safe-b)); z-index: 45;
  width: min(360px, calc(100vw - 24px)); max-height: 46vh; display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); overflow: hidden;
}
.tray-head { display: flex; align-items: center; gap: 8px; padding: 12px 10px 10px 16px; }
.tray-head > div { flex: 1; min-width: 0; }
.tray-title { margin: 0; font-weight: 650; }
.tray-sub { margin: 0; font-size: 12.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray-progress { height: 3px; background: var(--hover); }
.tray-progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.tray-list { list-style: none; margin: 0; padding: 6px 0; overflow-y: auto; }
.tray-item { display: flex; gap: 10px; justify-content: space-between; padding: 5px 16px; font-size: 13px; }
.tray-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray-state { flex: none; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-3); font-weight: 550; }
.tray-item.done .tray-state { color: var(--ok); }
.tray-item.error .tray-state { color: var(--danger); }
.tray-item.working .tray-state, .tray-item.sending .tray-state { color: var(--accent-text); }
.drop-hint {
  position: fixed; inset: calc(var(--top-h) + 12px) 12px 12px calc(var(--side-w) + 12px); z-index: 25;
  display: none; place-items: center; border: 2px dashed var(--accent); border-radius: 16px;
  background: color-mix(in srgb, var(--accent) 8%, transparent); color: var(--accent-text);
  font-size: 17px; font-weight: 650; pointer-events: none;
}
body.dragging-files .drop-hint { display: grid; }

/* ---------- dialogs ---------- */
dialog { color: var(--ink); }
dialog::backdrop { background: rgb(10 14 20 / .55); }
.modal {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0;
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); overflow: hidden;
}
.modal.wide { width: min(680px, calc(100vw - 24px)); }
.modal[open] { display: flex; flex-direction: column; animation: fade .14s ease-out; }
.modal-form { display: flex; flex-direction: column; min-height: 0; max-height: calc(100dvh - 24px); }
@keyframes fade { from { opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 14px 8px 20px; }
.modal-head h2, .sheet-head h2 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.modal-body { padding: 6px 20px 18px; overflow-y: auto; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 14px 12px 20px; border-top: 1px solid var(--line); background: var(--surface); }
.foot-status { margin: 0 auto 0 0; font-size: 13px; color: var(--ink-2); }
.foot-status.bad { color: var(--danger); font-weight: 550; }
.confirm-msg { margin: 0 0 14px; color: var(--ink-2); }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > label, .field > .label { font-size: 13px; font-weight: 600; }
.field input, .field textarea, .num {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--raised);
}
.field textarea { resize: vertical; min-height: 60px; line-height: 1.45; }
.field input:focus, .field textarea:focus, .num:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { margin: 0; font-size: 12.5px; color: var(--ink-2); }
.hint.indent { margin: 4px 0 0 25px; }
.check { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.check input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); flex: none; }
.num { width: 84px; padding: 4px 8px; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { position: relative; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; }
.swatch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.swatch .sw-dot { width: 26px; height: 26px; }
.swatch:has(input:checked) { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--sw, var(--ink-3)); }
.swatch:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 3px; }

.tabs { display: flex; gap: 4px; margin: 0 0 16px; border-bottom: 1px solid var(--line); }
.tabs button { padding: 9px 12px 8px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--ink-3); font-weight: 600; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tab-panel .hint { margin-bottom: 12px; }
.tpl-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 4px; }
.tpl-row { display: flex; align-items: center; gap: 6px; padding-left: calc(var(--depth) * 26px); }
.tpl-color { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); }
.tpl-color.inherit .ficon { opacity: .55; }
.tpl-name { flex: 1; min-width: 0; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); }
.tpl-name:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tpl-btns { display: flex; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 0; }
.facts.one { grid-template-columns: 1fr; margin-bottom: 18px; }
.facts dt { font-size: 12px; color: var(--ink-3); }
.facts dd { margin: 2px 0 0; font-weight: 560; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* action sheet */
.sheet { padding: 0; border: 0; background: transparent; max-width: none; max-height: none; overflow: visible; }
.sheet[open] { display: grid; place-items: center; width: 100vw; height: 100dvh; margin: 0; }
.sheet-card {
  width: min(380px, calc(100vw - 24px)); max-height: min(560px, calc(100dvh - 40px));
  display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow);
  animation: fade .12s ease-out;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 10px 8px 18px; }
.sheet-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-list { list-style: none; margin: 0; padding: 4px 6px 8px; overflow-y: auto; }
.sheet-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 0; border-radius: 9px; background: transparent; text-align: left; font-weight: 550; }
.sheet-item:hover { background: var(--hover); }
.sheet-item.danger { color: var(--danger); }
.sheet-icon { color: var(--ink-2); display: grid; }
.sheet-item.danger .sheet-icon { color: inherit; }
.sheet-hint { margin-left: auto; font-size: 12.5px; color: var(--ink-3); font-weight: 500; }
.sheet-div { height: 1px; margin: 4px 10px; background: var(--line); }
.sheet-foot { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); background: var(--surface); }
.pick-chosen { margin: 0; flex: 1; min-width: 0; font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-list { list-style: none; margin: 0; padding: 4px 8px 10px; overflow-y: auto; min-height: 120px; }
.pick-row { display: flex; align-items: center; padding-left: calc(var(--depth) * 16px); border-radius: 8px; }
.pick-row:hover { background: var(--hover); }
.pick-row.on { background: var(--accent-soft); }
.pick-row.on .pick-btn { color: var(--accent-text); font-weight: 650; }
.pick-btn { flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; padding: 8px 8px 8px 2px; border: 0; background: none; text-align: left; }
.pick-btn span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.color-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px 10px 14px; overflow-y: auto; }
.color-opt { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 0; border-radius: 9px; background: none; text-align: left; font-weight: 550; }
.color-opt:hover { background: var(--hover); }
.color-opt.on { background: var(--accent-soft); }

/* ---------- detail view ---------- */
.detail { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; margin: 0; padding: 0; border: 0; background: var(--panel); }
.detail::backdrop { background: var(--stage); }
.detail[open] { display: grid; grid-template-columns: minmax(0, 1fr) 390px; }
.detail-stage { position: relative; min-height: 0; overflow: hidden; display: grid; place-items: center; background: var(--stage); touch-action: pan-y; }
#dImg { display: block; max-width: 100%; max-height: 100%; border-radius: 3px; box-shadow: 0 12px 40px -14px rgb(0 0 0 / .45); }
#dImg.alpha { box-shadow: none; }
.doc-big { display: grid; justify-items: center; gap: 12px; color: var(--ink-2); font-weight: 650; }
.doc-big svg { width: 72px; height: 72px; }
.nav-btn {
  position: absolute; top: 50%; translate: 0 -50%; width: 44px; height: 44px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 50%; background: var(--panel); color: var(--ink); box-shadow: 0 2px 8px rgb(0 0 0 / .12);
}
.nav-btn.prev { left: 20px; }
.nav-btn.next { right: 20px; }
.nav-btn[disabled] { opacity: .3; cursor: default; }
.stage-counter { position: absolute; left: 22px; top: 16px; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.stage-close { position: absolute; top: 10px; right: 10px; background: var(--panel); }
.detail-side { display: flex; flex-direction: column; gap: 16px; padding: 14px 20px 28px; border-left: 1px solid var(--line); overflow-y: auto; }
.side-head { display: flex; align-items: flex-start; gap: 4px; }
.d-name { flex: 1; min-width: 0; margin: 4px 0 0; font-size: 18px; font-weight: 650; line-height: 1.3; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.d-where { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-top: -8px; font-size: 13px; }
.d-where a { padding: 2px 6px; border-radius: 6px; background: var(--hover); color: var(--ink-2); text-decoration: none; font-weight: 550; }
.d-where a:hover { color: var(--ink); background: var(--hover-strong); }
.d-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tool {
  display: grid; justify-items: center; gap: 4px; padding: 9px 4px 8px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--raised); color: var(--ink-2);
  font-size: 12px; font-weight: 600;
}
.tool:hover { color: var(--ink); border-color: color-mix(in srgb, var(--ink) 25%, var(--line)); }
.tool.on { color: #c08a00; border-color: color-mix(in srgb, #f5b301 60%, var(--line)); }
.tool.danger:hover { color: var(--danger); }
.snippet { border: 1px solid var(--line); border-radius: 11px; background: var(--raised); overflow: hidden; }
.fmt-tabs { display: flex; padding: 0 6px; border-bottom: 1px solid var(--line); }
.fmt-tabs button { flex: 1; padding: 10px 4px 9px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--ink-3); font-size: 13px; font-weight: 600; }
.fmt-tabs button:hover { color: var(--ink); }
.fmt-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.code { margin: 0; padding: 13px 14px; min-height: 66px; max-height: 140px; overflow: auto; font: 12.5px/1.6 var(--mono); color: var(--ink); white-space: pre-wrap; word-break: break-all; }
.snippet .btn-lg { border-radius: 0; border-width: 1px 0 0; }
.detail-side .field { margin-bottom: -4px; }
.saved { min-height: 1.3em; color: var(--ok); }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.d-actions .btn { flex: 1; }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: calc(22px + var(--safe-b)); z-index: 100; translate: -50% 0; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast {
  max-width: min(520px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 10px;
  background: var(--ink); color: var(--panel); font-size: 13.5px; font-weight: 560;
  box-shadow: 0 10px 30px -8px rgb(0 0 0 / .4); opacity: 0; translate: 0 8px; transition: opacity .18s, translate .18s;
}
.toast.in { opacity: 1; translate: 0 0; }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- phones ---------- */
@media (max-width: 760px) {
  :root { --top-h: 56px; }
  .only-narrow { display: grid !important; }
  .only-narrow[hidden], .m-title.only-narrow[hidden] { display: none !important; }
  .m-title.only-narrow { display: block !important; }
  .hide-narrow { display: none !important; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar { gap: 4px; padding: 0 6px 0 10px; padding-top: env(safe-area-inset-top, 0px); height: calc(var(--top-h) + env(safe-area-inset-top, 0px)); }
  #app[data-view="home"] .brand { display: flex; }
  #app:not([data-view="home"]) .brand { display: none; }
  #app[data-view="home"] .m-title { display: none !important; }
  .brand { width: auto; flex: 1; }
  .search { display: none; }
  body.searching .search { display: flex; position: absolute; inset: env(safe-area-inset-top, 0px) 8px 0 8px; height: var(--top-h); max-width: none; z-index: 2; background: var(--panel); align-items: center; }
  body.searching .search input { padding-right: 44px; font-size: 16px; }
  body.searching #searchClose { position: absolute; right: 4px; }
  .search kbd { display: none; }
  .main { padding: 14px 12px calc(110px + var(--safe-b)); }
  .crumbs { display: none; }
  .view-head { gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
  .view-head h1 { font-size: 21px; }
  .avatar.lg { --size: 44px; }
  .vh-glyph { width: 44px; height: 44px; }
  .vh-actions { width: 100%; justify-content: flex-start; }
  #app[data-view="company"] .vh-actions, #app[data-view="folder"] .vh-actions { width: auto; }
  .vh-actions .btn span { display: none; }
  .vh-actions .btn { width: 40px; padding: 0; }
  #app[data-view="home"] .vh-actions .btn { width: auto; padding: 0 14px; }
  #app[data-view="home"] .vh-actions .btn span { display: inline; }
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .cards.companies { grid-template-columns: 1fr; }
  .fcard { flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; border-left-width: 1px; border-top: 4px solid var(--c); }
  .fcard .ficon { width: 30px; height: 30px; }
  .fcard-text { width: 100%; }
  .ccard { flex-direction: row; flex-wrap: wrap; align-items: center; border-top-width: 1px; border-left: 4px solid var(--c); }
  .toolbar { gap: 8px; }
  .toolbar .count { flex-basis: 100%; order: -1; }
  .toolbar .sec-h { display: none; }
  .tools { width: 100%; }
  .tools .select { flex: 1; }
  .tools .select select { width: 100%; }
  .grid { --h: calc(var(--row-h) * .58); --gap: 6px; }
  .grid.squares { grid-template-columns: repeat(3, 1fr); }
  .tile { border-radius: 5px; }
  .tile-copy { top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 7px; }
  .tile-copy svg { width: 15px; height: 15px; }
  .tile-check { top: 6px; left: 6px; }
  .selbar { left: 8px; right: 8px; translate: none; max-width: none; padding: 8px; gap: 6px; justify-content: space-between; }
  .selbar .sel-count { flex-basis: 100%; text-align: center; margin: 0 0 2px; }
  .selbar .btn span:not([data-icon]) { display: none; }
  .selbar [data-sel="all"], .selbar [data-sel="done"] { flex: 1; }
  .selbar [data-sel="all"] span, .selbar [data-sel="done"] span { display: inline; }
  .tray { left: 8px; right: 8px; bottom: calc(86px + var(--safe-b)); width: auto; }
  .drop-hint { inset: calc(var(--top-h) + 8px) 8px 8px; }
  .detail[open] { grid-template-columns: minmax(0, 1fr); grid-template-rows: 58dvh auto; overflow-y: auto; }
  .detail-side { border-left: 0; border-top: 1px solid var(--line); overflow: visible; padding: 14px 14px calc(28px + var(--safe-b)); }
  .nav-btn { width: 38px; height: 38px; opacity: .9; }
  .nav-btn.prev { left: 8px; }
  .nav-btn.next { right: 8px; }
  .stage-counter { left: 14px; top: calc(14px + env(safe-area-inset-top, 0px)); }
  .stage-close { top: calc(8px + env(safe-area-inset-top, 0px)); }
  .modal, .modal.wide { width: 100vw; max-width: 100vw; max-height: 92dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; border-width: 1px 0 0; }
  .modal-form { max-height: 92dvh; }
  .modal-foot { padding-bottom: calc(12px + var(--safe-b)); }
  .sheet[open] { place-items: end center; }
  .sheet-card { width: 100vw; max-width: 100vw; max-height: 82dvh; border-radius: 16px 16px 0 0; border-width: 1px 0 0; padding-bottom: var(--safe-b); animation: rise .18s ease-out; }
  .sheet-item { padding: 13px 12px; font-size: 15px; }
  .field-grid { grid-template-columns: 1fr; }
  .tpl-row { padding-left: calc(var(--depth) * 14px); gap: 4px; }
  .tpl-btns .icon-btn.sm { width: 28px; }
  .field input, .field textarea, .tpl-name, .search input { font-size: 16px; } /* stops iOS zooming into inputs */
}
@keyframes rise { from { transform: translateY(24px); opacity: .4; } }
@media (min-width: 761px) and (max-width: 1080px) {
  :root { --side-w: 228px; }
  .detail[open] { grid-template-columns: minmax(0, 1fr) 340px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
