/* DIAMDOR content app: ONE design system for every screen. Tokens and look follow sklad/finance (Manrope, light grey page, white panels,
   thin borders, square corners, dark primary buttons, orange accent) but tuned for a dense desktop content tool; usable at 390 px.
   Order: 1 tokens · 2 base · 3 shell (top bar, rail, main) · 4 page layout · 5 controls (btn, input, fld, chip, badge, switch)
   · 6 table · 7 overlays (modal, drawer, toast) · 8 states (loading, empty, error) · 9 login · 10 phone.
   Components (class names): .btn (.light .gold .danger .sm .icon) · .input / select.input / textarea.input · .fld · .chip · .badge (.ok .bad .gold .warn)
   · .sw · .tbl-wrap > table.tbl (td.num, td.ed, tr.sel) · .tb toolbar · .pager · .ov > .modal · .drawer-ov > .drawer · .toast · .loading .skel .empty .errbox */

@font-face { font-family: 'Manrope'; font-weight: 400 800; font-display: swap; src: url('/fonts/manrope-v20-latin-ext.woff2') format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Manrope'; font-weight: 400 800; font-display: swap; src: url('/fonts/manrope-v20-latin.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }


/* ---------------------------------------------------------------- 1 tokens */
:root {
  --bg: #f8f9fa; --fg: #1d2024; --card: #fff; --soft: #f1f2f4; --primary: #ef7a38; --muted: #6b7077; --border: #dfe2e6; --bar: #FF6A00;
  --bad: #c8321f; --ok: #2f8f5b; --warn: #b7791f;
  --ok-bg: #eaf7ee; --warn-bg: #fffaf0; --bad-bg: #fdf1ef; --primary-bg: #fff4ea;
  --grid-line: #e8eaee; --head-bg: #eef0f3; --row-hover: #f6f8fa; --row-sel: #fff4ea;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --fs-xs: 11px; --fs-sm: 12.5px; --fs-md: 13.5px; --fs-lg: 17px; --fs-xl: 21px;
  --ctl: 32px; --ctl-sm: 26px;      /* dense desktop controls */
  --bar-h: 38px; --rail-w: 84px;
}
@media (max-width: 700px) { :root { --ctl: 44px; --ctl-sm: 36px; --fs-md: 15px; --fs-sm: 13px; --bar-h: 40px; } }

