/* =====================================================================
   AFAYAR DELIVERY - stylesheet (gold #D4AF5A on deep navy #1A2333)
   ===================================================================== */
:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --txt: #0f172a;
  --mut: #64748b;
  --afayar-gold: #D4AF5A;      /* primary actions, active nav, alerts */
  --afayar-gold-d: #A77A2F;
  --afayar-navy: #1A2333;        /* sidebar, headers, nav */
  --afayar-navy-soft: #2A3546;
  --pri: var(--afayar-gold);
  --pri-d: var(--afayar-gold-d);
  --ok: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
  --side-bg: var(--afayar-navy);
  --side-txt: #9fb0c7;
  --rad: 10px;
  --shadow: 0 1px 3px rgba(26,35,51,.08);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg); color: var(--txt);
}
a { color: var(--pri); text-decoration: none; }
.muted { color: var(--mut); }
.mono { font-family: Consolas, 'Courier New', monospace; }
.r { text-align: right; }
.c { text-align: center; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.grow { flex: 1; }

/* ------------------------------ layout ------------------------------ */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 235px; background: var(--side-bg); color: var(--side-txt);
  position: fixed; inset: 0 auto 0 0; overflow-y: auto; z-index: 50;
  display: flex; flex-direction: column; transition: transform .2s;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand .logo {
  width: 36px; height: 36px; border-radius: 9px;
  background: linear-gradient(135deg, var(--afayar-gold), #E4D5AF);
  display: grid; place-items: center; color: #fff; font-weight: 800;
}
.brand b { color: #fff; font-size: 15px; display: block; }
.brand small { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; }
.menu { flex: 1; padding: 10px 10px 30px; }
.menu-section {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .13em;
  padding: 16px 10px 6px; opacity: .55;
}
.menu-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; margin: 2px 0; border-radius: 8px;
  color: var(--side-txt); font-size: 13.5px; transition: .12s;
}
.menu-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.menu-item.active { background: var(--pri); color: #fff; box-shadow: 0 4px 12px rgba(212,175,90,.35); }
.mi-icon { width: 19px; text-align: center; font-style: normal; }

.main { flex: 1; margin-left: 235px; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 58px; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 0 22px;
  position: sticky; top: 0; z-index: 40;
}
.tb-title { font-size: 17px; font-weight: 700; }
.tb-sub { font-size: 12px; color: var(--mut); }
.grow { flex: 1; }
.tb-alerts { position: relative; cursor: pointer; }
.tb-alerts button {
  position: relative; border: 0; background: none; cursor: pointer;
  font-size: 19px; line-height: 1; padding: 8px;
}
.tb-alerts .cnt {
  position: absolute; top: 0; right: 0; background: var(--bad); color: #fff;
  border-radius: 999px; font-size: 10px; min-width: 17px; height: 17px;
  display: grid; place-items: center; padding: 0 4px; font-weight: 700;
}
.alerts-pop {
  display: none; position: absolute; right: 0; top: 46px; width: 340px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--rad);
  box-shadow: 0 10px 30px rgba(15,23,42,.14); overflow: hidden;
}
.tb-alerts.open .alerts-pop { display: block; }
.al { display: block; padding: 10px 14px; font-size: 12.5px; border-bottom: 1px solid var(--line); color: inherit; }
.al:last-child { border: 0; }
.al-danger { border-left: 3px solid var(--bad); background: #fef2f2; }
.al-warning { border-left: 3px solid var(--warn); background: #fffbeb; }
.tb-user { position: relative; }
.tb-user > button {
  display: flex; align-items: center; gap: 10px; border: 0; background: none; cursor: pointer;
  padding: 5px 8px; border-radius: 8px;
}
.tb-user > button:hover { background: var(--bg); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; color: #fff;
  background: linear-gradient(135deg, var(--pri), #E4D5AF);
  display: grid; place-items: center; font-weight: 700;
}
.user-menu {
  display: none; position: absolute; right: 0; top: 48px; width: 220px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--rad);
  box-shadow: 0 10px 30px rgba(15,23,42,.14); overflow: hidden; z-index: 60;
}
.tb-user.open .user-menu { display: block; }
.um-head { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.um-head b { display: block; }
.um-head small { color: var(--mut); }
.user-menu a {
  display: flex; gap: 9px; padding: 10px 14px; color: inherit; font-size: 13px;
}
.user-menu a:hover { background: var(--bg); }

.content { padding: 22px; max-width: 1500px; width: 100%; }

/* ------------------------------- KPI -------------------------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--rad);
  padding: 16px; display: block; color: inherit; box-shadow: var(--shadow); transition: .15s;
}
.kpi:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(15,23,42,.1); }
.kpi span { font-size: 12px; color: var(--mut); display: block; margin-bottom: 6px; }
.kpi b { font-size: 22px; }
.kpi.ok b { color: var(--ok); } .kpi.bad b { color: var(--bad); } .kpi.warn b { color: var(--warn); }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--rad);
  box-shadow: var(--shadow); padding: 16px;
}
.card h3 { font-size: 14px; margin-bottom: 12px; color: var(--txt); }
.card canvas { width: 100%; height: 190px; display: block; }
.banner { padding: 12px 16px; border-radius: var(--rad); margin-bottom: 14px; font-weight: 600; font-size: 13px; }
.banner.ok { background: #dcfce7; color: #14532d; border: 1px solid #86efac; }
.banner.bad { background: #fee2e2; color: #7f1d1d; border: 1px solid #fca5a5; }
.jsonview {
  background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 8px;
  font-size: 12px; overflow: auto; max-height: 60vh; white-space: pre-wrap;
}

/* ----------------------------- toolbar ------------------------------ */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.search-box {
  display: flex; align-items: center; gap: 8px; background: var(--card);
  border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; min-width: 240px;
}
.search-box svg { width: 15px; height: 15px; stroke: var(--mut); fill: none; stroke-width: 2; }
.search-box input { border: 0; outline: 0; flex: 1; font-size: 13.5px; background: none; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-sel select, .filter-dates input, .filter-dates select {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 12.5px; background: var(--card);
}
.filter-dates { display: flex; gap: 6px; align-items: center; }
.filter-dates span { color: var(--mut); font-size: 12px; }
.states-filter { position: relative; }
.states-pop {
  position: absolute; top: 40px; left: 0; z-index: 30; width: 240px; max-height: 320px; overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--rad);
  box-shadow: 0 10px 30px rgba(15,23,42,.15); padding: 8px;
}
.states-pop label { display: flex; gap: 8px; align-items: center; padding: 5px 6px; font-size: 12.5px; border-radius: 6px; cursor: pointer; }
.states-pop label:hover { background: var(--bg); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  padding: 6px 14px; border-radius: 999px; background: var(--card);
  border: 1px solid var(--line); font-size: 12.5px; color: var(--mut); cursor: pointer;
}
.chip:hover { border-color: var(--pri); color: var(--pri); }
.chip.active { background: var(--pri); border-color: var(--pri); color: #fff; font-weight: 600; }
.chips .chip a { color: inherit; font-weight: 800; margin-left: 4px; }

.toolbtns { display: flex; gap: 8px; flex-wrap: wrap; }

/* Reception page-lock banner */
.reception-lock-banner {
  background: #fef3cd; border: 1px solid #ffc107; color: #856404;
  padding: 10px 16px; border-radius: 8px; margin: 10px 0;
  font-size: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.reception-lock-banner .reception-unlock { margin-left: auto; }
.reception-locked .tbl { opacity: .55; }

/* ----------------------------- buttons ------------------------------ */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid transparent; border-radius: 8px; padding: 8px 16px;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: .13s; white-space: nowrap;
}
.btn-primary { background: var(--pri); color: #fff; }
.btn-primary:hover { background: var(--pri-d); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-ghost { background: var(--card); border-color: var(--line); color: var(--txt); }
.btn-ghost:hover { border-color: var(--pri); color: var(--pri); }
.btn-dark { background: var(--txt); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn.disabled, .pager .disabled { opacity: .38; pointer-events: none; }

.ico-btn {
  border: 0; background: none; cursor: pointer; font-size: 14px;
  width: 28px; height: 28px; border-radius: 7px; transition: .12s;
}
.ico-btn:hover { background: var(--bg); transform: scale(1.08); }

/* ------------------------------ table ------------------------------- */
.tbl-wrap {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--rad);
  overflow-x: auto; box-shadow: var(--shadow);
}
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--mut); padding: 10px 12px; border-bottom: 1px solid var(--line);
  background: #f8fafc; white-space: nowrap;
}
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--pri); }
.tbl tbody td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tbody tr:hover { background: #f8fafc; }
.tbl tbody tr.selected { background: #eff6ff; }
.tbl td.empty { text-align: center; color: var(--mut); padding: 34px !important; }
.c-sel { width: 34px; } .c-act { width: 40px; white-space: nowrap; }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px;
  font-weight: 700; color: #fff; background: var(--b, #64748b); white-space: nowrap;
}
table.tbl.mini { font-size: 12px; }
table.tbl.mini td, table.tbl.mini th { padding: 6px 8px; }

.listfoot { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.pager { display: flex; align-items: center; gap: 7px; }
.sel-sm { border: 1px solid var(--line); border-radius: 8px; padding: 5px 7px; font-size: 12.5px; background: var(--card); }
.bulkbar { display: flex; gap: 8px; align-items: center; background: #eff6ff; border: 1px solid #bfdbfe; padding: 8px 12px; border-radius: var(--rad); font-size: 13px; }

/* ------------------------------ forms ------------------------------- */
.frm { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; }
.field label { flex: 1; display: block; }
.field label > span {
  display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--mut); margin-bottom: 5px; font-weight: 600;
}
.field input[type=text], .field input[type=password], .field input[type=number],
.field input[type=date], .field input[type=color], .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  font-size: 13.5px; outline: none; transition: border .12s; background: #fff;
  font-family: inherit;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--pri); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.chk { display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; padding: 8px 0; }
.chk input { width: 16px; height: 16px; accent-color: var(--pri); }
.frm-sep { grid-column: 1 / -1; height: 0; }
.frm .chk { grid-column: span 2; }
.permgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; grid-column: 1/-1; }
.permgrid fieldset { border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; }
.permgrid legend { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--mut); padding: 0 6px; }
.confirm-msg { font-size: 14.5px; padding: 6px 2px 10px; }
.alert-ok { background: #dcfce7; color: #14532d; border-radius: 8px; padding: 10px 14px; margin-top: 10px; }
.alert-bad { background: #fee2e2; color: #7f1d1d; border-radius: 8px; padding: 10px 14px; margin-top: 10px; font-size: 12.5px; }

/* ------------------------------ modal ------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 100;
  display: grid; place-items: center; animation: fadein .15s; backdrop-filter: blur(2px);
}
@keyframes fadein { from { opacity: 0; } }
.modal {
  background: var(--card); border-radius: 14px; width: calc(100% - 32px);
  max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: 0 24px 70px rgba(15,23,42,.3); animation: pop .16s;
}
.modal.closing { opacity: 0; transition: .15s; }
@keyframes pop { from { transform: scale(.96) translateY(8px); opacity: 0; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 15px; }
.modal-head .x {
  border: 0; background: var(--bg); width: 30px; height: 30px; border-radius: 50%;
  font-size: 17px; cursor: pointer; line-height: 1;
}
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 13px 20px; border-top: 1px solid var(--line);
}

/* ------------------------------ drawer ------------------------------ */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 90;
  display: flex; justify-content: flex-end; animation: fadein .15s;
}
.drawer {
  width: min(720px, 94vw); background: var(--bg); height: 100%;
  display: flex; flex-direction: column; animation: slidein .2s; box-shadow: -10px 0 40px rgba(15,23,42,.25);
}
@keyframes slidein { from { transform: translateX(60px); opacity: 0; } }
.drawer > header {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.drawer > header h3 { font-size: 15px; }
.drawer > header .x { border: 0; background: var(--bg); width: 30px; height: 30px; border-radius: 50%; font-size: 17px; cursor: pointer; }
.dw-body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.drawer > footer { background: var(--card); padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.dw-meta { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; font-size: 13px; flex-wrap: wrap; }
.pickbox {
  max-height: 260px; overflow-y: auto; background: var(--card); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px; margin-bottom: 10px;
}
.pickbox label {
  display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: 7px;
  font-size: 12.5px; cursor: pointer;
}
.pickbox label:hover { background: var(--bg); }
.dw-body h4 { margin: 16px 0 8px; font-size: 13px; }

/* --------------------------- scan & misc ---------------------------- */
.scanbox input {
  width: 100%; border: 2px dashed var(--pri); background: #eff6ff;
  border-radius: 10px; padding: 13px 16px; font-size: 15px; font-weight: 700;
  font-family: Consolas, monospace; outline: none; letter-spacing: .08em;
}
.scanbox input:focus { border-style: solid; }
.collect-zone { background: var(--card); border: 1px solid var(--line); border-radius: var(--rad); padding: 14px 16px; margin-bottom: 16px; }
.collect-zone h3 { font-size: 13.5px; margin-bottom: 10px; }
.scan-card { font-size: 14px; line-height: 1.75; }
.scan-card hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.statebtns { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.stbtn {
  border: 0; background: var(--b, #64748b); color: #fff; padding: 6px 13px;
  border-radius: 999px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.stbtn:hover { filter: brightness(1.12); }

.state-btn { display: inline-block; cursor: default; }
.state-btn[data-inline-state] { cursor: pointer; border-radius: 10px; transition: box-shadow .12s ease, transform .12s ease; }
.state-btn[data-inline-state]:hover { box-shadow: 0 2px 10px rgba(37,99,235,.35); transform: translateY(-1px); }
.state-btn[data-inline-state]:focus-visible { outline: 2px solid #D4AF5A; outline-offset: 2px; }
.state-detail { margin-top: 3px; display: flex; flex-direction: column; gap: 1px; min-width: 120px; }
.state-detail .sd-date { font-size: 10.5px; color: var(--mut, #64748b); white-space: nowrap; }
.state-detail .sd-note {
  font-size: 10.5px; color: var(--mut, #64748b); font-style: italic; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  max-width: 240px;
}

.tl { position: relative; padding-left: 22px; }
.tl::before { content: ''; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: 7px 0; }
.tl-dot {
  position: absolute; left: -21px; top: 13px; width: 10px; height: 10px;
  background: var(--pri); border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 2px var(--line);
}
.toasts { position: fixed; bottom: 18px; left: 18px; z-index: 200; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: var(--txt); color: #fff; padding: 11px 17px; border-radius: 10px;
  font-size: 13px; box-shadow: 0 8px 26px rgba(15,23,42,.3); max-width: 420px; animation: tslide .2s;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--bad); }
.toast.warn { background: var(--warn); }
.toast.out { opacity: 0; transform: translateX(20px); transition: .35s; }
@keyframes tslide { from { transform: translateY(12px); opacity: 0; } }

/* reconciliation */
#rec-body .decl-in { width: 120px; border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; font-size: 13px; text-align: right; }
.rec-bar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--rad); padding: 12px 16px; }
.rec-bar input { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; }

/* assign console */
.assign-console { background: var(--card); border: 1px solid var(--line); border-radius: var(--rad); padding: 16px; margin-bottom: 16px; }
.assign-console .row1 { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.assign-console select { border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font-size: 13.5px; }
.assign-console input { flex: 1; min-width: 220px; border: 2px dashed var(--pri); background: #eff6ff; border-radius: 9px; padding: 10px 13px; font-size: 14px; font-family: Consolas, monospace; outline: none; }

/* account / settings */
.auth-card { max-width: 520px; margin: 40px auto; }
.settingsform { max-width: 640px; }
#pwdform { display: grid; gap: 12px; }

/* ------------------------------ login ------------------------------- */
.login-body {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1200px 500px at 20% -10%, rgba(37,99,235,.25), transparent),
              radial-gradient(900px 500px at 110% 110%, rgba(124,58,237,.22), transparent),
              var(--side-bg);
}
.login-card {
  width: 400px; background: var(--card); border-radius: 18px; padding: 34px 32px;
  box-shadow: 0 30px 80px rgba(0,0,0,.45);
}
.login-card .brand2 { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login-card .brand2 .logo {
  width: 44px; height: 44px; border-radius: 12px; color: #fff; font-weight: 800;
  background: linear-gradient(135deg, var(--pri), #E4D5AF); display: grid; place-items: center; font-size: 19px;
}
.login-card h1 { font-size: 20px; }
.login-card p.sub { color: var(--mut); font-size: 13px; margin-top: 2px; }
.login-card form { display: grid; gap: 14px; margin-top: 8px; }
.login-card button { width: 100%; padding: 12px; font-size: 14.5px; }
.login-note { margin-top: 18px; font-size: 11.5px; color: var(--mut); text-align: center; }

/* ---------------------------- responsive ---------------------------- */
@media (max-width: 1080px) {
  .dash-grid { grid-template-columns: 1fr; }
  .permgrid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  body.nav-open .sidebar { transform: none; }
  .main { margin-left: 0; }
  .nav-toggle { display: block !important; }
}
.nav-toggle {
  display: none; border: 0; background: none; font-size: 22px; cursor: pointer; line-height: 1;
}

/* ==================== v2 additions ==================== */
.pagebar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.inline-lab { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--mut); }
.grid2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; margin-bottom: 14px; }
@media (max-width: 1000px) { .grid2 { grid-template-columns: 1fr; } }

/* global search */
.gsearch-wrap { position: relative; margin-right: 6px; }
.gsearch { display: flex; align-items: center; gap: 6px; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 5px 10px; width: 300px; }
.gsearch svg { width: 15px; height: 15px; stroke: var(--mut); fill: none; stroke-width: 2; flex: none; }
.gsearch input { border: none; outline: none; background: transparent; width: 100%; font: inherit; font-size: 13px; color: var(--txt); }
.gsearch-pop { position: absolute; right: 0; top: calc(100% + 6px); width: 420px; max-height: 380px;
  overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 16px 40px rgba(2,6,23,.18); z-index: 60; padding: 4px; }
.gsearch-pop a { display: block; padding: 8px 10px; border-radius: 8px; font-size: 13px;
  color: var(--txt); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gsearch-pop a:hover { background: var(--bg); }
@media (max-width: 900px) { .gsearch { width: 150px; } .gsearch-pop { width: 320px; } }

/* ===================== AFAYAR DELIVERY v3 components ========================= */
.badge { display:inline-block; padding:2px 9px; border-radius:20px; font-size:11px; font-weight:600; }
.badge.critical { background:#fee2e2; color:#991b1b; }
.badge.high     { background:#ffedd5; color:#c2410c; }
.badge.medium   { background:#fef9c3; color:#a16207; }
.badge.low      { background:#dcfce7; color:#15803d; }
.badge.info     { background:#dbeafe; color:#1d4ed8; }
.badge.pending  { background:#fef9c3; color:#a16207; }
.badge.approved { background:#dcfce7; color:#15803d; }
.badge.rejected { background:#fee2e2; color:#991b1b; }
.badge.executed { background:#dbeafe; color:#1d4ed8; }

.bell { position:relative; cursor:pointer; padding:6px 10px; border-radius:8px; font-size:17px; }
.bell:hover { background:rgba(255,255,255,.08); }
.bell .dot {
  position:absolute; top:2px; right:2px; min-width:16px; height:16px;
  background:var(--afayar-gold); color:#fff; font-size:10px; font-weight:700;
  border-radius:8px; display:grid; place-items:center; padding:0 4px;
}
.notif-pop {
  position:absolute; right:14px; top:52px; width:360px; max-height:70vh; overflow:auto;
  background:var(--card); border:1px solid var(--line); border-radius:12px;
  box-shadow:0 12px 40px rgba(11,37,69,.18); z-index:120; display:none;
}
.notif-pop.open { display:block; }
.notif-item { padding:10px 14px; border-bottom:1px solid var(--line); font-size:13px; }
.notif-item:last-child { border-bottom:none; }
.notif-item b { display:block; margin-bottom:2px; }
.notif-item .when { font-size:11px; color:var(--mut); }
.notif-item.lv-danger b { color:var(--bad); } .notif-item.lv-warning b { color:var(--warn); }
.notif-item.lv-success b { color:var(--ok); }

.appr-card {
  border:1px solid var(--line); border-left:4px solid var(--afayar-gold);
  border-radius:10px; padding:14px 16px; margin-bottom:12px; background:var(--card);
}
.appr-card .meta { font-size:12.5px; color:var(--mut); margin:4px 0 10px; }

.scanbar {
  display:flex; gap:8px; align-items:center; background:var(--afayar-navy);
  color:#fff; padding:10px 14px; border-radius:10px; margin-bottom:14px;
}
.scanbar input { flex:1; }

.grid2 { display:grid; grid-template-columns:repeat(auto-fit,minmax(320px,1fr)); gap:16px; }
.kv { display:flex; justify-content:space-between; gap:10px; padding:5px 0; border-bottom:1px dashed var(--line); font-size:13px; }
.kv:last-child { border-bottom:none; }

.imp-steps { display:flex; gap:6px; margin-bottom:16px; flex-wrap:wrap; }
.imp-step { flex:1; min-width:110px; text-align:center; padding:8px 6px; border-radius:8px; background:var(--bg); font-size:12.5px; color:var(--mut); }
.imp-step.on { background:var(--afayar-gold); color:#fff; font-weight:600; }
.imp-err-row td { background:#fff7f7; color:#991b1b; }

.topbar-search input {
  background:rgba(255,255,255,.09); border:1px solid rgba(255,255,255,.14); color:#fff;
  border-radius:8px; padding:7px 12px; width:240px; font-size:13px; outline:none;
}
.topbar-search input::placeholder { color:rgba(255,255,255,.45); }

/* ===================== AFAYAR DELIVERY : mode téléphone ======================= */
@media (max-width: 640px) {
  /* sidebar: full-screen overlay + backdrop */
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(82vw, 300px); z-index: 200;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: none;
  }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 60px rgba(2,6,23,.5); }
  .sidebar .brand { padding-top: 14px; }
  body.nav-open::after {
    content: ''; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 150;
  }
  .main { margin-left: 0; }

  /* topbar compresses */
  .topbar { padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
  .topbar h1 { font-size: 15px; margin-right: auto; }
  .topbar .gsearch { display: none; }

  /* content paddings */
  main.content, .content { padding: 12px !important; }
  .pagebar { font-size: 13px; }

  /* toolbar + filters stack full width */
  .toolbar { flex-wrap: wrap; gap: 8px; }
  .search-box { width: 100%; order: -1; }
  .filters { width: 100%; flex-wrap: wrap; gap: 6px; }
  .toolbtns { width: 100%; justify-content: flex-start; flex-wrap: wrap; gap: 6px; }
  .toolbtns .btn { padding: 7px 10px; font-size: 12.5px; }

  /* tables scroll horizontally with sticky first column hint */
  .tbl { font-size: 12.5px; }
  .tbl th, .tbl td { padding: 8px 9px; white-space: nowrap; }

  /* KPIs two per row */
  .kpi-grid { grid-template-columns: 1fr 1fr !important; gap: 8px; }
  .kpi { padding: 10px !important; }
  .kpi b { font-size: 17px !important; }

  /* forms single column */
  .frm { grid-template-columns: 1fr !important; }
  .permgrid { grid-template-columns: 1fr !important; }

  /* modals near fullscreen */
  .modal { max-height: 94vh; border-radius: 12px; }
  .modal-body { padding: 14px; }
  .modal-foot { padding: 11px 14px; flex-wrap: wrap; }

  /* cards / grids single column */
  .cards { grid-template-columns: 1fr !important; }
  [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .dash-grid, .grid2 { grid-template-columns: 1fr !important; }

  /* chips row scrolls */
  .chips { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
}
/* very small phones */
@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr !important; }
  .topbar-search input { width: 130px; }
}

/* ===================== AFAYAR DELIVERY : RTL (arabe) ========================== */
html[dir="rtl"] .sidebar { inset: 0 0 0 auto; }
html[dir="rtl"] .main { margin-left: 0; margin-right: 235px; }
@media (max-width: 900px) {
  html[dir="rtl"] .sidebar { transform: translateX(100%); }
  html[dir="rtl"] body.nav-open .sidebar { transform: none; }
  html[dir="rtl"] .main { margin-right: 0; }
}
@media (max-width: 640px) {
  html[dir="rtl"] .sidebar { inset: 0 0 0 auto; }
}
html[dir="rtl"] .tbl, html[dir="rtl"] .kv,
html[dir="rtl"] input, html[dir="rtl"] select, html[dir="rtl"] textarea { text-align: right; }
html[dir="rtl"] .modal-foot { justify-content: flex-start; }
html[dir="rtl"] .menu-item { flex-direction: row; }

/* ===================== AFAYAR DELIVERY : PWA — écran d'accueil (encoche) ====== */
@media (display-mode: standalone), (display-mode: minimal-ui) {
  .topbar {
    height: calc(58px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    background: linear-gradient(to bottom,
      var(--afayar-navy) 0, var(--afayar-navy) env(safe-area-inset-top, 0px),
      var(--card) env(safe-area-inset-top, 0px));
  }
  .sidebar { padding-top: env(safe-area-inset-top, 0px); }
  .brand { padding-top: calc(env(safe-area-inset-top, 0px) + 18px); }
}
/* topbar passe en 2 lignes sur écran étroit : ne plus couper le contenu */
@media (display-mode: standalone) and (max-width: 900px),
       (display-mode: minimal-ui) and (max-width: 900px) {
  .topbar { height: auto; min-height: 58px; padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px; }
}


/* AFAYAR DELIVERY — Commandes page global lock when Réception is OFF */
#commands-page-lock {
  position: absolute;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(248,250,252,.88);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  cursor: not-allowed;
}
#commands-page-lock[hidden] { display: none !important; }
.commands-page-lock-card {
  width: min(560px, 92vw);
  padding: 28px;
  text-align: center;
  border: 1px solid #cbd5e1;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(15,23,42,.16);
}
.commands-page-lock-icon { font-size: 42px; margin-bottom: 8px; }
.commands-page-lock-card h2 { margin: 0 0 8px; }
.commands-page-lock-card p { margin: 0 0 8px; font-weight: 600; }
.commands-page-lock-card small { color: #64748b; }

.cc-toolbar{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}.table-wrap{overflow:auto}
.state-inline{border:0;background:transparent;padding:0;cursor:pointer;text-align:left}.state-inline:focus{outline:2px solid var(--accent,#D4AF5A);border-radius:4px}.state-meta{font-size:11px;margin-top:2px;white-space:normal}
/* Ramassage live scanner */
.btn-success { background: #16a34a; color: #fff; border-color: #16a34a; }
.btn-success:hover { filter: brightness(.92); }
.ramassage-live-zone { border: 2px solid #16a34a; }
.ramassage-live-zone #ramassage-scan-input { width: 100%; min-height: 46px; font-size: 16px; }
