:root {
  --brand: #0f6e56; --brand-600: #0b5a46; --brand-50: #e8f4f0; --brand-100: #cfe8df;
  --ink: #1b2430; --ink-2: #4a5565; --ink-3: #7b8594; --line: #e3e7ec; --line-2: #eef1f4;
  --bg: #f5f7f9; --card: #fff; --danger: #c2372f; --danger-50: #fdecea; --warn: #b26a00; --warn-50: #fff4e0;
  --ok: #1d7a46; --ok-50: #e6f5ec; --info: #2557a7; --info-50: #e8effb;
  --r: 12px; --r-sm: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --tap: 44px; --sidebar: 248px; --top: 58px; --bottom: 64px;
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Gujarati", sans-serif; color: var(--ink); background: var(--bg); -webkit-tap-highlight-color: transparent; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
.muted { color: var(--ink-3); } .small { font-size: 13px; } .tiny { font-size: 12px; } .b { font-weight: 600; } .r { text-align: right; } .c { text-align: center; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hidden { display: none !important; }
.boot { display: grid; place-items: center; height: 100vh; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--brand-100); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Layout */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: #0d2b24; color: #d6e6e0; position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 14px 10px 20px; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; color: #fff; font-weight: 700; letter-spacing: .2px; }
.sidebar .brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; font-size: 15px; }
.nav-group { margin-top: 12px; }
.nav-group > .label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: #7fa397; padding: 6px 10px; }
.nav a { display: flex; align-items: center; gap: 10px; color: #d6e6e0; padding: 9px 10px; border-radius: 8px; font-size: 14px; min-height: 40px; }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active { background: var(--brand); color: #fff; }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; height: var(--top); background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; padding: 0 16px; }
.topbar .title { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.company-chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--brand-100); background: var(--brand-50); color: var(--brand-600); border-radius: 999px; padding: 6px 12px 6px 6px; font-weight: 600; font-size: 13px; cursor: pointer; min-height: 38px; max-width: 46vw; }
.company-chip .code { background: var(--brand); color: #fff; border-radius: 999px; padding: 3px 8px; font-size: 12px; letter-spacing: .5px; }
.company-chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.net { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-50); flex: none; }
.net.off { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-50); }
.offline-bar { background: var(--danger); color: #fff; text-align: center; font-size: 13px; padding: 6px; }
.content { padding: 18px; max-width: 1400px; width: 100%; margin: 0 auto; }
.bottom-nav { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding: 12px 12px calc(var(--bottom) + 24px + env(safe-area-inset-bottom)); }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--bottom) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: #fff; border-top: 1px solid var(--line); z-index: 30; }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--ink-3); }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a.active { color: var(--brand); }
  .bottom-nav .fab { margin-top: -22px; width: 54px; height: 54px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; justify-self: center; box-shadow: 0 6px 16px rgba(15,110,86,.35); }
  .bottom-nav .fab svg { width: 26px; height: 26px; }
  .topbar .title { font-size: 15px; }
  .hide-m { display: none !important; }
}
@media (min-width: 901px) { .hide-d { display: none !important; } }

/* Cards & grids */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.card-b { padding: 16px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0,1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 640px) { .g2, .g3 { grid-template-columns: 1fr; } .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; } }
.page-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 14px; }

