:root {
  --primary: #1d4ed8; --primary-dark: #00346e; --primary-light: #e8efff; --accent: #f57c20;
  --bg: #eef1f7; --card: #fff; --text: #1e293b; --muted: #64748b; --border: #e2e8f0;
  --success: #16a34a; --warning: #f59e0b; --danger: #dc2626; --info: #0ea5e9;
  --sidebar-w: 255px; --topbar-h: 60px; --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
h1, h2, h3, h4 { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.text-right { text-align: right; } .text-center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; }
.flex { display: flex; gap: 10px; align-items: center; } .flex-wrap { flex-wrap: wrap; } .grow { flex: 1; }
.between { justify-content: space-between; }

/* ---------- Layout ---------- */
.layout { min-height: 100vh; }
.sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w); background: #fff; border-right: 1px solid var(--border); z-index: 40; display: flex; flex-direction: column; transition: transform .25s; }
.sidebar .brand { height: var(--topbar-h); display: flex; align-items: center; justify-content: center; gap: 10px; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; font-weight: 800; font-size: 19px; letter-spacing: -.3px; flex-shrink: 0; }
.sidebar .brand span { color: var(--accent); }
.sidebar .brand img { width: 30px; height: 30px; border-radius: 8px; object-fit: contain; background: #fff; }
.nav { overflow-y: auto; padding: 14px 12px 40px; flex: 1; }
.nav-item > a { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; color: #334155; font-weight: 500; margin-bottom: 3px; cursor: pointer; transition: background .15s; }
.nav-item > a:hover { background: #f1f5ff; }
.nav-item > a i.ico { width: 20px; text-align: center; color: #475569; font-size: 15px; }
.nav-item > a .lbl { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item > a .chev { font-size: 11px; color: #94a3b8; transition: transform .2s; }
.nav-item.open > a .chev { transform: rotate(-90deg); }
.nav-item.active > a { background: var(--primary-light); color: var(--primary); border: 1px solid #c7d7fe; box-shadow: 0 2px 8px rgba(29,78,216,.08); }
.nav-item.active > a i.ico { color: var(--primary); }
.nav-sub { display: none; margin: 2px 0 8px 22px; padding-left: 12px; border-left: 2px solid #e0e7ff; }
.nav-item.open .nav-sub { display: block; }
.nav-sub a { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 10px; color: #475569; font-size: 13px; }
.nav-sub a i { width: 16px; text-align: center; color: #64748b; font-size: 12px; }
.nav-sub a:hover { background: #f1f5ff; }
.nav-sub a.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-sub a.active i { color: var(--primary); }

.topbar { position: fixed; top: 0; left: var(--sidebar-w); right: 0; height: var(--topbar-h); background: linear-gradient(90deg, var(--primary-dark), var(--primary)); display: flex; align-items: center; gap: 10px; padding: 0 18px; z-index: 30; color: #fff; }
.topbar .tb-btn { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.22); color: #fff; height: 36px; padding: 0 13px; border-radius: 10px; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; font-size: 13px; position: relative; }
.topbar .tb-btn:hover { background: rgba(255,255,255,.2); }
.topbar .tb-badge { position: absolute; top: -5px; right: -5px; background: var(--warning); color: #fff; font-size: 10px; border-radius: 8px; padding: 1px 5px; }
.topbar .spacer { flex: 1; }
.content { margin-left: var(--sidebar-w); padding: calc(var(--topbar-h) + 22px) 22px 30px; min-height: 100vh; }
.content-hero { position: absolute; left: var(--sidebar-w); right: 0; top: var(--topbar-h); height: 340px; background: linear-gradient(160deg, var(--primary), var(--primary-dark)); z-index: 0; }
.content > * { position: relative; z-index: 1; }
.footer { color: var(--muted); font-size: 12px; padding: 24px 4px 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; font-weight: 800; letter-spacing: -.4px; }
.page-head h1 small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 8px; }
.page-head.light h1, .page-head.light h1 small { color: #fff; }
.dropdown-menu { position: fixed; background: #fff; color: var(--text); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 32px rgba(15,23,42,.18); min-width: 210px; padding: 6px; z-index: 300; max-height: 70vh; overflow-y: auto; }
.dropdown-menu a, .dropdown-menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; color: #334155; background: none; border: 0; cursor: pointer; text-align: left; font-size: 13px; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: #f1f5f9; }
.dropdown-menu .danger { color: var(--danger); }
.dropdown-menu i { width: 16px; text-align: center; color: #64748b; }
.dropdown-menu .danger i { color: var(--danger); }
.dropdown-menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.topbar .mobile-toggle { display: none; }
.sidebar-backdrop { display: none; }
body.sb-collapsed .sidebar { transform: translateX(-100%); }
body.sb-collapsed .topbar, body.sb-collapsed .content-hero { left: 0; }
body.sb-collapsed .content { margin-left: 0; }

/* ---------- Cards / boxes ---------- */
.box { background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: 0 1px 3px rgba(15,23,42,.04); margin-bottom: 20px; }
.box-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.box-head h3 { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.box-body { padding: 20px; }
.box.collapsed .box-body { display: none; }
.filters-head { cursor: pointer; color: var(--primary); font-size: 17px; font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 22px; }
.kpi { border-radius: 16px; padding: 20px; color: #fff; display: flex; align-items: center; gap: 16px; position: relative; overflow: hidden; box-shadow: 0 10px 24px rgba(15,23,42,.18); min-height: 110px; }
.kpi::after { content: ''; position: absolute; right: -30px; bottom: -40px; width: 160px; height: 120px; border-radius: 50%; border: 2px solid rgba(255,255,255,.18); }
.kpi .kpi-ico { width: 56px; height: 56px; border-radius: 14px; background: rgba(255,255,255,.22); display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.kpi .kpi-lbl { font-size: 13px; font-weight: 600; opacity: .95; }
.kpi .kpi-val { font-size: 22px; font-weight: 800; margin-top: 4px; letter-spacing: -.3px; }
.g1 { background: linear-gradient(135deg, #0ea5e9, #0369a1); } .g2 { background: linear-gradient(135deg, #10b981, #047857); }
.g3 { background: linear-gradient(135deg, #f59e0b, #c2410c); } .g4 { background: linear-gradient(135deg, #f43f5e, #be123c); }
.g5 { background: linear-gradient(135deg, #6366f1, #4338ca); } .g6 { background: linear-gradient(135deg, #fb923c, #ea580c); }
.g7 { background: linear-gradient(135deg, #d946ef, #a21caf); } .g8 { background: linear-gradient(135deg, #64748b, #334155); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.stat { background: #f8fafc; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.stat .s-lbl { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.stat .s-val { font-size: 20px; font-weight: 800; margin-top: 4px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; font-weight: 600; font-size: 13.5px; white-space: nowrap; transition: filter .15s, background .15s; text-decoration: none; }
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-light { background: #fff; color: var(--text); border-color: var(--border); }
.btn-light:hover { background: #f8fafc; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-add { background: linear-gradient(135deg, #4f46e5, #2563eb); color: #fff; height: 44px; padding: 0 20px; border-radius: 24px; box-shadow: 0 8px 18px rgba(79,70,229,.3); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn-xs { height: 26px; padding: 0 8px; font-size: 11.5px; border-radius: 7px; }
.btn-outline { background: #fff; border: 1px solid #334155; color: #334155; }
.btn-actions { background: #fff; border: 1.5px solid #60a5fa; color: var(--primary); height: 28px; padding: 0 10px; border-radius: 8px; font-size: 12px; }
.btn-icon { width: 34px; padding: 0; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px 20px; }
.col-12 { grid-column: span 12; } .col-9 { grid-column: span 9; } .col-8 { grid-column: span 8; } .col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; } .col-3 { grid-column: span 3; } .col-2 { grid-column: span 2; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: #1e293b; }
.field label .req { color: var(--danger); }
.field .help { color: var(--muted); font-size: 12px; margin-top: 5px; }
.input, .field input[type=text], .field input[type=number], .field input[type=email], .field input[type=password], .field input[type=date],
.field input[type=datetime-local], .field input[type=search], .field select, .field textarea, select.input {
  width: 100%; height: 40px; border: 1px solid #cbd5e1; border-radius: 9px; padding: 0 12px; background: #fff; color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s;
}
.field textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.field select[multiple] { height: auto; min-height: 90px; padding: 6px; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29,78,216,.12); }
.field input[readonly] { background: #f1f5f9; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.check input { width: 17px; height: 17px; accent-color: var(--primary); }
.input-group { display: flex; align-items: stretch; }
.input-group > .addon { display: flex; align-items: center; padding: 0 12px; background: #f1f5f9; border: 1px solid #cbd5e1; color: #475569; }
.input-group > .addon:first-child { border-radius: 9px 0 0 9px; border-right: 0; }
.input-group > .addon:last-child { border-radius: 0 9px 9px 0; border-left: 0; }
.input-group > input, .input-group > select { border-radius: 0 !important; flex: 1; min-width: 0; }
.input-group > :first-child:not(.addon) { border-radius: 9px 0 0 9px !important; }
.input-group > :last-child:not(.addon) { border-radius: 0 9px 9px 0 !important; }
.input-group > .addon.btnish { cursor: pointer; color: var(--primary); background: #fff; }
.img-input { display: flex; gap: 14px; align-items: center; }
.img-input .preview { width: 110px; height: 80px; border: 2px dashed #cbd5e1; border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #f8fafc; color: #94a3b8; font-size: 12px; text-align: center; }
.img-input .preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.alert { padding: 14px 18px; border-radius: 12px; margin-bottom: 16px; display: flex; gap: 10px; align-items: center; }
.alert-info { background: #0ea5e9; color: #fff; justify-content: center; font-size: 15px; }
.alert-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-soft { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ---------- Tables ---------- */
.dt-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.dt-toolbar .dt-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.dt-toolbar .dt-btns .btn { height: 28px; padding: 0 9px; font-size: 12px; border: 1.5px solid #334155; background: #fff; color: #1e293b; border-radius: 7px; }
.dt-length select { height: 32px; border: 1px solid #cbd5e1; border-radius: 7px; padding: 0 8px; margin: 0 6px; }
.dt-search input { height: 34px; border: 1px solid #cbd5e1; border-radius: 7px; padding: 0 10px; width: 220px; }
.table-wrap { overflow-x: auto; border-radius: 10px; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 700; font-size: 13px; padding: 12px 10px; border-bottom: 2px solid var(--border); color: #0f172a; vertical-align: bottom; white-space: nowrap; }
.table th.sortable { cursor: pointer; }
.table th .sort { color: #cbd5e1; font-size: 11px; margin-left: 4px; }
.table th.sorted .sort { color: var(--primary); }
.table td { padding: 11px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: top; font-size: 13.5px; }
.table tbody tr:nth-child(odd) { background: #fafbfd; }
.table tbody tr:hover { background: #f1f5ff; }
.table tfoot td { background: #cbd5e1; font-weight: 700; font-size: 14px; border: 0; padding: 14px 10px; }
.table.compact td, .table.compact th { padding: 7px 8px; }
.table.lines td { vertical-align: middle; }
.table.lines input, .table.lines select { height: 34px; border: 1px solid #cbd5e1; border-radius: 7px; padding: 0 8px; width: 100%; min-width: 70px; }
.dt-empty { text-align: center; color: var(--muted); padding: 28px !important; }
.dt-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; flex-wrap: wrap; gap: 10px; }
.pager { display: flex; }
.pager button { border: 1px solid var(--border); background: #fff; padding: 7px 13px; cursor: pointer; color: #475569; margin-left: -1px; }
.pager button:first-child { border-radius: 8px 0 0 8px; } .pager button:last-child { border-radius: 0 8px 8px 0; }
.pager button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager button:disabled { color: #cbd5e1; cursor: default; }
.badge { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.b-green { background: #dcfce7; color: #15803d; } .b-red { background: #fee2e2; color: #b91c1c; } .b-orange { background: #fef3c7; color: #b45309; }
.b-blue { background: #dbeafe; color: #1d4ed8; } .b-gray { background: #f1f5f9; color: #475569; } .b-purple { background: #f3e8ff; color: #7e22ce; }
.b-cyan { background: #0ea5e9; color: #fff; font-size: 10px; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 10px 16px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .count { background: #e2e8f0; border-radius: 10px; padding: 1px 8px; font-size: 11px; margin-left: 4px; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 200; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 640px; box-shadow: 0 30px 60px rgba(0,0,0,.3); animation: pop .18s ease; }
.modal.lg { max-width: 920px; } .modal.xl { max-width: 1180px; } .modal.sm { max-width: 440px; }
@keyframes pop { from { transform: translateY(12px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 18px; font-weight: 700; }
.modal-head .x { background: none; border: 0; font-size: 22px; cursor: pointer; color: #64748b; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); background: #f8fafc; border-radius: 0 0 16px 16px; }

#toasts { position: fixed; top: 74px; right: 20px; z-index: 400; display: flex; flex-direction: column; gap: 10px; }
.toast { background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.25); display: flex; gap: 10px; align-items: center; max-width: 380px; animation: pop .2s; }
.toast.ok { background: #15803d; } .toast.err { background: #b91c1c; }

/* ---------- Autocomplete ---------- */
.ac { position: relative; }
.ac-list { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 14px 30px rgba(15,23,42,.15); z-index: 60; max-height: 320px; overflow-y: auto; margin-top: 4px; }
.ac-item { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid #f1f5f9; }
.ac-item:hover, .ac-item.on { background: #eff6ff; }
.ac-item small { color: var(--muted); }

/* ---------- Doc editor ---------- */
.totals { width: 100%; max-width: 380px; margin-left: auto; }
.totals div { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.totals div.grand { font-size: 18px; font-weight: 800; color: var(--primary); border-bottom: 0; padding-top: 12px; }
.doc-view .meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.doc-view .meta b { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; margin-bottom: 3px; }
.chain { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-side { background: radial-gradient(circle at 20% 20%, rgba(245,124,32,.28), transparent 40%), linear-gradient(150deg, var(--primary), var(--primary-dark)); color: #fff; padding: 60px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side .logo img { height: 52px; width: auto; display: block; } .auth-side .logo .tagline { margin-top: 10px; font-size: 14px; opacity: .85; }
.auth-mlogo { display: none; width: 100%; max-width: 280px; margin: 0 auto 26px; }
.auth-side h2 { font-size: 38px; line-height: 1.15; font-weight: 800; letter-spacing: -.8px; max-width: 520px; }
.auth-side ul { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 12px; }
.auth-side li { display: flex; gap: 10px; align-items: center; opacity: .95; }
.auth-side li i { color: var(--accent); }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: #fff; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { font-size: 28px; font-weight: 800; margin-bottom: 6px; }
.auth-card .field { margin-bottom: 16px; }
.auth-card .btn { width: 100%; height: 46px; font-size: 15px; }

/* ---------- POS ---------- */
.pos { display: grid; grid-template-columns: 1.05fr 1fr; grid-template-rows: 56px minmax(0, 1fr); height: 100vh; background: var(--bg); }
.pos-top { grid-column: 1 / -1; }
.pos-left { display: flex; flex-direction: column; background: #fff; border-right: 1px solid var(--border); min-height: 0; }
.pos-right { display: flex; flex-direction: column; min-height: 0; padding: 14px; }
.pos-bar { height: 56px; background: linear-gradient(90deg, var(--primary-dark), var(--primary)); color: #fff; display: flex; align-items: center; gap: 10px; padding: 0 14px; }
.pos-cart { flex: 1; overflow-y: auto; }
.pos-cart table td { vertical-align: middle; }
.qty-ctl { display: inline-flex; align-items: center; border: 1px solid #cbd5e1; border-radius: 8px; overflow: hidden; }
.qty-ctl button { width: 28px; height: 30px; border: 0; background: #f1f5f9; cursor: pointer; }
.qty-ctl input { width: 52px; height: 30px; border: 0; text-align: center; }
.pos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; overflow-y: auto; padding: 4px; }
.pos-prod { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 10px; cursor: pointer; text-align: center; transition: transform .1s, box-shadow .15s; }
.pos-prod:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(15,23,42,.1); border-color: #93c5fd; }
.pos-prod .ph { height: 80px; border-radius: 9px; background: #f1f5f9; display: flex; align-items: center; justify-content: center; overflow: hidden; color: #94a3b8; font-size: 26px; margin-bottom: 8px; }
.pos-prod .ph img { width: 100%; height: 100%; object-fit: cover; }
.pos-prod .nm { font-weight: 600; font-size: 13px; line-height: 1.25; height: 33px; overflow: hidden; }
.pos-prod .pr { color: var(--primary); font-weight: 800; margin-top: 4px; }
.pos-prod .st { font-size: 11px; color: var(--muted); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }
.chip { border: 1px solid var(--border); background: #fff; border-radius: 20px; padding: 6px 14px; cursor: pointer; white-space: nowrap; font-weight: 600; font-size: 13px; }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.pos-total { padding: 14px; border-top: 2px solid var(--border); background: #f8fafc; }
.pos-pay { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.pos-pay .btn { height: 48px; }

/* ---------- Cachet preview ---------- */
.cachet-stage { position: relative; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 20px; min-height: 260px; background-image: linear-gradient(#f8fafc 1px, transparent 1px), linear-gradient(90deg, #f8fafc 1px, transparent 1px); background-size: 20px 20px; }
.cachet-stage .sig-zone { position: absolute; bottom: 20px; width: calc(50% - 30px); border-top: 1px solid #94a3b8; padding-top: 6px; font-size: 12px; color: #475569; text-align: center; height: 150px; }
.cachet-stage .sig-zone img { position: absolute; left: 50%; top: 50%; }
.checker { background-image: conic-gradient(#e2e8f0 25%, #fff 0 50%, #e2e8f0 0 75%, #fff 0); background-size: 16px 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.2); }
  body.sb-open .sidebar { transform: none; }
  body.sb-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  .topbar, .content-hero { left: 0 !important; }
  .content { margin-left: 0 !important; padding-left: 14px; padding-right: 14px; }
  .topbar .mobile-toggle { display: inline-flex; }
  .desk-toggle, .tb-hide-sm { display: none !important; }
  .form-grid > [class*=col-] { grid-column: span 12; }
  .auth-wrap { grid-template-columns: 1fr; } .auth-side { display: none; }
  .doc-view .meta { grid-template-columns: 1fr; }
  .pos { grid-template-columns: 1fr; grid-template-rows: auto; height: auto; }
  .pos-right { order: -1; max-height: 50vh; }
}
@media (max-width: 560px) { .kpis { grid-template-columns: 1fr; } .page-head h1 { font-size: 20px; } .dt-search input { width: 100%; } }

@media print {
  .sidebar, .topbar, .content-hero, .dt-toolbar, .dt-foot, .no-print, .btn { display: none !important; }
  .content { margin: 0; padding: 0; }
  .box { border: 0; box-shadow: none; }
}

/* ---------- Arabe / RTL ---------- */
[dir=rtl] body { font-family: 'Cairo', 'Inter', sans-serif; }
[dir=rtl] .sidebar { left: auto; right: 0; border-right: 0; border-left: 1px solid var(--border); }
[dir=rtl] .topbar, [dir=rtl] .content-hero { left: 0; right: var(--sidebar-w); }
[dir=rtl] .content { margin-left: 0; margin-right: var(--sidebar-w); }
[dir=rtl] .nav-sub { margin: 2px 22px 8px 0; padding-left: 0; padding-right: 12px; border-left: 0; border-right: 2px solid #e0e7ff; }
[dir=rtl] .nav-item > a .chev { transform: rotate(180deg); }
[dir=rtl] .nav-item.open > a .chev { transform: rotate(-90deg); }
[dir=rtl] .table th, [dir=rtl] .dropdown-menu a, [dir=rtl] .dropdown-menu button { text-align: right; }
[dir=rtl] .table th.text-right, [dir=rtl] .table td.text-right, [dir=rtl] .text-right { text-align: left; }
[dir=rtl] .totals { margin-left: 0; margin-right: auto; }
[dir=rtl] .kpi::after { right: auto; left: -30px; }
[dir=rtl] #toasts { right: auto; left: 20px; }
[dir=rtl] body.sb-collapsed .sidebar { transform: translateX(100%); }
[dir=rtl] body.sb-collapsed .topbar, [dir=rtl] body.sb-collapsed .content-hero { right: 0; }
[dir=rtl] body.sb-collapsed .content { margin-right: 0; }
@media (max-width: 960px) {
  [dir=rtl] .sidebar { transform: translateX(100%); }
  [dir=rtl] body.sb-open .sidebar { transform: none; }
  [dir=rtl] .topbar, [dir=rtl] .content-hero { right: 0 !important; }
  [dir=rtl] .content { margin-right: 0 !important; }
}
.check-cell { width: 34px; }
.check-cell input { width: 17px; height: 17px; accent-color: var(--primary); }
.bulk-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 14px; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 10px; margin-bottom: 12px; }
.var-table input { height: 34px; border: 1px solid #cbd5e1; border-radius: 7px; padding: 0 8px; width: 100%; }

/* ---------- Abonnement ---------- */
.alert-danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.plan-banner { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.plan-banner.urgent { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.plan-banner > i { font-size: 18px; }
.plan-banner .x { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: inherit; opacity: .6; }
.blocked-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(135deg, var(--primary-dark), var(--primary)); }
.blocked-card { background: #fff; border-radius: 20px; padding: 32px 28px; max-width: 480px; width: 100%; text-align: center; box-shadow: 0 30px 60px rgba(0,0,0,.25); }
.blocked-card .logo { font-weight: 800; font-size: 22px; letter-spacing: -.3px; margin-bottom: 18px; } .blocked-card .logo span { color: var(--primary); }
.blocked-card .ico { width: 74px; height: 74px; border-radius: 50%; margin: 0 auto 14px; display: flex; align-items: center; justify-content: center; font-size: 30px; background: #fef3c7; color: #b45309; }
.blocked-card .ico.red { background: #fee2e2; color: #b91c1c; }
.blocked-card h1 { font-size: 24px; margin-bottom: 8px; }
.blocked-card .info { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0; background: #f8fafc; border-radius: 12px; padding: 12px; }
.blocked-card .info span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; } .blocked-card .info b { font-size: 13px; }

/* ---------- Modèles de facture ---------- */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 18px; }
.tpl-card { border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: #fff; transition: box-shadow .15s, border-color .15s; display: flex; flex-direction: column; }
.tpl-card:hover { box-shadow: 0 10px 24px rgba(15,23,42,.1); border-color: #93c5fd; }
.tpl-card.on { border: 2px solid var(--success); }
.tpl-info { padding: 12px; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); }
.tpl-thumb { position: relative; width: 100%; aspect-ratio: 210 / 297; overflow: hidden; background: #f1f5f9; }
.tpl-thumb iframe { position: absolute; top: 0; left: 0; width: 794px; height: 1123px; border: 0; transform-origin: 0 0; pointer-events: none; background: #fff; }
.tpl-current { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; }
.tpl-current .tpl-thumb { border: 1px solid var(--border); border-radius: 10px; }

/* ---------- Mobile (iOS / Android) ---------- */
.install-tip { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 90; background: #0f172a; color: #fff; border-radius: 14px; padding: 14px 16px; display: flex; gap: 12px; align-items: center; box-shadow: 0 12px 30px rgba(0,0,0,.3); font-size: 13px; }
.install-tip .btn { flex-shrink: 0; }
.install-tip .x { background: none; border: 0; color: #fff; font-size: 22px; opacity: .7; cursor: pointer; }
.topbar { padding-top: env(safe-area-inset-top); height: calc(var(--topbar-h) + env(safe-area-inset-top)); }
.content { padding-top: calc(var(--topbar-h) + 22px + env(safe-area-inset-top)); }
.sidebar .brand { padding-top: env(safe-area-inset-top); height: calc(var(--topbar-h) + env(safe-area-inset-top)); }
@media (max-width: 960px) {
  input, select, textarea { font-size: 16px !important; }
  .page-head { flex-wrap: wrap; gap: 10px; }
  .modal-back { padding: 0 !important; align-items: flex-end !important; }
  .modal { width: 100% !important; max-width: 100% !important; max-height: 92vh; border-radius: 18px 18px 0 0 !important; margin: 0 !important; }
  .modal-body { overflow-y: auto; max-height: calc(92vh - 130px); }
  .modal-foot { flex-wrap: wrap; padding-bottom: calc(14px + env(safe-area-inset-bottom)) !important; }
  .modal-foot .btn { flex: 1 1 auto; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs button { white-space: nowrap; flex-shrink: 0; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .dt-toolbar { flex-wrap: wrap; }
  .dropdown-menu { max-width: calc(100vw - 20px); }
  .content { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px; }
  .stat-grid .s-val { font-size: 20px; overflow-wrap: anywhere; }
  .tpl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tpl-info .btn-sm { padding: 0 8px; }
  .blocked-card .info { grid-template-columns: 1fr; }
  .plan-banner { flex-wrap: wrap; }
  .topbar .tb-btn { padding-left: 8px; padding-right: 8px; }
}
@media (display-mode: standalone) { body { overscroll-behavior-y: none; } }
@media (max-width: 960px) {
  #page .flex { flex-wrap: wrap; }
  #page .flex > .input-group { flex: 1 1 100%; min-width: 0; }
  .img-input { flex-wrap: wrap; } .img-input > div { min-width: 0; max-width: 100%; }
  .img-input input[type=file] { max-width: 100%; }
  .form-grid > [class*=col-] { min-width: 0; }
  [class*=col-]:has(> table), .box-body:has(> table) { overflow-x: auto; }
}

/* ---------- Logo lagestion.ma ---------- */
.tb-logo { display: inline-flex; align-items: center; margin-left: 6px; }
.tb-logo img { height: 30px; width: auto; display: block; }
.blocked-card img.logo { height: 44px; width: auto; display: block; margin: 0 auto 18px; }
@media (max-width: 960px) { .auth-mlogo { display: block; } }
@media (max-width: 560px) { .tb-logo img { height: 22px; } }
@media (max-width: 380px) { .tb-logo { display: none; } }
