:root {
  --bg: #f4f4f2; --surface: #ffffff; --surface-2: #eeeeeb; --text: #1e2125; --muted: #5c636d; --border: #d9dadd;
  --accent: #1d5c87; --accent-text: #ffffff; --accent-soft: #e3eef6;
  --red: #b3261e; --red-soft: #fbe4e2; --amber: #8a5300; --amber-soft: #fcecc8; --green: #1e6b3a; --green-soft: #dff1e4;
  --agent: #5b3e96; --agent-soft: #ece6f7; --focus: #1d5c87;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131519; --surface: #1b1e23; --surface-2: #242830; --text: #e4e6ea; --muted: #9aa1ac; --border: #343942;
    --accent: #6aaad6; --accent-text: #0f1a22; --accent-soft: #1f3040;
    --red: #f09a93; --red-soft: #3d1f1d; --amber: #f0c06a; --amber-soft: #3b2d10; --green: #80cf9a; --green-soft: #1b3324;
    --agent: #bda4ee; --agent-soft: #2f2548; --focus: #6aaad6;
  }
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.45; font-size: 0.9375rem; }
h1 { font-size: 1.5rem; margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; font-weight: 650; }
h3 { font-size: .95rem; margin: 1.4rem 0 .5rem; font-weight: 650; }
h4 { font-size: .85rem; margin: .9rem 0 .3rem; color: var(--muted); font-weight: 600; text-transform: none; }
p { margin: 0 0 .6rem; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); } .small { font-size: .8125rem; } .r { text-align: right; } .neg { color: var(--red); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }
.noscript { padding: 1rem; }

