:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #0f766e;
  --primary-hover: #0d625b;
  --primary-soft: #f0fdfa;
  --accent: #14b8a6;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.08);
  --radius: 12px;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #263348;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #14b8a6;
  --primary-hover: #0d9488;
  --primary-soft: rgba(20, 184, 166, 0.14);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid transparent; font-size: 13.5px; font-weight: 600; cursor: pointer; text-decoration: none; transition: all 0.15s ease; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-teal-soft { background: var(--primary-soft); border-color: rgba(20,184,166,0.35); color: var(--primary); }
.btn-teal-soft:hover { background: var(--primary); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-xs { padding: 4px 9px; font-size: 12px; }
.btn-block { width: 100%; }
.text-danger { color: var(--danger) !important; }
.icon-btn { background: transparent; border: 1px solid var(--border); border-radius: 8px; width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; color: var(--text); cursor: pointer; font-size: 14px; }
.icon-btn:hover { background: var(--surface-2); }
.theme-toggle-btn { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 12.5px; font-weight: 600; cursor: pointer; }

/* Login */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; position: relative; background: radial-gradient(circle at top right, rgba(20,184,166,0.16), transparent 50%), var(--bg); }
.login-theme-btn { position: absolute; top: 18px; right: 18px; }
.login-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.login-brand h1 { margin: 0; font-size: 19px; }
.login-brand p { margin: 3px 0 0; font-size: 12.5px; color: var(--text-muted); }
.brand-badge { width: 48px; height: 48px; border-radius: 12px; background: linear-gradient(135deg, #0f766e, #14b8a6); color: #fff; font-weight: 800; font-size: 13px; line-height: 1.1; display: flex; align-items: center; justify-content: center; text-align: center; flex-shrink: 0; }
.brand-badge.sm { width: 36px; height: 36px; border-radius: 10px; font-size: 12px; }
.login-foot { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); text-align: center; line-height: 1.5; }
.alert-box { padding: 10px 12px; border-radius: 8px; background: rgba(220,38,38,0.1); border: 1px solid rgba(220,38,38,0.3); color: var(--danger); font-size: 13px; margin-bottom: 14px; }

/* Form */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.form-control, .form-group input, .form-group select, .form-group textarea { width: 100%; padding: 8px 11px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 13.5px; outline: none; }
.form-control:focus, .form-group input:focus, .form-group select:focus { border-color: var(--primary); background: var(--surface); }
.req { color: var(--danger); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.span-2 { grid-column: span 2; }

/* Shell Layout */
.app-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 295px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; z-index: 20; }
.sidebar-top { padding: 14px; border-bottom: 1px solid var(--border); }
.logo-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.logo-title { font-weight: 800; font-size: 15px; }
.logo-sub { font-size: 11.5px; color: var(--text-muted); }
.user-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; margin-bottom: 10px; }
.user-name { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 5px; }
.user-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.pill-teal { background: var(--primary-soft); color: var(--primary); }
.pill-blue { background: rgba(37,99,235,0.12); color: #2563eb; }
.pill-green { background: rgba(5,150,105,0.13); color: #059669; }
.pill-amber { background: rgba(217,119,6,0.15); color: #d97706; }
.pill-red { background: rgba(220,38,38,0.14); color: #dc2626; }
.pill-gray { background: rgba(100,116,139,0.14); color: var(--text-muted); }
.btn-add-shop { margin-bottom: 10px; padding: 9px 12px; }
.search-box input { width: 100%; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 13px; }
.shop-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.sidebar-foot { padding: 10px 14px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; gap: 8px; }

/* Sidebar Shop Card */
.shop-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px 11px; background: var(--surface); cursor: pointer; transition: all 0.14s ease; position: relative; }
.shop-card:hover { border-color: var(--accent); background: var(--surface-2); }
.shop-card.active { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary); }
.shop-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.shop-card-name { font-weight: 700; font-size: 13.5px; line-height: 1.3; }
.shop-card-qr-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 3px 6px; font-size: 11px; font-weight: 700; color: var(--primary); cursor: pointer; flex-shrink: 0; }
.shop-card-qr-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.shop-card-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.shop-card-rev { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; font-size: 12px; font-weight: 700; }
.mini-bar { height: 5px; border-radius: 99px; background: var(--border); overflow: hidden; margin-top: 5px; }
.mini-bar > span { display: block; height: 100%; border-radius: 99px; transition: width 0.25s ease; }
.bar-safe { background: #10b981; }
.bar-warn70 { background: #f59e0b; }
.bar-warn85 { background: #f97316; }
.bar-over100 { background: #ef4444; }

/* Main area */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.topbar { padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title { font-size: 16px; font-weight: 800; }
.topbar-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ctrl-select { padding: 6px 9px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 12.5px; font-weight: 600; }

.tab-bar { display: flex; gap: 4px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab-btn { background: transparent; border: none; border-bottom: 2.5px solid transparent; padding: 11px 14px; font-size: 13px; font-weight: 600; color: var(--text-muted); cursor: pointer; white-space: nowrap; transition: all 0.15s; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.workspace-shell { position: relative; flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.workspace { flex: 1; overflow-y: auto; padding: 18px; }
.workspace-loading-overlay { position: absolute; inset: 0; z-index: 15; background: rgba(241, 245, 249, 0.56); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; }
[data-theme="dark"] .workspace-loading-overlay { background: rgba(11, 17, 32, 0.56); }
.workspace-loading-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 18px; display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow); font-weight: 600; }
.ws-spinner { width: 18px; height: 18px; border: 2.5px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Cards, KPI, Tables */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-title { font-size: 15px; font-weight: 800; margin: 0; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.kpi-val { font-size: 21px; font-weight: 800; margin-top: 6px; }
.kpi-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

.meter-box { padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); margin-bottom: 16px; }
.meter-top { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.meter-bar { height: 14px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 99px; transition: width 0.35s ease; }
.meter-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-top: 7px; flex-wrap: wrap; gap: 8px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 11px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: var(--surface-2); font-weight: 700; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }
.tr { text-align: right; }
.tc { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Bar Chart */
.month-chart { display: grid; grid-template-columns: repeat(12, 1fr); gap: 8px; align-items: end; height: 165px; padding-top: 18px; }
.month-col { display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: 5px; }
.month-bar-wrap { width: 100%; flex: 1; display: flex; align-items: flex-end; justify-content: center; }
.month-bar { width: 72%; max-width: 34px; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, #14b8a6, #0f766e); min-height: 4px; transition: height 0.25s ease; }
.month-lbl { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.month-val { font-size: 10px; color: var(--text-muted); white-space: nowrap; }

/* Empty state */
.empty-box { text-align: center; padding: 42px 20px; color: var(--text-muted); }
.empty-box h3 { color: var(--text); margin: 10px 0 6px; }
.empty-muted { padding: 18px; text-align: center; color: var(--text-muted); font-size: 12.5px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(2, 6, 23, 0.62); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-dialog { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; box-shadow: var(--shadow); max-height: 92vh; overflow-y: auto; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }

.import-banner { background: var(--primary-soft); border: 1px solid rgba(20,184,166,0.3); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; }
.import-banner-head { font-size: 12px; font-weight: 700; color: var(--primary); margin-bottom: 6px; }

/* QR Modal */
.qr-modal-body { text-align: center; }
.qr-shop-badge { font-size: 17px; font-weight: 800; color: var(--primary); }
.qr-shop-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }
.qr-frame { display: inline-block; background: #fff; padding: 14px; border-radius: 14px; border: 2px solid var(--border); margin: 14px 0; box-shadow: 0 4px 16px rgba(0,0,0,0.06); }
.qr-frame img { display: block; width: 240px; height: 240px; }
.qr-guide { font-size: 12.5px; color: var(--text-muted); line-height: 1.5; margin-bottom: 12px; }
.qr-link-box { display: flex; gap: 6px; margin-bottom: 14px; }
.qr-link-box input { flex: 1; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 12px; font-family: monospace; }
.qr-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* Bill items editor */
.bill-items-section { border: 1px solid var(--border); border-radius: 10px; padding: 10px; background: var(--surface-2); margin-bottom: 12px; }
.bill-items-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 13px; }
.bill-item-row { display: grid; grid-template-columns: 2.2fr 0.8fr 0.7fr 1.1fr auto; gap: 6px; margin-bottom: 6px; align-items: center; }
.bill-item-row input { padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 12.5px; }
.bill-total-bar { display: flex; justify-content: space-between; align-items: center; padding-top: 8px; margin-top: 6px; border-top: 1px dashed var(--border); font-size: 14px; }

/* Filters toolbar */
.toolbar-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar-row input, .toolbar-row select { padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 13px; }

/* Toast */
.toast-root { position: fixed; top: 18px; right: 18px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast-item { background: #0f172a; color: #f8fafc; padding: 11px 16px; border-radius: 10px; border-left: 4px solid #14b8a6; font-size: 13px; font-weight: 600; box-shadow: 0 10px 25px rgba(0,0,0,0.28); max-width: 360px; }
.toast-item.error { border-left-color: #ef4444; }

.mobile-only { display: none; }
@media (max-width: 960px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .mobile-only { display: inline-flex; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform 0.22s ease; }
  .sidebar.open { transform: translateX(0); }
}
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .bill-item-row { grid-template-columns: 1fr 1fr; }
}
