:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --line: #d7dfec;
  --text: #0f172a;
  --muted: #5b6b86;
  --indigo: #4f46e5;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, Arial, sans-serif; color: var(--text); background: var(--bg); }
h1,h2,h3,p { margin: 0; }
button,input,select { font: inherit; }

.app-shell { max-width: 1380px; margin: 0 auto; }

.header { display:flex; justify-content:space-between; align-items:center; background:#fff; border-bottom:1px solid var(--line); padding:18px 24px; }
.header h1 { font-size: 34px; line-height: 1.1; }
.header p { color: var(--muted); margin-top: 4px; }
.header-right { display:flex; align-items:center; gap:12px; }
.user { display:flex; flex-direction:column; text-align:right; }
.user span { color: var(--muted); text-transform: capitalize; }
.header-right > button { height: 40px; font-weight: 700; }
.api { padding:8px 12px; border-radius:999px; font-weight:700; }
.api.ok { background:#f3e8ff; color:#7e22ce; }
.api.off { background:#ffedd5; color:#c2410c; }

.main { padding:16px 24px 20px; }
.app-footer { text-align:center; color:var(--muted); font-size:12px; padding:0 24px 16px; }
.tabs { display:flex; gap:8px; margin-bottom:14px; flex-wrap: wrap; }
.tab { background:#e2e8f0; border:0; border-radius:8px; padding:10px 16px; font-weight:700; cursor:pointer; white-space:nowrap; }
.tab.active { background:var(--indigo); color:#fff; }

.panel { background:var(--panel); border:1px solid var(--line); border-radius:16px; padding:16px; margin-bottom:14px; }
.panel.small { margin:0; }

.panel h2 { font-size: 26px; margin-bottom: 10px; }
.panel h3 { font-size: 22px; margin-bottom: 10px; }

.split { display:grid; grid-template-columns: 1.35fr 1fr; gap:16px; }
.chips { display:flex; gap:8px; flex-wrap:wrap; margin-bottom:12px; }
.chip { background:#e2e8f0; border:0; border-radius:8px; padding:8px 12px; cursor:pointer; }
.chip.active { background:var(--indigo); color:#fff; }

input, select { width:100%; height:40px; border:2px solid #b9d3fb; border-radius:8px; padding:0 12px; margin-bottom:10px; background:#fff; }
table { width:100%; border-collapse:collapse; display:block; overflow-x:auto; white-space:nowrap; }
th,td { text-align:left; padding:10px 8px; border-top:1px solid #e2e8f0; font-size: 14px; }
th { color:#536b91; }

.grid { display:grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap:12px; }
.product { background:linear-gradient(135deg, #3b82f6, #4338ca); color:#fff; border:0; border-radius:16px; padding:14px; text-align:left; cursor:pointer; }
.product .icon { width:64px; height:64px; border-radius:10px; display:grid; place-items:center; background:#dbeafe; color:#111; margin-bottom:10px; font-size:32px; overflow:hidden; }
.product .icon img { width:100%; height:100%; object-fit:cover; }
.product b { display:block; margin-bottom:4px; }
.product span { display:block; opacity:.9; margin-bottom:6px; font-size:13px; }
.product strong { font-size:30px; }

.total { display:flex; justify-content:space-between; border-top:1px solid var(--line); border-bottom:1px solid var(--line); padding:12px 0; margin:10px 0; font-size:22px; }

button { border:0; border-radius:8px; background:#e2e8f0; color:var(--text); padding:8px 12px; cursor:pointer; }
button.primary { background:var(--indigo); color:#fff; }
button.primary.lg { width:100%; height:54px; font-size:24px; font-weight:700; }
button.ok { background:#16a34a; color:#fff; }
button.danger { background:#fee2e2; color:#b91c1c; }
button:disabled { opacity:.5; cursor:not-allowed; }

.stats { display:flex; gap:8px; margin:10px 0; }
.stats span { padding:6px 10px; border-radius:6px; }
.stats .warn { background:#fef9c3; }
.stats .indigo { background:#e0e7ff; }
.stats .ok { background:#dcfce7; }

.badge { display:inline-block; padding:4px 8px; border-radius:999px; font-size:12px; font-weight:700; text-transform:capitalize; }
.badge.ok { background:#dcfce7; color:#166534; }
.badge.warn { background:#fef3c7; color:#92400e; }

.row-head { display:flex; justify-content:space-between; align-items:center; margin-bottom:10px; }
.thumb { width:48px; height:48px; border-radius:6px; object-fit:cover; }
.cart-item-wrap { display:inline-flex; align-items:center; gap:8px; max-width:280px; }
.cart-item-wrap span:last-child { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.cart-thumb { width:26px; height:26px; border-radius:6px; object-fit:cover; border:1px solid #dbe4f3; flex-shrink:0; }
.muted { color:var(--muted); }

.form-grid { display:grid; gap:8px; margin-bottom:10px; }
.form-grid.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.form-grid.four { grid-template-columns: 2fr 1fr 1fr auto; }
.form-grid.three { grid-template-columns: 1fr 1fr auto; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid.expense-form { grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto; }

.kpi-grid { display:grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap:8px; }
.kpi-grid .panel { display:flex; flex-direction:column; gap:8px; }
.kpi-grid .panel small { color: var(--muted); font-size: 12px; }
.trend-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); margin-bottom: 8px; }
.trend-card { min-height: 160px; }
.trend-head { display:flex; justify-content:space-between; align-items:center; font-weight:700; }
.trend-badge { font-size:11px; padding:4px 8px; border-radius:999px; font-weight:700; }
.trend-badge.up { background:#dcfce7; color:#166534; }
.trend-badge.down { background:#fee2e2; color:#991b1b; }
.trend-badge.flat { background:#e2e8f0; color:#334155; }
.spark { width:100%; height:70px; margin-top:4px; }
.trend-meta { display:flex; justify-content:space-between; gap:8px; }
.combined-chart-wrap { width: 100%; overflow-x: auto; }
.combined-chart { width: 100%; min-width: 760px; height: 280px; display:block; }
.legend-row { display:flex; flex-wrap:wrap; gap:12px; margin-bottom:10px; }
.legend-item { display:inline-flex; align-items:center; gap:6px; font-size:13px; color:#334155; }
.legend-item i { width:12px; height:12px; border-radius:999px; display:inline-block; }
.unit-grid { margin-top: 10px; grid-template-columns: repeat(4, minmax(0, 1fr)); }

.two-col { display:grid; grid-template-columns:1fr 1fr; gap:10px 14px; }
.line { display:flex; justify-content:space-between; border-bottom:1px solid #e2e8f0; padding-bottom:8px; }

.modal-wrap { position:fixed; inset:0; background:rgba(15,23,42,.45); display:grid; place-items:center; z-index:40; }
.modal { width:100%; max-width:480px; background:#fff; border-radius:14px; padding:16px; }
.actions { display:flex; justify-content:flex-end; gap:8px; margin-top:6px; }

.login-wrap { min-height:100vh; display:grid; place-items:center; padding:20px; }
.login-wrap .panel { width:100%; max-width:430px; }
.stack { display:grid; gap:10px; margin-top:14px; }

@media (max-width: 1400px) {
  .app-shell { max-width: 1240px; }
  .header h1 { font-size: 32px; }
}

@media (max-width: 1200px) {
  .app-shell { max-width: 1080px; }
  .header h1 { font-size: 30px; }
  .panel h2 { font-size: 24px; }
  .panel h3 { font-size: 20px; }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
  .app-shell { max-width: 100%; padding: 0 12px; }
  .header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .header-right { width: 100%; justify-content: space-between; }
  .split { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.six { grid-template-columns: 1fr 1fr; }
  .form-grid.four { grid-template-columns: 1fr 1fr; }
  .form-grid.three { grid-template-columns: 1fr 1fr; }
  .form-grid.expense-form { grid-template-columns: 1fr 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .trend-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .unit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .header { padding: 14px 14px; }
  .header h1 { font-size: 28px; }
  .header-right { flex-wrap: wrap; gap: 8px; }
  .main { padding: 12px; }
  .tabs { overflow-x: auto; white-space: nowrap; padding-bottom: 2px; flex-wrap: nowrap; }
  .tab { padding: 9px 12px; font-size: 14px; white-space: nowrap; }
  .panel { padding: 12px; border-radius: 12px; }
  .panel h2 { font-size: 22px; }
  .panel h3 { font-size: 18px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .product { padding: 12px; }
  .product .icon { width: 56px; height: 56px; font-size: 28px; }
  .product strong { font-size: 24px; }
  .total { font-size: 20px; }
  button.primary.lg { font-size: 20px; }
  .two-col { grid-template-columns: 1fr; }
  .form-grid.three,
  .form-grid.four,
  .form-grid.six,
  .form-grid.two,
  .form-grid.expense-form { grid-template-columns: 1fr; }
  .trend-grid { grid-template-columns: 1fr; }
}

@media (max-width: 540px) {
  .header h1 { font-size: 24px; }
  .header p { font-size: 14px; }
  .user { text-align: left; }
  .api { font-size: 13px; }
  .grid { grid-template-columns: 1fr; }
  .product strong { font-size: 22px; }
  .total { font-size: 18px; }
  button.primary.lg { font-size: 18px; height: 50px; }
  th, td { font-size: 13px; padding: 8px 6px; }
}
