/* Logistruck — stil aplicație */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #6b7385;
  --line: #e2e5eb;
  --brand: #0f4c81;
  --brand-ink: #ffffff;
  --brand-soft: #e7eef6;
  --ok: #1d7a46;
  --ok-soft: #e3f3ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --bad: #b42318;
  --bad-soft: #fde7e5;
  --idle: #fff7e0;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 4px 0 16px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none; }
.neg { color: var(--bad); }
.pos { color: var(--ok); }

/* ---------- bara de sus ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; background: var(--brand); color: var(--brand-ink); padding: 0 16px; min-height: 52px; box-shadow: 0 1px 0 rgba(0,0,0,.15); }
.brand { color: #fff; font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; background: #fff; color: var(--brand); font-weight: 800; font-size: 12px; letter-spacing: -.02em; }
.logo.big { width: 44px; height: 44px; font-size: 18px; background: var(--brand); color: #fff; }
.nav { display: flex; flex-wrap: wrap; gap: 2px; flex: 1; align-items: center; }
.nav > a, .nav summary { color: rgba(255,255,255,.88); padding: 15px 9px; display: block; cursor: pointer; white-space: nowrap; font-size: 13.5px; }
.nav > a:hover, .nav summary:hover { color: #fff; text-decoration: none; background: rgba(255,255,255,.08); }
.nav > a.active, .nav-group.active > summary { color: #fff; box-shadow: inset 0 -3px 0 #fff; }
.nav-group { position: relative; }
.nav-group summary { list-style: none; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::after { content: " ▾"; font-size: 10px; }
.nav-sub { position: absolute; top: 100%; left: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 240px; padding: 6px; }
.nav-sub a { display: block; padding: 8px 10px; color: var(--ink); border-radius: 6px; }
.nav-sub a:hover, .nav-sub a.active { background: var(--brand-soft); text-decoration: none; }
.userbox { display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; line-height: 1.25; }
.userbox a { color: #fff; font-weight: 600; }
.userbox .role { color: rgba(255,255,255,.75); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userbox .link { color: rgba(255,255,255,.85); padding: 0; font-size: 12px; }
.menu-btn { display: none; background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; padding: 8px; }

.container { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }
.container.wide { max-width: 1500px; }

/* ---------- elemente ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; border: 1px solid transparent; }
.alert.success { background: var(--ok-soft); color: var(--ok); border-color: #bfe3cd; }
.alert.error { background: var(--bad-soft); color: var(--bad); border-color: #f6c7c2; }
.alert.info { background: var(--brand-soft); color: var(--brand); border-color: #c9d9ea; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 6px; padding: 7px 12px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; line-height: 1.2; }
.btn:hover { border-color: #c5cad3; text-decoration: none; background: #fafbfc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #0c3f6b; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); border-color: #f2c2bd; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.small { padding: 4px 8px; font-size: 12.5px; }
.btn.link, button.link { border: 0; background: none; color: var(--brand); cursor: pointer; font: inherit; }
.btn.block { width: 100%; justify-content: center; padding: 10px; }
form.inline { display: inline; margin: 0; }

input, select, textarea { font: inherit; color: inherit; border: 1px solid #cfd4dc; border-radius: 6px; padding: 7px 9px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 76, 129, .25); border-color: var(--brand); }
input.found { border-color: var(--ok); background: var(--ok-soft); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
label > input, label > select, label > textarea { color: var(--ink); font-size: 14px; font-weight: 400; }
label.inline-check { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 13.5px; }
label.wide { grid-column: 1 / -1; }
.field-error { color: var(--bad); font-size: 12px; }
.hint { font-size: 11.5px; color: var(--muted); font-weight: 400; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; }
.inline-form label { flex-direction: row; align-items: center; gap: 6px; }
.search { min-width: 200px; }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 12.5px; color: var(--ink); }
.chip:hover { border-color: var(--brand); text-decoration: none; }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.calendar { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 14px; display: grid; gap: 6px; }
.cal-row { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }

.summary { display: flex; flex-wrap: wrap; gap: 10px; align-items: stretch; margin-bottom: 14px; }
.summary > div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; display: flex; flex-direction: column; justify-content: center; min-width: 130px; }
.summary .muted { font-size: 12px; }
.summary strong { font-size: 17px; font-variant-numeric: tabular-nums; }

/* ---------- tabele ---------- */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; -webkit-overflow-scrolling: touch; }
.card .table-wrap, .card > table.data { box-shadow: none; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; background: #f9fafb; border-bottom: 1px solid var(--line); padding: 9px 10px; white-space: nowrap; position: sticky; top: 0; }
table.data td:first-child { white-space: nowrap; }
table.data td { padding: 8px 10px; border-bottom: 1px solid #eef0f3; vertical-align: top; }
table.data tbody tr:hover td { background: #fafbfd; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tfoot td { font-weight: 700; background: #f9fafb; border-top: 2px solid var(--line); }
table.data td.empty { text-align: center; color: var(--muted); padding: 24px; }
table.data tr.idle td { background: var(--idle); }
table.data tr.inactive td { color: #9aa1ae; }
table.data tr.subtotal td { background: #f7f8fa; font-weight: 600; }
table.data tr.order-row td { background: #fbfcfe; }
.actions { white-space: nowrap; }
.actions .btn { margin: 1px 0; }
.form-table th { text-transform: none; font-size: 13px; color: var(--ink); background: transparent; }
.form-table input { width: 110px; }
.group-title { margin-top: 20px; color: var(--brand); }

.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #eef0f3; color: #475069; white-space: nowrap; }
.tag.load { background: #e6effa; color: #1b4f8a; }
.tag.unload { background: #f1e9fb; color: #5b2f91; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--warn); color: #fff; font-size: 11px; text-align: center; }

/* ---------- formulare ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.form-grid fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 0; display: grid; gap: 10px; align-content: start; }
fieldset legend { font-weight: 600; color: var(--ink); padding: 0 6px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 12px; }
.form-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }
.danger-zone { margin-top: -6px; display: flex; gap: 10px; align-items: center; }
.check-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-top: 10px; max-height: 480px; overflow: auto; }
.check-group { border: 1px solid var(--line); border-radius: 6px; padding: 8px; display: flex; flex-direction: column; gap: 3px; }
.check-group-title { border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-bottom: 2px; }
label.inactive { color: #9aa1ae; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* ---------- comandă / etape ---------- */
.leg { border-left: 4px solid var(--ok); }
.leg.pending { border-left-color: var(--warn); }
.leg-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.leg-meta { margin-top: 6px; font-size: 13px; }
.billing { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); align-items: end; }
.billing .wide { grid-column: span 3; }
.leg-total { display: flex; flex-direction: column; align-items: flex-end; }
.leg-total strong { font-size: 16px; }
.leg-actions { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(244, 245, 247, .95); padding: 10px 0; display: flex; gap: 16px; align-items: center; border-top: 1px solid var(--line); }

/* ---------- facturi ---------- */
.invoice-head { display: flex; flex-wrap: wrap; gap: 24px; justify-content: space-between; margin-bottom: 12px; }
.invoice-head h2 { margin: 2px 0 0; font-size: 18px; }
.invoice-head .right { text-align: right; }
.rechnung { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 36px 40px; max-width: 900px; margin: 0 auto; color: #111; font-size: 13px; box-shadow: var(--shadow); }
.r-head { display: flex; justify-content: space-between; gap: 30px; flex-wrap: wrap; }
.r-name { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.r-issuer p, .r-client p { margin: 1px 0; }
.r-client { min-width: 240px; }
.r-title { font-size: 22px; font-weight: 700; letter-spacing: .08em; margin: 30px 0 10px; }
.r-meta { display: flex; flex-wrap: wrap; gap: 18px; align-items: end; margin-bottom: 16px; }
.r-meta label { color: #333; }
.r-meta input, .r-in { border: 1px dashed #c8ccd4; padding: 3px 6px; border-radius: 4px; }
.r-in.wide { width: 100%; }
.r-in.num { width: 110px; text-align: right; }
.r-table { width: 100%; border-collapse: collapse; }
.r-table th, .r-table td { border-bottom: 1px solid #ddd; padding: 7px 6px; text-align: left; vertical-align: top; }
.r-table th { border-bottom: 2px solid #333; }
.r-table .num { text-align: right; }
.r-bottom { display: flex; justify-content: space-between; gap: 30px; margin-top: 20px; flex-wrap: wrap; }
.r-note { max-width: 420px; font-size: 12px; }
.r-sum td { padding: 3px 8px; }
.r-sum .num { text-align: right; min-width: 110px; }
.r-sum .grand td { font-weight: 700; border-top: 2px solid #333; }

/* ---------- autentificare ---------- */
.login-page { background: linear-gradient(160deg, #0f4c81 0%, #163a5f 60%, #0d2740 100%); min-height: 100vh; }
.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.card.login { width: 100%; max-width: 380px; padding: 28px; display: grid; gap: 14px; }
.card.login form { display: grid; gap: 12px; }
.login-brand { display: flex; align-items: center; gap: 12px; font-size: 18px; }
.login-brand .muted { font-size: 13px; }

.pager { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin: 8px 0 20px; }
.pager a, .pager .cur { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.pager .cur { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- mobil ---------- */
@media (max-width: 1100px) {
  .menu-btn { display: block; margin-left: auto; }
  .topbar { flex-wrap: wrap; }
  .nav, .userbox { display: none; width: 100%; }
  body.nav-open .nav { display: flex; flex-direction: column; align-items: stretch; padding-bottom: 8px; }
  body.nav-open .userbox { display: flex; align-items: flex-start; padding: 8px 9px 14px; border-top: 1px solid rgba(255,255,255,.15); }
  .nav > a, .nav summary { padding: 11px 9px; }
  .nav > a.active { box-shadow: inset 3px 0 0 #fff; }
  .nav-sub { position: static; background: rgba(255,255,255,.06); border: 0; box-shadow: none; }
  .nav-sub a { color: #fff; }
  .nav-sub a:hover, .nav-sub a.active { background: rgba(255,255,255,.12); }
}
@media (max-width: 640px) {
  .container { padding: 14px 10px 50px; }
  h1 { font-size: 19px; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters label, .inline-form label { width: 100%; }
  .search { min-width: 0; width: 100%; }
  .summary > div { flex: 1 1 45%; min-width: 0; }
  .billing .wide { grid-column: 1 / -1; }
  .rechnung { padding: 18px; }
}

/* ---------- tipărire ---------- */
@media (max-width: 640px) {
  table.cards-mobile thead { display: none; }
  table.cards-mobile, table.cards-mobile tbody, table.cards-mobile tr, table.cards-mobile td { display: block; width: 100%; }
  table.cards-mobile tr { border-bottom: 6px solid var(--bg); padding: 8px 4px; }
  table.cards-mobile td { border: 0; padding: 3px 8px; display: flex; gap: 10px; text-align: left !important; white-space: normal !important; }
  table.cards-mobile td::before { content: attr(data-label); flex: 0 0 82px; color: var(--muted); font-size: 12px; padding-top: 2px; }
  table.cards-mobile td[data-label=""]::before { display: none; }
  table.cards-mobile td.actions { flex-wrap: wrap; padding-top: 8px; }
  table.cards-mobile td.empty::before { display: none; }
}
@media print {
  body { background: #fff; font-size: 11px; }
  .no-print, .topbar, .filters, .chips, .toolbar, .pager, .calendar { display: none !important; }
  .container, .container.wide { max-width: none; padding: 0; }
  .table-wrap, .card, .rechnung { box-shadow: none; border: 0; padding: 0; overflow: visible; }
  table.data th { position: static; }
  .r-meta input, .r-in { border: 0; padding: 0; }
  .r-in.num { width: auto; }
  a { color: inherit; }
}
pre.log { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 6px; max-height: 420px; overflow: auto; font-size: 12px; white-space: pre-wrap; }

.distance-box { border: 1px solid var(--line); background: var(--brand-soft); border-radius: var(--radius); padding: 10px 12px; display: grid; gap: 4px; }
.distance-box strong { font-size: 22px; color: var(--brand); font-variant-numeric: tabular-nums; }
.distance-box label { margin-top: 4px; }

/* import DKV */
tr.row-warn > td { background: var(--warn-soft); }
.card h2 { font-size: 16px; margin: 0 0 10px; }
.card ul { margin: 8px 0 0; padding-left: 20px; }

/* coloanele formularelor nu se mai lățesc după conținut (ex. nume lungi de firme / șoferi în liste) */
.form-grid > fieldset { min-width: 0; min-inline-size: 0; }
.form-grid label { min-width: 0; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; }
.form-grid select { text-overflow: ellipsis; }
.price-show { display: grid; gap: 2px; }
.price-show strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.form-grid > fieldset.full { grid-column: 1 / -1; }
.form-grid textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.leg-comment { margin-top: 6px; padding: 6px 10px; background: var(--warn-soft); border-radius: 6px; white-space: normal; }
.billing textarea { font: inherit; width: 100%; box-sizing: border-box; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; resize: vertical; }
.leg-comment-edit { margin-top: 8px; display: grid; gap: 6px; }
.leg-comment-edit textarea { font: inherit; width: 100%; box-sizing: border-box; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; resize: vertical; }
.leg-comment-edit .btn { justify-self: start; }
.summary > .dkv-check { flex: 1 1 360px; gap: 4px; }
.dkv-half { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 13px; }
.dkv-half .tag { text-decoration: none; }
.unbilled { color: var(--bad); font-weight: 700; font-size: 16px; margin-left: 3px; cursor: help; }

/* import facturi emise */
.inv-table td { vertical-align: top; }
.inv-table input[name^="ord"] { width: 100%; min-width: 120px; }
table.data.compact { margin-top: 6px; font-size: 12px; }
table.data.compact th, table.data.compact td { padding: 3px 6px; }
.inv-table details summary { cursor: pointer; color: var(--muted, #667); margin-top: 4px; }
.inv-table td > div { min-width: 0; }
.inv-table td.nowrap { white-space: nowrap; }
@media (max-width: 760px) {
  .inv-table details { overflow-x: auto; max-width: 100%; }
  table.cards-mobile table.compact { display: table; width: auto; }
  table.cards-mobile table.compact thead { display: table-header-group; }
  table.cards-mobile table.compact tbody { display: table-row-group; width: auto; }
  table.cards-mobile table.compact tr { display: table-row; width: auto; border: 0; padding: 0; }
  table.cards-mobile table.compact td, table.cards-mobile table.compact th { display: table-cell; width: auto; padding: 3px 6px; }
  table.cards-mobile table.compact td::before { display: none; }
}
