:root {
  --bg: #f5f5f4;
  --panel: #ffffff;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --brand: #111827;
  --accent: #2563eb;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- bara de sus */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px; height: 52px;
}
.logo { font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.logo span { opacity: .55; font-weight: 500; }
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none; border: 0; color: rgba(255,255,255,.7); padding: 8px 12px; border-radius: 8px;
  cursor: pointer; white-space: nowrap; position: relative;
}
.tab:hover { color: #fff; background: rgba(255,255,255,.08); }
.tab.active { color: #111827; background: #fff; font-weight: 600; }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px;
  background: #f59e0b; color: #111; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
.logout { color: rgba(255,255,255,.7); text-decoration: none; font-size: 13px; white-space: nowrap; }
.logout:hover { color: #fff; }

/* ---------- banner fidelitate */
.reward-banner {
  display: none; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--warn-bg); color: #78350f; border-bottom: 1px solid #fcd34d;
  padding: 10px 16px; font-weight: 500;
}
.reward-banner.show { display: flex; }
.reward-banner .names { font-weight: 700; }

/* ---------- pagini */
main { padding: 16px; max-width: 1800px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { font-size: 20px; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.spacer { flex: 1; }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px;
  cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: #d6d3d1; background: #fafaf9; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: #1f2937; }
.btn.success { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.success:hover { background: #15803d; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: default; }

.search {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 220px; background: var(--panel);
}
.search:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 11px; cursor: pointer; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip .count { opacity: .6; font-size: 12px; }

.selbar {
  display: none; align-items: center; gap: 8px; flex-wrap: wrap;
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: var(--radius); padding: 8px 10px; margin-bottom: 10px;
}
.selbar.show { display: flex; }
.selbar strong { margin-right: 4px; }

.legend { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.pchip {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 6px; padding: 3px 8px; font-size: 12px; font-weight: 600;
  cursor: pointer; border: 2px solid transparent; font-variant-numeric: tabular-nums;
}
.pchip.active { border-color: var(--ink); }
.pchip .n { font-weight: 500; opacity: .75; }

.grid-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }

/* ---------- carduri statistici */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .value.pos { color: var(--ok); }

/* ---------- colete */
.parcels { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.parcel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.parcel-top { padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.parcel-top input[type=color] { width: 34px; height: 34px; border: 0; padding: 0; background: none; cursor: pointer; border-radius: 6px; }
.parcel-awb { font-weight: 700; font-size: 15px; border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 2px 4px; width: 100%; font-variant-numeric: tabular-nums; }
.parcel-awb:hover { border-color: var(--line); }
.parcel-body { padding: 0 12px 10px; flex: 1; }
.parcel-body ul { margin: 6px 0 0; padding-left: 18px; color: #44403c; font-size: 13px; max-height: 160px; overflow: auto; }
.parcel-foot { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.pill { white-space: nowrap; font-size: 12px; border-radius: 999px; padding: 2px 9px; font-weight: 600; }
.pill.on-way { background: #e0e7ff; color: #3730a3; }
.pill.arrived { background: var(--ok-bg); color: #166534; }
.muted { color: var(--muted); }

/* ---------- Tabulator ajustari */
.tabulator { font-size: 13px; border: 0; background: var(--panel); }
.tabulator .tabulator-header { background: #fafaf9; border-bottom: 1px solid var(--line); }
.tabulator .tabulator-header .tabulator-col { background: #fafaf9; border-right: 1px solid var(--line); }
.tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 7px 8px; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-title { white-space: normal; line-height: 1.2; }
.tabulator .tabulator-header .tabulator-col.gift-col { background: #fef3c7; }
.tabulator-row .tabulator-cell { padding: 6px 8px; border-right: 1px solid #f0efee; }
.tabulator-row { border-bottom: 1px solid #f0efee; }
.tabulator-row.tabulator-row-even { background: #fcfcfb; }
.tabulator-row.tabulator-selected { background: #dbeafe !important; }
.tabulator-row .tabulator-cell.tabulator-editing { border: 2px solid var(--accent); padding: 4px 6px; }
.tabulator-row .tabulator-cell.editable-cell { cursor: text; }
.tabulator .tabulator-tableholder .tabulator-placeholder span { color: var(--muted); font-weight: 500; font-size: 14px; }
.tabulator-row.tabulator-group { background: #eef2f7; border-top: 1px solid #dbe3ee; font-weight: 600; padding: 7px 10px; }
.tabulator-row.tabulator-group span { color: var(--muted); font-weight: 500; margin-left: 8px; }
.num { font-variant-numeric: tabular-nums; }
.cell-link { text-decoration: none; margin-left: 6px; font-size: 12px; }
.awb-chip { display: inline-block; padding: 1px 7px; border-radius: 5px; font-weight: 600; font-size: 12px; }
.status-tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.status-tag[data-s="Precomandă"] { background: #f3f4f6; color: #374151; }
.status-tag[data-s="În drum"] { background: #e0e7ff; color: #3730a3; }
.status-tag[data-s="Ajuns la mine"] { background: #fef3c7; color: #92400e; }
.status-tag[data-s="Trimis clientului"] { background: #dcfce7; color: #166534; }
.status-tag[data-s="Stoc"] { background: #f5f5f4; color: #57534e; border: 1px dashed #d6d3d1; }
.status-tag[data-s="Vândut"] { background: #111827; color: #fff; }
.progress { display: flex; align-items: center; gap: 8px; }
.progress .bar { flex: 1; height: 8px; background: #f0efee; border-radius: 6px; overflow: hidden; min-width: 60px; }
.progress .bar i { display: block; height: 100%; background: var(--accent); }
.progress.due .bar i { background: #f59e0b; }
.neg { color: var(--danger); }
.pos { color: var(--ok); }

/* ---------- modale */
.modal-back { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: none; align-items: flex-start; justify-content: center; z-index: 50; padding: 60px 16px 16px; overflow: auto; }
.modal-back.show { display: flex; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 480px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h2 { font-size: 17px; margin: 0; padding: 16px 18px 0; }
.modal .body { padding: 14px 18px; display: grid; gap: 12px; }
.modal .foot { padding: 12px 18px 16px; display: flex; justify-content: flex-end; gap: 8px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 7px; border: 2px solid transparent; cursor: pointer; }
.swatch.active { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }
.gift { font-size: 40px; text-align: center; }
.big-msg { text-align: center; font-size: 16px; }

/* ---------- toast */
.toasts { position: fixed; bottom: 16px; right: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 60; pointer-events: none; }
.toast { background: #111827; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 420px; pointer-events: auto; animation: pop .15s ease-out; }
.toast.err { background: var(--danger); }
.toast.ok { background: #14532d; }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }

/* ---------- setari / backup */
.cards2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card p { margin: 0 0 12px; color: var(--muted); }
.filelist { list-style: none; padding: 0; margin: 0; max-height: 360px; overflow: auto; }
.filelist li { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }

@media (max-width: 700px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .logo { display: none; }
  main { padding: 10px; }
  .search { min-width: 0; flex: 1; }
  .row2 { grid-template-columns: 1fr; }
  #statusChips, #loyaltyChips, #parcelChips, #stockChips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; width: 100%; }
  #statusChips::-webkit-scrollbar { display: none; }
  .chip { white-space: nowrap; }
}
.tabulator-row .tabulator-cell.gift-col { background: rgba(254,243,199,.45); }

/* ---------- adaugare rapida */
.quickadd { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px; margin-bottom: 10px; box-shadow: var(--shadow); }
.quickadd input:not([type=checkbox]) { border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; min-width: 0; flex: 1 1 140px; background: #fff; }
.quickadd input.qa-small { flex: 0 1 90px; }
.quickadd input.qa-mid { flex: 1 1 130px; }
.quickadd input:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
.qa-title { font-weight: 600; font-size: 13px; padding: 0 4px; white-space: nowrap; }
.qa-check { display: inline-flex; gap: 5px; align-items: center; font-size: 13px; white-space: nowrap; }
.tabulator-row.ghost-row { background: #fcfcfb !important; }
.tabulator-row.ghost-row .tabulator-cell { color: var(--muted); }
.ghost-hint { color: #a8a29e; font-style: italic; }
.nb-tag { font-size: 11px; font-weight: 700; background: #fee2e2; color: #991b1b; padding: 1px 6px; border-radius: 5px; }
.orig-client { color: #9a3412; font-weight: 600; }
.track-line { font-size: 12px; margin-top: 6px; padding: 6px 8px; border-radius: 8px; background: #f5f5f4; }
.track-line b { color: var(--ink); }
.steps { margin: 0 0 12px; padding-left: 18px; color: #44403c; font-size: 13px; }
.steps li { margin-bottom: 3px; }
.set-flag { font-weight: 500; color: var(--ok); }
.svc-status { font-size: 12px; color: var(--muted); margin-top: 8px; }
.svc-status .e { color: var(--danger); }
code { background: #f5f5f4; padding: 1px 5px; border-radius: 4px; }
@media (max-width: 700px) {
  .quickadd input:not([type=checkbox]) { flex: 1 1 45%; }
  .qa-title { width: 100%; }
}

/* ---------- furnizor */
.stat .value.debt { color: #b91c1c; }
.calc-list { display: grid; gap: 6px; max-height: 52vh; overflow: auto; padding-right: 4px; }
.calc-item { display: grid; grid-template-columns: 1fr 96px; gap: 8px; align-items: center; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; }
.calc-item.filled { background: #f0fdf4; border-color: #bbf7d0; }
.calc-item .who { font-weight: 600; }
.calc-item .what { font-size: 12px; color: var(--muted); }
.calc-item input { border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; width: 100%; text-align: right; font-variant-numeric: tabular-nums; }
.calc-total { display: flex; justify-content: space-between; align-items: baseline; background: #111827; color: #fff; border-radius: 10px; padding: 10px 14px; }
.calc-total b { font-size: 22px; font-variant-numeric: tabular-nums; }
.calc-total span { opacity: .75; font-size: 13px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
.modal.wide { max-width: 640px; }

.ship-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; font-size: 13px; }
.ship-row label { font-weight: 600; font-size: 12px; }
.ship-input { width: 90px; border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; text-align: right; }

/* ---------- comutator Fidelitate / Toti clientii */
.seg { display: inline-flex; background: #e7e5e4; border-radius: 10px; padding: 3px; margin-bottom: 12px; gap: 2px; }
.seg-b { border: 0; background: none; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; color: #44403c; }
.seg-b.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.reward-note { background: var(--warn-bg); color: #78350f; border: 1px solid #fcd34d; border-radius: var(--radius); padding: 9px 12px; margin-bottom: 10px; font-size: 13px; }
.reward-note button { margin-left: 8px; }

/* ---------- anuleaza / refa */
.hist { display: flex; gap: 4px; }
.hbtn { background: rgba(255,255,255,.1); color: #fff; border: 0; width: 34px; height: 32px; border-radius: 8px; font-size: 17px; cursor: pointer; }
.hbtn:hover:not(:disabled) { background: rgba(255,255,255,.22); }
.hbtn:disabled { opacity: .3; cursor: default; }
.badge.muted-badge { background: rgba(255,255,255,.25); color: #fff; }
.tab.active .badge.muted-badge { background: #e7e5e4; color: #111; }

/* ---------- de facut */
.todo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; align-items: start; }
.todo-list { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow: auto; }
.todo-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.todo-list li .t { flex: 1; min-width: 0; }
.todo-list li .t b { display: block; }
.todo-list li .t span { color: var(--muted); }
.todo-list li .age { font-weight: 700; color: #b91c1c; white-space: nowrap; font-size: 12px; }
.todo-list .empty { color: var(--ok); border: 0; }
.count-pill { font-size: 12px; background: #f5f5f4; border-radius: 999px; padding: 1px 8px; margin-left: 4px; color: var(--muted); }
.days-input { width: 58px; border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; font: inherit; }
@media (max-width: 700px) { .hbtn { width: 30px; } }

.deliv-opts { display: grid; gap: 6px; }
.deliv-opts .btn { justify-content: flex-start; padding: 10px 12px; }
.tabulator-row.tabulator-group { background: #fdf2f8; border-top: 2px solid #fbcfe8; color: #831843; }
.tabulator-row.tabulator-group:last-of-type { background: #f5f5f4; color: var(--ink); border-top-color: var(--line); }
.loc-tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }

/* ---------- acelasi client, fisa produs, telefon */
.same-client { color: inherit; opacity: .75; font-weight: 700; padding-left: 10px; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid var(--line); padding-top: 12px; }
.sheet-actions .btn { flex: 1 1 auto; justify-content: center; padding: 10px 12px; }
.qa-check.big { font-size: 15px; gap: 8px; }
.qa-check.big input { width: 20px; height: 20px; }
.mobile-only { display: none; }
@media (max-width: 799px) {
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none !important; }
  .quickadd { display: none; }
  .quickadd.open { display: flex; }
  .modal { border-radius: 14px 14px 0 0; }
  .modal-back { padding: 30px 0 0; align-items: flex-end; }
  .modal .body { max-height: 72vh; overflow: auto; }
  .field input, .field select, .field textarea { font-size: 16px; padding: 10px 12px; }  /* 16px = iPhone nu mai face zoom */
  .quickadd input:not([type=checkbox]) { font-size: 16px; }
  .search { font-size: 16px; }
  .tabulator-row .tabulator-cell { padding: 10px 8px; }
  .page-head h1 { font-size: 18px; }
}
.track-line.track-done { background: #dcfce7; color: #166534; }

/* ---------- stoc: alegere rapida loc */
.loc-pick { display: flex; gap: 4px; }
.loc-pick button { font: inherit; font-size: 12px; font-weight: 600; padding: 5px 9px; border-radius: 999px; border: 2px solid; background: #fff; color: #44403c; cursor: pointer; }
.loc-pick button.on { box-shadow: 0 1px 3px rgba(0,0,0,.15); }
@media (max-width: 799px) { .loc-pick button { padding: 7px 8px; } }
.tick { display: inline-flex; width: 24px; height: 24px; border: 2px solid #d6d3d1; border-radius: 6px; align-items: center; justify-content: center; font-weight: 800; color: #fff; cursor: pointer; }
.tick.on { background: var(--ok); border-color: var(--ok); }
.ret-tag { display: inline-block; background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 5px; white-space: nowrap; vertical-align: middle; }
.stock-lbl { opacity: .85; }
.orig-tag { display: inline-block; background: #f5f5f4; color: #44403c; border: 1px solid #d6d3d1; font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 5px; white-space: nowrap; vertical-align: middle; }
.loc-pick.dots { gap: 8px; align-items: center; }
.dot-btn { width: 26px; height: 26px; border-radius: 50%; border: 3px solid #fff !important; box-shadow: 0 0 0 1px #d6d3d1; padding: 0 !important; opacity: .45; }
.dot-btn.on { opacity: 1; box-shadow: 0 0 0 2px #111827; }
#stockGrid .tabulator-cell[tabulator-field="_prod"] { white-space: normal; line-height: 1.3; }
.box-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.box-row input { width: 70px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; text-align: center; font-size: 16px; }
.ship-result { display: grid; gap: 6px; background: #f5f5f4; border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.verdict { font-weight: 700; padding: 6px 10px; border-radius: 8px; }
.verdict.ok { background: #dcfce7; color: #166534; }
.verdict.bad { background: #fee2e2; color: #991b1b; }
.verdict.good { background: #dbeafe; color: #1e40af; }
#addBox { justify-self: start; }
