/* Hansa peržiūra. Tokens: see design_handoff README (not the apskaita.cloud palette). */
:root {
  --ink: #17211E; --text-2: #3C4743; --muted: #5B6661; --faint: #6B7A75; --placeholder: #A3ADA9;
  --page: #EEF0EC; --surface: #FFFFFF; --head: #F4F6F3; --foot: #FAFBF9; --input: #F7F8F6; --chip: #E3E7E2;
  --border: #D5DAD5; --row-line: #EBEEEA; --field-line: #F1F3F0; --foot-line: #E6E9E5;
  --accent: #1D5E58; --accent-hover: #164A45; --link-hover: #123F3B; --nav-active: #DCEBE6;
  --row-hover: #F3F7F5; --menu-hover: #F1F4F2;
  --bar: #17211E; --bar-raised: #222E2A; --bar-hover: #2A3733; --bar-line: #34403C; --bar-text: #E6ECE9;
  --bar-muted: #9AA8A3; --bar-btn: #C9D3CF;
  --on-bg: #DCEBE6; --on-fg: #1D5E58; --off-bg: #ECEEEB; --off-fg: #5B6661;
  --warn-bg: #FBEFD9; --warn-fg: #8A5200; --err-bg: #F6E1DC; --err-fg: #9A3423;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --ease: .15s ease;
}
* { box-sizing: border-box; }
html { background: var(--page); }
body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
a:hover { color: var(--link-hover); }
button, input { font-family: inherit; }
h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 13px; font-weight: 600; }
code, .mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ---- top bar ---- */
.topbar { position: sticky; top: 0; z-index: 10; height: 48px; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--bar); color: var(--bar-text); }
.brand { display: flex; align-items: baseline; gap: 6px; font-size: 15px; color: var(--bar-text); text-decoration: none; white-space: nowrap; }
.brand:hover { color: var(--bar-text); }
.brand-name { font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { font-weight: 400; color: var(--bar-muted); }
.topbar-sep { width: 1px; height: 20px; background: var(--bar-line); flex-shrink: 0; }
.switcher { position: relative; flex-shrink: 0; }
.switcher summary { list-style: none; display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 10px; cursor: pointer;
  background: var(--bar-raised); border: 1px solid var(--bar-line); border-radius: 3px; font-size: 13px; color: var(--bar-text);
  transition: background-color var(--ease); }
.switcher summary::-webkit-details-marker { display: none; }
.switcher summary:hover { background: var(--bar-hover); }
.switcher-name { font-weight: 500; }
.badge-backup { font-size: 11px; color: var(--warn-fg); background: var(--warn-bg); border-radius: 3px; padding: 0 6px; }
.caret { font-size: 10px; color: var(--bar-muted); }
.switcher-menu { position: absolute; top: 38px; left: 0; width: 340px; max-width: calc(100vw - 32px); z-index: 20; padding: 4px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 4px;
  box-shadow: 0 8px 24px rgba(23, 33, 30, .16); }
.switcher-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 8px 10px; border-radius: 3px;
  color: var(--ink); text-decoration: none; transition: background-color var(--ease); }
