:root {
  --bg: #f4f6f9; --surface: #fff; --surface-2: #f0f2f5; --text: #18202b; --muted: #5d6b7c; --border: #dde2e9;
  --primary: #1f6feb; --primary-text: #fff; --danger: #c62828; --warn: #b26a00; --ok: #1b7f3b;
  --chip-explicit: #e3eeff; --chip-explicit-t: #174ea6; --chip-dedus: #fff3dc; --chip-dedus-t: #8a5300;
  --st-nou: #eef1f5; --st-ma_ocup: #fff3dc; --st-ofertat: #e3eeff; --st-castigat: #e2f5e8; --st-pierdut: #fde7e7; --st-ignorat: #eceef1;
  --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 1px 3px rgb(16 24 40 / .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141a; --surface: #171d25; --surface-2: #1f2731; --text: #e6ebf1; --muted: #93a1b2; --border: #2a3441;
    --primary: #4c8dff; --primary-text: #0b1220; --danger: #ff6b6b; --warn: #f0b04f; --ok: #4cc777;
    --chip-explicit: #16294a; --chip-explicit-t: #9cc0ff; --chip-dedus: #3a2a0d; --chip-dedus-t: #f3c77a;
    --st-nou: #222b36; --st-ma_ocup: #3a2a0d; --st-ofertat: #16294a; --st-castigat: #123522; --st-pierdut: #3d1717; --st-ignorat: #1c222a;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141a; --surface: #171d25; --surface-2: #1f2731; --text: #e6ebf1; --muted: #93a1b2; --border: #2a3441;
  --primary: #4c8dff; --primary-text: #0b1220; --danger: #ff6b6b; --warn: #f0b04f; --ok: #4cc777;
  --chip-explicit: #16294a; --chip-explicit-t: #9cc0ff; --chip-dedus: #3a2a0d; --chip-dedus-t: #f3c77a;
  --st-nou: #222b36; --st-ma_ocup: #3a2a0d; --st-ofertat: #16294a; --st-castigat: #123522; --st-pierdut: #3d1717; --st-ignorat: #1c222a;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted, .hint { color: var(--muted); }
.hint { margin: 0 0 12px; font-size: 14px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 11px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.row { display: flex; gap: 8px; align-items: stretch; }
.row input { margin-top: 4px; }
.row .btn { margin-top: 4px; }

.btn { font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.error { color: var(--danger); font-size: 14px; margin: 0 0 12px; }

/* Logare */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .btn { width: 100%; padding: 11px; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; }
.brand img { width: 40px; height: 40px; }
.brand div { display: flex; flex-direction: column; }
.brand span { color: var(--muted); font-size: 14px; }
.brand.small { margin: 0; gap: 8px; }
.brand.small img { width: 28px; height: 28px; }

/* Bara de sus */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button { font: inherit; font-size: 14px; padding: 7px 12px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.tabs button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.me { display: flex; align-items: center; gap: 4px; font-size: 14px; }
.me #me-name { color: var(--muted); margin-right: 4px; }

.tab { max-width: 1600px; margin: 0 auto; padding: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; margin: 0; }
.toolbar input[type="search"] { flex: 1 1 220px; }
.sync { font-size: 13px; color: var(--muted); margin-left: auto; }
.sync.stale { color: var(--warn); font-weight: 600; }

/* Oferte – câte un rând pe cursă */
.offers { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.offers:has(> .empty) { background: transparent; border: 0; box-shadow: none; }
.orow { display: grid; align-items: center; gap: 12px; padding: 8px 12px; font-size: 14px;
  grid-template-columns: 158px minmax(200px, 2.2fr) minmax(150px, 1.4fr) 76px 74px 80px minmax(140px, 1.3fr) 336px;
  border-bottom: 1px solid var(--border); border-left: 4px solid transparent; }
.orow:last-child { border-bottom: 0; }
.orow > div { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.orow:not(.ohead):hover { background: var(--surface-2); }
.ohead { font-size: 12px; color: var(--muted); font-weight: 500; background: var(--surface-2); padding-top: 7px; padding-bottom: 7px; }
.orow.st-ma_ocup { border-left-color: var(--warn); }
.orow.st-ofertat { border-left-color: var(--primary); }
.orow.st-castigat { border-left-color: var(--ok); }
.orow.st-pierdut, .orow.st-ignorat { opacity: .65; }
.orow.urgent { border-left-color: var(--danger); }
.orow.expired { opacity: .5; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.c-deadline b { font-weight: 600; font-variant-numeric: tabular-nums; }
.c-deadline small { margin-left: 6px; color: var(--muted); font-size: 12px; }
.deadline.urgent b, .deadline.urgent small { color: var(--danger); font-weight: 600; }
.deadline.soon b, .deadline.soon small { color: var(--warn); }
.deadline.past b { color: var(--muted); text-decoration: line-through; }
.c-route .route { font-weight: 600; }
.oid { margin-left: 8px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.c-vehicle .veh { margin-left: 6px; }
.c-load, .c-unload { font-variant-numeric: tabular-nums; }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text); }
.chip.explicit { background: var(--chip-explicit); color: var(--chip-explicit-t); font-weight: 600; }
.chip.dedus { background: var(--chip-dedus); color: var(--chip-dedus-t); font-weight: 600; }
.status { font-size: 13px; padding: 3px 9px; border-radius: 6px; background: var(--st-nou); }
.status.st-ma_ocup { background: var(--st-ma_ocup); } .status.st-ofertat { background: var(--st-ofertat); }
.status.st-castigat { background: var(--st-castigat); } .status.st-pierdut { background: var(--st-pierdut); }
.status.st-ignorat { background: var(--st-ignorat); }
.orow > .c-actions { display: flex; gap: 4px; justify-content: flex-end; overflow: visible; }
.c-actions .btn.small { padding: 4px 9px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* Utilizatori */
.grid2 { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 16px; align-items: start; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td.actions-cell { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.inactive td { color: var(--muted); }
.inactive td:first-child { text-decoration: line-through; }

/* Dialoguri */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 20px; background: var(--surface); color: var(--text);
  width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.log { list-style: none; padding: 0; margin: 0 0 8px; max-height: 50vh; overflow: auto; font-size: 14px; }
.log li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.log li small { color: var(--muted); display: block; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 20; max-width: calc(100vw - 32px); }

@media (max-width: 1100px) {
  /* ecran îngust: același rând, strâns pe 2 linii */
  .ohead { display: none !important; }
  .orow { grid-template-columns: 96px 1fr 336px; grid-template-areas: "dl route actions" "dl info status"; row-gap: 2px; }
  .c-deadline { grid-area: dl; display: flex; flex-direction: column; }
  .c-deadline small { margin-left: 0; }
  .c-route { grid-area: route; }
  .c-actions { grid-area: actions; }
  .c-status { grid-area: status; text-align: right; }
  .c-vehicle { grid-area: info; font-size: 13px; color: var(--muted); }
  .c-kg, .c-load, .c-unload { display: none; }
}
@media (max-width: 720px) {
  .grid2 { grid-template-columns: 1fr; }
  .orow { grid-template-columns: 76px 1fr; grid-template-areas: "dl route" "dl info" "status actions"; }
  .c-status { text-align: left; }
  .me #me-name { display: none; }
  .tabs { order: 3; flex-basis: 100%; }
  .sync { margin-left: 0; flex-basis: 100%; }
  .toolbar select { flex: 1 1 100%; }
}