/* KPI */
.kpi { padding: 14px 16px; cursor: default; position: relative; }
.kpi .lbl { font-size: 12.5px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.kpi.warn .val { color: var(--warn); } .kpi.bad .val { color: var(--danger); } .kpi.good .val { color: var(--ok); }
.kpi[data-tip] .i { cursor: help; border: 1px solid var(--line); border-radius: 50%; width: 15px; height: 15px; display: inline-grid; place-items: center; font-size: 10px; }
@media (max-width: 640px) { .kpi .val { font-size: 18px; } }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; user-select: none; }
.btn:hover { background: var(--line-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; } .btn.primary:hover { background: var(--brand-600); }
.btn.danger { background: #fff; border-color: #f1c4c0; color: var(--danger); } .btn.danger:hover { background: var(--danger-50); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 34px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 0; width: var(--tap); }
.btn svg { width: 18px; height: 18px; }
.btn.wa { background: #1fa855; border-color: #1fa855; color: #fff; }
.btn-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(245,247,249,.95); backdrop-filter: blur(6px); padding: 10px 0; border-top: 1px solid var(--line); z-index: 5; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 900px) { .sticky-actions { bottom: calc(var(--bottom) + env(safe-area-inset-bottom)); margin: 0 -12px; padding: 10px 12px; } .sticky-actions .btn { flex: 1; } }

/* Forms */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field .req::after { content: ' *'; color: var(--danger); }
.field .hint { font-size: 12px; color: var(--ink-3); }
.field .err { font-size: 12px; color: var(--danger); }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); background: var(--danger-50); }
input, select, textarea { font: inherit; font-size: 16px; color: var(--ink); width: 100%; min-height: var(--tap); padding: 9px 12px; border: 1px solid #cfd6de; border-radius: 10px; background: #fff; outline: none; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-100); }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }
input[readonly] { background: var(--line-2); }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); font-weight: 500; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.form-grid .span2 { grid-column: span 2; } .form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span2 { grid-column: auto; } }
fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px 14px; margin: 0; }
legend { font-weight: 650; font-size: 13px; padding: 0 6px; color: var(--brand-600); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 600; padding: 0 14px; min-height: 38px; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: var(--brand); color: #fff; }

/* Tables */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .4px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.tbl th.sort { cursor: pointer; } .tbl th.sort:hover { color: var(--ink); }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: #f7faf9; }
.tbl tfoot td { font-weight: 700; background: #fafbfc; border-top: 2px solid var(--line); }
.tbl td.r, .tbl th.r { text-align: right; }
.empty { padding: 40px 16px; text-align: center; color: var(--ink-3); }
.empty svg { width: 42px; height: 42px; opacity: .4; }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; gap: 10px; font-size: 13px; color: var(--ink-3); flex-wrap: wrap; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select, .toolbar input[type=date] { width: auto; }
@media (max-width: 640px) { .toolbar input[type=search] { max-width: none; flex: 1 1 100%; } .toolbar select, .toolbar input[type=date] { flex: 1; } }

/* Mobile list cards (replace tables on phones) */
.mlist { display: none; }
@media (max-width: 640px) {
  .tbl-wrap.cards .tbl { display: none; }
  .tbl-wrap.cards .mlist { display: block; }
}
.mitem { display: flex; justify-content: space-between; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.mitem:active { background: var(--line-2); }
.mitem .t { font-weight: 600; } .mitem .s { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--ok-50); color: var(--ok); } .badge.warn { background: var(--warn-50); color: var(--warn); } .badge.bad { background: var(--danger-50); color: var(--danger); }
.badge.info { background: var(--info-50); color: var(--info); } .badge.brand { background: var(--brand-50); color: var(--brand-600); }

/* Document editor */
.doc-lines { width: 100%; border-collapse: collapse; }
.doc-lines th { font-size: 12px; color: var(--ink-3); text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.doc-lines td { padding: 6px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.doc-lines input, .doc-lines select { min-height: 40px; padding: 7px 8px; font-size: 15px; }
.doc-lines .w-qty { width: 82px; } .doc-lines .w-rate { width: 104px; } .doc-lines .w-sm { width: 74px; } .doc-lines .w-unit { width: 92px; }
.line-card { border: 1px solid var(--line); border-radius: var(--r); padding: 12px; margin-bottom: 10px; background: #fff; position: relative; }
.line-card .lc-h { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.line-card .lc-g { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.line-card .lc-g .field > label { font-size: 11.5px; }
.line-card .lc-tot { display: flex; justify-content: space-between; margin-top: 8px; font-weight: 600; }
.totals { width: 100%; max-width: 380px; margin-left: auto; }
.totals td { padding: 5px 0; } .totals td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.totals .grand td { font-size: 19px; font-weight: 750; border-top: 2px solid var(--ink); padding-top: 8px; }
.batch-pill { font-size: 12px; color: var(--ink-2); background: var(--line-2); border-radius: 6px; padding: 2px 6px; display: inline-block; margin-top: 3px; }
.batch-pill.exp { background: var(--danger-50); color: var(--danger); } .batch-pill.near { background: var(--warn-50); color: var(--warn); }

/* Autocomplete */
.ac { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(16,24,40,.15); z-index: 50; max-height: 320px; overflow-y: auto; min-width: 280px; }
.ac-item { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--line-2); }
.ac-item:last-child { border-bottom: 0; }
.ac-item.on, .ac-item:hover { background: var(--brand-50); }
.ac-item .s { font-size: 12px; color: var(--ink-3); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 100; display: grid; place-items: center; padding: 16px; animation: fade .15s; }
.modal { background: #fff; border-radius: 16px; width: min(640px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: min(1000px, 100%); }
.modal-h { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-b { padding: 16px 18px; overflow-y: auto; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 640px) { .modal-bg { place-items: end stretch; padding: 0; } .modal { border-radius: 16px 16px 0 0; max-height: 92vh; width: 100%; } .modal-f .btn { flex: 1; } }
@keyframes fade { from { opacity: 0; } }

/* Toasts */
#toasts { position: fixed; top: 12px; right: 12px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 24px)); }
.toast { background: var(--ink); color: #fff; padding: 12px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-size: 14px; animation: fade .2s; display: flex; gap: 10px; align-items: flex-start; }
.toast.ok { background: var(--ok); } .toast.bad { background: var(--danger); } .toast.warn { background: var(--warn); }

/* Alerts */
.alert { padding: 10px 14px; border-radius: 10px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.alert.warn { background: var(--warn-50); color: #7a4900; } .alert.bad { background: var(--danger-50); color: #8e2018; } .alert.info { background: var(--info-50); color: #1d4385; } .alert.ok { background: var(--ok-50); color: #145533; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #0d2b24, #0f6e56); }
.login .card { width: min(400px, 100%); padding: 28px; }
.login .brandmark { width: 56px; height: 56px; border-radius: 14px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 22px; margin-bottom: 14px; }

/* Misc */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 10px 14px; font-weight: 600; font-size: 14px; color: var(--ink-3); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; font-weight: 500; }
.preview-frame { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.chart-box { position: relative; height: 260px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tpl-card { border: 2px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; font-size: 13px; font-weight: 600; background: #fff; text-align: left; font-family: inherit; }
.tpl-card.on { border-color: var(--brand); background: var(--brand-50); }
.tpl-card .sw { height: 56px; border-radius: 6px; margin-bottom: 6px; background: var(--line-2); display: flex; flex-direction: column; gap: 4px; padding: 6px; }
.tpl-card .sw i { display: block; height: 6px; border-radius: 3px; background: #cfd6de; }
.perm-table td, .perm-table th { padding: 6px 8px; text-align: center; }
.perm-table td:first-child, .perm-table th:first-child { text-align: left; }
.wa-bubble { background: #dcf8c6; border-radius: 10px 10px 2px 10px; padding: 10px 12px; white-space: pre-wrap; font-size: 14px; max-width: 100%; box-shadow: 0 1px 1px rgba(0,0,0,.1); }
.wa-wrap { background: #ece5dd; border-radius: 12px; padding: 14px; }
.list-actions { display: flex; gap: 6px; justify-content: flex-end; }
.skeleton { background: linear-gradient(90deg, var(--line-2), #fafbfc, var(--line-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 6px; height: 14px; }
@keyframes sk { to { background-position: -200% 0; } }

.split { grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); }
.split-l { grid-template-columns: minmax(300px, 420px) minmax(0, 1fr); }
@media (max-width: 900px) { .split, .split-l { grid-template-columns: minmax(0, 1fr); } }
.modal-b, .modal-b > * { min-width: 0; }
.wa-bubble, .modal textarea, .alert, .kv dd { overflow-wrap: anywhere; word-break: break-word; }
.grid > * { min-width: 0; }