.switcher-item:hover, .switcher-item.current { background: var(--menu-hover); color: var(--ink); }
.switcher-item-name { font-size: 13px; font-weight: 500; }
.switcher-item-src { font-family: var(--mono); font-size: 11px; color: var(--muted); text-align: right; }
.switcher-item-loaded { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--bar-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs a { color: var(--bar-muted); text-decoration: none; overflow: hidden; text-overflow: ellipsis; }
.crumbs a:hover { color: var(--bar-text); }
.crumb-rec { color: var(--bar-text); overflow: hidden; text-overflow: ellipsis; }
.updated { display: flex; align-items: baseline; gap: 6px; font-size: 12px; color: var(--bar-muted); white-space: nowrap; flex-shrink: 0; }
.updated-at { font-family: var(--mono); color: var(--bar-text); }
.ro-pill { font-family: var(--mono); font-size: 11px; color: var(--bar-muted); border: 1px solid var(--bar-line); border-radius: 3px;
  padding: 2px 6px; white-space: nowrap; flex-shrink: 0; }
.user { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 13px; flex-shrink: 0; }
.user-name { color: var(--bar-text); }
.user button { height: 28px; padding: 0 10px; background: transparent; border: 1px solid var(--bar-line); border-radius: 3px;
  color: var(--bar-btn); font-size: 12px; cursor: pointer; transition: border-color var(--ease); }
.user button:hover { border-color: var(--faint); color: #FFFFFF; }
.nav-toggle { display: none; height: 28px; padding: 0 10px; background: transparent; border: 1px solid var(--bar-line); border-radius: 3px;
  color: var(--bar-btn); font-size: 12px; cursor: pointer; flex-shrink: 0; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: calc(100vh - 48px); }
.main { min-width: 0; padding: 20px 24px 32px; }
.page { padding: 20px 24px 32px; max-width: 1200px; }

/* ---- sidebar ---- */
.sidebar { position: sticky; top: 48px; height: calc(100vh - 48px); display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border); }
.sidebar-filter { padding: 12px 12px 8px; }
.sidebar-filter input { width: 100%; height: 32px; padding: 0 10px; background: var(--input); border: 1px solid var(--border);
  border-radius: 3px; font-size: 13px; color: var(--ink); outline: none; transition: border-color var(--ease), background-color var(--ease); }
.sidebar-filter input:focus { border-color: var(--accent); background: var(--surface); }
.sidebar-groups { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.nav-group-title { padding: 12px 8px 4px; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.nav-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 3px;
  color: var(--ink); text-decoration: none; transition: background-color var(--ease); }
.nav-item:hover { background: var(--menu-hover); color: var(--ink); }
.nav-item.active { background: var(--nav-active); }
.nav-item.active .nav-item-name { font-weight: 600; }
.nav-item-text { display: flex; flex-direction: column; min-width: 0; }
.nav-item-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item-code { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.nav-item-count { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.nav-item-count.none { color: var(--placeholder); }
.nav-item-count.warn { color: var(--warn-fg); }
.nav-item-count.err { color: var(--err-fg); }
.sidebar-foot { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 10px 16px;
  border-top: 1px solid var(--foot-line); font-size: 12px; color: var(--muted); }
.sidebar-foot dt { margin: 0; }
.sidebar-foot dd { margin: 0; color: var(--ink); min-width: 0; overflow-wrap: anywhere; }

/* ---- title row, toolbar ---- */
.title-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; margin-bottom: 14px; }
.code-chip { font-family: var(--mono); font-size: 12px; color: var(--muted); background: var(--chip); border-radius: 3px; padding: 1px 6px; }
.title-count { font-size: 13px; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.search { flex: 1 1 260px; max-width: 380px; margin: 0; }
.search input { width: 100%; height: 34px; padding: 0 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 3px;
  font-size: 13px; color: var(--ink); outline: none; transition: border-color var(--ease); }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(29, 94, 88, .12); }
.clear { font-size: 13px; color: var(--accent); text-decoration: underline; white-space: nowrap; padding: 0 6px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; white-space: nowrap; flex-shrink: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 3px; font-size: 13px; color: var(--ink);
  text-decoration: none; transition: border-color var(--ease); }
.toggle:hover { border-color: var(--bar-muted); color: var(--ink); }
.toggle-box { width: 14px; height: 14px; border: 1px solid var(--faint); border-radius: 2px; background: var(--surface); }
.toggle.on .toggle-box { background: var(--accent); border-color: var(--accent); }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; height: 30px; padding: 0 10px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 3px; color: var(--ink); font-size: 13px; text-decoration: none; white-space: nowrap;
  cursor: pointer; transition: border-color var(--ease), background-color var(--ease); }
.btn:hover { border-color: var(--bar-muted); color: var(--ink); }
.btn.sq { min-width: 30px; padding: 0 8px; }
.btn.disabled { opacity: .4; cursor: default; }
.btn.disabled:hover { border-color: var(--border); }
.btn.primary { height: 34px; background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #FFFFFF; }

/* ---- pills ---- */
.pill { display: inline-block; font-family: var(--sans); font-size: 12px; font-weight: 400; line-height: 1.45; padding: 1px 8px;
  border-radius: 10px; white-space: nowrap; flex-shrink: 0; vertical-align: baseline; }
.pill.on { background: var(--on-bg); color: var(--on-fg); }
.pill.off { background: var(--off-bg); color: var(--off-fg); }
.pill.warn { background: var(--warn-bg); color: var(--warn-fg); }
.pill.err { background: var(--err-bg); color: var(--err-fg); }

/* ---- tables ---- */
.table-card, .card { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.table-scroll { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th { position: sticky; top: 0; padding: 8px 12px; background: var(--head); border-bottom: 1px solid var(--border);
  text-align: left; font-weight: 500; color: var(--text-2); white-space: nowrap; }
.grid th a { color: inherit; text-decoration: none; display: block; }
.grid th a:hover { color: var(--ink); }
.grid th .arrow { margin-left: 4px; font-size: 11px; color: var(--accent); }
.field-code { display: block; font-family: var(--mono); font-size: 10px; font-weight: 400; color: var(--faint); }
.grid td { padding: 7px 12px; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid var(--row-line); }
.grid tbody tr { transition: background-color var(--ease); }
.grid tbody tr:hover { background: var(--row-hover); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid .num { text-align: right; font-family: var(--mono); }
.grid .mono { font-family: var(--mono); }
.grid th.num, .grid th.mono { font-family: var(--sans); }
table.list tbody tr { cursor: pointer; }
table.list td:first-child, table.list td:first-child a { color: var(--accent); font-weight: 500; text-decoration: none; }
.empty-result { padding: 32px; text-align: center; font-size: 13px; color: var(--muted); }
.table-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 12px; background: var(--foot);
  border-top: 1px solid var(--foot-line); font-size: 13px; color: var(--muted); }
.range { font-family: var(--mono); font-size: 12px; }
.pager { display: flex; align-items: center; gap: 4px; }
.page-of { padding: 0 10px; color: var(--ink); white-space: nowrap; }
.page-of b { font-weight: 600; }

/* ---- status message ---- */
.message { max-width: 640px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 4px;
  display: flex; flex-direction: column; gap: 10px; }
.message.err { background: #FBF3F1; border-color: #EBCFC8; }
.message-title { font-size: 14px; font-weight: 600; }
.message.err .message-title { color: var(--err-fg); }
.message-text { font-size: 13px; color: var(--text-2); }
.message-note { font-family: var(--mono); font-size: 11px; color: var(--faint); }

/* ---- record card ---- */
.rec-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 6px; }
.back { display: inline-flex; align-items: center; height: 28px; padding: 0 8px 0 4px; font-size: 13px; color: var(--accent); text-decoration: none; }
.back:hover { text-decoration: underline; }
.rec-pos { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.btn-pair { display: flex; gap: 4px; }
.rec-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px 16px; margin-bottom: 16px; }
.rec-head-main { flex: 1 1 320px; min-width: 0; }
.rec-head h1 { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; overflow-wrap: anywhere; }
.rec-sub { margin: 4px 0 0; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.rec-toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.rec-toggles .toggle { height: 32px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); gap: 12px; align-items: start; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding: 10px 14px; border-bottom: 1px solid var(--row-line); }
.card-tab { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.card-hidden { font-size: 12px; color: var(--faint); white-space: nowrap; }
.fields { margin: 0; padding: 8px 14px 10px; }
.field { display: grid; grid-template-columns: minmax(110px, 42%) minmax(0, 1fr); gap: 12px; align-items: baseline; padding: 5px 0;
  border-bottom: 1px solid var(--field-line); }
.field:last-child { border-bottom: 0; }
.field dt { margin: 0; font-size: 12px; color: var(--muted); }
.field dd { margin: 0; font-size: 13px; overflow-wrap: anywhere; white-space: pre-wrap; }
.field dd.mono { font-family: var(--mono); }
.field .none { color: var(--placeholder); }
.fields-card.wide { grid-column: 1 / -1; }
.fields-card.wide .fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); column-gap: 24px; }
.fields-card.wide .field:last-child { border-bottom: 1px solid var(--field-line); }
.matrix-card { margin-top: 12px; }
.matrix-card .card-head { align-items: center; }
.after-matrix { margin-top: 12px; }
.grid.matrix th { padding: 6px 12px 8px; }
.grid.matrix .group-row th { padding: 6px 12px 0; border-bottom: 0; font-size: 11px; font-weight: 500; color: var(--accent); }
.grid .gstart { border-left: 1px solid var(--border); }
.grid td.warn { color: var(--warn-fg); }
.grid tfoot td { background: var(--foot); border-top: 1px solid var(--foot-line); border-bottom: 0; font-family: var(--mono); font-weight: 500; }
.grid tfoot td:first-child { font-family: var(--sans); }
.grid.backup td { white-space: pre; font-family: var(--mono); font-size: 12px; }

/* matrix view switch (radio inputs, no JS) */
.mview { position: absolute; opacity: 0; pointer-events: none; }
.segmented { display: inline-flex; padding: 2px; background: var(--page); border-radius: 3px; flex-shrink: 0; }
.seg { display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: 3px; font-size: 12px; color: var(--muted);
  cursor: pointer; white-space: nowrap; transition: background-color var(--ease); }
.mview-main:checked ~ .card-head .seg-main,
.mview-full:checked ~ .card-head .seg-full { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.mview-main:focus-visible ~ .card-head .seg-main,
.mview-full:focus-visible ~ .card-head .seg-full { outline: 2px solid var(--accent); }
.mview-main:checked ~ .mtable-full,
.mview-full:checked ~ .mtable-main { display: none; }

/* ---- login ---- */
.login { max-width: 340px; margin: 60px auto; padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { font-size: 20px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.login input { height: 34px; padding: 0 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 3px;
  font-size: 13px; color: var(--ink); outline: none; }
.login input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(29, 94, 88, .12); }
.form-error { margin: 0; padding: 8px 10px; background: var(--err-bg); color: var(--err-fg); border-radius: 3px; font-size: 13px; }

/* ---- narrow screens ---- */
@media (max-width: 1100px) {
  .updated, .ro-pill { display: none; }
}
@media (max-width: 800px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .nav-toggle { display: inline-flex; align-items: center; }
  .brand-sub, .topbar-sep, .user-name { display: none; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; position: fixed; top: 48px; left: 0; bottom: 0; width: min(300px, 86vw); height: auto; z-index: 9;
    box-shadow: 0 8px 24px rgba(23, 33, 30, .16); }
  body.nav-open .sidebar { display: flex; }
  .main, .page { padding: 16px 16px 24px; }
}
