/* macOS look: system font and colours, grouped sidebar, inset grouped tables.
   Themes: light by default, dark via <html data-theme="dark"> (toggle in the sidebar, remembered in the browser) */
:root {
  --bg: #ffffff;               /* window */
  --card: #f5f5f7;             /* grouped boxes */
  --field: #ffffff;            /* inputs, buttons, tiles inside a box */
  --border: #e3e3e8;
  --border-strong: #d2d2d7;
  --text: #1d1d1f;
  --muted: #86868b;
  --accent: #007aff;
  --accent-2: #007aff;
  --accent-soft: rgba(0, 122, 255, .1);
  --focus: rgba(0, 122, 255, .35);
  --red: #e0352b;      --red-bg: rgba(255, 59, 48, .12);
  --orange: #d97c00;   --orange-bg: rgba(255, 149, 0, .14);
  --green: #1f9d45;    --green-bg: rgba(52, 199, 89, .14);
  --blue: #007aff;     --blue-bg: rgba(0, 122, 255, .1);
  --purple: #9b3fd6;   --purple-bg: rgba(175, 82, 222, .12);
  --gray-bg: rgba(120, 120, 128, .12);
  --dot-red: #ff3b30; --dot-orange: #ff9500; --dot-green: #34c759; --dot-blue: #007aff; --dot-purple: #af52de; --dot-gray: #aeaeb2;
  --tile: #ffffff;             /* tiles and stripes inside a grouped box */
  --zebra: rgba(255, 255, 255, .6);
  --row-hover: rgba(0, 122, 255, .06);
  --shadow: 0 10px 30px rgba(0, 0, 0, .12), 0 0 0 1px rgba(0, 0, 0, .05);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .06);
  --btn-shadow: 0 1px 1px rgba(0, 0, 0, .06), 0 0 0 .5px rgba(0, 0, 0, .12);
  --sidebar: #f0eff4;
  --sidebar-active: rgba(0, 0, 0, .08);
  --tint-red: rgba(255, 59, 48, .07); --tint-orange: rgba(255, 149, 0, .08); --tint-purple: rgba(175, 82, 222, .07); --tint-blue: rgba(0, 122, 255, .06);
  --stock-row: #ececf0; --stage-negotiation: #f5f5f7; --stage-production: #fff8ea; --stage-pickup: #f8f1fc;
  --stage-transit: #eef5ff; --stage-arrived: #eefaf1;
  --plate-orange-text: #8a4b00; --plate-orange-border: rgba(255, 149, 0, .4);
  --chip-production-text: #8a4b00; --chip-pickup-text: #7a2ea8; --chip-transit-text: #0059c2; --chip-arrived-text: #177a36;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #1e1e1e;
  --card: #2a2a2c;
  --field: #3a3a3c;
  --border: #3a3a3c;
  --border-strong: #48484a;
  --text: #f5f5f7;
  --muted: #98989d;
  --accent: #0a84ff;
  --accent-2: #0a84ff;
  --accent-soft: rgba(10, 132, 255, .2);
  --focus: rgba(10, 132, 255, .5);
  --red: #ff6961;      --red-bg: rgba(255, 69, 58, .2);
  --orange: #ffb340;   --orange-bg: rgba(255, 159, 10, .2);
  --green: #4cd964;    --green-bg: rgba(48, 209, 88, .18);
  --blue: #409cff;     --blue-bg: rgba(10, 132, 255, .2);
  --purple: #da8fff;   --purple-bg: rgba(191, 90, 242, .22);
  --gray-bg: rgba(120, 120, 128, .24);
  --dot-red: #ff453a; --dot-orange: #ff9f0a; --dot-green: #30d158; --dot-blue: #0a84ff; --dot-purple: #bf5af2; --dot-gray: #636366;
  --tile: #323234;
  --zebra: rgba(255, 255, 255, .025);
  --row-hover: rgba(10, 132, 255, .12);
  --shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255, 255, 255, .08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --btn-shadow: 0 0 0 .5px rgba(255, 255, 255, .1), 0 1px 1px rgba(0, 0, 0, .3);
  --sidebar: #2b2a2e;
  --sidebar-active: rgba(255, 255, 255, .1);
  --tint-red: rgba(255, 69, 58, .12); --tint-orange: rgba(255, 159, 10, .12); --tint-purple: rgba(191, 90, 242, .12); --tint-blue: rgba(10, 132, 255, .12);
  --stock-row: #333336; --stage-negotiation: #2c2c2e; --stage-production: #3a3120; --stage-pickup: #33283d;
  --stage-transit: #223246; --stage-arrived: #213828;
  --plate-orange-text: #ffb340; --plate-orange-border: rgba(255, 159, 10, .35);
  --chip-production-text: #ffb340; --chip-pickup-text: #da8fff; --chip-transit-text: #409cff; --chip-arrived-text: #4cd964;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

