/* RCT Portal. Colour tokens: dark is the default; light follows the OS or the toggle (html[data-theme]). */
:root {
  color-scheme: dark;
  --plane: #0d0d0d; --surface: #1a1a19; --surface-2: #222221; --surface-3: #2c2c2a;
  --border: rgba(255, 255, 255, .10); --text: #ffffff; --text-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835;
  --s1: #3987e5; --s2: #d95926; --s1-soft: rgba(57, 135, 229, .16);
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --crit: #d03b3b;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --plane: #f9f9f7; --surface: #fcfcfb; --surface-2: #f3f2ee; --surface-3: #e9e8e2;
    --border: rgba(11, 11, 11, .10); --text: #0b0b0b; --text-2: #52514e; --muted: #898781;
    --grid: #e1e0d9; --axis: #c3c2b7;
    --s1: #2a78d6; --s2: #eb6834; --s1-soft: rgba(42, 120, 214, .12);
    --shadow: 0 10px 30px rgba(11, 11, 11, .12);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --plane: #f9f9f7; --surface: #fcfcfb; --surface-2: #f3f2ee; --surface-3: #e9e8e2;
  --border: rgba(11, 11, 11, .10); --text: #0b0b0b; --text-2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7;
  --s1: #2a78d6; --s2: #eb6834; --s1-soft: rgba(42, 120, 214, .12);
  --shadow: 0 10px 30px rgba(11, 11, 11, .12);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--plane); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

