:root {
    --primary: #C0100D;
    --primary-hover: #a00d0b;
    --primary-soft: rgba(192, 16, 13, 0.08);
    --gray-50: #fafafa;
    --gray-100: #f5f5f5;
    --gray-200: #e5e5e5;
    --gray-300: #d4d4d4;
    --gray-400: #a3a3a3;
    --gray-500: #737373;
    --gray-600: #525252;
    --gray-700: #404040;
    --gray-900: #171717;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --border: #e5e5e5;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font); background: var(--gray-50); color: var(--gray-900); line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* Loading */
.loading-screen {
    position: fixed; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 1rem;
    background: var(--gray-50); z-index: 1000;
}
.spinner-lg {
    width: 40px; height: 40px; border: 3px solid var(--gray-200);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

/* Sidebar */
#sidebar {
    width: 240px; background: #fff; border-right: 1px solid var(--border);
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-header {
    padding: 24px 20px 16px; border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 2px; }
.sidebar-sub { font-size: 0.75rem; color: var(--gray-500); }

.nav-menu { list-style: none; padding: 8px 12px; flex: 1; }
.nav-link {
    display: block; padding: 10px 14px; margin: 2px 0;
    border-radius: var(--radius); font-size: 0.9rem; font-weight: 500;
    color: var(--gray-700); transition: all 0.15s;
}
.nav-link:hover { background: var(--gray-100); color: var(--gray-900); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }

.sidebar-footer {
    padding: 16px 20px; border-top: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 8px;
}
.sidebar-footer #user-display { font-size: 0.875rem; font-weight: 500; }

/* Content */
#content { flex: 1; padding: 0; max-width: calc(100vw - 240px); }
#page-header {
    background: #fff; padding: 20px 32px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    position: sticky; top: 0; z-index: 10;
}
#page-header h1 { font-size: 1.5rem; font-weight: 700; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.muted { color: var(--gray-500); font-size: 0.813rem; }
.page-content { padding: 24px 32px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px; border: 1px solid var(--border); background: #fff;
    border-radius: var(--radius); font-size: 0.875rem; font-weight: 500;
    color: var(--gray-700); transition: all 0.15s;
}
.btn:hover:not(:disabled) { background: var(--gray-100); border-color: var(--gray-300); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 0.813rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }

/* Phase banner */
.phase-banner {
    background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af;
    padding: 14px 18px; border-radius: var(--radius-lg); margin-bottom: 24px;
    font-size: 0.9rem; line-height: 1.5;
}
.phase-banner.phase-pending {
    background: #fef3c7; border-color: #fde68a; color: #854d0e;
}

/* Stats */
.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px; margin-bottom: 32px;
}
.stat-card {
    background: #fff; padding: 20px; border-radius: var(--radius-lg);
    border: 1px solid var(--border); box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 4px;
}
.stat-num { font-size: 2rem; font-weight: 700; color: var(--gray-900); }
.stat-label { font-size: 0.813rem; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.5px; }

/* Section titles */
.section-title { font-size: 1rem; font-weight: 600; margin-bottom: 16px; color: var(--gray-700); }

/* Sites grid */
.sites-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}
.site-card {
    background: #fff; padding: 20px; border-radius: var(--radius-lg);
    border: 1px solid var(--border); box-shadow: var(--shadow);
    transition: all 0.15s;
}
.site-card:hover { box-shadow: var(--shadow-md); }
.site-card.is-master { border-color: var(--primary); border-width: 2px; }
.site-card-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 12px; }
.site-card-name { font-size: 1.1rem; font-weight: 700; }
.site-card-master {
    background: var(--primary); color: #fff; font-size: 0.7rem; font-weight: 600;
    padding: 2px 8px; border-radius: 4px; text-transform: uppercase; letter-spacing: 0.5px;
}
.site-card-meta { font-size: 0.85rem; color: var(--gray-600); }
.site-card-meta div { margin-bottom: 4px; }
.site-card-meta strong { color: var(--gray-900); font-weight: 500; }

/* Status pill */
.status-pill {
    display: inline-block; padding: 2px 10px; border-radius: 999px;
    font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
}
.status-connected, .status-online { background: rgba(22, 163, 74, 0.1); color: var(--success); }
.status-offline, .status-disconnected { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.status-unknown { background: var(--gray-100); color: var(--gray-600); }

/* Tables */
.data-table {
    width: 100%; background: #fff; border: 1px solid var(--border);
    border-radius: var(--radius-lg); overflow: hidden; border-collapse: collapse;
}
.data-table th {
    text-align: left; padding: 12px 16px; font-size: 0.813rem; font-weight: 600;
    color: var(--gray-700); background: var(--gray-50); border-bottom: 1px solid var(--border);
    text-transform: uppercase; letter-spacing: 0.3px;
}
.data-table td {
    padding: 12px 16px; font-size: 0.9rem; border-bottom: 1px solid var(--border);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: var(--gray-50); }

/* Filter bar */
.filter-bar {
    display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.filter-bar label { font-size: 0.875rem; font-weight: 500; color: var(--gray-700); }
.filter-bar select {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    font-family: inherit; font-size: 0.9rem; background: #fff;
}

/* Devices */
.devices-list {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}
.device-card {
    background: #fff; padding: 14px 16px; border-radius: var(--radius);
    border: 1px solid var(--border); display: flex; gap: 12px; align-items: start;
}
.device-icon { font-size: 1.5rem; }
.device-info { flex: 1; min-width: 0; }
.device-info .name { font-weight: 600; font-size: 0.9rem; margin-bottom: 2px; }
.device-info .meta { font-size: 0.78rem; color: var(--gray-500); }
.device-info .mac { font-family: 'JetBrains Mono', Consolas, monospace; font-size: 0.72rem; color: var(--gray-400); }

/* Empty state */
.empty {
    text-align: center; padding: 48px 24px; color: var(--gray-500);
    background: #fff; border-radius: var(--radius-lg); border: 1px dashed var(--border);
}

/* Responsive */
@media (max-width: 768px) {
    #sidebar { width: 60px; }
    .sidebar-header h2, .sidebar-sub, .nav-link { font-size: 0; }
    #content { max-width: calc(100vw - 60px); }
    .page-content { padding: 16px; }
}
