:root {
  --ink: #16213b;
  --muted: #73809b;
  --line: #e7eaf1;
  --paper: #ffffff;
  --canvas: #f5f7fb;
  --navy: #101a35;
  --indigo: #5b5ce2;
  --green: #19a974;
  --amber: #ee9c24;
  --red: #e24d61;
  font-family: "Noto Sans Khmer", "Khmer OS Battambang", Inter, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.auth-pending { overflow: hidden; }
.auth-pending .sidebar, .auth-pending main { pointer-events: none; filter: blur(5px); user-select: none; }
.auth-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 75% 20%, #6f70e040, transparent 34%), linear-gradient(145deg, #0d1730f2, #17254bf2); backdrop-filter: blur(6px); }
.authenticated .auth-overlay { display: none; }
.auth-card { width: min(440px, 100%); padding: 34px; border: 1px solid #ffffff1f; border-radius: 22px; color: var(--ink); background: #fff; box-shadow: 0 30px 90px #050a1f73; }
.auth-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 28px; }
.auth-brand .brand-mark { color: white; font-size: 13px; }
.auth-brand strong, .auth-brand span { display: block; }
.auth-brand span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.auth-card h1 { margin: 6px 0; font-size: 24px; }
.auth-copy { margin: 0 0 22px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.auth-form { display: grid; gap: 14px; }
.auth-form label { display: grid; gap: 7px; color: #4c5872; font-size: 11px; }
.auth-form input { width: 100%; padding: 11px 12px; border: 1px solid #dfe3ec; border-radius: 9px; outline: none; }
.auth-form input:focus { border-color: #7a7ce8; box-shadow: 0 0 0 3px #7779e817; }
.auth-form .primary-button { width: 100%; margin-top: 3px; padding: 12px; }
.auth-error { min-height: 16px; margin: 0; color: var(--red); font-size: 10px; }
.field-help { margin-top: -3px; color: var(--muted); font-size: 9px; }
.user-pill { padding: 7px 10px; border-radius: 20px; color: #4e51bc; background: #ececfd; font-weight: 700; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 242px; z-index: 20;
  display: flex; flex-direction: column; padding: 28px 18px;
  background: linear-gradient(180deg, #101a35 0%, #172446 100%); color: white;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 30px; }
.brand-mark { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-weight: 800; font-size: 22px; background: linear-gradient(135deg, #797aff, #4b4dcc); box-shadow: 0 8px 18px #060c1f66; }
.brand strong, .brand span { display: block; }
.brand span { color: #9aa7c8; font-size: 12px; margin-top: 2px; }
nav { display: grid; gap: 7px; }
.nav-item { width: 100%; border: 0; background: transparent; text-align: left; text-decoration: none; color: #aeb8d2; padding: 11px 14px; border-radius: 10px; display: flex; gap: 12px; align-items: center; }
.nav-item div { display: grid; gap: 1px; }
.nav-item small { color: #7785a9; font-size: 9px; }
.nav-item.active small { color: #abb7d6; }
.nav-item:hover, .nav-item.active { color: white; background: #ffffff16; }
.nav-item.active { box-shadow: inset 3px 0 #7a7cff; }
.sidebar-note { margin-top: auto; border: 1px solid #ffffff16; border-radius: 12px; padding: 13px; display: flex; align-items: center; gap: 10px; background: #ffffff08; }
.sidebar-note strong, .sidebar-note small { display: block; font-size: 11px; }
.sidebar-note small { color: #96a2c0; margin-top: 3px; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: #3ed79e; box-shadow: 0 0 0 5px #3ed79e1f; }

main { margin-left: 242px; }
.topbar { height: 94px; padding: 18px 38px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10; }
.topbar h1 { margin: 2px 0 0; font-size: 24px; }
.eyebrow, .panel-heading p { margin: 0; font-size: 10px; letter-spacing: .14em; font-weight: 800; color: #6f74dd; }
.topbar-actions { display: flex; gap: 16px; align-items: center; color: var(--muted); font-size: 12px; }
.refresh-button, .pagination button, .dialog-actions button { border: 1px solid var(--line); border-radius: 9px; padding: 9px 13px; background: white; color: var(--ink); }
.refresh-button:hover, .pagination button:hover { border-color: #b9bdf7; color: var(--indigo); }
.menu-button { display: none; border: 0; background: none; font-size: 24px; }
.content { padding: 28px 38px 50px; max-width: 1550px; margin: auto; }
.view { display: none; animation: view-in .2s ease; }
.view.active { display: block; }
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.section-label { margin: 23px 2px 12px; }
.section-label span { color: #7779de; font-size: 9px; letter-spacing: .13em; font-weight: 800; }
.section-label h2 { margin: 3px 0 0; font-size: 16px; }
.view-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.view-header h2 { margin: 4px 0 0; font-size: 22px; }
.header-buttons { display: flex; gap: 9px; }
.primary-button, .secondary-button { border-radius: 9px; padding: 10px 15px; border: 1px solid var(--indigo); font-size: 11px; }
.primary-button { color: white; background: var(--indigo); }
.primary-button:hover { background: #494ac5; }
.secondary-button { color: var(--indigo); background: white; }
.hero { color: white; background: linear-gradient(120deg, #5556d7 0%, #6d70eb 52%, #7883ee 100%); padding: 25px 30px; border-radius: 16px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 15px 35px #5556d72c; overflow: hidden; position: relative; }
.hero::after { content: ""; position: absolute; right: -30px; top: -90px; width: 250px; height: 250px; border: 40px solid #ffffff0b; border-radius: 50%; }
.hero p { margin: 0 0 7px; color: #e6e7ff; font-size: 13px; }
.hero h2 { margin: 0; font-size: 21px; font-weight: 650; }
.hero-date { padding: 10px 15px; background: #ffffff18; border: 1px solid #ffffff22; border-radius: 10px; z-index: 1; font-size: 13px; }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 17px; margin: 22px 0; }
.metric-card { background: var(--paper); border: 1px solid var(--line); padding: 19px; border-radius: 14px; display: flex; align-items: center; gap: 15px; box-shadow: 0 5px 18px #25345c08; }
.metric-card .metric-icon { width: 45px; height: 45px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; font-weight: 700; }
.metric-card span, .metric-card small, .metric-card strong { display: block; }
.metric-card span { color: var(--muted); font-size: 12px; }
.metric-card strong { font-size: 26px; line-height: 1.15; margin: 3px 0; }
.metric-card small { color: #a2aabb; font-size: 10px; }
.metric-card.indigo .metric-icon { color: var(--indigo); background: #eeeefe; }
.metric-card.amber .metric-icon { color: var(--amber); background: #fff4e2; }
.metric-card.green .metric-icon { color: var(--green); background: #e8f8f2; }
.metric-card.red .metric-icon { color: var(--red); background: #fdecef; }
.metric-card.blue .metric-icon { color: #248dcc; background: #e6f5fd; }
.metric-card.violet .metric-icon { color: #8b5fd3; background: #f2eafd; }
.operations-cards { grid-template-columns: repeat(3, 1fr); }

.charts-grid { display: grid; grid-template-columns: minmax(300px, .8fr) minmax(420px, 1.5fr); gap: 20px; margin-bottom: 20px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 5px 18px #25345c08; }
.panel-heading { padding: 20px 22px 10px; display: flex; align-items: center; justify-content: space-between; }
.panel-heading h3 { margin: 3px 0 0; font-size: 16px; }
.donut-wrap { position: relative; width: 220px; margin: 5px auto 12px; }
.donut-wrap canvas { display: block; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.donut-center strong { font-size: 25px; }
.donut-center span { font-size: 10px; color: var(--muted); }
.legend { padding: 0 22px 20px; display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; }
.legend-item { font-size: 10px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.legend-item i { width: 8px; height: 8px; border-radius: 50%; }
.bar-chart { padding: 8px 22px 24px; height: 255px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.bar-row { display: grid; grid-template-columns: minmax(115px, 1fr) 3fr 58px; align-items: center; gap: 12px; font-size: 11px; }
.bar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #4c5872; }
.bar-track { height: 9px; border-radius: 6px; background: #eff1f7; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, #5b5ce2, #8c8df5); }
.bar-value { text-align: right; color: var(--muted); }

.inventory-heading { padding-bottom: 17px; border-bottom: 1px solid var(--line); }
.result-count { font-size: 11px; color: var(--muted); background: #f3f4f8; border-radius: 20px; padding: 6px 10px; }
.filters { padding: 15px 20px; display: grid; grid-template-columns: minmax(250px, 1fr) 170px 210px; gap: 10px; }
.filters input, .filters select, dialog input, dialog select, dialog textarea { width: 100%; border: 1px solid #dfe3ec; background: #fff; border-radius: 9px; padding: 10px 12px; outline: none; color: var(--ink); }
.filters input:focus, .filters select:focus, dialog input:focus, dialog select:focus, dialog textarea:focus { border-color: #7a7ce8; box-shadow: 0 0 0 3px #7779e817; }
.single-filter { grid-template-columns: minmax(280px, 520px); }
.search-box { position: relative; }
.search-box span { position: absolute; left: 13px; top: 8px; color: var(--muted); font-size: 20px; }
.search-box input { padding-left: 37px; }
.table-wrap { overflow-x: auto; min-height: 330px; }
table { width: 100%; border-collapse: collapse; min-width: 970px; }
th { background: #fafbfc; color: #8992a5; font-size: 9px; letter-spacing: .08em; text-transform: uppercase; text-align: left; padding: 11px 14px; border-block: 1px solid var(--line); }
td { font-size: 11px; padding: 12px 14px; border-bottom: 1px solid #edf0f5; color: #46516a; }
tbody tr:hover { background: #fafaff; }
.item-name strong, .item-name span { display: block; }
.item-name strong { color: var(--ink); font-size: 11px; }
.item-name span { color: var(--muted); font-size: 10px; margin-top: 3px; }
.stock-number { font-weight: 800; color: var(--ink); }
.badge { display: inline-block; padding: 5px 8px; border-radius: 20px; font-size: 9px; font-weight: 800; letter-spacing: .04em; }
.badge.reorder { color: #a96500; background: #fff1d9; }
.badge.sufficient { color: #087a52; background: #def7ed; }
.badge.expired { color: #b1283e; background: #fde4e8; }
.badge.pending, .badge.unpaid, .badge.expiring_soon, .badge.overdue { color: #a96500; background: #fff1d9; }
.badge.paid, .badge.received { color: #087a52; background: #def7ed; }
.badge.new { color: #4e51bc; background: #ececfd; }
.badge.returning { color: #087a52; background: #def7ed; }
.badge.safety_stock { color: #b1283e; background: #fde4e8; }
.edit-button { border: 1px solid #dfe3ec; background: white; color: var(--indigo); border-radius: 7px; padding: 5px 9px; }
.empty-state { text-align: center; color: var(--muted); padding: 70px 20px; }
.pagination { padding: 15px 20px; display: flex; justify-content: flex-end; align-items: center; gap: 14px; }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination span { font-size: 11px; color: var(--muted); }

.product-catalog-panel { overflow: hidden; }
.product-display-filters { grid-template-columns: minmax(280px, 1fr) 230px; border-bottom: 1px solid var(--line); }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; padding: 22px; }
.product-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: white; transition: transform .18s ease, box-shadow .18s ease; }
.product-card:hover { transform: translateY(-3px); box-shadow: 0 13px 30px #25345c16; }
.product-picture { aspect-ratio: 4 / 3; overflow: hidden; background: #f1f3f8; }
.product-picture img { width: 100%; height: 100%; display: block; object-fit: cover; }
.product-card-body { padding: 15px; }
.product-card-code { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .06em; }
.product-card h3 { margin: 10px 0 3px; overflow: hidden; color: var(--ink); font-size: 14px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.product-khmer-name { min-height: 16px; margin: 0; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.product-price-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 14px; }
.product-price { padding: 10px; border-radius: 9px; background: #f7f7fb; }
.product-price span, .product-price strong { display: block; }
.product-price span { color: var(--muted); font-size: 8px; text-transform: uppercase; letter-spacing: .06em; }
.product-price strong { margin-top: 3px; color: var(--ink); font-size: 12px; }
.product-stock { margin-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 10px; }
.product-stock strong { color: var(--green); }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(430px, calc(100vw - 30px)); color: var(--ink); box-shadow: 0 25px 80px #111a3c52; }
dialog::backdrop { background: #0c132a99; backdrop-filter: blur(3px); }
dialog form { padding: 25px; position: relative; }
dialog h2 { margin: 5px 0; font-size: 19px; }
.dialog-code { margin: 0 0 20px; color: var(--muted); font-size: 12px; }
dialog label { display: grid; gap: 7px; font-size: 12px; color: #4c5872; }
dialog textarea { resize: vertical; min-height: 65px; }
.wide-dialog { width: min(920px, calc(100vw - 30px)); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 13px; margin-top: 18px; }
.form-grid.four { grid-template-columns: repeat(4, 1fr); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .span-two { grid-column: span 2; }
.line-heading { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 9px; }
.line-items { display: grid; gap: 8px; max-height: 275px; overflow-y: auto; }
.line-row { display: grid; grid-template-columns: minmax(220px, 2fr) 90px 110px 130px 34px; gap: 8px; align-items: center; padding: 9px; border: 1px solid var(--line); border-radius: 10px; background: #fafbfe; }
.line-row button { border: 0; color: var(--red); background: transparent; font-size: 19px; }
.dialog-close { position: absolute; right: 18px; top: 15px; background: none; border: 0; font-size: 22px; color: var(--muted); }
.dialog-actions { margin-top: 22px; display: flex; justify-content: flex-end; gap: 9px; }
.dialog-actions button:not(.secondary) { color: white; border-color: var(--indigo); background: var(--indigo); }
.toast { position: fixed; right: 25px; bottom: 25px; padding: 12px 18px; border-radius: 10px; color: white; background: var(--navy); box-shadow: 0 12px 35px #111a3c42; transform: translateY(100px); opacity: 0; transition: .25s; z-index: 50; font-size: 12px; }
.toast.show { transform: none; opacity: 1; }
.alert-grid, .report-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin-bottom: 20px; }
.alert-count { min-width: 28px; text-align: center; padding: 5px 8px; color: var(--red); background: #fdecef; border-radius: 20px; font-size: 10px; font-weight: 800; }
.alert-list { min-height: 120px; max-height: 280px; overflow-y: auto; padding: 8px 20px 18px; }
.alert-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.alert-item:last-child { border-bottom: 0; }
.alert-item strong, .alert-item small { display: block; }
.alert-item strong { font-size: 11px; }
.alert-item small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.report-range { display: flex; align-items: center; gap: 8px; }
.report-range input { border: 1px solid var(--line); border-radius: 8px; padding: 8px; color: var(--ink); }
.report-bars, .rank-list { min-height: 220px; padding: 8px 20px 20px; display: grid; align-content: start; gap: 9px; }
.report-bar { display: grid; grid-template-columns: 82px 1fr 70px; gap: 9px; align-items: center; font-size: 10px; }
.rank-item { display: grid; grid-template-columns: 25px 1fr auto; gap: 9px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 10px; }
.rank-number { width: 23px; height: 23px; display: grid; place-items: center; color: var(--indigo); background: #eeeeff; border-radius: 7px; font-weight: 800; }
.muted { color: var(--muted); }
.ring-balance-panel { margin-bottom: 20px; }
.ring-type-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; padding: 10px 22px 22px; }
.ring-type-card { display: flex; justify-content: space-between; align-items: center; gap: 15px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: linear-gradient(135deg, #fafaff, #f2f3ff); }
.ring-type-card strong, .ring-type-card small { display: block; }
.ring-type-card strong { font-size: 13px; }
.ring-type-card small { color: var(--muted); margin-top: 4px; font-size: 10px; }
.ring-type-card span { color: var(--indigo); font-size: 24px; font-weight: 800; }
.reward-line-row { grid-template-columns: minmax(260px, 2fr) 100px 130px 34px; }
.analytics-title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.demo-badge { margin-bottom: 12px; padding: 7px 10px; border: 1px solid #c8caf8; border-radius: 20px; color: #5556c9; background: #f0f0ff; font-size: 9px; font-weight: 800; letter-spacing: .08em; }
.analytics-kpis { grid-template-columns: repeat(3, 1fr); }
.trend-up { color: #087a52 !important; }
.trend-down { color: #b1283e !important; }
.analytics-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.analytics-wide { grid-column: 1 / -1; }
.analytics-legend { display: flex; gap: 12px; color: var(--muted); font-size: 9px; }
.analytics-legend span { display: flex; align-items: center; gap: 5px; }
.analytics-legend i { width: 9px; height: 9px; border-radius: 3px; }
.year-2024 { background: #a7abbb; }
.year-2025 { background: #8b8def; }
.year-2026 { background: #5556d7; }
.monthly-comparison { height: 290px; padding: 20px 22px 18px; display: grid; grid-template-columns: repeat(12, minmax(45px, 1fr)); gap: 8px; border-top: 1px solid var(--line); overflow-x: auto; }
.analytics-month-group { min-width: 45px; height: 250px; display: grid; grid-template-rows: 1fr auto; gap: 8px; text-align: center; color: var(--muted); font-size: 9px; }
.analytics-month-bars { min-height: 0; display: flex; align-items: flex-end; justify-content: center; gap: 3px; border-bottom: 1px solid #dfe3ec; background: repeating-linear-gradient(to top, transparent 0, transparent 49px, #edf0f5 50px); }
.analytics-month-bar { position: relative; width: min(12px, 28%); min-height: 3px; border-radius: 4px 4px 0 0; transition: opacity .15s; }
.analytics-month-bar:hover { opacity: .72; }
.analytics-month-bar span { display: none; position: absolute; left: 50%; bottom: calc(100% + 5px); transform: translateX(-50%); z-index: 4; padding: 4px 6px; border-radius: 5px; color: white; background: var(--navy); white-space: nowrap; font-style: normal; font-size: 8px; }
.analytics-month-bar:hover span { display: block; }
.analytics-breakdown { padding: 10px 22px 22px; display: grid; gap: 15px; }
.analytics-breakdown-row { display: grid; grid-template-columns: minmax(120px, 1.2fr) 2fr 65px; align-items: center; gap: 12px; font-size: 10px; }
.analytics-breakdown-label strong, .analytics-breakdown-label span { display: block; }
.analytics-breakdown-label span { margin-top: 3px; color: var(--muted); font-size: 8px; }
.analytics-breakdown-row > strong { text-align: right; }
.analytics-table-panel { margin-bottom: 20px; }
.analytics-table { min-width: 900px; }

@media (max-width: 1050px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .operations-cards { grid-template-columns: repeat(2, 1fr); }
  .form-grid.four { grid-template-columns: repeat(2, 1fr); }
  .analytics-kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  main { margin-left: 0; }
  .topbar { height: 82px; padding: 14px 18px; }
  .menu-button { display: block; }
  .topbar-actions > span:not(.user-pill) { display: none; }
  .user-pill { max-width: 105px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .auth-card { padding: 26px 22px; }
  .content { padding: 18px; }
  .hero-date { display: none; }
  .hero h2 { font-size: 17px; }
  .cards { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
  .product-display-filters { grid-template-columns: 1fr; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); padding: 15px; gap: 12px; }
  .alert-grid, .report-grid { grid-template-columns: 1fr; }
  .analytics-grid { grid-template-columns: 1fr; }
  .analytics-kpis { grid-template-columns: 1fr; }
  .analytics-title-row { align-items: flex-start; flex-direction: column; }
  .demo-badge { margin: -5px 0 12px; }
  .view-header, .report-range { align-items: flex-start; flex-direction: column; }
  .line-row { grid-template-columns: 1fr 75px; }
  .line-row .line-unit, .line-row .line-price { grid-column: span 1; }
  .reward-line-row { grid-template-columns: 1fr 75px; }
}
