:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1c2430; --muted: #5d6878; --line: #dde1e7;
  --brand: #1f3a5f; --brand-2: #2e5eaa; --accent: #e08a1e;
  --ok: #1e7b4a; --ok-bg: #e3f4ea; --warn: #9a5b00; --warn-bg: #fdf0d9;
  --bad: #b3261e; --bad-bg: #fbe4e2; --idle: #6b7280; --idle-bg: #eef0f3;
  --radius: 8px;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", Arial, sans-serif;
       background: var(--bg); color: var(--ink); line-height: 1.4; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* top bar */
.topbar { background: var(--brand); color: #fff; display: flex; align-items: center; gap: 18px; padding: 0 18px;
          min-height: 52px; flex-wrap: wrap; position: sticky; top: 0; z-index: 10; }
.topbar .brand { font-weight: 700; letter-spacing: .3px; color: #fff; white-space: nowrap; }
.topbar .brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.topbar nav a { color: #d6e0ee; padding: 15px 10px; font-size: .95rem; border-bottom: 3px solid transparent; }
.topbar nav a:hover { color: #fff; text-decoration: none; }
.topbar nav a.active { color: #fff; border-bottom-color: var(--accent); }
.topbar .user { font-size: .85rem; color: #d6e0ee; white-space: nowrap; }
.topbar .user a, .topbar .user button { color: #fff; }
.topbar .user form { display: inline; }
.topbar .user button { background: none; border: 0; cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

main { padding: 18px; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* panels & grids */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: block; color: inherit; }
.kpi:hover { text-decoration: none; border-color: var(--brand-2); }
.kpi .v { font-size: 1.7rem; font-weight: 700; }
.kpi .l { color: var(--muted); font-size: .85rem; }
.kpi.bad .v { color: var(--bad); }

/* buttons */
.btn { display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px;
       border-radius: 6px; font: inherit; font-size: .95rem; cursor: pointer; white-space: nowrap; line-height: 1.2; }
.btn:hover { text-decoration: none; border-color: var(--brand-2); }
.btn-primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn-primary:hover { background: var(--brand); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { color: var(--bad); }
.btn-sm { padding: 4px 9px; font-size: .85rem; }
.btn-lg { padding: 12px 20px; font-size: 1.05rem; }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: var(--panel); }
th, td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #eef1f5; font-size: .8rem; text-transform: uppercase; letter-spacing: .3px; color: #3b4656; white-space: nowrap; position: sticky; top: 0; }
tbody tr:hover { background: #f8fafc; }
tfoot td { font-weight: 700; background: #f6f7f9; }
tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--bad); }

/* status chips */
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.chip-done, .chip-completed { background: var(--ok-bg); color: var(--ok); }
.chip-in_progress, .chip-in_production { background: var(--warn-bg); color: var(--warn); }
.chip-pending, .chip-released, .chip-draft { background: var(--idle-bg); color: var(--idle); }
.chip-hold, .chip-cancelled, .chip-overdue { background: var(--bad-bg); color: var(--bad); }
.chip-skipped { background: transparent; color: var(--idle); border: 1px dashed #b5bcc7; }

/* order x stage grid cells */
.cell { min-width: 92px; font-size: .8rem; }
.cell .bar { height: 6px; background: var(--idle-bg); border-radius: 3px; overflow: hidden; margin: 3px 0 2px; }
.cell .bar i { display: block; height: 100%; background: var(--warn); }
.cell.st-done .bar i { background: var(--ok); }
.cell.st-done { color: var(--ok); }
.cell.st-pending { color: var(--idle); }
.cell.st-skipped { color: #a0a7b2; font-style: italic; }
.cell.current { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 4px; }
.cell .q { font-variant-numeric: tabular-nums; }
.progress { height: 8px; background: var(--idle-bg); border-radius: 4px; overflow: hidden; min-width: 70px; }
.progress i { display: block; height: 100%; background: var(--brand-2); }

/* forms */
form.stack p, .field { margin: 0 0 12px; }
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], input[type=file], select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid #c8ced8; border-radius: 6px; font: inherit; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: var(--brand-2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.helptext, .help { display: block; color: var(--muted); font-size: .8rem; margin-top: 3px; font-weight: 400; }
.errorlist { color: var(--bad); margin: 4px 0; padding: 0; list-style: none; font-size: .85rem; }
.checks ul, ul.checks { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.checks label, ul.checks label { font-weight: 400; display: flex; gap: 6px; align-items: center; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin: 0; min-width: 140px; }
.filters .field.grow { flex: 1; min-width: 180px; }
.inline-form { display: inline; }

/* messages */
.messages { list-style: none; padding: 0; margin: 0 0 14px; }
.messages li { padding: 10px 14px; border-radius: 6px; margin-bottom: 6px; background: #e8f0fb; border: 1px solid #c6d8f2; }
.messages li.success { background: var(--ok-bg); border-color: #bfe3cd; }
.messages li.error { background: var(--bad-bg); border-color: #f1c1bd; }

/* key/value spec */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .92rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.login-box { max-width: 380px; margin: 8vh auto; }

@media (max-width: 700px) {
  html { font-size: 16px; }
  main { padding: 12px; }
  .topbar { position: static; padding: 6px 12px 0; gap: 4px 12px; }
  .topbar nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .topbar nav a { padding: 10px 8px; white-space: nowrap; }
  .topbar .user { margin-left: auto; }
  .hide-sm { display: none; }
  .btn-lg { width: 100%; }
}

/* print */
@media print {
  .topbar, .no-print, .messages { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .panel { border: 0; padding: 0; }
  th { position: static; }
}
