:root{
  --bg:#f4f6f9; --panel:#ffffff; --border:#d7dde5; --muted:#6b7785;
  --text:#1f2933; --accent:#2563eb; --accent-dark:#1d4ed8;
  --ok:#16a34a; --warn:#d97706; --danger:#dc2626;
  --planned:#0ea5e9; --in_progress:#d97706; --produced:#16a34a; --cancelled:#9ca3af;
  --radius:8px; --shadow:0 1px 3px rgba(16,24,40,.08);
}
*{box-sizing:border-box}
body{margin:0;font-family:-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;
  background:var(--bg);color:var(--text);font-size:14px;line-height:1.45}
a{color:var(--accent);text-decoration:none}
a:hover{text-decoration:underline}

/* Layout */
.topbar{display:flex;align-items:center;gap:18px;background:#0f172a;color:#e2e8f0;
  padding:0 18px;height:52px;position:sticky;top:0;z-index:50}
.topbar .brand{font-weight:700;color:#fff;letter-spacing:.3px}
.topbar nav{display:flex;gap:4px;flex:1}
.topbar nav a{color:#cbd5e1;padding:8px 12px;border-radius:6px;font-weight:500}
.topbar nav a:hover{background:#1e293b;text-decoration:none}
.topbar nav a.active{background:var(--accent);color:#fff}
.topbar .user{display:flex;align-items:center;gap:10px;color:#cbd5e1;font-size:13px}
.topbar .role-badge{background:#1e293b;padding:3px 8px;border-radius:12px;font-size:12px}
.container{max-width:1400px;margin:0 auto;padding:18px}

/* Buttons / inputs */
.btn{display:inline-flex;align-items:center;gap:6px;background:var(--accent);color:#fff;
  border:none;border-radius:6px;padding:8px 14px;font-size:14px;cursor:pointer;font-weight:500}
.btn:hover{background:var(--accent-dark);text-decoration:none;color:#fff}
.btn.secondary{background:#e5e9f0;color:#1f2933}
.btn.secondary:hover{background:#d7dde5}
.btn.danger{background:var(--danger)}
.btn.ghost{background:transparent;color:var(--accent);border:1px solid var(--border)}
.btn.sm{padding:5px 10px;font-size:13px}
.btn:disabled{opacity:.5;cursor:not-allowed}
.input,select.input,textarea.input{width:100%;padding:8px 10px;border:1px solid var(--border);
  border-radius:6px;font-size:14px;background:#fff}
.input:disabled{background:#f1f3f6;color:#7a8694}
label{font-weight:600;font-size:13px;color:#3a4654;display:block;margin-bottom:4px}

/* Cards / panels */
.panel{background:var(--panel);border:1px solid var(--border);border-radius:var(--radius);
  box-shadow:var(--shadow)}
.toolbar{display:flex;gap:10px;align-items:center;margin-bottom:14px;flex-wrap:wrap}
.toolbar .spacer{flex:1}

/* Table */
table.grid{width:100%;border-collapse:collapse;background:#fff}
table.grid th,table.grid td{padding:8px 10px;border-bottom:1px solid var(--border);
  text-align:left;vertical-align:top}
table.grid th{background:#eef2f7;font-size:12px;text-transform:uppercase;color:#54616e;
  letter-spacing:.4px}
table.grid tbody tr{cursor:pointer}
/* Orders table: fixed column widths (via colgroup) so filter fields and
   columns never shift when a filter narrows the result set. Cell content
   wraps within its column. */
table.orders-grid{table-layout:fixed}
table.orders-grid td{overflow-wrap:anywhere}
/* Order number (col 8) stays on one line — РЭ-000001 must not break. */
table.orders-grid td:nth-child(8){overflow-wrap:normal;white-space:nowrap}
/* Custom filter autocomplete: the input keeps its column width, but the
   suggestions dropdown auto-sizes to the longest option (native <datalist>
   can't — its width is locked to the input and it truncates). */
.filter-combo{position:relative}
.filter-options{position:absolute;top:100%;left:0;z-index:40;margin-top:2px;
  width:max-content;min-width:100%;max-width:520px;background:#fff;
  border:1px solid var(--border);border-radius:6px;box-shadow:0 6px 18px rgba(16,24,40,.16);
  max-height:280px;overflow:auto}
.filter-options:empty{display:none}
.filter-option{display:block;width:100%;text-align:left;background:none;border:0;
  border-bottom:1px solid #eef1f5;padding:7px 10px;cursor:pointer;font-size:13px;
  white-space:nowrap;text-transform:none;letter-spacing:0;color:var(--text)}
.filter-option:last-child{border-bottom:0}
.filter-option:hover{background:#eff6ff}
.filter-combo .input{padding-right:24px}
.filter-clear{position:absolute;right:3px;top:50%;transform:translateY(-50%);z-index:5;
  border:0;background:none;cursor:pointer;color:#9aa3af;font-size:12px;line-height:1;padding:2px 4px}
.filter-clear:hover{color:var(--danger)}
/* Row tint by status (TЗ UX). Hover/selected below override via higher specificity. */
table.grid tbody tr.row-planned td{background:#eff6ff}
table.grid tbody tr.row-in_progress td{background:#fff7ed}
table.grid tbody tr.row-produced td{background:#f0fdf4}
table.grid tbody tr.row-cancelled td{background:#f4f5f7;color:#8a929c}
table.grid tbody tr.order-row:hover td{background:#e0ecff}
table.grid tbody tr.order-row.selected td{background:#cfe0fb}
.org-list{white-space:pre-line;font-size:13px}

/* Forecast-date deadline proximity */
.due-soon{color:#ea580c;font-weight:700}
.due-month{color:#2563eb;font-weight:700}

/* Per-column filter row */
table.grid thead tr.filter-row th{background:#f6f8fb;padding:4px 6px}
table.grid thead tr.filter-row .input{padding:4px 7px;font-size:12px;font-weight:400;
  text-transform:none;letter-spacing:0;color:var(--text)}
.date-range{display:flex;flex-direction:column;gap:3px}

/* Status pill / select */
.status{display:inline-block;padding:3px 9px;border-radius:12px;color:#fff;font-size:12px;font-weight:600}
.status.planned{background:var(--planned)}
.status.in_progress{background:var(--in_progress)}
.status.produced{background:var(--produced)}
.status.cancelled{background:var(--cancelled)}
select.status-select{border-radius:12px;border:1px solid var(--border);padding:3px 8px;font-size:12px;font-weight:600}

/* Messages */
.messages{list-style:none;padding:0;margin:0 0 14px}
.messages li{padding:10px 14px;border-radius:6px;margin-bottom:8px;border:1px solid}
.messages li.success{background:#ecfdf5;border-color:#a7f3d0;color:#065f46}
.messages li.error{background:#fef2f2;border-color:#fecaca;color:#991b1b}
.messages li.info{background:#eff6ff;border-color:#bfdbfe;color:#1e40af}
.messages li.warning{background:#fffbeb;border-color:#fde68a;color:#92400e}

/* Inline edit card (expanded under a table row) */
#card-detail-row{cursor:default}
#card-detail-row td.detail-cell{padding:10px;background:#e9eef5}
.detail-cell .card-section{margin-bottom:10px}
.detail-cell .card-section:last-child{margin-bottom:0}
.card-head{display:flex;justify-content:space-between;align-items:center;gap:10px}

/* Bottom block (card) */
.card-block{margin-top:16px}
.card-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:14px}
.card-section{padding:16px}
.card-section h3{margin:0 0 12px;font-size:15px;border-bottom:1px solid var(--border);padding-bottom:8px}
.field{margin-bottom:12px}
.field .hint{font-size:12px;color:var(--muted);margin-top:3px}
.field .lookup-result{font-size:13px;margin-top:4px;color:#0f5132}
.field .lookup-result.err{color:var(--danger)}
.readonly-value{padding:8px 10px;background:#f1f3f6;border:1px dashed var(--border);border-radius:6px;color:#54616e}
.errorlist{list-style:none;padding:0;margin:4px 0 0;color:var(--danger);font-size:12px}

/* Participants widget */
.participant-row{margin-bottom:8px}
.prow-line{display:flex;gap:8px;align-items:center}
.prow-line .input{flex:1}

/* Organization combobox dropdown */
.org-combo{position:relative}
.org-line{display:flex;gap:8px;align-items:center}
.org-line .input,.org-line .org-link{flex:1;min-width:0}
.org-link{padding:8px 10px;border:1px solid var(--border);border-radius:6px;background:#f1f3f6;
  text-decoration:none;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.org-link:hover{color:var(--accent);text-decoration:underline}
.org-cell-link{color:var(--text);text-decoration:none}
.org-cell-link:hover{color:var(--accent);text-decoration:underline}
.sort-link{color:inherit;text-decoration:none}
.sort-link:hover{color:var(--accent)}
.org-options{position:absolute;top:100%;left:0;right:0;z-index:40;background:#fff;
  border:1px solid var(--border);border-radius:6px;box-shadow:0 6px 18px rgba(16,24,40,.14);
  max-height:240px;overflow:auto;margin-top:2px}
.org-options:empty{display:none}
.org-option{display:flex;flex-direction:column;align-items:flex-start;gap:1px;width:100%;
  text-align:left;background:none;border:0;border-bottom:1px solid #eef1f5;
  padding:7px 10px;cursor:pointer;font-size:13px}
.org-option:last-child{border-bottom:0}
.org-option:hover,.org-option:focus{background:#eff6ff}
.org-option .oo-name{font-weight:600}
.org-option-msg{padding:8px 10px;font-size:13px}
.org-option-msg.err{color:var(--danger)}
/* Distributor combo reads as a dropdown: chevron caret + pointer, still typeable. */
[data-distributor-combo] .org-search{
  cursor:pointer;padding-right:30px;
  background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%236b7280' stroke-width='1.6' d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");
  background-repeat:no-repeat;background-position:right 10px center}
/* Branch (КПП) choice on adding a distributor. */
.org-choice-list{display:flex;flex-direction:column;gap:6px;margin-top:4px}
.org-choice{display:flex;gap:10px;align-items:flex-start;padding:10px;border:1px solid var(--border);
  border-radius:6px;cursor:pointer}
.org-choice:hover{background:#eff6ff;border-color:var(--accent)}
.org-choice input{margin-top:3px}

/* Kanban */
.kanban{display:grid;grid-template-columns:repeat(4,1fr);gap:14px;align-items:start}
.kanban .column{background:#eef2f7;border-radius:var(--radius);padding:10px;min-height:200px}
.kanban .column h4{margin:0 0 10px;font-size:13px;text-transform:uppercase;color:#54616e;display:flex;justify-content:space-between}
/* The sortable drop target is .cards — give it height so empty columns accept drops */
.kanban .cards{min-height:140px}
.kanban .kcard{background:#fff;border:1px solid var(--border);border-radius:6px;padding:10px;margin-bottom:8px;
  box-shadow:var(--shadow);cursor:grab}
.kanban .kcard .num{font-weight:700}
.kanban .kcard .meta{font-size:12px;color:#54616e;margin-top:4px}
.kanban .column.locked .kcard{cursor:default}
.kanban .kcard.sel{outline:2px solid var(--accent);outline-offset:1px}
.sortable-ghost{opacity:.4}
.kanban-filters{flex-wrap:wrap;gap:8px;background:#fff;border:1px solid var(--border);border-radius:var(--radius);padding:10px;margin-bottom:14px}
.kanban-filters .input{max-width:190px}
.kanban-filters input[type=date].input{max-width:150px}
.check-inline{display:inline-flex;align-items:center;gap:6px;font-weight:500;font-size:13px;margin:0;cursor:pointer}
.saved-note{color:var(--ok);font-weight:600;font-size:13px}
.pager{display:flex;align-items:center;gap:10px;margin-top:12px;flex-wrap:wrap}
.mgr-blocked{color:var(--danger);font-weight:700;cursor:help}

/* History */
.history{font-size:13px;max-height:280px;overflow:auto}
.history table{width:100%;border-collapse:collapse}
.history td,.history th{padding:5px 8px;border-bottom:1px solid var(--border);text-align:left}

/* Misc */
.muted{color:var(--muted)}
.file-link{font-weight:600}
.row-actions{display:flex;gap:6px}
.login-wrap{max-width:360px;margin:8vh auto;padding:28px}
.login-wrap h1{font-size:20px;margin:0 0 18px;text-align:center}
.idle-banner{display:none}