/* ---------------------------------------------------------------- 2 base */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: var(--fs-md)/1.4 'Manrope', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif; -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; }
h1 { font-size: var(--fs-xl); font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
h2 { font-size: var(--fs-lg); font-weight: 700; }
h3 { font-size: var(--fs-md); font-weight: 700; }
.hidden, [hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
code, .mono { font: 12px ui-monospace, Menlo, monospace; }

/* ---------------------------------------------------------------- 3 shell */
.app { height: 100dvh; display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); grid-template-rows: var(--bar-h) minmax(0, 1fr); grid-template-areas: "bar bar" "rail main"; }
.appbar { grid-area: bar; display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: env(safe-area-inset-top) var(--s4) 0; background: var(--bar); color: #fff; font-size: var(--fs-sm); }
.appbar .brand { display: flex; align-items: center; gap: 10px; color: #fff; min-width: 0; }
.appbar .brand b { font-weight: 800; letter-spacing: .16em; text-transform: uppercase; white-space: nowrap; font-size: 12px; }
.appbar .brand span { opacity: .85; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .who { display: flex; align-items: center; gap: var(--s3); min-width: 0; font-weight: 600; }
.appbar .who .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28vw; }
.appbar .out { background: none; border: 0; padding: 0; min-height: 28px; color: #fff; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.appbar .mode { padding: 1px 8px; border: 1px solid rgba(255,255,255,.7); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }

.rail { grid-area: rail; display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: var(--s3) 0; background: var(--card); border-right: 1px solid var(--border); overflow-y: auto; }
.rail a.rk { --c: #9a8f86; --ic: color-mix(in srgb, var(--c) 78%, #000); display: grid; justify-items: center; gap: 5px; width: 72px; padding: 8px 4px 7px; color: var(--muted); font-size: 11px; font-weight: 700; text-align: center; line-height: 1.2; border-left: 3px solid transparent; position: relative; }
.rail a.rk .ti { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: linear-gradient(180deg, #fff, color-mix(in srgb, var(--c) 17%, #fff)); box-shadow: inset 0 1px 0 #fff, inset 0 0 0 1px color-mix(in srgb, var(--c) 38%, transparent), 0 6px 12px -9px color-mix(in srgb, var(--c) 60%, transparent); }
.rail a.rk svg { width: 22px; height: 22px; color: var(--ic); fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.rail a.rk:hover { color: var(--fg); }
.rail a.rk.on { color: var(--fg); border-left-color: var(--primary); background: var(--primary-bg); }
.rail a.rk.on .ti { box-shadow: inset 0 1px 0 #fff, inset 0 0 0 2px var(--c), 0 8px 14px -8px color-mix(in srgb, var(--c) 60%, transparent); }
.rail .sp { flex: 1; }
.rail .ver { font-size: 10px; color: var(--muted); opacity: .7; }

.app-main { grid-area: main; min-width: 0; min-height: 0; overflow: auto; position: relative; }

/* ---------------------------------------------------------------- 4 page layout */
.page > * { min-width: 0; }
.page { display: flex; flex-direction: column; min-height: 100%; padding: var(--s4) var(--s5) var(--s5); gap: var(--s3); }
.page.fill { height: 100%; min-height: 0; padding-bottom: var(--s3); }          /* table pages: the table scrolls inside, the page does not */
.page-head { display: flex; align-items: flex-end; gap: var(--s4); flex-wrap: wrap; }
.page-head .ttl { display: grid; gap: 2px; margin-right: auto; min-width: 0; }
.page-head .sub { color: var(--muted); font-size: var(--fs-sm); }
.crumbs { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: var(--fs-sm); }
.crumbs a:hover { color: var(--fg); text-decoration: underline; }
.panel { background: var(--card); border: 1px solid var(--border); padding: var(--s4); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s3); }
.panel > h3 { margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--s3); }
.row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.note { color: var(--muted); font-size: var(--fs-sm); line-height: 1.45; }

/* ---------------------------------------------------------------- 5 controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: var(--ctl); padding: 0 var(--s4); border: 1px solid var(--fg); background: var(--fg); color: var(--bg); border-radius: 0; font-weight: 700; font-size: var(--fs-md); white-space: nowrap; }
.btn:hover { opacity: .9; }
.btn.light { background: var(--card); color: var(--fg); border-color: var(--border); }
.btn.light:hover { border-color: var(--fg); opacity: 1; }
.btn.gold { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { background: var(--card); color: var(--bad); border-color: var(--bad); }
.btn.sm { min-height: var(--ctl-sm); padding: 0 var(--s3); font-size: var(--fs-sm); }
.btn.icon { padding: 0; width: var(--ctl); }
.btn.icon.sm { width: var(--ctl-sm); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn svg, .ico { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.input { width: 100%; height: var(--ctl); border: 1px solid var(--border); background: var(--card); border-radius: 0; padding: 0 var(--s3); font-size: var(--fs-md); outline: none; }
select.input { padding-right: 6px; }
textarea.input { height: auto; min-height: 76px; padding: var(--s2) var(--s3); resize: vertical; line-height: 1.4; }
.input:focus { border-color: var(--primary); }
.input[disabled], .input[readonly] { background: var(--soft); color: var(--muted); }
.input.bad { border-color: var(--bad); background: var(--bad-bg); }
.input.sm { height: var(--ctl-sm); font-size: var(--fs-sm); }
.fld { display: grid; gap: 5px; font-size: var(--fs-sm); font-weight: 600; color: var(--muted); min-width: 0; }
.fld .input { font-weight: 400; color: var(--fg); }
.fld .hint { font-weight: 400; font-size: var(--fs-xs); }
.fld .msg { font-weight: 600; font-size: var(--fs-xs); color: var(--bad); }
.fld-row { display: grid; align-items: start; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s3); }
.fieldset { display: grid; gap: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--border); }
.fieldset > .lg { font-size: var(--fs-xs); font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: var(--ctl-sm); padding: 0 var(--s3); border: 1px solid var(--border); background: var(--card); color: var(--muted); font-size: var(--fs-sm); font-weight: 600; border-radius: 0; }
.chip:hover { border-color: var(--fg); }
.chip[aria-pressed=true], .chip.on { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.chip .x { opacity: .7; font-weight: 800; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; line-height: 1.5; padding: 0 var(--s2); border: 1px solid var(--border); color: var(--muted); background: var(--card); white-space: nowrap; }
.badge.ok { border-color: var(--ok); color: var(--ok); background: var(--ok-bg); }
.badge.bad { border-color: var(--bad); color: var(--bad); background: var(--bad-bg); }
.badge.gold { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }
.badge.warn { border-color: var(--warn); color: var(--warn); background: var(--warn-bg); }

.sw { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--fs-md); font-weight: 600; cursor: pointer; }
.sw input { position: absolute; opacity: 0; width: 0; height: 0; }
.sw i { position: relative; width: 34px; height: 20px; background: #c5c9cf; transition: background .15s; flex: none; }
.sw i::after { content: ''; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; background: #fff; transition: transform .15s; }
.sw input:checked + i { background: var(--ok); }
.sw input:checked + i::after { transform: translateX(14px); }
.sw input:focus-visible + i { outline: 2px solid var(--primary); outline-offset: 2px; }

/* toolbar above a table: search, filters, counters */
.tb { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.tb .grow { flex: 1; min-width: 160px; }
.tb .input { width: auto; }
.tb .input.search { width: min(320px, 100%); }
.tb .count { margin-left: auto; color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; }

/* ---------------------------------------------------------------- 6 table (dense, sticky header) */
.tbl-wrap { position: relative; flex: 1; min-height: 0; overflow: auto; background: var(--card); border: 1px solid #cfd3d8; }
table.tbl { border-collapse: separate; border-spacing: 0; width: 100%; font-size: var(--fs-md); }
.tbl th { position: sticky; top: 0; z-index: 3; height: 30px; padding: 0 var(--s3); background: var(--head-bg); border-bottom: 1px solid #c9cdd3; border-right: 1px solid #d3d6db; font-size: 12px; font-weight: 700; color: #3d434a; text-align: left; white-space: nowrap; user-select: none; }
.tbl th.sortable { cursor: pointer; }
.tbl th.sortable:hover { background: #e6e9ed; }
.tbl th .ar { font-size: 9px; color: var(--primary); margin-left: 4px; }
.tbl td { height: 34px; max-width: 360px; padding: 0 var(--s3); border-bottom: 1px solid var(--grid-line); border-right: 1px solid var(--grid-line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.tbl tbody tr:hover td { background: var(--row-hover); }
.tbl tbody tr.sel td { background: var(--row-sel); }
.tbl tbody tr { cursor: default; }
.tbl tbody tr.clk { cursor: pointer; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td.wrap { white-space: normal; }
.tbl td.act { width: 1%; text-align: right; }
.tbl td .thumb { display: block; width: 26px; height: 26px; object-fit: cover; background: var(--soft); }
/* inline-edit cell: shows the value, a click turns it into an input; .dirty = changed, not yet saved */
.tbl td.ed { cursor: text; position: relative; }
.tbl td.ed:hover { box-shadow: inset 0 0 0 1px var(--primary); }
.tbl td.ed.dirty { background: var(--primary-bg); }
.tbl td.ed.dirty::after { content: ''; position: absolute; right: 0; top: 0; border: 4px solid transparent; border-top-color: var(--primary); border-right-color: var(--primary); }
.tbl td.ed.err { box-shadow: inset 0 0 0 1px var(--bad); background: var(--bad-bg); }
.tbl td.ed.editing { padding: 0; box-shadow: inset 0 0 0 2px var(--primary); background: var(--card); overflow: visible; }
.tbl td.ed.editing input, .tbl td.ed.editing select { width: 100%; height: 100%; min-height: 32px; border: 0; outline: none; padding: 0 var(--s3); background: transparent; font-size: var(--fs-md); text-align: inherit; }
.tbl td.ro { color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; font-size: var(--fs-sm); color: var(--muted); }

/* ---------------------------------------------------------------- 7 overlays */
.ov { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 8vh var(--s4) var(--s4); background: rgba(20, 22, 26, .45); overflow: auto; }
.modal { width: 100%; max-width: 480px; display: grid; gap: var(--s3); padding: var(--s4); background: var(--bg); border: 1px solid var(--border); box-shadow: 0 20px 50px -20px rgba(0,0,0,.4); }
.modal h2 { font-size: var(--fs-lg); }
.modal .row.end .btn { min-width: 90px; }

.drawer-ov { position: fixed; inset: 0; z-index: 90; background: rgba(20, 22, 26, .35); display: flex; justify-content: flex-end; }
.drawer { width: min(560px, 100%); height: 100%; display: flex; flex-direction: column; background: var(--bg); border-left: 1px solid var(--border); box-shadow: -20px 0 50px -30px rgba(0,0,0,.45); animation: slidein .18s ease-out; }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-h { flex: none; display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); background: var(--card); border-bottom: 1px solid var(--border); }
.drawer-h h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-b { flex: 1; min-height: 0; overflow: auto; padding: var(--s4); display: grid; gap: var(--s3); align-content: start; }
.drawer-f { flex: none; display: flex; justify-content: flex-end; align-items: center; gap: var(--s2); padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--border); }
.drawer-f .info { margin-right: auto; color: var(--muted); font-size: var(--fs-sm); }

.toast { position: fixed; left: 50%; top: calc(var(--bar-h) + 10px); z-index: 400; max-width: min(560px, calc(100vw - 28px)); padding: 10px 16px; background: var(--fg); color: var(--bg); font-size: var(--fs-sm); font-weight: 600; opacity: 0; transform: translate(-50%, -8px); transition: opacity .18s, transform .18s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

/* ---------------------------------------------------------------- 8 states */
.loading { color: var(--muted); font-size: var(--fs-sm); padding: var(--s3) 0; }
.loading::before { content: ''; display: inline-block; width: 12px; height: 12px; margin-right: var(--s2); border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; vertical-align: -2px; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skel { display: block; height: 14px; background: linear-gradient(90deg, var(--soft), #e6e8eb, var(--soft)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty { padding: var(--s5) var(--s4); border: 1px dashed var(--border); background: var(--card); text-align: center; color: var(--muted); font-size: var(--fs-md); display: grid; gap: var(--s2); justify-items: center; }
.empty b { color: var(--fg); font-size: var(--fs-lg); }
.errbox { padding: var(--s3) var(--s4); border: 1px solid var(--bad); background: var(--bad-bg); color: var(--bad); font-size: var(--fs-md); display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.errbox .btn { margin-left: auto; }
.stub { align-self: start; max-width: 720px; }
.stub ul { margin: 0; padding-left: 18px; color: var(--muted); display: grid; gap: 4px; }

/* ---------------------------------------------------------------- 9 login */
.gate { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; background: var(--bg); padding: var(--s5); overflow: auto; }
.gate-card { width: 100%; max-width: 380px; display: grid; gap: 14px; padding: 28px; background: var(--card); border: 1px solid var(--border); }
.gate-card img.logo { height: 28px; width: auto; justify-self: start; }
.gate-card h1 { font-size: 20px; }
.gate-card .sub { color: var(--muted); font-size: var(--fs-sm); margin-top: -6px; }
.gate-card .err { color: var(--bad); font-size: var(--fs-sm); min-height: 18px; margin: 0; }
.gate-card .input { height: 40px; font-size: 15px; }
.gate-card .btn { min-height: 42px; width: 100%; }

/* gallery (hidden route #/ui): component showcase */
.gal { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s4); }
.gal h3 { margin-bottom: var(--s2); }

/* ---------------------------------------------------------------- 10 phone: the rail becomes a bottom bar */
@media (max-width: 700px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: var(--bar-h) minmax(0, 1fr) auto; grid-template-areas: "bar" "main" "rail"; }
  .appbar { padding-left: var(--s3); padding-right: var(--s3); }
  .appbar .brand span { display: none; }
  .appbar .who .nm { max-width: 38vw; }
  .rail { flex-direction: row; justify-content: space-around; align-items: stretch; gap: 0; padding: 0 0 env(safe-area-inset-bottom); border-right: 0; border-top: 1px solid var(--border); overflow: visible; }
  .rail a.rk { flex: 1; width: auto; grid-template-columns: auto; align-content: center; padding: 6px 4px; border-left: 0; border-top: 3px solid transparent; min-height: 56px; }
  .rail a.rk .ti { width: 30px; height: 30px; border-radius: 9px; }
  .rail a.rk svg { width: 18px; height: 18px; }
  .rail .sp, .rail .ver { display: none; }
  .page { padding: var(--s3) var(--s3) var(--s4); }
  .page.fill { padding-bottom: var(--s2); }
  .rail a.rk.on { border-top-color: var(--primary); }
  .tb .input.search { width: 100%; flex: 1 1 100%; }
  .tb .count { margin-left: 0; }
  .drawer { width: 100%; border-left: 0; }
  .ov { padding-top: 6vh; }
  .tbl td { height: 44px; max-width: 220px; }
  .toast { top: calc(var(--bar-h) + 6px); }
}
