
:root{ --brand:#c5810e; --bg:#fff; --fg:#111; --muted:#666; --border:#e5e5e5; }
*{ box-sizing:border-box; }
body{ margin:0; font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial; color:var(--fg); background:var(--bg); }
.app-header{ display:flex; align-items:center; gap:12px; padding:12px 16px; border-bottom:1px solid var(--border); position:sticky; top:0; background:#fff; z-index:10;}
.app-header .logo{ width:28px; height:28px; border-radius:6px; }
h1{ font-size:18px; margin:0; }
h2{ font-size:18px; margin:16px 0 8px; }
h3{ font-size:16px; margin:0 0 8px; }
main{ padding:12px; max-width:1100px; margin:0 auto; }
.app-footer{ padding:12px; text-align:center; color:var(--muted); border-top:1px solid var(--border); margin-top:24px; }
.spacer{ flex:1; }

.card{ border:1px solid var(--border); height:100%; border-radius:12px; padding:12px; background:#fff; }
.grid.two{ display:grid; grid-template-columns:1fr; gap:12px; align-items:start; }
@media(min-width:900px){ .grid.two{ grid-template-columns:repeat(2, minmax(0,1fr)); } }

label{ display:block; font-size:12px; color:var(--muted); margin:10px 0 4px; }
input, select, textarea{ width:100%; padding:10px; border:1px solid var(--border); border-radius:10px; font-size:14px; }
textarea{ min-height:64px; resize:vertical; }

.tabs{ display:flex; gap:8px; border-bottom:1px solid var(--border); margin-bottom:12px; }
.tabs button{ padding:10px 14px; border:none; background:none; border-bottom:2px solid transparent; cursor:pointer; }
.tabs button.active{ border-bottom-color:var(--brand); color:var(--brand); font-weight:600; }

.btn{ padding:8px 12px; border-radius:10px; border:1px solid var(--border); background:#fafafa; cursor:pointer; font-size:13px;}
.btn.primary{ background:var(--brand); color:#fff; border-color:var(--brand); }
.btn.ghost{ background:transparent; border-color:var(--border); }
.btn.sm{ padding:6px 8px; font-size:12px; }

.actions{ display:flex; gap:8px; justify-content:flex-end; margin-top:12px; }
.list{ display:flex; flex-direction:column; gap:8px; }
.item{ border:1px dashed var(--border); border-radius:10px; padding:10px; }
.meta{ color:var(--muted); font-size:12px; }
.muted{ color:var(--muted); font-size:12px; }
.hidden{ display:none !important; }

.groups{ display:flex; flex-direction:column; gap:8px; }
.group{ border:1px solid var(--border); border-radius:12px; overflow:hidden; }
.group-header{ display:flex; justify-content:space-between; align-items:center; padding:10px 12px; background:#fafafa; cursor:pointer; }
.group-title{ font-weight:600; }
.group-body{ padding:8px; display:flex; flex-direction:column; gap:8px; }
.badge{ display:inline-block; padding:2px 6px; border-radius:8px; border:1px solid var(--border); font-size:11px; color:#333; }
.badge.store{ border-color:#ffd7a3; background:#fff6e9; }


/* Items repeater */
.item-row .row { display:flex; gap:.5rem; align-items:center; margin:.25rem 0; }
.item-row input[type="text"], .item-row input[type="number"], .item-row input { flex:1; }
.item-row .remove { opacity:.7; }


.phone-row input { flex:1; }
.phone-row .remove { opacity:.7; }

/* Item location status controls */
.location-controls{display:flex;gap:8px;align-items:center;margin-top:6px;flex-wrap:wrap;font-size:12px}
.location-controls .status-option{display:flex;gap:4px;align-items:center;padding:2px 6px;border:1px solid var(--border);border-radius:8px}

/* Orders compact table */
.orders-table{width:100%; border-collapse:collapse; font-size:14px}
.orders-table thead th{position:sticky; top:0; background:var(--card); text-align:left; padding:6px; border-bottom:1px solid var(--border)}
.orders-table td{padding:6px; border-bottom:1px solid var(--border); vertical-align:top}
.orders-table .badge{padding:2px 8px; border-radius:999px; border:1px solid var(--border); font-size:12px}
.orders-table .badge.paid{background:#e6ffe6}
.orders-table .badge.partial{background:#fffbe6}
.orders-table .badge.due{background:#ffe6e6}

/* Horizontal orders row layout v2 */
.order-row{display:flex; gap:12px; align-items:flex-start; padding:10px 0; border-bottom:1px solid var(--border)}
.order-col.client{min-width:240px; max-width:300px; flex:0 0 260px}
.order-col.items{flex:1; min-width:0}
.order-col.totals{min-width:220px; flex:0 0 220px}
.order-col .line{margin:2px 0}
.order-col .label{display:inline-block; min-width:64px; color:var(--muted)}
.store-box{border:1px solid var(--border); border-radius:12px; padding:8px; margin-bottom:8px; background:var(--card)}
.store-head{display:flex; flex-direction:column; align-items:flex-start; gap:4px; margin-bottom:4px}
.badge.store{border:1px solid var(--border); padding:2px 8px; border-radius:999px}
.items-collapsible{margin-top:6px; padding:6px; border:1px dashed var(--border); border-radius:10px; background:var(--bg)}
.itemline{margin:2px 0}
.chip{display:inline-block; padding:1px 6px; font-size:11px; border-radius:999px; border:1px solid var(--border); margin-left:6px}
.chip.store{background:#eef7ff}
.chip.warehouse{background:#f1f1ff}
.chip.in_transit{background:#fff3e6}
.badge.paid{background:#e6ffe6}
.badge.partial{background:#fffbe6}
.badge.due{background:#ffe6e6}
.comment-ico{cursor:help; margin-right:6px}
@media (max-width: 900px){
  .order-row{flex-direction:column}
  .order-col.client, .order-col.totals{flex:unset; max-width:unset; min-width:unset}
}

.store-head .muted{display:block; white-space:normal; overflow-wrap:anywhere}
.store-head .btn{align-self:flex-start}

/* Grid layout for order row: client + totals top, stores full-width below */
@media(min-width:900px){
  .order-row{
    display:grid;
    grid-template-columns: 1fr 300px;
    grid-template-areas:
      "client totals"
      "stores stores";
    column-gap:16px;
    align-items:start;
  }
  .order-col.client{grid-area: client; max-width:none; flex:unset}
  .order-col.totals{grid-area: totals; min-width:0; flex:unset}
  .order-col.items{grid-area: stores; min-width:0; flex:unset}
}

/* Fine-tune orders row typography and actions layout */
.order-row{font-size:13px}
.order-row .badge{font-size:11px}
.order-row .itemline{font-size:13px}
.order-row .comments{font-size:12px}
.order-row .actions{display:flex; flex-wrap:wrap; gap:6px}
.order-row .actions .btn{font-size:12px; padding:6px 10px}
.order-col.totals{min-width:200px}

.order-col.totals{min-width:240px; font-size:12.5px; overflow:visible}

.order-row .actions{display:flex; flex-wrap:wrap; gap:6px; justify-content:flex-start; margin-top:6px}

.order-row .actions .btn{font-size:12px; padding:5px 9px}

.group-body{overflow:visible}

/* Background highlight per payment status */
.order-row.status-paid{ background: #eafbea; border-left: 4px solid #7fd77f; border-radius: 12px; padding-left: 10px; }
.order-row.status-partial{ background: #fff7e6; border-left: 4px solid #ffc24a; border-radius: 12px; padding-left: 10px; }
.order-row.status-due{ background: #ffe8ee; border-left: 4px solid #ff7aa8; border-radius: 12px; padding-left: 10px; }



/* === Fix: clip inner boxes inside rounded order row === */
.order-row.status-paid,
.order-row.status-partial,
.order-row.status-due{
  overflow: hidden;         /* clip child backgrounds to rounded corners */
  padding: 10px;            /* add right padding so .store-box doesn't flush to edge */
}
/* === Expressive badges/chips for stores & item location === */
.badge.store{
  background:#e6f2ff;
  border-color:#91caff;
  color:#0b53b0;
  font-weight:600;
  padding:3px 10px;
}
.badge.store::before{ content:'🏬'; margin-right:6px }

.chip{ font-weight:600 }
.chip.store{ background:#e6f4ff; border-color:#91caff; color:#0958d9 }
.chip.warehouse{ background:#f3e8ff; border-color:#d3adf7; color:#531dab }
.chip.in_transit{ background:#fff7e6; border-color:#ffd591; color:#d48806 }

.chip.store::before{ content:'🏪'; margin-right:4px }
.chip.warehouse::before{ content:'📦'; margin-right:4px }
.chip.in_transit::before{ content:'🚚'; margin-right:4px }

.itemline .code{
  display:inline-block;
  padding:0 6px;
  margin-right:6px;
  border-radius:8px;
  background:rgba(0,0,0,.05);
}



/* --- FIX: checkbox labels overlapping on mobile for location controls --- */
input[type="checkbox"], input[type="radio"]{
  width:auto !important;
  padding:0 !important;
  border:none;
  border-radius:0;
  height:auto;
  -webkit-appearance:auto;
  appearance:auto;
}

.location-controls{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
  font-size:12px;
}

.location-controls .status-option{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:4px 8px;
  border:1px solid var(--border);
  border-radius:8px;
  background:#fff;
  line-height:1.2;
}

@media (max-width: 480px){
  .location-controls{ gap:6px; }
  .location-controls .status-option{ padding:4px 6px; }
}
/* --- END FIX --- */


/* === Wally 2025-08-13: Mobile & visual polish === */

/* Payment status background for store boxes */
.store-box.paid{ background:#e6ffe6; border-color:#b8e6b8; }
.store-box.partial{ background:#fffbe6; border-color:#e6d8a3; }
.store-box.due{ background:#ffe6e6; border-color:#e3b3b3; }

/* Make store badges more expressive */
.badge.store{ font-weight:600; background:#fff3e0; border-color:#ffc88a; }

/* Location controls – ensure checkbox spacing & no overlap on mobile */
.location-controls{ display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin-top:6px; font-size:12px; }
.location-controls .status-option{ display:inline-flex; align-items:center; gap:6px; padding:4px 8px; border:1px solid var(--border); border-radius:8px; background:#fff; line-height:1.2; }
.location-controls .status-option input[type="checkbox"]{ margin:0; }

@media (max-width: 520px){
  /* Wrap item inputs so delete button isn't cut off */
  .item-row .row{ flex-wrap:wrap; }
  .order-row{ font-size:12.5px; }
  .order-row .actions .btn{ padding:6px 10px; }
}

/* Put shop name & mini totals on separate lines explicitly */
.store-head{ display:flex; flex-direction:column; align-items:flex-start; gap:4px; }
.store-head .muted{ display:block; white-space:normal; overflow-wrap:anywhere; }

/* Ensure status chips sit nicely next to codes */
.itemline .chip{ margin-left:6px; }


/* === Fix: prevent store box overflow & clip background === */
.store-box{ max-width:100%; overflow:hidden; }
.items-collapsible{ width:100%; max-width:100%; overflow-x:auto; }
.items-collapsible .itemline{ white-space:nowrap; }


/* === Desktop-only width for store boxes === */
@media (min-width: 900px){
  .store-box{ max-width:84%; }
}


/* Orders toolbar */
.orders-toolbar{ display:flex; gap:8px; align-items:center; margin-bottom:8px; }
.orders-toolbar input[type="search"]{ flex:1; }


/* Stock tab overrides */


/* Stock tab: desktop width match orders */
@media (min-width: 900px){
  #tab-stock .store-box{ max-width:84%; }
}

/* Modal */
.modal{ position:fixed; inset:0; display:flex; align-items:center; justify-content:center; z-index:1000; }
.modal.hidden{ display:none !important; }
.modal-backdrop{ position:absolute; inset:0; background:rgba(0,0,0,.35); }
.modal-dialog{ position:relative; background:#fff; border-radius:12px; border:1px solid var(--border);
  padding:12px; width:min(520px, 92vw); box-shadow:0 10px 30px rgba(0,0,0,.15); }
.modal-dialog .list .item{ border:1px solid var(--border); }

/* Delivery modal payment options */
#dmPaymentBlock{ margin-top:10px; }
#dmPaymentBlock label{ display:inline-flex; align-items:center; gap:6px; margin:0 !important; }
#dmPaymentBlock input[type="radio"]{ margin:0; }
#dmPaymentBlock .options{ display:flex; gap:16px; align-items:center; flex-wrap:wrap; }

.order-row.in-delivery{background:#eaf4ff;}

/* Hide delivery action buttons inside the Products tab */
#tab-products .send-to-delivery,
#tab-products .cancel-delivery { display: none !important; }
.toggle-store{    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fafafa;
    cursor: pointer;
    font-size: 13px;}
.btn.danger{ background:#e64545; color:#fff; border-color:#e64545; }


/* Date chips for grouped lists */
.date-chip{display:inline-block; padding:2px 8px; border-radius:999px; font-weight:600;}
.date-today{background:#e8f5e9; color:#1b5e20; border:1px solid #c8e6c9;}
.date-future{background:#e3f2fd; color:#0d47a1; border:1px solid #bbdefb;}
.date-past{background:#fde7ef; color:#8e0038; border:1px solid #f8bbd0;}


.badge.reserve{ background:#fff3cd; color:#7a5b00; border:1px solid #ffe08a; }

.reserve-flag{ margin-top:6px; }

/* Keep modal actions visible */
.modal-dialog .actions{
  position: sticky;
  bottom: 0;
  display:flex;
  gap:8px;
  justify-content:flex-end;
  padding-top:8px;
  margin-top:8px;
  background:#fff;
  border-top:1px solid var(--border);
}
.itemline[data-status="completed"] small { opacity: .9; font-weight: 600; }


/* Hide action buttons for completed items */
.itemline[data-status="completed"] .btn.move-to-store,
.itemline[data-status="completed"] .btn.complete-item,
.itemline[data-status="completed"] .move-to-store,
.itemline[data-status="completed"] .complete-item {
  display: none !important;
}


/* ARCHIVE GROUPS */
.group { border:1px solid rgba(0,0,0,.06); border-radius:12px; margin:6px 0; background:#fff; }
.group-header { display:flex; align-items:center; justify-content:space-between; padding:10px 12px; background:#f8f8f8; border-radius:12px 12px 0 0; }
.group-header .title { font-weight:600; }
.group-body { padding:10px 12px; }
.date-label.date-today { color:#2e7d32; }
.date-label.date-past { color:#555; }
.date-label.date-future { color:#1565c0; }


/* Compact layout for Archive tab */
#tab-archive .order-row { padding: 8px 0; }
#tab-archive .order-col.client .line { margin: 2px 0; }
#tab-archive .store-box { border-radius: 10px; padding: 8px 10px; }
#tab-archive .store-box.paid { background: #f3fbf3; border: 1px dashed rgba(76, 175, 80, .35); }
#tab-archive .store-head { display:flex; align-items:center; justify-content:space-between; }
#tab-archive .store-head .muted { font-size: 12px; opacity: .8; }
#tab-archive .itemline { padding: 4px 6px; margin: 4px 0; border-radius: 8px; background: #fff; border: 1px solid rgba(0,0,0,.06); }
#tab-archive .itemline .meta { font-size: 12px; opacity: .85; }
#tab-archive .group { border: 1px solid #eee; border-radius: 10px; background:#fff; }
#tab-archive .group-header { padding: 8px 10px; }
#tab-archive .group-body { padding: 10px; }



/* Compact Archive sizing tweaks */
#tab-archive .order-row { gap: 10px; }
#tab-archive .order-col.client { min-width: 260px; }
#tab-archive .order-col.totals { min-width: 200px; }

/* === Archive compact layout (v16 tweak) === */
#tab-archive .order-row{ padding:8px 0; gap:10px; }
#tab-archive .order-col.client{ min-width:220px; max-width:280px; flex:0 0 240px; }
#tab-archive .order-col.items{ flex:1; min-width:0; }
#tab-archive .store-box{ margin-bottom:0; }
#tab-archive .store-head{ gap:6px; margin-bottom:4px; }
#tab-archive .items-collapsible{ margin-top:4px; padding:4px; }
#tab-archive .label{ min-width:58px; }


#tab-archive .order-row { display: flex; flex-wrap: nowrap; }

/* === Archive unified row background === */
#tab-archive .order-row {
  background: #f3fbf3;
  border: 1px dashed rgba(76, 175, 80, .35);
  border-radius: 12px;
  padding: 12px;
}
#tab-archive .store-box { background: transparent; border: 0; padding: 0; }
#tab-archive .store-box.paid { background: transparent; border: 0; }
#tab-archive .order-row + .order-row { margin-top: 10px; }

/* === Archive design pass v4 === */
#tab-archive .order-row{
  background: #f5fbf6;
  border: 1px solid rgba(76,175,80,.25);
  border-left: 4px solid rgba(76,175,80,.7);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
#tab-archive .order-col.client{
  padding-right: 16px;
}
#tab-archive .order-col.items{
  padding-left: 16px;
  border-left: 1px dashed rgba(0,0,0,.08);
}
#tab-archive .store-head{
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 8px;
}
#tab-archive .badge.paid{
  background: rgba(76,175,80,.10); border-color: rgba(76,175,80,.35);
}
#tab-archive .itemline{
  border: 1px solid rgba(0,0,0,.06);
  background: #fff;
  border-radius: 10px;
  padding: 6px 8px;
  margin: 6px 0;
}
#tab-archive .itemline-head{
  display:flex; align-items:center; gap:8px; margin-bottom:2px;
}
#tab-archive .chip.code{
  background:#eef7ff; border-color: rgba(0,0,0,.08); border-radius:8px; padding:1px 8px; font-weight:600; font-size:12px;
}
#tab-archive .item-name{ font-weight:600; }
#tab-archive .meta{ font-size:12px; color: var(--muted); }
#tab-archive .order-row + .order-row{ margin-top: 12px; }

@media(max-width: 800px){
  #tab-archive .order-row{ padding: 12px; }
  #tab-archive .order-col.items{ border-left: 0; padding-left: 0; margin-top: 8px; }
}

/* === Archive footer (badge + totals moved down) === */
#tab-archive .store-foot{ margin-top:10px; padding-top:8px; border-top:1px dashed rgba(0,0,0,.08); }
#tab-archive .store-foot .foot-top{ display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap; }
#tab-archive .store-foot .foot-date{ font-size:12px; opacity:.85; margin-top:4px; }

/* === Archive searchbar alignment === */
#tab-archive .searchbar{ position: relative; display:flex; align-items:center; }
#tab-archive #archiveSearch{ flex:1; padding-right: 36px; }
#tab-archive #archiveSearchClear{
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  height: 26px; min-width: 26px; padding: 0 6px; border-radius: 999px;
}


/* Stack delivery & complete buttons vertically in Warehouse */
#reservesGroups .order-col.totals .actions{
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  gap:6px;
}

/* === Mobile UX upgrades for Products & Stock (v1) === */
@media(max-width: 800px){

  /* General card spacing */
  #tab-products .card, #tab-stock .card{ padding:14px; border-radius:14px; }

  /* Inputs: bigger tap targets */
  #tab-products input, #tab-products select, #tab-products textarea,
  #tab-stock input, #tab-stock select, #tab-stock textarea{
    min-height:44px; font-size:16px;
  }
  #tab-products textarea, #tab-stock textarea{ min-height:92px; }

  /* Products: item row becomes stacked on mobile */
  #tab-products .row{ display:flex; flex-direction:column; gap:8px; }
  #tab-products .row > input, #tab-products .row > select, #tab-products .row > button{ width:100% !important; }

  /* Location controls compact */
  #tab-products .location-controls{ margin-top:6px; padding:8px; border-radius:10px; background:#f8f9fb; }

  /* Repeater list spacing */
  #tab-products #itemsRepeater .item-row, #tab-products #extraStoreContainer .item-row{ margin:8px 0; }

  /* Phones repeater neat spacing */
  #tab-products #phonesRepeater > .row{ display:flex; gap:8px; }
  #tab-products #phonesRepeater input{ flex:1; }

  /* Buttons: full-width primary actions */
  #tab-products .actions .btn,
  #tab-stock .actions .btn{ width:100%; }

  /* Stock: order row becomes stacked card */
  #tab-stock .order-row{ display:block; background:#fff; border:1px solid var(--border); border-radius:14px; padding:12px; box-shadow:0 1px 2px rgba(0,0,0,.04); }
  #tab-stock .order-col{ margin-bottom:10px; }
  #tab-stock .order-col.items{ border-left:0; padding-left:0; }
  #tab-stock .store-box{ background:#f9fbff; border-color:#e9eef6; }
  #tab-stock .store-head{ margin-bottom:6px; }
  #tab-stock .items-collapsible{ padding:6px; }

  /* Make action buttons stick to bottom with separator */
  #tab-stock .order-col.totals .actions{
    position:sticky; bottom:0; background:#fff; padding-top:8px; margin-top:8px;
    border-top:1px dashed var(--border);
    display:flex; flex-direction:column; gap:8px; align-items:stretch;
  }

  /* Search bars */
  #tab-products .orders-toolbar, #tab-stock .orders-toolbar{ position:sticky; top:0; background:#fff; padding:6px 0; z-index:5; }
  #tab-stock .orders-toolbar input{ padding-right:36px; }
  #tab-stock .orders-toolbar button{ position:absolute; right:8px; top:50%; transform:translateY(-50%); }

  /* Chips and badges */
  #tab-stock .chip{ font-size:12px; padding:2px 8px; border-radius:999px; }
  #tab-stock .badge{ font-size:12px; }
}

/* === Mobile UX upgrades for Products & Stock (v2 refined) === */
@media(max-width: 800px){
  :root{ --appbar-h: 56px; }

  /* Keep space for app header */
  .app-header{ min-height: var(--appbar-h); }

  /* Sticky search/toolbars with proper offset */
  #tab-stock .orders-toolbar,
  #tab-products .orders-toolbar{
    position: sticky; top: calc(var(--appbar-h) + 6px);
    background:#fff; z-index: 10; padding: 6px 0;
  }

  /* Group headers also sticky, below toolbar */
  #tab-stock .group-header{ position: sticky; top: calc(var(--appbar-h) + 46px); z-index: 9; background:#fff; }

  /* Cards & typography */
  #tab-products .card, #tab-stock .card{ padding:14px; border-radius:14px; }
  #tab-products label, #tab-stock label{ font-size:13px; color:var(--muted); }

  /* Inputs bigger for touch */
  #tab-products input, #tab-products select, #tab-products textarea,
  #tab-stock input, #tab-stock select, #tab-stock textarea{
    min-height:44px; font-size:16px; border-radius:10px;
  }
  #tab-products textarea, #tab-stock textarea{ min-height:92px; }

  /* Products form rows become stacked */
  #tab-products .row{ display:flex; flex-direction:column; gap:8px; }
  #tab-products .row > *{ width:100% !important; }

  #tab-products #itemsRepeater .item-row,
  #tab-products #extraStoreContainer .item-row{
    border:1px solid #eef1f7; background:#fbfcff; padding:10px; border-radius:12px; margin:8px 0;
  }
  #tab-products .location-controls{ background:#f6f7fb; border:1px solid #eef1f7; border-radius:10px; padding:8px; }

  /* Stock list cards */
  #tab-stock .order-row{
    display:block; background:#fff; border:1px solid #eaeaef; border-radius:14px; padding:12px;
    box-shadow:0 1px 2px rgba(0,0,0,.03);
  }
  #tab-stock .order-col{ margin-bottom:10px; }
  #tab-stock .order-col.items{ border-left:0; padding-left:0; }
  #tab-stock .order-col.client .line{ display:flex; gap:8px; }
  #tab-stock .order-col.client .label{ min-width:90px; color:var(--muted); }

  #tab-stock .store-box{ background:#f8fbff; border:1px solid #e8eef7; border-radius:12px; padding:8px; }
  #tab-stock .items-collapsible{ padding:6px; }
  #tab-stock .itemline{ background:#fff; border:1px solid #eef1f7; border-radius:10px; padding:8px; margin:6px 0; }
  #tab-stock .itemline-head{ display:flex; gap:6px; align-items:center; }
  #tab-stock .chip.code{ font-size:12px; padding:2px 6px; }
  #tab-stock .chip.store{ font-size:12px; padding:2px 6px; background:#f1f5ff; border:1px solid #e3e8ff; }
  #tab-stock .meta{ font-size:12px; color:var(--muted); }

  /* Actions: full width & stacked */
  #tab-stock .order-col.totals .actions{
    position:sticky; bottom:0; background:#fff; padding-top:8px; margin-top:8px;
    border-top:1px dashed var(--border);
    display:flex; flex-direction:column; gap:10px; align-items:stretch;
  }
  #tab-stock .order-col.totals .actions .btn{ height:44px; border-radius:10px; font-size:15px; }

  /* Toolbars clear button alignment */
  #tab-stock .orders-toolbar{ position: sticky; }
  #tab-stock .orders-toolbar input{ padding-right:36px; }
  #tab-stock .orders-toolbar button{ position:absolute; right:8px; top:50%; transform:translateY(-50%); }

  /* Reduce excessive gaps between groups */
  #tab-stock .group + .group{ margin-top:10px; }
}

/* === Mobile Stock fixes v3: wrap line buttons, prevent overflow === */
@media(max-width: 800px){
  html, body{ overflow-x:hidden; }

  /* Item line: allow wrapping; buttons two-per-row */
  #tab-stock .itemline{ display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
  #tab-stock .itemline-head{ width:100%; }
  #tab-stock .itemline .meta{ width:100%; }
  #tab-stock .itemline .btn{ flex:1 1 calc(50% - 8px); max-width: calc(50% - 8px); }

  /* Reserve groups: ensure inner actions won't stretch beyond */
  #tab-stock .group .actions{ display:flex; flex-wrap:wrap; gap:8px; }
  #tab-stock .group .actions .btn{ flex:1 1 calc(50% - 8px); max-width: calc(50% - 8px); }

  /* Movement plan (right column) buttons wrap nicely */
  #tab-stock .card:has(h3:contains('Перемещение')) .actions,
  #tab-stock .move-row .actions{ display:flex; flex-wrap:wrap; gap:8px; }
  #tab-stock .card:has(h3:contains('Перемещение')) .actions .btn,
  #tab-stock .move-row .actions .btn{ flex:1 1 calc(50% - 8px); max-width: calc(50% - 8px); }

  /* Guard: full-width primary long buttons */
  #tab-stock .order-col.totals .actions .btn{ width:100%; max-width:100%; }
}


@media(max-width: 800px){
  /* Fallback for movement plan actions */
  #tab-stock .groups .actions{ display:flex; flex-wrap:wrap; gap:8px; }
  #tab-stock .groups .actions .btn{ flex:1 1 calc(50% - 8px); max-width: calc(50% - 8px); }
}

/* === Mobile Stock hotfix v3.1 === */
@media(max-width: 800px){
  /* 1) Client lines: wrap long phones/addresses */
  #tab-stock .order-col.client .line{ flex-wrap: wrap; overflow-wrap: anywhere; word-break: break-word; }
  #tab-stock .order-col.client .label{ flex: 0 0 90px; }

  /* 2) Restore status-based colors for store boxes on mobile */
  #tab-stock .store-box.paid{ background:#e6ffe6; border-color:#b8e6b8; }
  #tab-stock .store-box.partial{ background:#fff7e6; border-color:#ffc24a; }
  #tab-stock .store-box.due{ background:#ffe6e6; border-color:#ffb3c2; }

  /* 3) Put "Переместить в магазин" on the next line */
  #tab-stock .itemline .btn.move-to-store{ flex:1 1 100%; max-width:100%; }
}

/* === Mobile Stock sticky header overlap fix === */
@media(max-width: 800px){
  /* Reserve space under sticky date header so it doesn't cover client info */
  #tab-stock .group-header{ position: sticky; top: calc(var(--appbar-h, 56px) + 46px); z-index: 9; background:#fff; }
  #tab-stock .group-header + .group-body{ padding-top: 36px; }
  /* Slight separator for readability */
  #tab-stock .group-header{ border-bottom: 1px solid rgba(0,0,0,.06); }
}

/* === Mobile Stock sticky header OFF (v1.1) === */
@media(max-width: 800px){
  #tab-stock .group-header{ position: static !important; top:auto !important; z-index:auto !important; border-bottom: none; }
  #tab-stock .group-header + .group-body{ padding-top: 0 !important; }
}

/* === Archive mobile gap fix v10 === */
@media(max-width: 800px){
  /* Stack columns and kill flex gap injected inline */
  #tab-archive .order-row{ display:block !important; padding-top:12px; padding-bottom:12px; }
  #tab-archive .order-col.client{ margin:0 0 8px 0; }
  #tab-archive .order-col.items{ border-left:0; padding-left:0; margin:0; }
  #tab-archive .store-box{ margin-top:0; }
  #tab-archive .items-collapsible{ margin-top:6px; }
}


/* v19: hide action buttons for items in transit */
.itemline[data-status="in_transit"] .btn.move-to-store,
.itemline[data-status="in_transit"] .btn.complete-item { display: none !important; }


/* MULTI-ITEMS STYLES */
.items-repeater{ margin:8px 0 12px; }
.item-row{ border:1px dashed var(--border); border-radius:10px; padding:10px; margin:8px 0; }
.item-head{ display:flex; align-items:center; gap:8px; }
.item-actions{ display:flex; gap:6px; margin-left:auto; }
.icon-btn{ width:28px; height:28px; border-radius:8px; border:1px solid var(--border); background:#fff; cursor:pointer; display:inline-flex; align-items:center; justify-content:center; }
.icon-btn:disabled{ opacity:.5; cursor:not-allowed; }


/* === Delivery Groups (dl-*) === */
.dl-groups { display: flex; flex-direction: column; gap: 12px; }
.dl-group { background:#fff; border:1px solid #eee; border-radius:14px; box-shadow:0 1px 2px rgba(0,0,0,.06); overflow:hidden; }
.dl-group-head { display:flex; align-items:center; justify-content:space-between; padding:10px 12px; border-bottom:1px solid #f0f0f0; }
.dl-toggle { width:28px; height:28px; border-radius:10px; border:1px solid #ddd; background:#fafafa; cursor:pointer; font-size:18px; line-height:0; }
.dl-toggle::after { content:'+'; } .dl-toggle.open::after{ content:'−'; }
.dl-badge { padding:6px 10px; border-radius:20px; background:#ffe6eb; color:#a4133c; font-weight:600; }
.dl-badge.today { background:#e7f7ec; color:#1b7a37; }
.dl-badge.yesterday { background:#ffe6eb; color:#a4133c; }
.dl-badge.future { background:#e6efff; color:#1242a3; }
.dl-group-body { padding:8px 12px 14px; }

.dl-card { border:1px solid #f0f0f0; border-radius:12px; padding:12px; margin:6px 0; background:#fff; }
.dl-card-top { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.dl-title { font-weight:700; }
.dl-actions { display:flex; gap:6px; }

.dl-meta { color:#444; margin-top:8px; }
.dl-meta .row { margin:3px 0; }

.dl-items { list-style:none; padding:0; margin:10px 0 0; display:grid; gap:6px; }
.dl-items li { display:flex; flex-wrap:wrap; align-items:center; gap:8px; background:#fafbff; border:1px dashed #dde1ff; padding:6px 8px; border-radius:10px; }
.dl-items .code { color:#666; }
.dl-items .qty { opacity:.7; }

.dl-status { padding:4px 8px; border-radius:999px; font-size:12px; border:1px solid transparent; }
.dl-status.route { background:#fff7e6; color:#ad5a00; border-color:#ffe0b2; }
.dl-status.partial { background:#fff1f2; color:#c81e1e; border-color:#ffd5d9; }
.dl-status.delivered { background:#e8faf0; color:#166534; border-color:#b8e3c7; }
.dl-status.cancelled { background:#f3f4f6; color:#6b7280; border-color:#e5e7eb; }


.dl-source { padding:4px 8px; border-radius:999px; font-size:12px; background:#eef2ff; color:#3730a3; border:1px solid #c7d2fe; }
@media (max-width: 640px) {
  .dl-card-top { flex-direction:column; align-items:flex-start; }
  .dl-actions { width:100%; }
}



/* === Courier (Erik) read-only UI rules === */
body.role-courier .tabs button[data-tab="products"],
body.role-courier #tab-products { display:none !important; }

/* Hide action buttons for courier */
body.role-courier .dl-actions,
body.role-courier .remove-move-row,
body.role-courier [data-edit],
body.role-courier [data-del],
body.role-courier #addMoveItemBtn,
body.role-courier #removeStoreGroupBtn,
body.role-courier #moveStoreForm .actions,
body.role-courier #deliveryForm { display:none !important; }

/* Toggle reserves vs moves visibility inside stock tab */
body.role-courier.view-moves #reservesGroups { display:none !important; }
body.role-courier.view-reserve #moveStoreForm,
body.role-courier.view-reserve #movesList,
body.role-courier.view-reserve #addMoveItemBtn { display:none !important; }


/* Hide Archive for courier */
body.role-courier .tabs [data-tab="archive"] { display:none !important; }


/* === Courier: make stock tab single-column and hide opposite card === */
body.role-courier.view-moves #tab-stock .grid.two{ grid-template-columns:1fr !important; }
body.role-courier.view-moves #tab-stock .grid.two > .card:first-of-type{ display:none !important; } /* hide left 'Резерв на складе' */

body.role-courier.view-reserve #tab-stock .grid.two{ grid-template-columns:1fr !important; }
body.role-courier.view-reserve #tab-stock .grid.two > .card:nth-of-type(2){ display:none !important; } /* hide right 'Перемещение' */


/* === Courier: hide move form on 'Перемещение' tab === */
body.role-courier.view-moves #moveStoreForm{ display:none !important; }


/* === Courier: Delivery tab one-column & hide left "Новая доставка" card === */
body.role-courier #tab-delivery .grid.two{ grid-template-columns:1fr !important; }
body.role-courier #tab-delivery .grid.two > .card:first-of-type{ display:none !important; }


/* === Courier: hide all action buttons in Reserve tab === */
body.role-courier.view-reserve #reservesGroups .send-to-delivery,
body.role-courier.view-reserve #reservesGroups .cancel-delivery,
body.role-courier.view-reserve #reservesGroups .complete-order,
body.role-courier.view-reserve #reservesGroups .complete-item,
body.role-courier.view-reserve #reservesGroups .move-to-store,
body.role-courier.view-reserve #reservesGroups .actions .btn,
body.role-courier.view-reserve #reservesGroups .itemline .btn { display:none !important; }


/* === Courier: hide H2 headers in tabs === */
body.role-courier #tab-stock > h2,
body.role-courier #tab-delivery > h2 { display:none !important; }

/* v13 */
.view-signature{ display:inline-flex; }

/* v15 */
.sig-inline-link{ display:inline-block; text-decoration:underline; cursor:pointer; }

/* v16 signature button */
.view-signature{
  display:inline-flex;
  align-items:center;
  gap:6px;
  background: #fff7eb;
  border-color: #f3c26a;
  color: #8a5a00;
  box-shadow: 0 1px 0 rgba(0,0,0,.02);
}
.view-signature:hover{ background:#ffeccf; }
.view-signature .ico{ line-height:1; }

/* v18 — Courier Delivery UI polish */
#tab-delivery .dl-card{ border:1px solid #eae6dd; border-radius:14px; background:#fffdfa; box-shadow: 0 1px 2px rgba(0,0,0,.03); }
#tab-delivery .dl-card-top{ display:flex; align-items:center; gap:8px; }
#tab-delivery .dl-title{ font-weight:600; }
#tab-delivery .dl-store{ background:#f1f6ff; color:#1f4fa3; border:1px solid #d9e7ff; border-radius:999px; padding:2px 8px; font-size:12px; }
#tab-delivery .dl-badge{ display:inline-flex; align-items:center; gap:6px; padding:4px 10px; border-radius:999px; font-size:12px; border:1px solid transparent; }
#tab-delivery .dl-badge.muted{ background:#f5f5f5; color:#666; border-color:#e5e5e5; }
#tab-delivery .dl-badge.delivered{ background:linear-gradient(180deg,#eafff2,#dcffe9); color:#0e6a3a; border-color:#a9e7c2; box-shadow: 0 1px 0 rgba(0,0,0,.02); }
#tab-delivery .dl-badge.pending{ background:#fff7eb; color:#8a5a00; border-color:#f3c26a; }
#tab-delivery .dl-badge .ico{ line-height:1; }
#tab-delivery .dl-card-body{ background:#fff; border:1px dashed #eee; border-radius:12px; padding:10px; }
#tab-delivery .dl-items{ margin:8px 0 0; padding-left:16px; }
#tab-delivery .dl-items li{ margin:3px 0; }
#tab-delivery .dl-footer{ display:flex; align-items:center; justify-content:space-between; gap:8px; margin-top:10px; }
#tab-delivery .dl-meta{ font-size:12px; color:#666; }
#tab-delivery .dl-courier-actions .btn.primary{ box-shadow:0 1px 0 rgba(0,0,0,.04); }

/* Reserve header badge */
.dl-badge.reserve{ background:#fff6e6; color:#a35b00; margin-left:6px; }

/* Reserve badge pill */
.reserve-pill{display:inline-block;padding:2px 8px;border-radius:9999px;font-size:11px;margin-left:6px;border:1px solid rgba(0,0,0,0.12)}


/* === Manager role layout overrides === */
body.role-manager main{ max-width:1100px; }
body.role-manager .grid.two{ grid-template-columns: 1fr !important; }
body.role-manager .card{ width: 100%; }



/* === Manager totals cosmetics === */
body.role-manager .order-row{
  grid-template-columns: minmax(520px, 1fr) 360px;
  column-gap: 20px;
}
/* Keep card wide but visually align content */
body.role-manager #ordersGroups .order-col.totals{
  background: #f8fff4;
  border: 1px dashed #cfe9c7;
  border-radius: 12px;
  padding: 10px 12px;
}
body.role-manager #ordersGroups .order-col.totals .badge{ float:right; }
body.role-manager #ordersGroups .order-col.totals .comments{ margin-top:6px; opacity:0.9; }
@media(max-width: 1200px){
  body.role-manager .order-row{ grid-template-columns: 1fr; }
  body.role-manager #ordersGroups .order-col.totals{ order:-1; margin-bottom:8px; }
}



/* Manager: force grid layout so stores take full width below header */
body.role-manager #ordersGroups .order-row{
  display:grid !important;
  grid-template-columns: 1fr 340px !important;
  grid-template-areas:
    "client totals"
    "stores stores" !important;
  column-gap: 16px;
}
body.role-manager #ordersGroups .order-col.client{ grid-area: client; }
body.role-manager #ordersGroups .order-col.totals{ grid-area: totals; }
body.role-manager #ordersGroups .order-col.items{ grid-area: stores; }
@media(max-width: 1100px){
  body.role-manager #ordersGroups .order-row{ grid-template-columns: 1fr !important; grid-template-areas: "totals" "client" "stores"; }
}
/* Hide 'Товары' title for managers */
body.role-manager #tab-products > h2{ display:none; }



/* Manager: stock tab one column full-width */
body.role-manager #tab-stock .grid.two{ grid-template-columns: 1fr !important; }


/* Managers: hide edit/delete actions in Delivery */
.role-manager .dl-actions{ display:none !important; }

/* Managers: hide 'Новая доставка' card in Delivery */
.role-manager #tab-delivery .grid.two > .card:first-child{ display:none !important; }


/* Manager mobile layout fix (stack neatly, readable labels) */
@media(max-width: 760px){
  body.role-manager #ordersGroups .order-row{
    grid-template-columns: 1fr !important;
    grid-template-areas:
      "totals"
      "client"
      "stores" !important;
  }
  body.role-manager #ordersGroups .order-col.client .line{
    display:flex; align-items:flex-start; gap:8px;
  }
  body.role-manager #ordersGroups .order-col.client .label{
    min-width:92px; flex:0 0 92px; color:var(--muted);
  }
  body.role-manager #ordersGroups .order-col.client .value{
    flex:1 1 auto; min-width:0; word-break:break-word;
  }
}


/* Month grouping */
.month-header { display:flex; align-items:center; justify-content:space-between; background:#f7f7f7; border:1px solid #eee; border-radius:10px; padding:10px 14px; margin:6px 0; }
.month-title { font-weight:600; font-size:14px; text-transform:capitalize; }
.month-toggle { width:28px; height:28px; line-height:26px; border-radius:50%; border:1px solid #ddd; }





/* day groups inside month body: compact */
.month-body > .group,
.month-body > .date-group,
.month-body > .dl-group,


/* remove extra top margin for first child inside month */
.month-body > .group:first-child,
.month-body > .date-group:first-child,
.month-body > .dl-group:first-child,
.month-body > div.group:first-child { margin-top: 0 !important; }


/* month-override-groups-container */
#ordersGroups > .month-group,
#deliveryGroups > .month-group,
#deliveriesList > .month-group,


/* === Courier Erik visibility bump (scoped) === */
body.user-erik #tab-delivery .dl-meta{
  font-size: 15px !important;
  color: #333 !important;
  line-height: 1.55;
}
body.user-erik #tab-delivery .dl-meta b,
body.user-erik #tab-delivery .dl-meta strong{
  color: #111 !important;
}
/* Optional emphasis for amounts */
body.user-erik #tab-delivery .dl-meta .money,
body.user-erik #tab-delivery .dl-meta .price,
body.user-erik #tab-delivery .dl-meta .sum{
  font-weight: 700;
}
/* === /Courier Erik visibility bump === */


/* Fallback for any courier role (in case user-erik flag didn't attach) */
body.role-courier #tab-delivery .dl-meta{
  font-size: 15px !important;
  color: #333 !important;
  line-height: 1.55;
}