/* shell */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 1.25rem; padding: 1.25rem 1rem; background: var(--surface); border-right: 1px solid var(--border); }
.brand { font-weight: 700; letter-spacing: .01em; padding: 0 .5rem; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a { padding: .5rem .6rem; border-radius: var(--radius); color: var(--text); text-decoration: none; }
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.main { min-width: 0; padding: 1.5rem 2rem 4rem; max-width: 1200px; width: 100%; outline: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-actions { display: flex; gap: .5rem; }

/* buttons & inputs */
.btn { font: inherit; padding: .45rem .85rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; min-height: 36px; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--red); border-color: var(--red); color: var(--surface); font-weight: 600; }
.btn-danger:hover { background: var(--red); filter: brightness(1.1); }
.btn-danger-text { color: var(--red); }
.btn-quiet { border-color: transparent; background: transparent; }
.btn-small { padding: .2rem .55rem; min-height: 28px; font-size: .8125rem; margin-top: .3rem; }
.link-btn { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 2px; font-weight: 600; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], select, textarea {
  font: inherit; width: 100%; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); min-height: 36px;
}
input[type=file] { font: inherit; max-width: 100%; }
textarea { resize: vertical; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.lbl, .filter label { display: block; font-size: .8125rem; font-weight: 600; margin-bottom: .25rem; color: var(--muted); }
.req { color: var(--red); }
.hint { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1rem; }
.field.full { grid-column: 1 / -1; }
.field-bool { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.field-bool .lbl { margin: 0; color: var(--text); font-weight: 500; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.1rem; }
.form-error { background: var(--red-soft); color: var(--red); padding: .5rem .75rem; border-radius: var(--radius); margin-top: .8rem; font-size: .875rem; }
.form-error[hidden] { display: none; }
.feat-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: .4rem; margin-bottom: .4rem; }
.filters { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: 1rem; align-items: flex-end; }
.filter { min-width: 150px; } .filter.grow, .field.grow { flex: 1; min-width: 200px; }

/* cards, kpis */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.cols .wide { grid-column: 1 / -1; }
.stack { display: grid; gap: 1rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; }
.kpi-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 1.5rem; font-weight: 650; margin: .15rem 0; }
.kpi-sub { font-size: .78rem; color: var(--muted); }
.card-foot { margin: .75rem 0 0; font-size: .875rem; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; justify-content: space-between; gap: 1rem; align-items: center; padding: .55rem 0; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row-title { font-weight: 600; }
.row-tags { display: flex; gap: .35rem; flex-wrap: wrap; justify-content: flex-end; }
.empty { color: var(--muted); padding: .5rem 0; }
.error-box { background: var(--red-soft); color: var(--red); padding: 1rem; border-radius: var(--radius); }

/* badges */
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; border: 1px solid var(--border); }
.badge.actor-agent { background: var(--agent-soft); color: var(--agent); border-color: var(--agent); }
.badge.actor-user { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.st-active, .badge.ok, .badge.sst-done { background: var(--green-soft); color: var(--green); border-color: transparent; }
.badge.st-cancelled, .badge.warn { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.badge.sst-open { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.sst-rejected { background: var(--red-soft); color: var(--red); border-color: transparent; }
.badge.best { background: var(--green-soft); color: var(--green); border-color: transparent; }
.deadline { display: inline-flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.pill { font-size: .75rem; padding: .05rem .45rem; border-radius: 4px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.urg-red { background: var(--red-soft); color: var(--red); font-weight: 650; }
.pill.urg-amber { background: var(--amber-soft); color: var(--amber); font-weight: 650; }

/* tables */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .6rem .75rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: .6rem .75rem; border-top: 1px solid var(--border); vertical-align: top; }
table.data tbody tr:first-child td { border-top: 0; }
table.data th.r, table.data td.r { text-align: right; }
tr.row-best td { background: var(--green-soft); }
.chart { display: block; }
.chart-line { stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-dot { fill: var(--accent); } .chart-pt { fill: var(--surface); stroke: var(--accent); stroke-width: 1.5; }
.chart-zero { stroke: var(--border); stroke-dasharray: 3 3; }
.chart-axis { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart-large { max-width: 640px; height: auto; margin-bottom: .5rem; }

/* detail */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1.25rem; margin: .75rem 0; }
.facts dt { color: var(--muted); font-size: .85rem; } .facts dd { margin: 0; }
.facts.compact { margin: .25rem 0; }
.detail-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.cmp { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: 1rem; }
.cmp-head { display: flex; gap: .5rem; align-items: center; margin-bottom: .5rem; flex-wrap: wrap; }
.cmp .table-wrap { border-radius: 4px; }
.feat-list, .plain { margin: 0; padding-left: 1.1rem; } .plain { list-style: none; padding: 0; }
.doc-list { list-style: none; padding: 0; margin: 0 0 .75rem; } .doc-list li { padding: .3rem 0; border-top: 1px solid var(--border); display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.upload-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.src-link { word-break: break-all; font-weight: 600; }

/* suggestions + activity */
.cards { display: grid; gap: 1rem; }
.sug-head { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-bottom: .4rem; }
.sug h3 { margin: .2rem 0 .5rem; font-size: 1.05rem; }
.sug-actions { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; margin-top: 1rem; padding-top: .9rem; border-top: 1px solid var(--border); }
.btn-row { display: flex; gap: .5rem; }
.diff { list-style: none; margin: .3rem 0 0; padding: 0; font-size: .85rem; }
.diff-block { background: var(--surface-2); padding: .6rem .8rem; border-radius: var(--radius); font-size: .9rem; }
.diff-field { font-weight: 600; } .diff-old { color: var(--red); text-decoration: line-through; text-decoration-thickness: 1px; } .diff-new { color: var(--green); font-weight: 600; }
.diff-details summary { cursor: pointer; color: var(--muted); font-size: .8125rem; }
.act-list { list-style: none; margin: 0; padding: 0; }
.act { padding: .6rem 0; border-top: 1px solid var(--border); }
.act:first-child { border-top: 0; }
.act-head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.act-time { margin-left: auto; font-size: .78rem; }
.act-note { margin: .25rem 0 0; font-size: .875rem; }
.info ul { margin: 0 0 .5rem; padding-left: 1.1rem; } .info h3 { margin-top: .8rem; }

/* dialog */
.dlg { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); }
.dlg-wide { width: min(860px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgb(0 0 0 / .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .8rem 1.1rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dlg-head h2 { margin: 0; }
.dlg-body { padding: 1rem 1.1rem 1.2rem; }

/* login + toasts */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1.75rem; width: min(380px, 100%); display: grid; gap: .9rem; }
.toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 200; }
.toast { background: var(--text); color: var(--bg); padding: .6rem .9rem; border-radius: var(--radius); max-width: 360px; }
.toast-error { background: var(--red); color: var(--surface); }

/* mobile */
@media (max-width: 899px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; height: auto; z-index: 20; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .25rem .75rem; padding: .5rem .75rem; border-right: 0; border-bottom: 1px solid var(--border); }
  .nav { order: 3; flex-direction: row; flex: 1 1 100%; overflow-x: auto; gap: 2px; padding-bottom: 2px; }
  .nav a { white-space: nowrap; }
  .brand { flex: 1; }
  .main { padding: 1rem 1rem 3rem; }
  .cols { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .form-grid { grid-template-columns: 1fr; }
  .feat-row { grid-template-columns: 1fr 1fr; } .feat-row .btn { grid-column: 1 / -1; }
  .table-wrap { background: transparent; border: 0; overflow: visible; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.data tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .75rem; padding: .35rem .75rem; }
  table.data td { border: 0 !important; padding: .3rem 0; display: grid; grid-template-columns: 8.5rem 1fr; gap: .5rem; text-align: left !important; }
  table.data td::before { content: attr(data-label); color: var(--muted); font-size: .78rem; }
  .facts { grid-template-columns: 1fr; gap: 0; } .facts dd { margin-bottom: .45rem; }
  .row { flex-direction: column; align-items: flex-start; gap: .3rem; }
  .sug-actions { flex-direction: column; align-items: stretch; }
  .dlg { max-height: calc(100vh - 12px); }
  .page-head h1 { font-size: 1.3rem; }
}
@media (prefers-reduced-motion: no-preference) { .btn { transition: background-color .12s; } }

.offers { display: grid; gap: .6rem; margin-top: .5rem; }
.offer { border: 1px solid var(--border); border-radius: var(--radius); padding: .65rem .85rem; }
.offer-best { background: var(--green-soft); }
.offer-head { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.offer .facts { margin: .4rem 0; }
.offer-foot { display: flex; justify-content: space-between; gap: .75rem; align-items: center; flex-wrap: wrap; }
