/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #f59e0b;
    --info: #0ea5e9;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Navbar ===== */
.navbar {
    background: var(--gray-900);
    color: white;
    display: flex;
    align-items: center;
    padding: 0 24px;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand a { color: white; font-weight: 700; font-size: 18px; text-decoration: none; }
.nav-links { display: flex; gap: 4px; margin-left: 32px; flex: 1; }
.nav-links a {
    color: var(--gray-300);
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    text-decoration: none;
    transition: background 0.15s;
}
.nav-links a:hover, .nav-links a.active { background: rgba(255,255,255,0.1); color: white; }
.nav-user { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--gray-300); }

/* ===== Container ===== */
.container { max-width: 1400px; margin: 0 auto; padding: 24px; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius);
    border: 1px solid var(--gray-300);
    background: white; color: var(--gray-700);
    font-size: 14px; cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}
.btn:hover { background: var(--gray-50); border-color: var(--gray-500); text-decoration: none; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 4px; font-size: 14px; font-weight: 500; color: var(--gray-700); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 8px 12px;
    border: 1px solid var(--gray-300); border-radius: var(--radius);
    font-size: 14px; background: white;
}
.form-group input:focus, .form-group select:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px; border-radius: var(--radius);
    margin-bottom: 16px; font-size: 14px;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ===== Badges ===== */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 12px;
    font-size: 12px; font-weight: 500;
}
.badge-admin { background: #ede9fe; color: #6d28d9; }
.badge-viewer { background: #e0f2fe; color: #0369a1; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #fee2e2; color: #991b1b; }

/* ===== Tables ===== */
.data-table {
    width: 100%; border-collapse: collapse;
    background: white; border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}
.data-table th {
    background: var(--gray-50); text-align: left;
    padding: 10px 16px; font-size: 13px;
    color: var(--gray-500); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 1px solid var(--gray-200);
}
.data-table td {
    padding: 12px 16px; font-size: 14px;
    border-bottom: 1px solid var(--gray-100);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table .actions { white-space: nowrap; }
.data-table .actions form { margin-right: 4px; }
.text-center { text-align: center; }

/* ===== Page Header ===== */
.page-header, .dashboard-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px;
}
.page-header h1, .dashboard-header h1 { font-size: 24px; font-weight: 700; }
.page-subtitle { color: var(--gray-500); font-size: 14px; margin-top: 4px; }

/* ===== Modals ===== */
.modal {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 200;
    align-items: center; justify-content: center;
}
.modal.show { display: flex; }
.modal-content {
    background: white; border-radius: var(--radius);
    padding: 24px; width: 100%; max-width: 480px;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px;
}
.modal-header h2 { font-size: 18px; }
.modal-close {
    background: none; border: none; font-size: 24px;
    cursor: pointer; color: var(--gray-500);
}

/* ===== System Tabs ===== */
.system-tabs {
    display: flex; gap: 4px; margin-bottom: 24px;
    border-bottom: 2px solid var(--gray-200);
    padding-bottom: 0; overflow-x: auto;
}
.tab-btn {
    padding: 10px 20px; border: none; background: none;
    font-size: 14px; font-weight: 500;
    color: var(--gray-500); cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px; white-space: nowrap;
    transition: all 0.15s;
}
.tab-btn:hover { color: var(--gray-700); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== Dashboard System Sections ===== */
.system-section { margin-bottom: 32px; }
.system-section.hidden { display: none; }
.system-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
}
.system-header h2 { font-size: 20px; font-weight: 600; }
.system-status {
    font-size: 13px; padding: 4px 10px;
    border-radius: 12px; background: var(--gray-100); color: var(--gray-500);
}
.system-status.ok { background: #dcfce7; color: #166534; }
.system-status.error { background: #fef2f2; color: #991b1b; }

/* ===== Widgets Grid ===== */
.widgets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

/* ===== Widget Card ===== */
.widget {
    background: white; border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}
.widget.size-small { grid-column: span 1; }
.widget.size-medium { grid-column: span 1; }
.widget.size-large { grid-column: span 2; }

.widget-header {
    padding: 14px 16px 0;
}
.widget-title {
    font-size: 13px; font-weight: 600;
    color: var(--gray-500); text-transform: uppercase;
    letter-spacing: 0.5px;
}
.widget-description { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

.widget-body { padding: 12px 16px 16px; }

/* ===== Stat Card ===== */
.stat-value { font-size: 32px; font-weight: 700; color: var(--gray-900); line-height: 1.1; }
.stat-unit { font-size: 16px; font-weight: 400; color: var(--gray-500); }
.stat-change { font-size: 13px; margin-top: 6px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }
.stat-change.neutral { color: var(--gray-500); }

/* ===== Chart Widgets ===== */
.chart-container { position: relative; width: 100%; height: 200px; }
.chart-container canvas { width: 100% !important; height: 100% !important; }

/* ===== Table Widget ===== */
.widget-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.widget-table th {
    text-align: left; padding: 6px 8px;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600; color: var(--gray-500);
}
.widget-table td { padding: 6px 8px; border-bottom: 1px solid var(--gray-100); }
.widget-table tr:last-child td { border-bottom: none; }

/* ===== List Widget ===== */
.widget-list { list-style: none; }
.widget-list li {
    padding: 8px 0; border-bottom: 1px solid var(--gray-100);
    font-size: 13px;
}
.widget-list li:last-child { border-bottom: none; }
.widget-list .timestamp { color: var(--gray-500); font-size: 12px; }

/* ===== Progress Widget ===== */
.progress-bar-container {
    background: var(--gray-200); border-radius: 8px;
    height: 12px; overflow: hidden; margin: 12px 0 8px;
}
.progress-bar-fill {
    height: 100%; border-radius: 8px;
    background: var(--primary);
    transition: width 0.6s ease;
}
.progress-label { font-size: 13px; color: var(--gray-500); }
.progress-value { font-size: 28px; font-weight: 700; }

/* ===== Alert Widget ===== */
.widget-alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; }
.widget-alert.severity-info { background: #eff6ff; color: #1e40af; border-left: 4px solid var(--info); }
.widget-alert.severity-warning { background: #fffbeb; color: #92400e; border-left: 4px solid var(--warning); }
.widget-alert.severity-critical { background: #fef2f2; color: #991b1b; border-left: 4px solid var(--danger); }

/* ===== Widget Placeholder ===== */
.widget-placeholder {
    text-align: center; padding: 40px;
    color: var(--gray-500); font-size: 14px;
    grid-column: 1 / -1;
}

/* ===== Systems Grid (Admin) ===== */
.systems-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; }
.system-card {
    background: white; border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 20px;
}
.system-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.system-card-header h3 { font-size: 18px; }
.system-card-actions { margin-top: 12px; }
.system-card-footer {
    margin-top: 16px; padding-top: 12px;
    border-top: 1px solid var(--gray-200);
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.system-card-footer small { color: var(--gray-500); margin-left: auto; }

/* ===== Login Page ===== */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: var(--gray-900);
}
.login-card {
    background: white; border-radius: var(--radius);
    padding: 40px; width: 100%; max-width: 400px;
    box-shadow: var(--shadow-lg);
}
.login-card h1 {
    font-size: 28px; font-weight: 700;
    color: var(--gray-900); text-align: center;
}
.login-subtitle {
    text-align: center; color: var(--gray-500);
    margin-bottom: 24px; font-size: 14px;
}

/* ===== Footer ===== */
.footer {
    text-align: center; padding: 24px;
    color: var(--gray-500); font-size: 13px;
    border-top: 1px solid var(--gray-200);
    margin-top: 40px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .navbar { padding: 0 12px; }
    .nav-links { margin-left: 12px; gap: 0; }
    .container { padding: 16px; }
    .widgets-grid { grid-template-columns: 1fr; }
    .widget.size-large { grid-column: span 1; }
    .systems-grid { grid-template-columns: 1fr; }
    .data-table { font-size: 13px; }
    .data-table th, .data-table td { padding: 8px 10px; }
}