/* ---------- layout: grouped menu on the left, like Finder ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 224px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 18px 10px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.brand { font-weight: 700; font-size: 15px; padding: 0 10px 12px; line-height: 1.25; color: var(--text); }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }

nav { display: flex; flex-direction: column; gap: 1px; }
.nav-group { font-size: 11px; font-weight: 600; color: var(--muted); padding: 14px 10px 4px; }
.nav-group[hidden] { display: none; }
nav button {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  font-family: inherit;
}
nav button .ico { width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: var(--accent); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
nav button:hover { background: var(--sidebar-active); }
nav button.active { background: var(--sidebar-active); font-weight: 600; }

.theme-toggle {
  margin-top: auto;
  background: transparent;
  border: none;
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  text-align: left;
}
.theme-toggle:hover { background: var(--sidebar-active); }

.main { flex: 1; min-width: 0; padding: 20px 28px 28px; max-width: 1500px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 16px; min-height: 30px; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.page-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.sync-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.fx-chip { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--text); margin-right: 14px; }
.fx-chip .fx-label, .fx-chip .fx-old { color: var(--muted); }
.fx-chip span[title] { cursor: help; }
.sync-bar button.secondary { padding: 4px 12px; }
.sync-quick { cursor: help; }
.sync-error { color: var(--red); white-space: pre-line; flex-basis: 100%; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0 8px 0 0; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .nav-group { display: none; }
  .theme-toggle { margin-top: 0; margin-left: auto; }
  .user-box { flex-direction: row; align-items: center; margin-top: 0; }
  .main { padding: 16px; }
}

/* ---------- grouped boxes, tables ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 16px;
}

.table-wrap { overflow: auto; max-height: 70vh; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
/* sticky relative to .table-wrap's own scroll, not the page */
th { color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; z-index: 1; background: var(--card); }
tbody tr:nth-child(even) td { background: var(--zebra); }
tr:hover td, tbody tr:nth-child(even):hover td { background: var(--row-hover); }
.col-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: default; }

/* dashboard: inset grouped table, the status is a coloured dot */
.dash-table td { vertical-align: top; padding: 10px 10px; }
.dash-table th { padding-left: 10px; padding-right: 10px; }
.dash-table .col-name { max-width: 190px; color: var(--muted); }

.segmented { display: inline-flex; flex-wrap: wrap; gap: 2px; background: var(--gray-bg); border-radius: 8px; padding: 2px; margin-bottom: 16px; }
.segmented button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 6px; cursor: pointer; }
.segmented button:hover { background: var(--sidebar-active); }
.segmented button.active { background: var(--field); box-shadow: var(--btn-shadow); font-weight: 600; }
.segmented .n { color: var(--muted); font-weight: 500; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--dot-gray); }
.dot-OVERDUE { background: var(--dot-red); }
.dot-URGENT { background: var(--dot-orange); }
.dot-PICKUP, .dot-IN_PROGRESS { background: var(--dot-blue); }
.dot-ACCELERATE { background: var(--dot-purple); }
.dot-OK { background: var(--dot-green); }
.status { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; }
.ring { display: inline-block; width: 16px; height: 16px; border-radius: 50%; vertical-align: -3px; margin-right: 6px;
  background: conic-gradient(var(--c) var(--p), var(--gray-bg) 0); }
.ring-empty { background: var(--gray-bg); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-OVERDUE { background: var(--red-bg); color: var(--red); }
.badge-URGENT { background: var(--orange-bg); color: var(--orange); }
.badge-ACCELERATE { background: var(--purple-bg); color: var(--purple); }
.badge-OK { background: var(--green-bg); color: var(--green); }
.badge-IN_PROGRESS { background: var(--blue-bg); color: var(--blue); }
.badge-PHASE_OUT { background: var(--gray-bg); color: var(--muted); }
.badge-PICKUP { background: var(--blue-bg); color: var(--blue); }
.badge-NO_DATA { background: var(--gray-bg); color: var(--muted); }
.badge-INACTIVE { background: var(--gray-bg); color: var(--muted); }
.badge-SEASONAL_HOLD { background: var(--blue-bg); color: var(--muted); }

.row-OVERDUE { background: var(--tint-red); }
.row-URGENT { background: var(--tint-orange); }
.row-ACCELERATE { background: var(--tint-purple); }
.dash-table .row-OVERDUE, .dash-table .row-URGENT, .dash-table .row-ACCELERATE { background: none; }

button.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
}
button.primary:hover { filter: brightness(1.08); }
button.secondary {
  background: var(--field);
  color: var(--text);
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  box-shadow: var(--btn-shadow);
}
button.secondary:hover { filter: brightness(.97); }
button:disabled { opacity: .5; cursor: default; }
button.danger { color: var(--red); background: var(--field); border: none; box-shadow: var(--btn-shadow); border-radius: 6px; padding: 5px 10px; cursor: pointer; font-family: inherit; }