/* ---------- brand, login ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #3987e5, #1c5cab); box-shadow: 0 4px 14px rgba(57, 135, 229, .35); }
.brand-name { font-weight: 650; font-size: 16px; letter-spacing: .01em; }
.login { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(900px 500px at 50% -10%, var(--s1-soft), transparent 70%), var(--plane); }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-sub { color: var(--text-2); margin-bottom: 4px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--text-2); }
.form-error { color: var(--serious); font-size: 13px; min-height: 18px; }

input, select { background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; outline: none; min-width: 0; }
input:focus, select:focus { border-color: var(--s1); box-shadow: 0 0 0 3px var(--s1-soft); }
.btn { border: 1px solid var(--border); background: var(--surface-2); border-radius: 9px; padding: 8px 14px; cursor: pointer; }
a.btn { text-decoration: none; display: inline-block; }
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--s1); border-color: transparent; color: #fff; font-weight: 600; padding: 10px 14px; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.link { border: 0; background: none; color: var(--s1); padding: 0; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100%; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; padding: 18px 12px; border-right: 1px solid var(--border); background: var(--surface); }
.side .brand { padding: 2px 8px 6px; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 9px; color: var(--text-2); text-decoration: none; font-weight: 500; }
.nav a svg, .icon-btn svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--s1-soft); color: var(--text); }
.nav a.on svg { color: var(--s1); }
.nav .count { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.side-foot { margin-top: auto; display: grid; gap: 10px; }
.fresh { font-size: 12px; color: var(--muted); padding: 0 8px; display: grid; gap: 2px; }
.fresh b { color: var(--text-2); font-weight: 500; }
.user-row { display: flex; align-items: center; gap: 6px; padding: 8px; border-top: 1px solid var(--border); }
.user-name { flex: 1; min-width: 0; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: 0; background: none; padding: 7px; border-radius: 8px; cursor: pointer; color: var(--text-2); display: grid; }
.lang-btn { font-size: 12px; font-weight: 600; letter-spacing: .04em; }
.login-lang { justify-self: center; font-size: 12.5px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.main { min-width: 0; }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 14px 28px; background: color-mix(in srgb, var(--plane) 86%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.top h1 { font-size: 20px; font-weight: 650; flex: 1; }
.search input { width: min(380px, 42vw); }
.page { padding: 22px 28px 60px; display: grid; gap: 18px; animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- building blocks ---------- */
.grid { display: grid; gap: 14px; }
.g-tiles { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.g-stages { grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (max-width: 1180px) { .g-stages { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .g-stages { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.g-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; min-width: 0; }
.card h2 { font-size: 14px; font-weight: 600; }
.card-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.card-head .right { margin-left: auto; }

.tile { display: grid; gap: 4px; align-content: start; }
button.tile { text-align: left; cursor: pointer; }
button.tile:hover { border-color: color-mix(in srgb, var(--s1) 55%, var(--border)); }
.tile.on { border-color: var(--s1); box-shadow: inset 0 0 0 1px var(--s1); }
.tile .label { color: var(--text-2); font-size: 13px; }
.tile .value { font-size: 28px; font-weight: 650; line-height: 1.15; }
.tile .note { color: var(--muted); font-size: 12.5px; }
.meter { height: 8px; border-radius: 4px; background: var(--s1-soft); overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; background: var(--s1); border-radius: 4px 0 0 4px; }

.list { display: grid; }
.row { padding: 10px 0; border-top: 1px solid var(--border); display: grid; gap: 2px; }
.row:first-child { border-top: 0; padding-top: 2px; }
.row .what { font-weight: 550; }
.row .why { color: var(--text-2); font-size: 13px; }
.clickable { cursor: pointer; }
.clickable:hover .what, tr.clickable:hover td { color: var(--s1); }
.meta { color: var(--muted); font-size: 12.5px; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); white-space: nowrap; }
.chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.chip.accent i { background: var(--s1); }
.chip.good i { background: var(--good); } .chip.warn i { background: var(--warn); }
.chip.serious i { background: var(--serious); } .chip.crit i { background: var(--crit); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input[type="search"] { flex: 1 1 220px; }
.filters select { max-width: 240px; }
.filters .count { margin-left: auto; color: var(--muted); font-size: 12.5px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 6px 11px; border-radius: 7px; cursor: pointer; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }

.table-wrap { overflow-x: auto; margin: 0 -18px -6px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
td .sub { color: var(--muted); font-size: 12.5px; }
td.wide { min-width: 190px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.more { display: flex; justify-content: center; padding-top: 12px; }

/* ---------- charts ---------- */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .band { fill: transparent; }
.chart .band:hover { fill: var(--s1-soft); }
.hbars { display: grid; gap: 9px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hbar .track { display: flex; gap: 2px; height: 12px; }
.hbar .track i { display: block; height: 100%; min-width: 2px; }
.hbar .track i:last-child { border-radius: 0 4px 4px 0; }
.hbar .val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface-3); border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; font-size: 12.5px; box-shadow: var(--shadow); max-width: 280px; }
.tip b { display: block; margin-bottom: 3px; }
.tip span { display: flex; align-items: center; gap: 6px; color: var(--text-2); }
.tip i { width: 8px; height: 8px; border-radius: 2px; }

/* ---------- forms (procurement record) ---------- */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form label { display: grid; gap: 5px; font-size: 12.5px; color: var(--text-2); min-width: 0; }
.form .full { grid-column: 1 / -1; }
.form .pair { display: grid; grid-template-columns: 1fr 86px; gap: 6px; }
.form .actions { display: flex; align-items: center; gap: 12px; }
textarea { font: inherit; color: inherit; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; outline: none; resize: vertical; }
textarea:focus { border-color: var(--s1); box-shadow: 0 0 0 3px var(--s1-soft); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.pick { display: inline-flex; align-items: center; gap: 8px; padding: 5px 10px 5px 5px; border-radius: 999px; background: none; }
.btn.pick .chip { border: 0; background: none; padding-right: 0; }
.btn.pick b { font-variant-numeric: tabular-nums; }
.btn.pick.on { border-color: var(--s1); box-shadow: inset 0 0 0 1px var(--s1); }
.linkish { color: var(--s1); cursor: pointer; }
@media (max-width: 480px) { .form { grid-template-columns: 1fr; } }

/* ---------- order drawer ---------- */
.drawer-wrap { position: fixed; inset: 0; z-index: 20; }
.drawer-shade { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); }
.drawer { position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--surface); border-left: 1px solid var(--border); padding: 20px 22px 40px; overflow: auto; box-shadow: var(--shadow); animation: slide .2s ease-out; display: grid; gap: 16px; align-content: start; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer h2 { font-size: 20px; }
.drawer h3 { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.steps { display: grid; }
.step { display: grid; grid-template-columns: 18px 1fr; gap: 10px; padding-bottom: 14px; position: relative; }
.step::before { content: ""; position: absolute; left: 8px; top: 16px; bottom: 0; width: 2px; background: var(--axis); }
.step:last-child::before { display: none; }
.step .dot { width: 12px; height: 12px; border-radius: 50%; margin: 4px 3px; background: var(--s1); box-shadow: 0 0 0 2px var(--surface); position: relative; }
.step.wait .dot { background: var(--surface); border: 2px solid var(--muted); }
.step.bad .dot { background: var(--crit); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; gap: 8px; padding: 8px 10px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .side .brand-name, .fresh, .user-name, .nav .count { display: none; }
  .nav { display: flex; }
  .nav a span { display: none; }
  .side-foot { margin: 0 0 0 auto; }
  .user-row { border: 0; padding: 0; }
  .top { padding: 10px 16px; }
  .page { padding: 16px 16px 50px; }
  .search input { width: 44vw; }
  .table-wrap { margin: 0 -18px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
