*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-muted: #666;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --online: #16a34a;
  --offline: #dc2626;
  --warning-color: #d97706;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* Auth */
#login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: 360px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card .subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.login-card .error-msg { background: #fee2e2; border: 1px solid #fca5a5; color: var(--danger); padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; font-size: 13px; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 4px; font-size: 13px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; background: var(--surface); color: var(--text); }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.form-group textarea { resize: vertical; min-height: 80px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: none; cursor: pointer; font-size: 13px; font-weight: 500; transition: background .15s; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* Shell */
#app-shell { display: flex; flex-direction: column; min-height: 100vh; }

header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 20px; height: 52px; display: flex; align-items: center; justify-content: space-between; }
.header-brand { font-size: 16px; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 12px; }
.user-pill { display: flex; align-items: center; gap: 6px; background: var(--bg); padding: 4px 10px; border-radius: 20px; font-size: 13px; }
.role-badge { font-size: 11px; font-weight: 600; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; background: #dbeafe; color: #1e40af; }

/* Customer tabs */
#customer-tabs { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 20px; display: flex; gap: 2px; overflow-x: auto; }
.customer-tab { padding: 10px 16px; cursor: pointer; border-bottom: 2px solid transparent; font-size: 13px; white-space: nowrap; color: var(--text-muted); transition: color .15s, border-color .15s; }
.customer-tab:hover { color: var(--text); }
.customer-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.customer-tab.all-tab { font-style: italic; }
.customer-tab .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

/* Nav */
nav { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 20px; display: flex; gap: 2px; }
.nav-link { padding: 10px 14px; cursor: pointer; font-size: 13px; color: var(--text-muted); border-bottom: 2px solid transparent; }
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

/* Main content */
main { flex: 1; padding: 24px 20px; max-width: 1200px; width: 100%; margin: 0 auto; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; }

/* Stat grid */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat-card.online .value { color: var(--online); }
.stat-card.offline .value { color: var(--offline); }
.stat-card.warning-stat .value { color: var(--warning-color); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border); font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.badge-online { background: #dcfce7; color: var(--online); }
.badge-offline { background: #fee2e2; color: var(--offline); }
.badge-warning { background: #fef3c7; color: var(--warning-color); }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-admin { background: #f3e8ff; color: #7c3aed; }
.badge-owner { background: #dbeafe; color: #1d4ed8; }
.badge-technician { background: #dcfce7; color: #15803d; }
.badge-viewer { background: #f3f4f6; color: #6b7280; }

/* Search / filter bar */
.filter-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; background: var(--surface); }
.filter-bar input { min-width: 200px; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 24px; width: min(480px, 95vw); box-shadow: 0 8px 32px rgba(0,0,0,.2); max-height: 90vh; overflow-y: auto; }
.modal h2 { font-size: 16px; margin-bottom: 16px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* Toast */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 16px; border-radius: 6px; font-size: 13px; font-weight: 500; box-shadow: 0 4px 12px rgba(0,0,0,.15); animation: slideIn .2s ease; }
.toast-success { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.toast-error { background: #fee2e2; color: #dc2626; border: 1px solid #fca5a5; }
.toast-info { background: #dbeafe; color: #1d4ed8; border: 1px solid #93c5fd; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Sync meta footer */
#sync-footer { background: var(--surface); border-top: 1px solid var(--border); padding: 8px 20px; font-size: 12px; color: var(--text-muted); display: flex; gap: 16px; flex-wrap: wrap; }
#sync-footer .sync-item { display: flex; align-items: center; gap: 4px; }
#sync-footer .sync-item .err { color: var(--warning-color); }

/* Settings sections */
.settings-section { margin-bottom: 24px; }
.settings-section .section-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }

/* Empty state */
.empty { text-align: center; padding: 40px; color: var(--text-muted); font-size: 13px; }

/* Color swatch */
.color-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--border); vertical-align: middle; margin-right: 4px; }

/* Pagination */
.pagination { display: flex; gap: 8px; align-items: center; margin-top: 12px; font-size: 13px; }

/* Page title row */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h2 { font-size: 18px; font-weight: 600; }

/* Detail drawer */
.detail-row { display: flex; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.detail-row .key { color: var(--text-muted); min-width: 130px; }

/* Responsive */
@media (max-width: 600px) {
  main { padding: 16px 12px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