input, select, textarea {
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  font-family: inherit;
  background: var(--field);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

.summary-cards { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.summary-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  min-width: 140px;
}
.card .summary-card { background: var(--tile); }
.summary-card .num { font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.summary-card .label { color: var(--muted); font-size: 12px; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }
.section-title { font-weight: 700; margin: 0 0 10px 0; font-size: 15px; }
.actions-cell { display: flex; gap: 6px; }
.hidden { display: none; }
a { color: var(--accent); }
details.card > summary { cursor: pointer; }

.picker-list { position: fixed; z-index: 1000; max-height: 320px; overflow-y: auto; background: var(--card);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); }
.picker-item { padding: 8px 12px; cursor: pointer; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-item.active, .picker-item:hover { background: var(--accent-soft); }
.picker-empty { padding: 10px 12px; color: var(--muted); font-size: 13px; }

.per-day { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* administrator deals table */
.pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pill { border: 1px solid var(--border); background: var(--field); color: var(--text); border-radius: 999px; padding: 4px 12px; font-size: 13px; cursor: pointer; font-family: inherit; }
.pill.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.pill.stage-negotiation { background: var(--gray-bg); } .pill.stage-production { background: var(--orange-bg); }
.pill.stage-pickup { background: var(--purple-bg); } .pill.stage-transit { background: var(--blue-bg); } .pill.stage-arrived { background: var(--green-bg); }
/* deals board: a card per article with a coverage strip (segments = what covers demand, day by day) */
:root {
  --seg-stock: #9fdcbf; --seg-negotiation: #cdd3e0; --seg-production: #f6cd6a; --seg-pickup: #c3b3fb;
  --seg-transit: #93bef7; --seg-plan: #e4e6ff; --seg-plan-line: #8f93f7; --seg-gap: #f08a80; --seg-stop: #d9dce6;
  --seg-tick: rgba(30, 35, 64, .16);
  --seg-deal: #9cc3f5; --seg-text: #1e2340; --seg-gap-text: #7f1d1d;
}
:root[data-theme="dark"] {
  --seg-stock: #2f7657; --seg-negotiation: #3b4453; --seg-production: #8c6b17; --seg-pickup: #56469c;
  --seg-transit: #2c5b96; --seg-plan: #252c4f; --seg-plan-line: #6e7dff; --seg-gap: #b8433b; --seg-stop: #3a414d;
  --seg-tick: rgba(255, 255, 255, .14);
  --seg-deal: #2c5b96; --seg-text: #e6edf3; --seg-gap-text: #ffe4e1;
}
.admin-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.admin-toolbar #admin-q { flex: 1 1 220px; max-width: 320px; }
.admin-toolbar select { max-width: 240px; }
.seg-toggle { display: inline-flex; gap: 2px; background: var(--gray-bg); border-radius: 8px; padding: 2px; }
.seg-toggle button { border: 0; background: transparent; color: var(--text); padding: 4px 12px; border-radius: 6px; font: inherit; font-size: 13px; cursor: pointer; }
.seg-toggle button.active { background: var(--field); box-shadow: var(--btn-shadow); font-weight: 600; }
.admin-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; margin: 14px 0 12px; }
.sum-tile { display: flex; flex-direction: column; gap: 2px; text-align: left; background: var(--tile); border: 1px solid var(--border); border-radius: 8px; padding: 9px 14px; cursor: pointer; color: var(--text); font: inherit; }
.sum-tile:hover { border-color: var(--accent); }
.sum-tile.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.sum-tile .v { font-size: 20px; font-weight: 700; line-height: 1.2; }
.sum-tile .l { font-size: 12px; color: var(--muted); }
.text-red { color: var(--red); }
.admin-checks { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; }
.admin-checks label { display: flex; gap: 6px; align-items: center; }
.legend { display: flex; gap: 6px 14px; flex-wrap: wrap; margin-top: 12px; font-size: 11.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { display: inline-block; width: 14px; height: 10px; border-radius: 3px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 12.5px; }
.link-btn:hover { text-decoration: underline; }

.deal-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px 8px; margin-bottom: 12px; }
.dc-head { display: flex; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap; align-items: baseline; }
.dc-title { font-size: 15px; min-width: 0; }
.dc-name { color: var(--muted); font-size: 13px; }
.dc-flags { display: flex; gap: 4px; flex-wrap: wrap; }
.dc-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.dc-meta strong { color: var(--text); }
.dc-note { margin-top: 8px; padding: 7px 10px; background: var(--tint-orange); border: 1px solid var(--plate-orange-border); border-radius: 10px; font-size: 13px; white-space: pre-wrap; }
.note-edit { margin-top: 8px; }
.note-edit textarea { width: 100%; resize: vertical; }
.note-actions { display: flex; gap: 6px; margin-top: 6px; }
.note-dot { color: var(--orange); font-size: 13px; }

.strip { position: relative; height: 18px; background: var(--tile); border-radius: 6px; overflow: hidden; margin-top: 10px; }
.strip.strip-lg { height: 26px; }
/* 2px gap in the card's colour between pieces, so neighbouring deals never merge into one block */
.strip .seg { position: absolute; top: 0; bottom: 0; font-style: normal; box-shadow: inset -2px 0 0 var(--card); transition: opacity .12s; }
.strip .seg span { display: block; padding: 0 5px; font-size: 11px; font-weight: 600; line-height: 26px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--seg-text); }
.strip .seg-gap span { color: var(--seg-gap-text); }
.strip .tick { position: absolute; bottom: 0; height: 5px; width: 1px; background: var(--seg-tick); pointer-events: none; }
.strip-dim .seg:not(.hl) { opacity: .35; }
.strip .seg.hl { box-shadow: inset 0 0 0 2px var(--text); z-index: 2; }
.dc-row.hl { background: var(--row-hover); box-shadow: inset 3px 0 0 var(--accent); }
.strip-empty { position: absolute; left: 8px; top: 1px; font-size: 11px; color: var(--muted); }
.seg-stock { background: var(--seg-stock); }
.seg-deal { background: var(--seg-deal); }
.seg-negotiation { background: var(--seg-negotiation); }
.seg-production { background: var(--seg-production); }
.seg-pickup { background: var(--seg-pickup); }
.seg-transit { background: var(--seg-transit); }
.seg-arrived { background: var(--seg-stock); }
.seg-est { background-image: repeating-linear-gradient(135deg, rgba(255, 255, 255, .55) 0 3px, transparent 3px 7px); }
.seg-plan { background: repeating-linear-gradient(135deg, var(--seg-plan-line) 0 2px, var(--seg-plan) 2px 7px); }
.seg-gap { background: var(--seg-gap); }
.seg-stop { background: repeating-linear-gradient(135deg, var(--seg-stop) 0 3px, transparent 3px 7px); }
.strip-axis { position: relative; height: 16px; font-size: 10.5px; color: var(--muted); }
.strip-axis span { position: absolute; top: 2px; padding-left: 3px; white-space: nowrap; }

.dc-rows { margin-top: 4px; container-type: inline-size; }
.dc-row {
  display: grid;
  grid-template-columns: 150px 60px minmax(90px, 1fr) 80px 80px 96px 100px 104px minmax(150px, 1.3fr);
  gap: 8px; align-items: center; padding: 7px 6px; border-top: 1px solid var(--border); font-size: 12.5px; border-radius: 8px;
}
.dc-row.dc-cols { font-size: 11px; color: var(--muted); padding: 8px 6px 3px; border-top: 0; align-items: end; }
.dc-row[data-deal] { cursor: pointer; }
.dc-row[data-deal]:hover, .dc-row[data-deal]:focus { background: var(--row-hover); outline: none; }
.dc-row > span { min-width: 0; }
.dc-row .c-inv { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.two-line { display: flex; flex-direction: column; line-height: 1.35; }
.dc-row .c-flags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.dc-row .c-flags .badge { white-space: nowrap; }
.plan-row { background: var(--tint-purple); }
.plan-row .c-inv { white-space: normal; }
.chip-plan { background: transparent; border: 1px dashed var(--seg-plan-line); color: var(--accent); }
/* the card is narrower than a full row (small screen, or the side menu takes room): two lines per deal */
/* the card is narrower than a full row (small screen): two lines per deal, the three dates still in columns */
@container (max-width: 980px) {
  .dc-row { grid-template-columns: 150px 60px repeat(3, minmax(0, 1fr)); row-gap: 4px; }
  .dc-row .c-prod { grid-column: 3; grid-row: 1; }
  .dc-row .c-pick { grid-column: 4; grid-row: 1; }
  .dc-row .c-arr { grid-column: 5; grid-row: 1; }
  .dc-row .c-cover { grid-column: 1 / 3; grid-row: 2; }
  .dc-row .c-inv { grid-column: 3; grid-row: 2; }
  .dc-row .c-money { grid-column: 4; grid-row: 2; }
  .dc-row .c-flags { grid-column: 5; grid-row: 2; justify-content: flex-start; }
  .dc-row.dc-cols .c-cover, .dc-row.dc-cols .c-inv, .dc-row.dc-cols .c-money, .dc-row.dc-cols .c-flags { display: none; }
}
@container (max-width: 560px) {
  .dc-row { display: flex; flex-wrap: wrap; gap: 4px 12px; }
  .dc-row.dc-cols { display: none; }
}

.tl-card { padding: 12px 16px; }
.tl-row { display: grid; grid-template-columns: 230px minmax(0, 1fr) 118px; gap: 12px; align-items: center; padding: 5px 4px; border-top: 1px solid var(--border); font-size: 12.5px; cursor: pointer; border-radius: 6px; }
.tl-row:hover, .tl-row:focus { background: var(--row-hover); outline: none; }
.tl-row .strip { margin-top: 0; height: 16px; }
.tl-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tl-flag { text-align: right; }
.tl-flag .badge { white-space: nowrap; }
.tl-axis { cursor: default; border-top: 0; position: sticky; top: 0; background: var(--card); z-index: 2; }
.tl-axis:hover { background: var(--card); }
@media (max-width: 700px) { .tl-row { grid-template-columns: 110px minmax(0, 1fr); } .tl-flag { display: none; } }

.pay-panel { background: var(--tile); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; max-height: 360px; overflow: auto; }
.pay-week { padding: 6px 0; border-top: 1px solid var(--border); }
.pay-week:first-child { border-top: 0; }
.pay-head { display: flex; justify-content: space-between; font-size: 13px; }
.pay-row { display: grid; grid-template-columns: 84px minmax(0, 1.3fr) minmax(0, 1fr) 100px; gap: 8px; font-size: 12.5px; padding: 2px 0 2px 10px; }
.pay-row .num { text-align: right; }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .25); z-index: 50; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: var(--bg); box-shadow: var(--shadow); z-index: 51; overflow: auto; padding: 20px 22px; }
.drawer-x { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; }
.drawer dl { display: grid; grid-template-columns: 170px 1fr; gap: 7px 10px; font-size: 13px; margin: 12px 0 0; }
.drawer dt { color: var(--muted); }
.drawer dd { margin: 0; }
.steps { display: flex; gap: 4px; margin: 10px 0 12px; }
.steps span { flex: 1; font-size: 11px; text-align: center; padding: 5px 2px; border-radius: 6px; background: var(--gray-bg); color: var(--muted); }
.steps .done { background: var(--green-bg); color: var(--green); }
.steps .now { background: var(--accent); color: #fff; font-weight: 600; }
.drawer-tip { background: var(--tint-purple); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 8px; }
.drawer-tip-red { background: var(--tint-red); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 600; }
.chip-stock { background: var(--gray-bg); color: var(--text); } .chip-negotiation { background: var(--gray-bg); color: var(--muted); }
.chip-production { background: var(--orange-bg); color: var(--chip-production-text); }
.chip-pickup { background: var(--purple-bg); color: var(--chip-pickup-text); }
.chip-transit { background: var(--blue-bg); color: var(--chip-transit-text); }
.chip-arrived { background: var(--green-bg); color: var(--chip-arrived-text); }
.stepper { display: inline-flex; gap: 2px; margin-right: 6px; vertical-align: middle; }
.stepper i { width: 7px; height: 7px; border-radius: 50%; background: var(--card); border: 1px solid var(--muted); display: inline-block; }
.stepper i.done { background: var(--green); border-color: var(--green); }
.stepper i.now { background: var(--accent); border-color: var(--accent); }

.report-group summary { cursor: pointer; }
.btn-link { display: inline-block; padding: 6px 14px; border-radius: 6px; background: var(--field); box-shadow: var(--btn-shadow); color: var(--text); text-decoration: none; font-size: 13px; }
.btn-link:hover { filter: brightness(.97); }

.spike-plate { background: var(--orange-bg); color: var(--plate-orange-text); border: 1px solid var(--plate-orange-border); border-radius: 8px;
  padding: 9px 13px; font-size: 13px; margin: 10px 0; }

.sku-link { background: none; border: none; padding: 0; font: inherit; font-weight: 600; color: var(--accent);
  cursor: pointer; text-decoration: underline; text-decoration-color: transparent; }
.sku-link:hover { text-decoration-color: var(--accent); }

/* login */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-screen[hidden], .layout[hidden], .user-box[hidden] { display: none; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; padding: 24px; border-radius: 12px; background: var(--card, #fff); border: 1px solid var(--border, #ddd); box-shadow: var(--shadow); }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.login-error { color: #c0392b; min-height: 1.2em; font-size: 13px; }
.user-box { display: flex; flex-direction: column; gap: 1px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.user-box span { padding: 6px 10px; font-size: 13px; font-weight: 600; color: var(--text); }
.user-box .link-btn {
  background: transparent; border: none; padding: 6px 10px; border-radius: 6px; cursor: pointer;
  font-size: 13px; color: var(--text); text-align: left; font-family: inherit;
}
.user-box .link-btn:hover { background: var(--sidebar-active); text-decoration: none; }
.accel-ask { margin-top: 4px; max-width: 230px; white-space: normal; font-size: 11px; color: var(--purple); font-weight: 600; }
.pickup-ask { margin-top: 4px; max-width: 230px; white-space: normal; font-size: 11px; color: var(--blue); font-weight: 600; }

/* planning tab: "needs attention" panel, replacing the old dashboard-row hints */
.attention-card { border-left: 4px solid var(--orange); background: var(--tint-orange); }
:root[data-theme="dark"] .attention-card { background: var(--tint-orange); }
.attention-item { font-size: 14px; padding: 6px 0; border-top: 1px solid rgba(0,0,0,.06); }
.attention-item:first-of-type { border-top: none; }
:root[data-theme="dark"] .attention-item { border-top-color: rgba(255,255,255,.08); }
.attention-card .pickup-ask, .attention-card .accel-ask { font-size: 14px; font-weight: 500; color: var(--text); max-width: none; white-space: normal; margin-top: 0; }
.pickup-earlier-tag { display: block; font-size: 11px; font-weight: 500; color: var(--purple); }

.manual-arrival-box {
  display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap;
  margin: 10px 0; padding: 10px 12px; border: 1px dashed var(--border-strong); border-radius: 8px; background: var(--tile);
}
.manual-arrival-box label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.manual-arrival-box input[type="date"] { font-family: inherit; }

/* batch turnover tab */
.text-green { color: var(--green); }
.turn-wrap { max-height: 72vh; }
.turn-table td { font-size: 12.5px; padding: 7px 7px; vertical-align: top; }
.turn-table th { font-size: 11.5px; white-space: normal; vertical-align: bottom; padding: 7px 7px; }
.turn-table .num { text-align: right; }
.turn-table td.wrap { white-space: normal; max-width: 115px; word-break: break-all; }
.turn-table .turn-name { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.tdots { display: inline-flex; gap: 3px; vertical-align: middle; }
.tdot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.badge-MEGA { background: var(--green); color: #fff; }
.text-mega { color: var(--green); }
.tdot-mega { background: var(--green); } .tdot-fc.tdot-mega { border-color: var(--green); }
.tdot-top { background: #86d9a4; } .tdot-norm { background: var(--orange); } .tdot-slow { background: var(--red); }
.tdot-none { background: var(--gray-bg); border: 1px solid var(--border); }
.tdot-fc { background: transparent; border: 2px solid; box-sizing: border-box; }
.tdot-fc.tdot-top { border-color: #86d9a4; } .tdot-fc.tdot-norm { border-color: var(--orange); } .tdot-fc.tdot-slow { border-color: var(--red); }

/* planning: batch size under the payment deferral */
.sizing-card { background: var(--tile); margin: 12px 0; padding: 14px 16px; }
.sizing-verdict { font-size: 14px; margin: 6px 0 10px; }
.sizing-table { width: auto; min-width: 420px; font-size: 13px; }
.sizing-table td, .sizing-table th { padding: 5px 12px 5px 0; border-bottom: 1px solid var(--border); background: transparent; position: static; }
.sizing-details summary { cursor: pointer; margin-top: 10px; font-size: 13px; color: var(--accent); }

/* payments calendar */
.pay-chart { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; align-items: end; margin-top: 8px; }
.pay-col { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; padding: 4px; border-radius: 10px; }
.pay-col:hover { background: var(--row-hover); }
.pay-bar { width: 56%; max-width: 70px; height: 170px; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; }
.pay-seg { display: block; width: 100%; min-height: 2px; }
.pay-bar .pay-seg:first-child { border-radius: 4px 4px 0 0; }
.pay-seg-deal { background: var(--accent); }
.pay-seg-plan { background: repeating-linear-gradient(135deg, var(--accent) 0 2px, var(--accent-soft) 2px 7px); }
.pay-total { font-size: 12.5px; font-weight: 700; }
.pay-month { font-size: 12.5px; color: var(--muted); }
.pay-frozen { font-size: 11.5px; }
.pay-month-row td { background: var(--tile); }
.pay-plan-row td { color: var(--muted); }
/* labels on hatched pieces sit on a small plate, or the stripes make them unreadable */
.strip .seg-plan span, .strip .seg-stop span { display: inline-block; max-width: calc(100% - 10px); margin: 4px 5px; padding: 0 5px; line-height: 18px; border-radius: 4px; background: var(--card); color: var(--accent); }
.strip .seg-stop span { color: var(--muted); }
.tg-preview { white-space: pre-wrap; background: var(--tile); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; font: 13px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; max-height: 420px; overflow: auto; margin-top: 10px; }

@media (max-width: 900px) {
  .user-box { flex-direction: row; align-items: center; margin-top: 0; padding-top: 0; border-top: 0; }
}

/* fact vs forecast: solid = fact, dashed / hatched / grey italic = forecast (same rule on every tab) */
.fc, .fc strong { font-style: italic; color: var(--muted); font-weight: 500; }
.fc.text-red span:first-child { color: var(--red); }
.fc.text-green span:first-child { color: var(--green); }
.badge-fc { background: transparent; border: 1px dashed currentColor; padding: 1px 7px; }
.fc-tag { font-size: 11px; color: var(--muted); }
.sold-bar { display: flex; width: 64px; height: 6px; margin: 5px 0 0 auto; border-radius: 3px; overflow: hidden; background: var(--gray-bg); }
.sold-bar i { display: block; height: 100%; }
.sold-bar .sb-fact { background: var(--dot-blue); }
.sold-bar .sb-fc { flex: 1; background: repeating-linear-gradient(135deg, var(--dot-blue) 0 1.5px, transparent 1.5px 5px); opacity: .55; }
.turn-table tr.turn-group td { background: var(--card); font-weight: 600; font-size: 13px; padding-top: 14px; border-bottom: 1px solid var(--border-strong); }
.turn-table tr.turn-group:hover td { background: var(--card); }

/* sortable column headings */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sorted { color: var(--accent); }
.sort-ar { margin-left: 4px; font-size: 11px; opacity: .45; }
th.sorted .sort-ar { opacity: 1; }

/* payments calendar: paid = solid (fact), still to pay = outlined (plan, can move), new deals = hatched */
.pay-seg-due { background: var(--accent-soft); border: 1.5px dashed var(--accent); box-sizing: border-box; }
.legend i.pay-seg-due { border-width: 1px; }

/* turnover, «по партиям»: six columns, one figure per cell, details in the hover tips */
.turn-batches { table-layout: fixed; }
.turn-batches td { white-space: normal; vertical-align: middle; padding-top: 10px; padding-bottom: 10px; }
.turn-batches th { white-space: normal; }
.turn-batches .turn-name { max-width: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn-batches td.wrap { max-width: none; word-break: normal; overflow: hidden; text-overflow: ellipsis; }
.turn-batches .sold-bar { width: 100%; height: 8px; border-radius: 4px; margin: 0 0 5px; }
.sku-cell { font-weight: 600; }
.late-tag { display: inline-block; margin-top: 3px; padding: 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--orange-bg); color: var(--plate-orange-text); font-style: normal; }

/* profit: period pickers, monthly chart (selected period = accent, comparison = outlined), share bar, ABC */
.pf-periods { display: flex; flex-direction: column; gap: 8px; }
.pf-line { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pf-lbl { width: 86px; color: var(--muted); font-size: 12.5px; }
.pf-picker { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; color: var(--muted); }
.pf-picker select { min-width: 170px; }
.pf-picker input[type="date"] { font-family: inherit; }
.sum-tile.pf-static { cursor: default; }
.sum-tile.pf-static:hover { border-color: var(--border); }
.pf-chart { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 4px; align-items: end; height: 190px; margin-top: 4px; }
.pf-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 3px; height: 100%;
  padding: 0 0 2px; border: 0; border-radius: 6px; background: transparent; color: var(--text); font: inherit; cursor: pointer; }
.pf-col:hover { background: var(--row-hover); }
.pf-bar { display: block; width: 72%; max-width: 34px; border-radius: 4px 4px 0 0; background: var(--dot-gray); opacity: .55; }
.pf-col.pf-main .pf-bar { background: var(--accent); opacity: 1; }
.pf-col.pf-cmp .pf-bar { background: var(--accent-soft); opacity: 1; box-shadow: inset 0 0 0 1.5px var(--accent); }
.pf-val { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.pf-col.pf-main .pf-val { color: var(--text); font-weight: 600; }
.pf-m { font-size: 11px; color: var(--muted); white-space: nowrap; }
.pf-m b { font-weight: 600; }
.pf-legend { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pf-sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.pf-sw.pf-main { background: var(--accent); }
.pf-sw.pf-cmp { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.pf-check { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.pf-table .turn-name { max-width: 300px; }
.pf-table td { vertical-align: middle; }
.pf-cmpcol { color: var(--muted); }
.pf-share { display: block; width: 56px; height: 4px; margin: 4px 0 0 auto; border-radius: 2px; background: var(--gray-bg); overflow: hidden; }
.pf-share i { display: block; height: 100%; background: var(--accent); }
.abc { display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 5px; font-size: 11.5px; font-weight: 700; text-align: center; }
.abc-A { background: var(--green-bg); color: var(--green); }
.abc-B { background: var(--blue-bg); color: var(--blue); }
.abc-C { background: var(--gray-bg); color: var(--muted); }
.pf-total td { position: sticky; bottom: 0; background: var(--card); font-weight: 700; border-top: 1px solid var(--border-strong); }
.pf-bar-fc { display: block; width: 72%; max-width: 34px; margin-bottom: -3px; border-radius: 4px 4px 0 0; box-sizing: border-box;
  border: 1.5px dashed var(--accent); border-bottom: 0; background: repeating-linear-gradient(135deg, var(--accent-soft) 0 3px, transparent 3px 6px); }
.pf-val.fc { font-style: italic; }
.pf-table td.fc, .pf-table .pf-total td.fc { white-space: nowrap; }

/* B2B clients: expandable client card */
.text-orange { color: var(--orange); }
.cl-table tr.cl-row { cursor: pointer; }
.cl-table tr.cl-row.open td { background: var(--row-hover); }
.cl-table td { vertical-align: middle; }
.cl-table tr.cl-detail td { white-space: normal; background: var(--tile); padding: 14px 16px; }
.cl-table tr.cl-detail:hover td { background: var(--tile); }
.cl-detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 24px; }
.cl-mini { font-size: 12.5px; }
.cl-mini th { position: static; background: transparent; padding: 4px 10px 4px 0; }
.cl-mini td { padding: 4px 10px 4px 0; white-space: nowrap; }
.cl-mini .num { text-align: right; }
.cl-months { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 3px; align-items: end; height: 84px; }
.cl-m { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 3px; }
.cl-m i { display: block; width: 70%; background: var(--accent); border-radius: 3px 3px 0 0; }
.cl-m b { font-size: 10.5px; font-weight: 500; color: var(--muted); }

/* profit × turnover matrix */
.mx-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.mx-fx { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-left: auto; font-size: 12.5px; }
.mx-grid { display: grid; grid-template-columns: 110px repeat(4, minmax(0, 1fr)); gap: 8px; align-items: stretch; }
.mx-head { display: flex; flex-direction: column; gap: 2px; justify-content: flex-end; padding: 0 4px 2px; }
.mx-rowhead { justify-content: center; align-items: flex-start; }
.mx-cell { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--tile); color: var(--text); font: inherit; cursor: pointer; }
.mx-cell:hover { border-color: var(--accent); }
.mx-cell.active { box-shadow: 0 0 0 2px var(--accent); border-color: var(--accent); }
.mx-cell .mx-n { font-size: 22px; font-weight: 700; line-height: 1.1; }
.mx-cell .mx-s { font-size: 11.5px; color: var(--muted); }
.mx-good { background: var(--green-bg); }
.mx-warn { background: var(--orange-bg); }
.mx-bad { background: var(--red-bg); }
.mx-neutral { background: var(--gray-bg); }
.mx-advice { margin: 10px 0 12px; font-size: 13px; }

/* cash calendar by week */
.cf-chart { display: grid; grid-template-columns: repeat(13, minmax(0, 1fr)); gap: 6px; align-items: end; margin-top: 10px; }
.cf-col { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 2px; border-radius: 8px; }
.cf-col.cf-tight { background: var(--tint-orange); }
.cf-val { font-size: 11px; color: var(--muted); white-space: nowrap; min-height: 14px; }
.cf-plot { position: relative; width: 100%; height: 180px; }
.cf-bar { position: absolute; left: 20%; width: 60%; bottom: 0; display: flex; flex-direction: column; overflow: hidden; border-radius: 4px 4px 0 0; }
.cf-bar i { display: block; width: 100%; min-height: 1px; }
.cf-deal { background: var(--accent-soft); border: 1.5px dashed var(--accent); box-sizing: border-box; }
.cf-plan { background: repeating-linear-gradient(135deg, var(--accent) 0 2px, var(--accent-soft) 2px 7px); }
.cf-frozen { position: absolute !important; left: 0; bottom: 0; background: var(--dot-red); opacity: .6; }
.cf-profit { position: absolute; left: 4%; width: 92%; height: 0; border-top: 2.5px solid var(--green); }
.cf-wk { font-size: 11px; color: var(--muted); }
.cf-fz { font-size: 11px; white-space: nowrap; }

/* B2B clients: returns */
.cl-ret-summary .cl-ret-months { grid-column: span 2; min-width: 260px; }
.cl-ret-summary .cl-months { height: 56px; margin-top: 6px; }

/* «Себестоимость» (landed.js) */
.lc-table tr.lc-row { cursor: pointer; }
.lc-table tr.lc-row.open td { background: var(--row-hover); }
.lc-table td.lc-issues { white-space: normal; min-width: 150px; max-width: 420px; font-size: 12px; }
.lc-issue + .lc-issue { margin-top: 3px; }
.lc-issue b { font-weight: 600; }
.lc-man { color: var(--accent); font-size: 11px; }
.lc-help { font-size: 12px; margin: 0 0 12px; max-width: 980px; }
.lc-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 8px; }
.lc-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.lc-field input { width: 100%; box-sizing: border-box; }
