/* InvoiceMNG — admin UI (on top of Bootstrap 5) */
:root {
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-soft: #eef2ff;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #ffffff;
  --body-bg: #f4f6fb;
  --card-radius: 14px;
  --border: #e5e7eb;
  --muted: #64748b;
  --sidebar-w: 248px;
  --bs-primary: #4f46e5;
  --bs-primary-rgb: 79, 70, 229;
  --bs-link-color: #4f46e5;
  --bs-link-hover-color: #4338ca;
  --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body { background: var(--body-bg); color: #1e293b; font-size: 14px; }
a { text-decoration: none; }
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-dark); --bs-btn-hover-border-color: var(--brand-dark); --bs-btn-active-bg: var(--brand-dark); --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); --bs-btn-active-bg: var(--brand-dark); }
.text-primary { color: var(--brand) !important; }
.bg-primary { background-color: var(--brand) !important; }
.bg-orange { background-color: #f97316 !important; }
.form-control:focus, .form-select:focus { border-color: #a5b4fc; box-shadow: 0 0 0 .2rem rgba(79,70,229,.15); }
.form-label { font-weight: 500; font-size: 13px; color: #334155; margin-bottom: .3rem; }
.required::after { content: " *"; color: #dc2626; }

/* ---------- Layout ---------- */
.app-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); background: var(--sidebar-bg);
  display: flex; flex-direction: column; z-index: 1040; transition: transform .25s ease;
}
.app-brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; color: #fff; font-weight: 700; font-size: 17px; border-bottom: 1px solid rgba(255,255,255,.06); }
.app-brand .logo-dot { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg,#6366f1,#8b5cf6); display: grid; place-items: center; font-size: 16px; }
.app-brand img { max-height: 34px; max-width: 34px; border-radius: 8px; background: #fff; object-fit: contain; }
.app-brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.app-nav .nav-section { color: #475569; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 14px 12px 6px; }
.app-nav a { display: flex; align-items: center; gap: 12px; color: var(--sidebar-text); padding: 9px 12px; border-radius: 9px; font-weight: 500; margin-bottom: 2px; }
.app-nav a i { font-size: 17px; width: 20px; text-align: center; }
.app-nav a:hover { color: #e2e8f0; background: rgba(255,255,255,.05); }
.app-nav a.active { color: var(--sidebar-active); background: var(--brand); box-shadow: 0 4px 14px rgba(79,70,229,.35); }
.app-nav .badge { margin-left: auto; }
.app-sidebar-footer { padding: 12px 20px; color: #475569; font-size: 12px; border-top: 1px solid rgba(255,255,255,.06); }

.app-main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.app-topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 1030; background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border); padding: 10px 24px; display: flex; align-items: center; gap: 12px;
}
.app-topbar .search { flex: 1; max-width: 460px; position: relative; }
.app-topbar .search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #94a3b8; }
.app-topbar .search input { padding-left: 36px; background: #f1f5f9; border-color: transparent; border-radius: 10px; }
.app-topbar .search input:focus { background: #fff; }
.app-content { padding: 24px; flex: 1; }
.app-footer { padding: 14px 24px; color: var(--muted); font-size: 12px; }
.sidebar-toggle { display: none; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; }

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); }
  body.sidebar-open .app-sidebar { transform: none; }
  body.sidebar-open::after { content: ""; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1035; }
  .app-main { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .app-content { padding: 16px; }
  .app-topbar { padding: 10px 16px; }
}

/* ---------- Page header ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-header h1 { font-size: 22px; font-weight: 700; margin: 0; }
.page-header .subtitle { color: var(--muted); margin: 2px 0 0; }
.page-header .actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--border); border-radius: var(--card-radius); box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.card-header { background: transparent; border-bottom: 1px solid var(--border); padding: 14px 18px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-body { padding: 18px; }
.stat-card { padding: 18px; display: flex; gap: 14px; align-items: flex-start; height: 100%; }
.stat-card .icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; flex-shrink: 0; }
.stat-card .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat-card .value { font-size: 21px; font-weight: 700; line-height: 1.25; margin-top: 2px; word-break: break-word; }
.stat-card .hint { font-size: 12px; color: var(--muted); }
.i-indigo { background: #eef2ff; color: #4f46e5; } .i-green { background: #dcfce7; color: #16a34a; }
.i-amber { background: #fef3c7; color: #d97706; } .i-red { background: #fee2e2; color: #dc2626; }
.i-sky { background: #e0f2fe; color: #0284c7; } .i-violet { background: #f3e8ff; color: #9333ea; }
.i-slate { background: #f1f5f9; color: #475569; } .i-teal { background: #ccfbf1; color: #0d9488; }
.mini-stat { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: #fff; height: 100%; }
.mini-stat .label { font-size: 12px; color: var(--muted); }
.mini-stat .value { font-size: 18px; font-weight: 700; }

/* ---------- Tables ---------- */
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .7rem .9rem; vertical-align: middle; }
.table thead th { background: #f8fafc; color: #475569; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tbody tr:hover { background: #fafbff; }
.table-card .table thead th:first-child { border-top-left-radius: var(--card-radius); }
.sort-link { color: inherit; }
.text-money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions-col { white-space: nowrap; text-align: right; }
.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty-state i { font-size: 42px; color: #cbd5e1; display: block; margin-bottom: 8px; }

.badge-status { font-weight: 600; font-size: 11.5px; padding: .38em .7em; border-radius: 999px; }
.badge.bg-info { background-color: #0ea5e9 !important; }
.badge.bg-warning { color: #78350f; }

/* ---------- Filters ---------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.filter-bar .form-control, .filter-bar .form-select { min-width: 140px; }
.filter-bar .grow { flex: 1 1 220px; }

/* ---------- Forms ---------- */
.form-section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 6px 0 12px; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(244,246,251,.95); padding: 12px 0; margin-top: 12px; z-index: 5; border-top: 1px solid var(--border); }

/* Invoice item editor */
.items-table { min-width: 980px; }
.items-table td { vertical-align: top !important; }
.items-table .form-control, .items-table .form-select { font-size: 13px; padding: .38rem .5rem; }
.items-table .col-item { min-width: 260px; }
.items-table .col-qty { width: 90px; }
.items-table .col-price { width: 120px; }
.items-table .col-disc { width: 150px; }
.items-table .col-tax { width: 96px; }
.items-table .col-total { width: 130px; }
.items-table .line-total { font-weight: 600; padding-top: .45rem; }
.items-table .line-tax { font-size: 11.5px; color: var(--muted); }
.totals-box { border-radius: 12px; background: #f8fafc; border: 1px solid var(--border); padding: 14px 16px; }
.totals-box .row-line { display: flex; justify-content: space-between; padding: 4px 0; }
.totals-box .grand { font-size: 18px; font-weight: 700; border-top: 1px dashed #cbd5e1; margin-top: 6px; padding-top: 10px; }

/* Nav tabs */
.nav-tabs-clean { border-bottom: 1px solid var(--border); gap: 4px; flex-wrap: nowrap; overflow-x: auto; }
.nav-tabs-clean .nav-link { border: 0; color: var(--muted); font-weight: 500; padding: 10px 14px; border-bottom: 2px solid transparent; white-space: nowrap; }
.nav-tabs-clean .nav-link.active { color: var(--brand); border-bottom-color: var(--brand); background: transparent; }

/* Invoice preview wrapper on screen */
.doc-wrap { background: #e9edf5; border-radius: var(--card-radius); padding: 24px; overflow-x: auto; }
.doc-paper { background: #fff; max-width: 860px; margin: 0 auto; box-shadow: 0 10px 30px rgba(15,23,42,.08); border-radius: 6px; }

/* Auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 10% -10%, #e0e7ff 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #ede9fe 0%, transparent 60%), #f8fafc; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .card { border-radius: 18px; box-shadow: 0 20px 50px rgba(15,23,42,.08); }

/* Toasts */
.toast-stack { position: fixed; top: calc(70px + env(safe-area-inset-top, 0px)); right: 16px; z-index: 1090; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast-stack .alert { box-shadow: 0 10px 24px rgba(15,23,42,.12); margin: 0; min-width: 280px; }

.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 240px; }
.list-compact .item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid #f1f5f9; }
.list-compact .item:last-child { border-bottom: 0; }
.list-compact .title { font-weight: 600; color: #1e293b; }
.list-compact .meta { font-size: 12px; color: var(--muted); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; word-break: break-word; }
@media (max-width: 575.98px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: 6px; } .page-header h1 { font-size: 19px; } }

/* Print */
@media print {
  .app-sidebar, .app-topbar, .app-footer, .no-print, .page-header .actions, .toast-stack { display: none !important; }
  .app-main { margin: 0; }
  .app-content { padding: 0; }
  body { background: #fff; }
  .card { border: 0; box-shadow: none; }
  .doc-wrap { background: #fff; padding: 0; }
  .doc-paper { box-shadow: none; max-width: none; }
  .chart-box { page-break-inside: avoid; }
}

/* Refinements */
.list-compact a.item { color: inherit; }
.list-compact a.item:hover { background: #fafbff; }
a.stat-card:hover { border-color: #c7d2fe; }
@media (max-width: 575.98px) {
  .stat-card { flex-direction: column; gap: 8px; padding: 14px; }
  .stat-card .icon { width: 36px; height: 36px; font-size: 17px; }
  .stat-card .value { font-size: 16px; word-break: normal; }
  .page-header .actions { width: 100%; }
}
