/* KT — light theme on CRM 2.0 tokens (reference/crmnew app.css), sidebar shell, mobile first. */
:root {
  --ink: #1C232B; --ink-2: #4A5561; --muted: #5B6673; --faint: #9AA5B1;
  --line: #DCE2E8; --line-soft: #EDF0F3; --field: #CBD3DB;
  --paper: #FFFFFF; --ground: #F2F4F7; --sunk: #F4F6F8;
  --blue: #0057B8; --blue-dark: #00408A; --blue-soft: #EAF2FC; --blue-ink: #003F87;
  --green: #4F7A3A; --green-soft: #EAF2E4;
  --signal: #FFC400; --signal-soft: #FFF1BF; --signal-ink: #5E4A00;
  --ok: #2F7D4E; --ok-soft: #DDEFE3; --ok-ink: #1F5E36;
  --alert: #C62828; --alert-soft: #FBE1E1; --alert-ink: #9B1C1C;
  --radius: 12px; --radius-s: 8px;
  --font: 'Onest', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --side-w: 240px; --top-h: 56px;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.45; color: var(--ink); background: var(--ground); -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-dark); }
button, input, select, textarea { font: inherit; color: inherit; }
svg { flex: none; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 18px; margin-top: 8px; } h3 { font-size: 16px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.center { text-align: center; }
[x-cloak], [hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- shell: phone first ---------- */
.topbar { position: sticky; top: 0; z-index: 20; height: var(--top-h); display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--paper); border-bottom: 1px solid var(--line); }
.topbar-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell { display: flex; min-height: calc(100dvh - var(--top-h)); }
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(86vw, 300px); background: var(--paper); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; transform: translateX(-100%); transition: transform .18s ease; padding-bottom: env(safe-area-inset-bottom);
}
.menu-open .sidebar { transform: none; box-shadow: 0 18px 48px rgba(28, 35, 43, .2); }
.scrim { display: none; }
.menu-open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(28, 35, 43, .35); }
.brand { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: var(--green); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }
.brand-name { flex: 1; font-weight: 600; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; }
.side-nav { flex: 1; overflow-y: auto; padding: 4px 8px; display: flex; flex-direction: column; gap: 2px; }
.side-nav a { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 10px; color: var(--ink-2); }
.side-nav a:hover { background: var(--sunk); color: var(--ink); }
.side-nav a.on { background: var(--blue-soft); color: var(--blue-ink); font-weight: 600; }
.side-group { margin: 14px 12px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 600; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line-soft); }
.side-user-name { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.side-user-name b { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-name small { color: var(--muted); font-size: 12px; }
.avatar { width: 36px; height: 36px; border-radius: 18px; background: #DCE8F7; color: var(--blue-ink); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex: none; }
.main { flex: 1; min-width: 0; }
.page { padding: 16px 12px 32px; display: flex; flex-direction: column; gap: 14px; max-width: 1100px; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grow { flex: 1; }
.only-phone { display: inline-flex; }
.hide-phone { display: none; }

@media (min-width: 900px) {
  .topbar { display: none; }
  .shell { min-height: 100dvh; }
  .sidebar { position: sticky; top: 0; height: 100dvh; width: var(--side-w); transform: none; flex: none; }
  .menu-open .sidebar { box-shadow: none; }
  .menu-open .scrim { display: none; }
  .only-phone { display: none; }
  .hide-phone { display: table-cell; }
  .page { padding: 24px 28px 40px; }
  h1 { font-size: 24px; }
}

/* ---------- impersonation banner ---------- */
.imp-banner { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; padding: 8px 12px; background: var(--signal); color: var(--signal-ink); font-weight: 600; font-size: 14px; }
.imp-banner form { margin: 0; }
.muted-inv { font-weight: 400; opacity: .8; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 9px; border: 1px solid var(--field); background: #fff; color: var(--ink); font-weight: 500; white-space: nowrap; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--sunk); color: var(--ink); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { color: var(--alert); }
.btn-apple { background: #000; border-color: #000; color: #fff; }
.btn-apple:hover { background: #222; color: #fff; }
.btn-s { height: 32px; padding: 0 12px; font-size: 14px; }
.btn-lg { height: 48px; font-size: 16px; }
.btn-block { width: 100%; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 9px; border: 1px solid var(--field); background: #fff; color: var(--ink); cursor: pointer; }
.icon-btn:hover { background: var(--sunk); }
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 11px; background: var(--sunk); color: var(--ink-2); font-size: 12px; font-weight: 600; }
.badge-ok { background: var(--ok-soft); color: var(--ok-ink); }

.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.empty { padding: 28px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.error-code { font-size: 44px; font-weight: 700; color: var(--faint); }
.flash { margin: 12px 12px 0; padding: 10px 14px; border-radius: var(--radius-s); background: var(--ok-soft); color: var(--ok-ink); }
.flash-error { background: var(--alert-soft); color: var(--alert-ink); margin: 0; }
@media (min-width: 900px) { .flash:not(.flash-error) { margin: 20px 28px 0; max-width: 1044px; } }

.form { display: flex; flex-direction: column; gap: 14px; }
.card.form { padding: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 700px) { .form-grid { grid-template-columns: 1fr 1fr; } .span-all { grid-column: 1 / -1; } }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0; border: 0; padding: 0; min-width: 0; }
.field > span { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.field input, .field select, select, textarea { height: 44px; padding: 0 12px; border: 1px solid var(--field); border-radius: var(--radius-s); background: #fff; width: 100%; }
.field input:focus, select:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-soft); }
.field-error { color: var(--alert); font-size: 13px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 32px; cursor: pointer; }
.check input { width: 18px; height: 18px; }
.checks { gap: 2px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.dim td { opacity: .55; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions form { display: inline-block; margin: 2px 0 2px 6px; }
.table select { height: 36px; min-width: 140px; }
.inline { margin: 0; }

.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); margin: 0; }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { display: flex; flex-direction: column; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 6px; padding: 16px; color: var(--ink); min-height: 110px; }
.tile svg { color: var(--green); }
.tile:hover { border-color: var(--blue); color: var(--ink); }
.req-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.req { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; color: var(--ink); }
.req:hover { border-color: var(--blue); color: var(--ink); }
.module-card { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; cursor: pointer; }
.module-card input { width: 20px; height: 20px; margin-top: 2px; }
.module-card span { display: flex; flex-direction: column; gap: 2px; }
.roles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.perm-group { display: flex; flex-direction: column; }
.or { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 13px; margin: 6px 0; }
.or::before, .or::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.stub { padding: 32px 20px; text-align: center; color: var(--muted); }

/* ---------- bare pages ---------- */
.bare-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; padding: 24px 20px; display: flex; flex-direction: column; gap: 14px; }
.auth-brand { font-weight: 700; color: var(--green); }
.bare .page { width: 100%; max-width: 440px; }

/* ---------- CRM: filters, counters, statuses, timeline, order items, print ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; color: var(--ink); }
.stat b { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat:hover { border-color: var(--blue); color: var(--ink); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input, .filters select { height: 40px; width: auto; flex: 1 1 140px; min-width: 0; }
.filters .btn { flex: none; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
.chip { display: inline-flex; align-items: center; height: 32px; padding: 0 12px; border-radius: 16px; border: 1px solid var(--line); background: var(--paper); color: var(--ink-2); white-space: nowrap; font-size: 14px; }
.chip.on { background: var(--blue-soft); border-color: var(--blue-soft); color: var(--blue-ink); font-weight: 600; }
.st { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 600; background: var(--sunk); color: var(--ink-2); white-space: nowrap; }
.st-new { background: var(--blue-soft); color: var(--blue-ink); }
.st-work, .st-quote, .st-confirmed, .st-production { background: var(--signal-soft); color: var(--signal-ink); }
.st-ready, .st-shipped, .st-converted, .st-closed { background: var(--ok-soft); color: var(--ok-ink); }
.st-lost, .st-cancelled { background: var(--alert-soft); color: var(--alert-ink); }
.row-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--muted); }
.list-row .end { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.overdue { color: var(--alert); font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 10px 12px; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--blue-ink); border-color: var(--blue); font-weight: 600; }
.kv { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: 6px 12px; padding: 14px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 14px; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.actions-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.actions-bar form { margin: 0; }
textarea { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; }
details.card > summary { padding: 14px 16px; cursor: pointer; font-weight: 600; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { border-bottom: 1px solid var(--line-soft); }
details.card > .form { padding: 16px; }
.pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 2px 12px; max-height: 260px; overflow-y: auto; }
.timeline { display: flex; flex-direction: column; }
.tl { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); }
.tl:last-child { border-bottom: 0; }
.tl p { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.tl-system p, .tl-status p { color: var(--muted); font-size: 14px; }
.items { display: flex; flex-direction: column; }
.item { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); margin: 0; }
.item .item-name { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; }
.item .item-name input { flex: 1; }
.item input, .item select { height: 40px; width: 100%; min-width: 0; padding: 0 8px; border: 1px solid var(--field); border-radius: var(--radius-s); background: #fff; }
.item label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); min-width: 0; }
.item .item-sum { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; }
.items-total { display: flex; justify-content: flex-end; gap: 12px; padding: 14px; font-size: 18px; }
@media (min-width: 900px) {
  .item { grid-template-columns: 3fr 90px 90px 110px 80px 130px; align-items: end; }
  .item .item-name, .item .item-sum { grid-column: auto; }
}
.attr-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 700px) { .attr-grid { grid-template-columns: 1fr 1fr; } }
.print { background: #fff; max-width: 800px; margin: 0 auto; padding: 24px 16px; }
.print h1 { font-size: 20px; margin-bottom: 8px; }
.print .table td, .print .table th { padding: 6px 8px; border: 1px solid var(--line); }
.print .table .r { text-align: right; white-space: nowrap; }
@media print { .no-print { display: none !important; } body { background: #fff; } .print { padding: 0; } }
.filters input, .list-row input:not([type=checkbox]) { height: 40px; padding: 0 12px; border: 1px solid var(--field); border-radius: var(--radius-s); background: #fff; }
.filters input:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-soft); }
.input-s { max-width: 80px; }
