/* =============================================================
   Z Billing — UI theme (navy sidebar / white cards, after the
   reference billing screen). Bootstrap 5 + custom tokens.
   ============================================================= */
:root {
  --navy-900: #0b1a3f;
  --navy-800: #102457;
  --navy-700: #16307a;
  --blue-600: #1d4ed8;
  --blue-500: #2563eb;
  --blue-50:  #eef4ff;
  --purple:   #7c3aed;
  --purple-50:#f6f0ff;
  --green:    #16a34a;
  --ink:      #0f172a;
  --muted:    #64748b;
  --line:     #e6eaf2;
  --bg:       #f3f5f9;
  --card:     #ffffff;
  --radius:   12px;
  --topbar-h: 60px;
  --sidebar-w:240px;
  --bs-primary: var(--blue-600);
  --bs-primary-rgb: 29, 78, 216;
  --bs-body-font-family: "Inter", "Noto Sans Lao", system-ui, sans-serif;
}
html[lang="lo"] { --bs-body-font-family: "Noto Sans Lao", "Inter", system-ui, sans-serif; }
body { font-family: var(--bs-body-font-family); color: var(--ink); background: var(--bg); font-size: 14px; }
.btn-primary { --bs-btn-bg: var(--blue-600); --bs-btn-border-color: var(--blue-600); --bs-btn-hover-bg: var(--navy-700); --bs-btn-hover-border-color: var(--navy-700); }
.btn-outline-primary { --bs-btn-color: var(--blue-600); --bs-btn-border-color: var(--blue-600); --bs-btn-hover-bg: var(--blue-600); --bs-btn-hover-border-color: var(--blue-600); }
.btn-navy { background: var(--navy-800); color: #fff; border: 0; }
.btn-navy:hover { background: var(--navy-700); color: #fff; }
.text-purple { color: var(--purple) !important; }
.text-bg-primary-soft { background: var(--blue-50) !important; color: var(--blue-600) !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 1030;
  display: flex; align-items: center; gap: 14px; padding: 0 18px;
  background: linear-gradient(90deg, var(--navy-900), var(--navy-800)); color: #fff;
}
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: #fff; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8); font-weight: 800; font-size: 18px; }
.brand-name { font-weight: 800; letter-spacing: .06em; font-size: 18px; }
.brand-sub { color: #c7d2fe; font-size: 13px; padding-left: 14px; border-left: 1px solid rgba(255,255,255,.18); }
.topbar-date { color: #e2e8f0; font-size: 13px; align-items: center; }
.btn-icon { font-size: 22px; padding: 2px 6px; }
.btn-lang { color: #fff; border: 1px solid rgba(255,255,255,.3); font-size: 12px; padding: 3px 10px; border-radius: 999px; }
.btn-lang:hover { background: rgba(255,255,255,.12); color: #fff; }
.company-switcher { display: flex; align-items: center; gap: 8px; color: #c7d2fe; }
.company-switcher .form-select { background-color: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.2); min-width: 220px;
  --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e"); }
.company-switcher .form-select option { color: var(--ink); }
.company-pill { align-items: center; font-size: 13px; padding: 4px 12px; border-radius: 999px; background: rgba(255,255,255,.1); }
.user-chip { display: flex; align-items: center; gap: 10px; background: none; border: 0; color: #fff; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: #dbe4ff; color: var(--navy-800); font-weight: 700; }
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11px; color: #c7d2fe; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w); z-index: 1020;
  background: var(--navy-900); color: #cbd5e1; display: flex; flex-direction: column; padding: 14px 12px; overflow-y: auto;
}
.sidebar-nav { flex: 1; }
.nav-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; margin: 16px 10px 6px; }
.nav-group:first-child { margin-top: 2px; }
.nav-link-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px; margin-bottom: 2px;
  color: #dbe3f1; text-decoration: none; font-weight: 500; font-size: 13.5px; transition: background .15s; }
.nav-link-item i { font-size: 17px; width: 20px; text-align: center; }
.nav-link-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link-item.active { background: var(--blue-600); color: #fff; box-shadow: 0 6px 16px rgba(29,78,216,.35); }
.phase-dot { margin-left: auto; font-size: 9.5px; padding: 1px 6px; border-radius: 999px; background: rgba(255,255,255,.08); color: #94a3b8; }
.nav-link-item.active .phase-dot { background: rgba(255,255,255,.2); color: #fff; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.08); padding-top: 10px; }
.sidebar-backdrop { display: none; }

/* ---------- Main ---------- */
.main { margin-left: var(--sidebar-w); padding: calc(var(--topbar-h) + 22px) 24px 18px; min-height: 100vh; }
.page-head { margin-bottom: 18px; }
.page-head h1 { font-size: 24px; font-weight: 700; margin: 0 0 4px; }
.crumbs { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs span:last-child { color: var(--blue-600); font-weight: 600; }
.crumbs i { font-size: 10px; }
.app-footer { text-align: center; color: var(--muted); font-size: 12px; margin: 26px 0 0; }

.card-soft { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.section-title { font-size: 12.5px; font-weight: 700; color: var(--navy-700); letter-spacing: .03em; margin-bottom: 12px; }
.alert-info-soft { background: var(--blue-50); color: var(--navy-700); border: 1px solid #d6e2ff; border-radius: var(--radius); }

/* entity strip */
.entity-avatar { width: 64px; height: 64px; border-radius: 14px; background: #e8efff; color: var(--blue-500); display: grid; place-items: center; font-size: 30px; flex: none; }
.entity-grid { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: 12px; }
.entity-grid .k { font-size: 11.5px; color: var(--muted); }
.entity-grid .v { font-size: 13.5px; }
.balance-card { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 16px;
  background: linear-gradient(180deg, var(--purple-50), #fff); }
.balance-card .label { font-size: 12px; font-weight: 700; color: var(--navy-700); text-transform: uppercase; letter-spacing: .04em; }
.balance-card .amount { font-size: 28px; font-weight: 700; color: var(--purple); margin-top: 6px; white-space: nowrap; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; gap: 12px; align-items: center; }
.kpi-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 19px; flex: none; }
.kpi-value { font-size: 20px; font-weight: 700; line-height: 1.1; }
.kpi-label { font-size: 12px; color: var(--muted); }
.tone-blue .kpi-icon, .qt-icon.tone-blue { background: #e8efff; color: #1d4ed8; }
.tone-indigo .kpi-icon { background: #eceafe; color: #4f46e5; }
.tone-green .kpi-icon { background: #e7f7ee; color: #16a34a; }
.tone-amber .kpi-icon, .qt-icon.tone-amber { background: #fff4e5; color: #ea8a0c; }
.tone-violet .kpi-icon, .qt-icon.tone-violet { background: #f3ecff; color: #9333ea; }
.tone-navy .kpi-icon { background: #e5e9f5; color: var(--navy-800); }
.tone-teal .kpi-icon, .qt-icon.tone-teal { background: #e3f6f5; color: #0f8f87; }

/* tables */
.card-tabs { display: flex; gap: 28px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.card-tabs .tab { padding: 14px 2px 12px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.card-tabs .tab.active { color: var(--blue-600); border-color: var(--blue-600); }
.table-app { --bs-table-bg: transparent; font-size: 13px; }
.table-app thead th { background: #f6f8fc; color: #334155; font-weight: 600; font-size: 12.5px; border-bottom: 1px solid var(--line); padding: 11px 14px; white-space: nowrap; }
.table-app td { padding: 11px 14px; border-color: #eef1f6; }
.table-app tbody tr:hover { background: #fafbff; }
.doc-type { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; }
.doc-qt { background: #e3f6f5; color: #0f8f87; } .doc-inv { background: #e8efff; color: #1d4ed8; } .doc-rec { background: #e7f7ee; color: #16a34a; }
.badge-status { font-weight: 600; font-size: 11px; }
.empty-row { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 28px; color: var(--muted); }
.empty-row i { font-size: 22px; }
.empty-state .empty-icon { width: 72px; height: 72px; margin: 0 auto; border-radius: 18px; background: var(--blue-50); color: var(--blue-600); display: grid; place-items: center; font-size: 32px; }

/* overview card */
.overview-card { overflow: hidden; }
.overview-head { background: linear-gradient(90deg, var(--blue-600), var(--navy-700)); color: #fff; font-weight: 700; font-size: 13px; padding: 13px 16px; letter-spacing: .03em; }
.ov-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13.5px; }
.ov-row.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-size: 15px; }

/* quick tiles */
.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.quick-tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 6px; text-align: center;
  color: var(--ink); text-decoration: none; font-size: 12px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 8px; transition: transform .15s, box-shadow .15s; }
.quick-tile:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(15,23,42,.08); color: var(--ink); }
.qt-icon { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; font-size: 20px; }

/* timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 12px 18px; }
.timeline li::before { content: ""; position: absolute; left: 3px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--blue-500); }
.timeline li::after { content: ""; position: absolute; left: 6.5px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }

/* ---------- Login ---------- */
.login-page { background: var(--bg); }
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login-side { background: linear-gradient(150deg, var(--navy-900), var(--navy-700)); color: #fff; align-items: center; justify-content: center; padding: 48px; }
.login-side h1 { font-size: 30px; font-weight: 700; max-width: 420px; line-height: 1.35; }
.login-points { list-style: none; padding: 0; margin: 28px 0 0; }
.login-points li { display: flex; gap: 12px; align-items: center; padding: 8px 0; color: #dbe4ff; }
.login-points i { font-size: 18px; color: #93c5fd; }
.login-card { background: #fff; border-radius: 16px; padding: 36px; width: 100%; max-width: 420px; margin: auto; box-shadow: 0 20px 50px rgba(15,23,42,.08); }
.login-card h2 { font-weight: 700; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1010; }
  .main { margin-left: 0; padding-left: 16px; padding-right: 16px; }
  .login-wrap { grid-template-columns: 1fr; padding: 16px; }
  .entity-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 575.98px) {
  .quick-grid { grid-template-columns: repeat(2, 1fr); }
  .balance-card .amount { font-size: 22px; }
}

/* ---------- polish ---------- */
.table-app td.nowrap, .table-app td.text-end { white-space: nowrap; }
.table-app td.cust { min-width: 160px; }
.kpi-grid { grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); }
.kpi { padding: 12px; }
.balance-card .amount { font-size: clamp(18px, 1.9vw, 28px); max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.entity-grid { grid-template-columns: minmax(150px, 1.6fr) repeat(3, minmax(80px, 1fr)); }
.quick-tile { font-size: 11.5px; line-height: 1.35; }
.company-col { max-width: 130px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.balance-card .amount { font-size: clamp(17px, 1.55vw, 26px); white-space: nowrap; overflow: visible; text-overflow: clip; }
.balance-card { overflow: hidden; }

/* ---------- Phase 2: CRUD screens ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.search-box { max-width: 320px; }
.search-box .input-group-text { background: #fff; color: var(--muted); }
.table-foot { background: #fbfcfe; border-radius: 0 0 var(--radius) var(--radius); }
.pagination { --bs-pagination-active-bg: var(--blue-600); --bs-pagination-active-border-color: var(--blue-600); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; padding: 14px 0; position: sticky; bottom: 0;
  background: linear-gradient(180deg, rgba(243,245,249,0), var(--bg) 35%); }
.form-label { font-weight: 500; font-size: 13px; color: #334155; }
.form-control:focus, .form-select:focus { border-color: #93b4fb; box-shadow: 0 0 0 .2rem rgba(37,99,235,.12); }
.logo-thumb { width: 36px; height: 36px; border-radius: 9px; background: #eef2fb; color: var(--blue-600); display: grid; place-items: center; overflow: hidden; flex: none; }
.logo-thumb img, .entity-avatar img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.entity-avatar { overflow: hidden; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px 18px; }
.info-grid dt { font-size: 11.5px; color: var(--muted); font-weight: 500; }
.info-grid dd { margin: 0; font-size: 13.5px; }
.info-grid .span-2 { grid-column: span 2; }
.role-pill { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--blue-50); color: var(--navy-700); font-size: 12px; font-weight: 600; }
.avatar-sm { width: 30px; height: 30px; font-size: 12px; }
.role-option { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.role-option:has(input:checked) { border-color: var(--blue-500); background: var(--blue-50); }
.role-option input { margin-top: 3px; }
.upload-box { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border: 1px dashed #cdd6e6; border-radius: 10px; background: #fbfcff; }
.upload-preview { width: 72px; height: 72px; border-radius: 10px; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; flex: none; color: #9aa7bd; font-size: 26px; }
.upload-preview img { width: 100%; height: 100%; object-fit: contain; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.perm-grid .form-check { padding-top: 3px; padding-bottom: 3px; }
.settings-layout { display: flex; gap: 16px; align-items: flex-start; }
.settings-nav { width: 230px; flex: none; position: sticky; top: calc(var(--topbar-h) + 16px); }
.settings-link { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: #334155; text-decoration: none; font-weight: 500; }
.settings-link:hover { background: #f4f7fd; color: var(--ink); }
.settings-link.active { background: var(--blue-50); color: var(--blue-600); }
.min-w-0 { min-width: 0; }
fieldset[disabled] .form-control, fieldset[disabled] .form-select { background: #f6f7fa; }
@media (max-width: 991.98px) {
  .settings-layout { flex-direction: column; }
  .settings-nav { width: 100%; position: static; display: flex; overflow-x: auto; }
  .settings-link { white-space: nowrap; }
  .info-grid .span-2 { grid-column: auto; }
}
.table-app code { color: #475569; font-size: 12px; }

/* ---------- Phase 3: documents ---------- */
.text-navy { color: var(--navy-700); }
.table-items td { padding: 8px 6px; vertical-align: top; }
.table-items .form-control { font-size: 13px; }
.table-items textarea { resize: none; overflow: hidden; min-height: 31px; }
.table-items .line-amount { padding-top: 13px; }
.totals-box { min-width: 300px; }
.sticky-summary { position: sticky; top: calc(var(--topbar-h) + 16px); }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.action-grid > *:only-child, .action-grid > .btn-primary-wide { grid-column: span 2; }
.action-grid .btn { font-size: 13px; }
.related-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px;
  text-decoration: none; color: var(--ink); margin-bottom: 6px; }
.related-item:hover { background: #f8faff; color: var(--ink); }
@media (max-width: 575.98px) { .action-grid { grid-template-columns: 1fr; } .totals-box { min-width: 0; width: 100%; } }
.entity-grid { grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); }
.entity-grid > div:first-child { grid-column: span 2; }
.table-items th, .table-items td { padding-left: 4px; padding-right: 4px; }
.table-items th:first-child, .table-items td:first-child { padding-left: 12px; }
.table-items .form-control-sm { padding-left: 6px; padding-right: 6px; }

/* ---------- Phase 5: template list ---------- */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.tpl-card { overflow: hidden; }
.tpl-thumb { display: block; height: 300px; overflow: hidden; background: #e9edf3; border-bottom: 1px solid var(--line); position: relative; }
.tpl-thumb iframe { width: 820px; height: 1160px; border: 0; transform: scale(.345); transform-origin: top left; pointer-events: none; position: absolute; left: 0; top: 0; }

/* ---------- Phase 7: reports ---------- */
.tone-purple .kpi-icon { background: #f1ebff; color: #7c3aed; }
.tone-orange .kpi-icon { background: #fff1e6; color: #ea580c; }
.tone-red .kpi-icon { background: #fde8e8; color: #dc2626; }
.section-title { font-size: 14px; font-weight: 700; color: var(--navy-800); text-transform: uppercase; letter-spacing: .03em; }
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.report-tile { display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; color: inherit; text-decoration: none; transition: border-color .15s, box-shadow .15s, transform .15s; }
.report-tile:hover { border-color: #93b4ff; box-shadow: 0 6px 18px rgba(15, 35, 95, .08); transform: translateY(-1px); color: inherit; }
.report-tile-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 21px; flex: none;
  background: #e8efff; color: #1d4ed8; }
.report-tile-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.report-tile-title { font-weight: 700; }
.report-tile-desc { font-size: 12.5px; color: var(--muted); }
.report-tile-go { color: #94a3b8; }
.report-kpis { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.report-kpis .kpi-value { word-break: break-word; }
.min-w-0 { min-width: 0; }
.card-title-sm { font-size: 15px; font-weight: 700; }
tr.report-total td { background: #eef2ff !important; font-weight: 700; border-top: 2px solid #c7d2fe; }
.print-only { display: none; }
@media print {
  .sidebar, .topbar, .no-print, .page-head .d-flex.gap-2, .app-footer, .toast-container { display: none !important; }
  .main { margin: 0 !important; padding: 0 !important; }
  .print-only { display: block; }
  .card-soft { box-shadow: none !important; break-inside: avoid; }
  .table-responsive { overflow: visible !important; }
}

/* ---------- Phase 8 ---------- */
.card-pad { padding: 16px 18px; }
.system-tabs .nav-link { color: var(--navy-800); font-weight: 600; }
.system-tabs .nav-link.active { background: #1d4ed8; color: #fff; }
.btn-nowrap, form .btn { white-space: nowrap; }
