:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1d2430;
  --muted: #687385;
  --accent: #2858c7;
  --accent-soft: #e8eefb;
  --ok: #1c7c4a;
  --ok-soft: #e3f4ea;
  --warn: #9a6100;
  --warn-soft: #fdf1dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --info-soft: #eef0f3;
  --radius: 8px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* layout */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 0 24px; height: 52px;
  background: #1d2430; color: #fff;
}
.topbar a { color: #cdd5e3; }
.topbar a.active, .topbar a:hover { color: #fff; text-decoration: none; }
.topbar .brand { font-weight: 600; color: #fff; margin-right: 12px; }
.topbar .spacer { flex: 1; }
.topbar form { margin: 0; }
.topbar button { background: none; border: 0; color: #cdd5e3; cursor: pointer; font: inherit; }
main { padding: 20px 24px 60px; max-width: 1600px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* buttons */
.btn {
  display: inline-block; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--info-soft); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1f4aad; }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn-danger { color: var(--bad); }

/* pills */
.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap;
  background: var(--info-soft); color: var(--text);
}
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-bad { background: var(--bad-soft); color: var(--bad); }
.pill-accent { background: var(--accent-soft); color: var(--accent); }

/* summary tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.tile .num { font-size: 22px; font-weight: 600; }
.tile .lbl { color: var(--muted); font-size: 12px; }
.tile.bad .num { color: var(--bad); }
.tile.warn .num { color: var(--warn); }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { min-width: 260px; }
.filters label { display: flex; gap: 4px; align-items: center; color: var(--muted); }
input, select, textarea {
  font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text);
}
textarea { width: 100%; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
td.num, th.num { text-align: right; white-space: nowrap; }

/* order strip */
.strip {
  display: grid; grid-template-columns: 210px 1.3fr 1fr 1.1fr 1.2fr 1fr;
  gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; color: var(--text);
}
.strip:hover { border-color: #c4cbd6; text-decoration: none; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.strip.risk { border-left-color: var(--bad); }
.strip.attention { border-left-color: var(--warn); }
.strip.ok { border-left-color: var(--ok); }
.strip .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.strip .num-title { font-weight: 600; font-size: 15px; }
.flags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
@media (max-width: 1100px) { .strip { grid-template-columns: 1fr 1fr; } }

/* progress bar by states */
.bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--info-soft); min-width: 120px; }
.bar span { display: block; height: 100%; }
.s-not_shipped { background: #c9ced8; }
.s-in_transit { background: #6b93e6; }
.s-awaiting { background: #e9b04a; }
.s-accepted { background: #2f9e62; }
.s-discrepancy { background: #d9534f; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* route timeline */
.route { display: flex; gap: 0; overflow-x: auto; padding: 8px 0 4px; }
.stop { min-width: 190px; flex: 1; position: relative; padding: 0 10px 0 0; }
.stop::before {
  content: ""; position: absolute; top: 9px; left: 18px; right: 0; height: 2px; background: var(--border);
}
.stop:last-child::before { display: none; }
.stop .dot {
  position: relative; width: 20px; height: 20px; border-radius: 50%; border: 2px solid #b8c0cc; background: #fff;
  margin-bottom: 6px; z-index: 1;
}
.stop.done .dot { background: var(--ok); border-color: var(--ok); }
.stop.done::before { background: var(--ok); }
.stop.current .dot { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.stop .name { font-weight: 600; }
.stop .times { font-size: 12px; margin-top: 4px; }
.stop .times div { white-space: nowrap; }
.src-fact { color: var(--ok); font-weight: 600; }
.src-forecast, .src-auto { color: var(--warn); }
.src-plan { color: var(--muted); }
.late { color: var(--bad); font-weight: 600; }
.early { color: var(--ok); }

/* forms */
.form-card { max-width: 820px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field input:not([type=checkbox]):not([type=radio]), .field select { width: 100%; max-width: 480px; }
.field .help { color: var(--muted); font-size: 12px; margin-top: 2px; }
.field ul { list-style: none; padding: 0; margin: 0; }
.errorlist { color: var(--bad); margin: 4px 0; padding-left: 16px; font-size: 13px; }
.form-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }

.messages { list-style: none; padding: 0; margin: 0 0 12px; }
.messages li { padding: 8px 12px; border-radius: 6px; background: var(--ok-soft); color: var(--ok); margin-bottom: 6px; }
.messages li.error { background: var(--bad-soft); color: var(--bad); }
.notice { padding: 10px 12px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); margin-bottom: 12px; }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.info { background: var(--accent-soft); color: var(--accent); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 0 0 16px; position: sticky; top: 0; background: var(--bg); padding: 8px 0; z-index: 5; }
.tabs a { padding: 5px 12px; border-radius: 6px; color: var(--text); background: var(--surface); border: 1px solid var(--border); }
.tabs a:hover { background: var(--accent-soft); text-decoration: none; }

.history-entry { padding: 8px 0; border-bottom: 1px solid var(--border); }
.history-entry:last-child { border-bottom: 0; }
.history-entry .chg { font-size: 12px; margin-left: 12px; }
.history-entry del { color: var(--bad); }
.history-entry ins { color: var(--ok); text-decoration: none; }

.login-box { max-width: 360px; margin: 10vh auto; }

/* cycles */
.cycle-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.cycle { border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; background: #fafbfc; }
.cycle .lbl { font-size: 12px; color: var(--muted); }
.cycle .val { font-size: 17px; font-weight: 600; }
.cycle.done { border-left: 3px solid var(--ok); }
.cycle.running { border-left: 3px solid var(--warn); background: var(--warn-soft); }
.cycle.total { background: var(--accent-soft); }
.cycle.total.running { background: var(--warn-soft); }

/* delay chain */
details.chain { margin-top: 8px; border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; background: #fff; }
details.chain summary { cursor: pointer; font-size: 13px; font-weight: 600; }
.chain-steps { margin: 8px 0 4px; padding-left: 20px; }
.chain-steps li { margin-bottom: 6px; }
.route .stop form { margin: 2px 0; }

/* language switch */
.lang-switch { display: inline-flex; gap: 2px; }
.lang-switch button { background: none; border: 1px solid #4a5568; color: #cdd5e3; padding: 2px 8px; border-radius: 4px; cursor: pointer; font: inherit; font-size: 12px; }
.lang-switch button.active { background: #fff; color: #1d2430; border-color: #fff; }
main .lang-switch button { border-color: var(--border); color: var(--muted); }
main .lang-switch button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
