: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;
  --blue: #2563eb;
  --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: 13.5px; }
.hidden { display: none !important; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 13px; border-radius: 8px; border: 1px solid transparent; font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none; transition: all 0.15s; }
.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 10px; font-size: 12.5px; }
.btn-xs { padding: 4px 8px; font-size: 11.5px; }
.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; }
.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: 12px; color: var(--text-muted); }
.brand-badge { width: 46px; height: 46px; border-radius: 12px; background: linear-gradient(135deg, #0f766e, #2563eb); color: #fff; font-weight: 800; font-size: 13px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.brand-badge.sm { width: 36px; height: 36px; border-radius: 10px; font-size: 11px; }
.login-foot { margin-top: 16px; padding-top: 12px; 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; }

/* Forms */
.form-group { margin-bottom: 10px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 13px; outline: none; }
.form-group input:focus, .form-group select:focus { border-color: var(--primary); background: var(--surface); }
.section-lbl { font-size: 12.5px; font-weight: 800; color: var(--primary); text-transform: uppercase; letter-spacing: 0.4px; margin: 12px 0 8px; padding-bottom: 4px; border-bottom: 1px dashed var(--border); }
.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 */
.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: 10px; }
.logo-title { font-weight: 800; font-size: 15px; }
.logo-sub { font-size: 11px; color: var(--text-muted); }
.user-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; margin-bottom: 9px; }
.user-name { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 4px; }
.user-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-chips { display: flex; gap: 5px; margin-bottom: 8px; }
.chip { flex: 1; padding: 5px 6px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); font-size: 11.5px; font-weight: 700; cursor: pointer; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.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: 12.5px; }
.biz-list { flex: 1; overflow-y: auto; padding: 9px; display: flex; flex-direction: column; gap: 7px; }
.sidebar-foot { padding: 9px 12px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; }

.biz-card { border: 1px solid var(--border); border-radius: 10px; padding: 9px 10px; background: var(--surface); cursor: pointer; transition: all 0.14s; }
.biz-card:hover { border-color: var(--accent); background: var(--surface-2); }
.biz-card.active { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary); }
.biz-card-name { font-weight: 700; font-size: 12.8px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.biz-card-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.biz-card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; gap: 6px; flex-wrap: wrap; }

.pill { display: inline-flex; align-items: center; padding: 2px 7px; border-radius: 999px; font-size: 10.5px; 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); }

/* Main Area */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.topbar { padding: 11px 16px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title { font-size: 15.5px; font-weight: 800; }
.topbar-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 7px; 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 14px; 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: 10px 13px; font-size: 13px; font-weight: 600; color: var(--text-muted); cursor: pointer; white-space: nowrap; }
.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: 16px; }
.workspace-loading-overlay { position: absolute; inset: 0; z-index: 15; background: rgba(241,245,249,0.55); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; }
[data-theme="dark"] .workspace-loading-overlay { background: rgba(11,17,32,0.55); }
.workspace-loading-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 11px 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: 14px 16px; margin-bottom: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-title { font-size: 14.5px; font-weight: 800; margin: 0; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 11px; margin-bottom: 14px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 15px; }
.kpi-label { font-size: 11.5px; color: var(--text-muted); font-weight: 600; }
.kpi-val { font-size: 20px; font-weight: 800; margin-top: 5px; }
.kpi-sub { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

.toolbar-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 11px; }
.toolbar-row input, .toolbar-row select { padding: 6px 9px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 12.5px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { padding: 8px 9px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: var(--surface-2); font-weight: 700; font-size: 11.5px; 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, Menlo, monospace; }

/* Attendance Matrix */
.att-table th, .att-table td { padding: 5px 4px; font-size: 11.5px; text-align: center; }
.att-table .sticky-col { position: sticky; left: 0; background: var(--surface); z-index: 2; text-align: left; min-width: 155px; max-width: 180px; border-right: 1px solid var(--border); }
.att-table th.sticky-col { background: var(--surface-2); z-index: 3; }
.att-cell { cursor: pointer; min-width: 30px; font-weight: 700; border-radius: 4px; user-select: none; position: relative; }
.att-cell:hover { outline: 2px solid var(--primary); }
.att-wknd { background: rgba(148,163,184,0.16) !important; }
.sym-X { color: #059669; }
.sym-X2 { color: #0284c7; }
.sym-P, .sym-L, .sym-CT { color: #7c3aed; }
.sym-KL, .sym-V, .sym-TS { color: #dc2626; }
.ot-dot { display: block; font-size: 9px; color: #ea580c; font-weight: 800; line-height: 1; }

/* Payroll inline edit */
.pay-input { width: 88px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font-size: 12px; text-align: right; font-weight: 600; }
.pay-input:focus { border-color: var(--primary); outline: none; }

/* Distribution bars */
.stat-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12.5px; }
.stat-bar-lbl { width: 120px; color: var(--text-muted); font-weight: 600; }
.stat-bar-track { flex: 1; height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.stat-bar-fill { height: 100%; background: linear-gradient(90deg, #0f766e, #14b8a6); border-radius: 99px; }

/* 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: 14px; }
.modal-dialog { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); max-height: 92vh; overflow-y: auto; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; padding-bottom: 9px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 15.5px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }

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

.empty-muted { padding: 20px; text-align: center; color: var(--text-muted); font-size: 12.5px; }
.toast-root { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast-item { background: #0f172a; color: #f8fafc; padding: 10px 15px; 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; }
  .sidebar.open { transform: translateX(0); }
}
@media (max-width: 600px) {
  .kpi-grid, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}
