:root {
  --navy: #1D2D5A;
  --navy-2: #2a3d73;
  --blue: #33AFE4;
  --blue-soft: #e8f6fc;
  --bg: #f3f5f9;
  --card: #fff;
  --line: #d9dee8;
  --text: #1b2333;
  --muted: #6b7280;
  --danger: #c0392b;
  --ok: #1e8e5a;
  --radius: 8px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: "Segoe UI", Calibri, Arial, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
small { font-weight: normal; color: var(--muted); font-size: .82em; }
a { color: var(--navy); }
.muted { color: var(--muted); }
.strong { font-weight: 600; text-decoration: none; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 28px; background: #fff; border-bottom: 3px solid var(--navy);
          padding: 8px 24px; position: sticky; top: 0; z-index: 30; }
.brand img { height: 38px; display: block; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { text-decoration: none; padding: 8px 14px; border-radius: 6px; font-weight: 600; color: var(--navy); }
.topbar nav a small { display: block; font-size: 11px; }
.topbar nav a:hover { background: var(--blue-soft); }
.topbar nav a.active { background: var(--navy); color: #fff; }
.topbar nav a.active small { color: #cfe9f7; }

main { max-width: 1400px; margin: 0 auto; padding: 20px 24px 60px; }
main.wide { max-width: 1700px; }

.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
h1 { font-size: 22px; margin: 0; color: var(--navy); }
h2 { font-size: 16px; margin: 0 0 12px; color: var(--navy); display: flex; align-items: center; gap: 6px; }
h2 small { margin-left: 2px; }
h2 .right { margin-left: auto; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--navy);
       padding: 7px 14px; border-radius: 6px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
       white-space: nowrap; }
.btn small { color: inherit; opacity: .7; }
.btn:hover { border-color: var(--navy); }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); background: #fdf1f0; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .35; cursor: default; }

/* ---------- forms ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.row { display: grid; grid-template-columns: repeat(12, 1fr); gap: 10px 12px; margin-bottom: 10px; }
.row:last-child { margin-bottom: 0; }
.w-1 { grid-column: span 1; } .w-2 { grid-column: span 2; } .w-3 { grid-column: span 3; } .w-4 { grid-column: span 4; }
.w-5 { grid-column: span 5; } .w-6 { grid-column: span 6; } .w-7 { grid-column: span 7; } .w-9 { grid-column: span 9; }
.w-10 { grid-column: span 10; } .w-12 { grid-column: span 12; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); font-weight: 600; min-width: 0; }
label.check { flex-direction: row; align-items: center; gap: 6px; margin-top: 6px; }
input, select, textarea { font: inherit; font-size: 14px; color: var(--text); border: 1px solid var(--line); border-radius: 5px;
                          padding: 6px 8px; background: #fff; width: 100%; min-width: 0; }
textarea { resize: vertical; }
textarea.mono { font-family: Consolas, monospace; font-size: 12.5px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(51, 175, 228, .2); }
input.upper { text-transform: uppercase; }
input::placeholder, textarea::placeholder { color: #b6bcc8; font-style: italic; }
input.invalid { border-color: var(--danger); background: #fdf1f0; }

/* dd.mm.yyyy date field with calendar button */
.date-wrap { position: relative; display: flex; gap: 4px; min-width: 0; }
.date-wrap input.parsed { flex: 1 1 auto; min-width: 0; }
.date-wrap .cal { flex: 0 0 auto; border: 1px solid var(--line); background: #fff; border-radius: 5px; padding: 0 7px;
                  cursor: pointer; font-size: 14px; }
.date-wrap .cal:hover { border-color: var(--blue); }
.date-wrap .picker { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none;
                     border: 0; padding: 0; }
.form-actions { display: flex; gap: 8px; margin-top: 12px; }
.sticky-bottom { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; }
.hint { font-size: 12.5px; color: var(--muted); }
.hint code, p code { background: #eef1f6; padding: 1px 5px; border-radius: 3px; }
.images .img-box { height: 110px; border: 1px dashed var(--line); border-radius: 6px; display: flex; align-items: center;
                   justify-content: center; margin-bottom: 8px; background: #fafbfd; }
.images .img-box img { max-height: 90px; max-width: 90%; }

/* ---------- flash / toast ---------- */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; font-weight: 600; }
.flash-ok { background: #e7f6ee; color: var(--ok); }
.flash-error { background: #fdecea; color: var(--danger); }
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 8px;
         box-shadow: 0 6px 20px rgba(0, 0, 0, .2); z-index: 100; font-weight: 600; }
.toast.error { background: var(--danger); }

/* ---------- lists ---------- */
.filters { display: flex; gap: 8px; margin-bottom: 14px; }
.filters input[type=search] { flex: 1; }
.filters select { width: auto; }
/* orders list filter bar */
.filters.card { flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; padding: 12px 14px; }
.filters.card label { flex: 0 0 auto; }
.filters.card label.grow { flex: 1 1 260px; }
.filters.card .date-filter input { width: 118px; }
.filters.card .filter-actions { display: flex; gap: 6px; margin-left: auto; }
.filters.card input:disabled { background: #f3f5f9; color: var(--muted); }

/* sortable columns and totals */
.grid th.sortable a { color: inherit; text-decoration: none; display: inline-flex; gap: 4px; align-items: baseline; white-space: nowrap; }
.grid th.sortable .arrow { color: #c3c9d4; font-size: 10px; }
.grid th.sortable:hover .arrow, .grid th.sorted .arrow { color: var(--blue); }
.grid th.sorted { background: var(--blue-soft); }
.grid th.r a { justify-content: flex-end; width: 100%; }
.grid tfoot td { background: #f7f9fc; border-top: 2px solid var(--line); font-size: 13px; color: var(--muted); }
.grid tfoot b { color: var(--navy); }
.grid .nowrap { white-space: nowrap; }
.grid.orders td { font-size: 13.5px; }
.grid.orders td.route { max-width: 280px; }
.contact-cell div { line-height: 1.35; }
table.grid { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.grid th { text-align: left; font-size: 12.5px; color: var(--navy); background: #f7f9fc; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.grid td { padding: 8px 10px; border-bottom: 1px solid #eef0f4; vertical-align: middle; }
.grid tr:hover td { background: #fafcff; }
.grid .r { text-align: right; }
/* the cell stays a real table cell (full row height); the buttons sit in a flex row inside it */
.grid td.actions-cell { width: 1%; white-space: nowrap; vertical-align: middle; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.row-actions form { margin: 0; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 10px; background: #eef1f6; color: var(--navy); }
.tag.carrier_order, .tag.carrier { background: var(--blue-soft); color: #0b6e99; }
.tag.customer_confirmation, .tag.customer { background: #f1ecfb; color: #5b3aa4; }
.tag.location { background: #eef6ea; color: #3b7a26; }
select.status { width: auto; padding: 3px 6px; font-size: 12.5px; font-weight: 600; }
select.status.draft { color: var(--muted); }
select.status.sent { color: #0b6e99; }
select.status.done { color: var(--ok); }
select.status.cancelled { color: var(--danger); }
select.status.saved { border-color: var(--ok); background: #e7f6ee; }
.empty { text-align: center; padding: 50px; background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); }

tr.clickable { cursor: pointer; user-select: none; }

/* ---------- language toggle ---------- */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 7px 11px; font: inherit; font-weight: 600; font-size: 13px;
              color: var(--muted); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--blue); color: #fff; }
.seg .seg-label { padding: 7px 9px; font-size: 11px; font-weight: 700; color: var(--muted); background: #f3f5f9;
                  border-right: 1px solid var(--line); display: flex; align-items: center; letter-spacing: .4px; }
.topbar .ui-lang { margin: 0 0 0 auto; display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.topbar .ui-lang .seg button { padding: 5px 10px; font-size: 12px; }

/* ---------- order form ---------- */
.sticky-bar { position: sticky; top: 57px; z-index: 20; background: var(--bg); padding: 10px 0 12px; margin-bottom: 4px;
              display: flex; align-items: center; gap: 16px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.sticky-bar .title { display: flex; align-items: baseline; gap: 12px; position: relative; flex: 0 0 auto; }
.sticky-bar h1 .num { margin-left: 8px; color: var(--blue); }
.sticky-bar .totals { margin-left: auto; font-size: 13px; color: var(--muted); min-width: 0; white-space: nowrap;
                      overflow: hidden; text-overflow: ellipsis; }
.sticky-bar .actions { flex: 0 0 auto; flex-wrap: nowrap; }
@media (min-width: 1100px) { .sticky-bar { flex-wrap: nowrap; } }
.sticky-bar .totals b { color: var(--navy); }

/* unsaved changes: orange pulsing title and Save button */
@keyframes unsaved-blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes unsaved-glow { 0%, 100% { box-shadow: 0 0 0 0 rgba(234, 88, 12, .55); } 50% { box-shadow: 0 0 0 6px rgba(234, 88, 12, 0); } }
body.unsaved .sticky-bar h1, body.unsaved .sticky-bar h1 small, body.unsaved .sticky-bar h1 .num {
  color: #ea580c; animation: unsaved-blink 1.2s ease-in-out infinite; }
body.unsaved #btn-save { background: #ea580c; border-color: #ea580c; color: #fff; animation: unsaved-glow 1.2s ease-out infinite; }
body.unsaved #btn-save small { color: #fff; opacity: .9; }
.section-head { display: flex; align-items: baseline; gap: 14px; margin: 22px 0 8px; }
.section-head h2 { margin: 0; }
.section-head .toggle-volume { margin: 0 0 0 auto; color: var(--navy); font-size: 13px; cursor: pointer; }
.section-head .toggle-volume input { width: auto; }
.hide-volume .col-volume { display: none; }

.shipment { border-left: 4px solid var(--navy); }
.shipment-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.shipment-head h3 { margin: 0; color: var(--navy); font-size: 16px; letter-spacing: .3px; }
.shipment-head .ship-totals { color: var(--muted); font-size: 13px; }
.shipment-head .tools { margin-left: auto; display: flex; gap: 4px; }
.stops { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 6px 0 12px; }
fieldset.stop { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px 10px; margin: 0; min-width: 0; }
fieldset.stop legend { font-weight: 700; color: var(--navy); padding: 0 6px; font-size: 14px; }
fieldset.stop.loading { background: linear-gradient(#fff, #fbfdff); border-top: 3px solid var(--blue); }
fieldset.stop.unloading { border-top: 3px solid var(--navy); }
fieldset.stop .row { margin-bottom: 7px; gap: 6px 8px; }
.stop-tools { display: flex; gap: 6px; justify-content: flex-end; margin-top: 4px; }
.cargo h4 { margin: 0 0 6px; color: var(--navy); }
.cargo-table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.cargo-table th { font-size: 12px; text-align: left; color: var(--muted); padding: 2px 4px; line-height: 1.1; }
.cargo-table td { padding: 2px 3px; }
.cargo-table input { padding: 5px 6px; }
.cargo-table input.calc { background: var(--blue-soft); border-color: #bfe3f4; }
.cargo-table input.calc[data-manual="1"] { background: #fff; border-color: var(--line); }
.cargo-table th.calc-h { color: #0b6e99; }
.cargo-hint { font-size: 12px; margin: 2px 0 8px; }
.c-stack { width: 64px; text-align: center; }
.cargo-table td.c-stack input { width: 18px; height: 18px; margin-top: 5px; cursor: pointer; }
.c-qty { width: 64px; } .c-pkg { width: 160px; } .c-dim { width: 70px; } .c-num { width: 84px; }
.add-shipment { width: 100%; justify-content: center; padding: 12px; border-style: dashed; margin-bottom: 20px; font-size: 15px; }

/* ---------- autocomplete ---------- */
.ac-wrap { position: relative; }
.ac-list { position: absolute; top: 100%; left: 0; right: 0; z-index: 50; list-style: none; margin: 2px 0 0; padding: 4px 0;
           background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
           max-height: 280px; overflow: auto; }
.ac-list li { padding: 6px 10px; cursor: pointer; font-size: 13.5px; color: var(--text); font-weight: normal;
              display: flex; gap: 8px; align-items: baseline; }
.ac-list li .tag { margin-left: auto; }
.ac-list li:hover, .ac-list li.active { background: var(--blue-soft); }

@media (max-width: 1000px) {
  .stops { grid-template-columns: 1fr; }
  .row { grid-template-columns: repeat(6, 1fr); }
  .row > * { grid-column: span 6 !important; }
}

/* ---------- billing in the orders list ---------- */
.grid th.bill-h, .grid td.bill { background: #fbfcf6; }
.grid th.two a { display: inline-flex; }
.grid th.two a.sorted { color: var(--blue); }
/* both billing cells start at the top, so their two input pairs always line up */
.grid td.bill { width: 170px; padding: 10px 12px; vertical-align: top; }
.grid td.bill .bill-in { display: block; width: 150px; height: 28px; margin: 0; padding: 4px 9px; font-size: 13px;
                         border: 1px solid #dfe3eb; border-radius: 6px; background: #fff; }
.grid td.bill .bill-in + .bill-in { margin-top: 5px; }
.grid td.bill .bill-in:hover { border-color: #c5ccd9; }
.grid td.bill .bill-in.amount { text-align: right; font-variant-numeric: tabular-nums; }
.grid td.bill .bill-in.saved { border-color: var(--ok); background: #e7f6ee; }
.grid td.bill .bill-in.not-saved { border-color: #d64545; background: #fdecea; }  /* could not be saved (no connection) */
.grid td.bill.sub.drop { outline: 2px dashed var(--blue); outline-offset: -3px; background: var(--blue-soft); }
/* same width as the two inputs above it, so the 📎 button and file chips sit centred under them */
.grid td.bill .attach { display: flex; flex-direction: column; align-items: center; gap: 5px; margin-top: 8px; width: 150px; }
.grid td.bill .attach .chips { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.grid td.bill .attach .chips:empty { display: none; }
/* button and file chip share one look: same height, rounded, centred */
.btn.tiny { height: 24px; padding: 0 10px; font-size: 12px; font-weight: 600; border-radius: 12px; }
.chip { display: inline-flex; align-items: center; height: 24px; background: #eaf3fb; border: 1px solid #cfe2f3;
        border-radius: 12px; font-size: 12px; max-width: 150px; }
.chip a { text-decoration: none; padding: 0 2px 0 10px; color: var(--navy); font-weight: 600; white-space: nowrap;
          overflow: hidden; text-overflow: ellipsis; }
.chip a:hover { text-decoration: underline; }
.chip-x { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 8px 0 4px; font-size: 14px; line-height: 1; }
.chip-x:hover { color: var(--danger); }
.earnings.pos { color: var(--ok); font-weight: 700; }
.earnings.neg { color: var(--danger); font-weight: 700; }
.earnings.zero { color: var(--muted); font-weight: 600; }  /* break-even, e.g. 1.400 − 1.400 */
.earnings.est { color: var(--muted); font-style: italic; font-weight: 600; }

/* ---------- billing card on the order screen ---------- */
.billing-card { border-top: 3px solid #b9c98f; }
.billing-card .hint-inline { font-size: 12px; font-weight: normal; margin-left: 6px; }
.billing-card input.amount { text-align: right; }
.billing-card .earn-box { display: flex; flex-direction: column; gap: 3px; font-size: 12px; font-weight: 600; color: var(--muted); }
.billing-card .earn-box b { font-size: 18px; padding-top: 4px; }
.billing-card .attach-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.billing-card .attach-row .chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.grid tfoot td.tot-cell div { line-height: 1.45; }

/* ---------- backup card in settings ---------- */
.backup-actions { display: flex; gap: 8px; align-items: flex-end; }
.backup-status { margin-top: 6px; padding: 8px 12px; border-radius: 6px; background: #e7f6ee; color: var(--ok); font-size: 13px; }
.backup-status.bad { background: #fdf1f0; color: var(--danger); }
.backup-status b { color: inherit; }

/* ---------- internal received-invoice code: light red until booked, whole row green when booked ---------- */
.grid td.bill.pr.pending .bill-in[data-field="pr_number"] { background: #fdecea; border-color: #f3c6c0; }
.grid tr.booked td, .grid tr.booked:hover td { background: #dff3e6; }
.grid td.bill .pr-done { flex-direction: row; align-items: center; gap: 6px; margin-top: 6px; color: var(--navy); cursor: pointer; }
.grid td.bill .pr-done input { width: 16px; height: 16px; margin: 0; }
.billing-card input.pending { background: #fdecea; border-color: #f3c6c0; }
.billing-card .pr-box { align-self: end; padding-bottom: 8px; color: var(--navy); font-size: 13px; }
.billing-card .pr-box input { width: 16px; height: 16px; }
.billing-card .pr-box.done { color: var(--ok); }

/* ---------- login (online version) ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { width: 340px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login-box img { height: 46px; align-self: center; }
.login-box h1 { text-align: center; font-size: 20px; }
.topbar .logout { margin: 0 0 0 10px; }

/* ---------------------------------------------------------------- received order (customer's original PDF) */
.grid td.received { white-space: nowrap; text-align: center; }
.grid td.received .received-list { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.grid td.received .received-list:not(:empty) + .btn { margin-top: 4px; opacity: .55; }
.grid td.received.drop { outline: 2px dashed var(--blue); outline-offset: -3px; background: var(--blue-soft); }
.btn.received-btn, .chip.received { background: #fff4e0; border-color: #f0cf95; color: #7a4b00; }
.chip.received a { color: #7a4b00; }
.received-toggle { color: #7a4b00; }
.received-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.received-row .chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.drop-overlay { position: fixed; inset: 0; z-index: 50; pointer-events: none; display: flex; align-items: center;
                justify-content: center; background: rgba(29, 45, 90, .12); border: 4px dashed var(--blue); }
.drop-overlay[hidden] { display: none; }
.drop-overlay div { background: var(--navy); color: #fff; padding: 16px 24px; border-radius: 10px; font-size: 17px; font-weight: 600; }
/* side panel: the original next to the form (wide screens only, see order_form.js) */
.doc-panel { position: fixed; top: 57px; right: 0; bottom: 0; width: var(--doc-w, 44vw); z-index: 25; background: #fff;
             border-left: 1px solid var(--line); box-shadow: -4px 0 14px rgba(0, 0, 0, .06); display: flex; flex-direction: column; }
.doc-panel[hidden] { display: none; }
.doc-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px 8px 14px; border-bottom: 1px solid var(--line);
            background: #fff4e0; color: #7a4b00; }
.doc-head .spacer { flex: 1; }
.doc-tabs { display: inline-flex; gap: 4px; }
.doc-panel iframe { flex: 1; width: 100%; border: 0; background: #525659; }
.doc-resize { position: absolute; left: -4px; top: 0; bottom: 0; width: 8px; cursor: col-resize; z-index: 1; }
body.doc-open main.form-page { max-width: none; margin: 0 var(--doc-w, 44vw) 0 0; }
body.doc-open .sticky-bar, body.doc-open .sticky-bar .actions { flex-wrap: wrap; }  /* narrower form: buttons may wrap */
/* ‹ › in an order: previous / next order of the Nalogi list */
.order-nav { display: inline-flex; align-items: center; gap: 4px; align-self: center; }
.order-nav .nav-btn { width: 34px; height: 34px; justify-content: center; padding: 0; font-size: 22px; line-height: 1; text-decoration: none; }
.order-nav .nav-btn.disabled { opacity: .35; cursor: default; }
.order-nav small { margin: 0 6px 0 2px; font-size: 12px; white-space: nowrap; }
