/* --- Modern Admin Theme --- */

/* 1. Variables & Basic Reset */
:root {
    --primary-color: #4A90E2;
    --primary-color-dark: #3a7ac8;
    --secondary-color: #34495e;
    --background-color: #f8f9fa;
    --surface-color: #ffffff;
    --text-color: #343a40;
    --text-muted-color: #6c757d;
    --border-color: #dee2e6;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;

    --sidebar-width: 250px;
    --header-height: 60px;
    --border-radius: 6px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --content-max-width: 1600px; /* Increased max width for content */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    line-height: 1.6;
}

h1, h2, h3 { color: var(--secondary-color); margin-top: 0; font-weight: 600; }
a { color: var(--primary-color); text-decoration: none; transition: color 0.2s ease; }
a:hover { color: var(--primary-color-dark); }

/* 2. Main Layout */
.container { display: flex; }
.sidebar { width: var(--sidebar-width); background-color: var(--secondary-color); color: #ecf0f1; display: flex; flex-direction: column; flex-shrink: 0; height: 100vh; position: fixed; top: 0; left: 0; z-index: 1000; transition: transform 0.3s ease; }
.main-content { 
    flex-grow: 1; 
    padding: 30px; 
    padding-top: var(--header-height); 
    width: 100%; 
    box-sizing: border-box; 
    /* The FIX for large whitespace: Removed auto margins, letting content flow closer to sidebar */
    max-width: var(--content-max-width);
}

/* 3. Sidebar */
.sidebar-header { padding: 20px; text-align: center; font-size: 1.2em; font-weight: bold; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }
.sidebar-nav { overflow-y: auto; }
.sidebar-nav ul { list-style: none; padding: 10px 0; margin: 0; }
.sidebar-nav a { display: flex; align-items: center; gap: 12px; padding: 12px 20px; margin: 4px 10px; color: #ecf0f1; border-radius: var(--border-radius); transition: background-color 0.2s ease, color 0.2s ease; }
.sidebar-nav a svg { width: 20px; height: 20px; flex-shrink: 0; }
.sidebar-nav a:hover { background-color: rgba(255, 255, 255, 0.1); }
.sidebar-nav a.active { background-color: var(--primary-color); color: #fff; font-weight: 500; }
.sidebar-footer { margin-top: auto; padding: 20px; font-size: 0.9em; border-top: 1px solid rgba(255, 255, 255, 0.1); }
.sidebar-footer a { color: var(--danger-color); }

/* 4. Top Header & Menu Toggle (Mobile) */
.top-header { display: none; position: fixed; top: 0; left: 0; width: 100%; height: var(--header-height); background: var(--surface-color); box-shadow: var(--shadow-sm); z-index: 900; align-items: center; box-sizing: border-box; padding: 0 15px; }
.menu-toggle { display: none; background: transparent; border: 1px solid var(--border-color); color: var(--text-muted-color); padding: 6px 10px; border-radius: var(--border-radius); cursor: pointer; font-size: 20px; }
.menu-toggle:hover { background-color: #f1f3f5; }

/* 5. Login Page */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background-color: var(--background-color); }
.login-container { width: 380px; padding: 40px; background: var(--surface-color); border-radius: var(--border-radius); box-shadow: var(--shadow-md); }
.login-container.frosted { background: rgba(255, 255, 255, 0.85); backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, 0.2); }
.login-footer { margin-top: 20px; text-align: center; font-size: 0.8em; color: var(--text-muted-color); }

/* 6. Dashboard (Stat Cards & Device Cards) */
.dashboard-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; margin-bottom: 30px; }
.stat-card { background: var(--surface-color); padding: 20px; border-radius: var(--border-radius); box-shadow: var(--shadow-sm); display: flex; align-items: center; gap: 20px; border-left: 4px solid transparent; transition: box-shadow 0.2s ease, transform 0.2s ease; }
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-card:nth-child(1) { border-left-color: var(--primary-color); }
.stat-card:nth-child(2) { border-left-color: var(--success-color); }
.stat-card:nth-child(3) { border-left-color: var(--danger-color); }
.stat-card:nth-child(4) { border-left-color: var(--warning-color); }
.stat-card-icon { flex-shrink: 0; width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; }
.stat-card-icon svg { width: 24px; height: 24px; }
.icon-devices { background-color: var(--primary-color); }
.icon-online { background-color: var(--success-color); }
.icon-offline { background-color: var(--danger-color); }
.icon-master { background-color: var(--warning-color); }
.stat-card-content h2 { font-size: 0.9em; color: var(--text-muted-color); margin-bottom: 4px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card-content p { font-size: 2em; font-weight: 700; margin: 0; line-height: 1.2; }
.stat-card-content small { font-size: 0.85em; color: var(--text-muted-color); word-break: break-all; }
.device-card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
.device-card { background: var(--surface-color); border-radius: var(--border-radius); box-shadow: var(--shadow-sm); padding: 20px; border-left: 4px solid var(--border-color); display: flex; flex-direction: column; transition: box-shadow 0.2s ease, transform 0.2s ease; }
.device-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.device-card.online { border-left-color: var(--success-color); }
.device-card.offline { border-left-color: var(--danger-color); }
.device-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.device-card-header h3 { margin: 0; font-size: 1.2em; }
.status-indicator { font-size: 0.85em; font-weight: bold; padding: 4px 8px; border-radius: 4px; color: #fff; }
.status-indicator.online { background-color: var(--success-color); }
.status-indicator.offline { background-color: var(--danger-color); }
.device-card-info { list-style: none; padding: 0; margin: 0 0 20px 0; }
.device-card-info li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid #f1f3f5; font-size: 0.9em; }
.device-card-info li:last-child { border-bottom: none; }
.device-card-info li span { color: var(--text-muted-color); }
.device-card-info li strong { color: var(--text-color); text-align: right; word-break: break-all; }
.badge { padding: 4px 10px; font-size: 0.8em; font-weight: 500; border-radius: 12px; color: #fff; }
.badge-master { background-color: var(--warning-color); }
.badge-slave { background-color: var(--primary-color); }
.device-card-actions { margin-top: auto; display: flex; gap: 10px; }

/* 7. Forms & Buttons */
.form-layout { background: var(--surface-color); padding: 30px; border-radius: var(--border-radius); box-shadow: var(--shadow-sm); max-width: 800px; }
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 8px; font-weight: 500; }
input, select, textarea { width: 100%; padding: 12px 15px; border: 1px solid var(--border-color); border-radius: var(--border-radius); box-sizing: border-box; background-color: #fff; transition: border-color 0.2s ease, box-shadow 0.2s ease; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.25); }
textarea { resize: vertical; min-height: 150px; font-family: monospace; }
.button, button { display: inline-block; background-color: var(--primary-color); color: #fff; padding: 12px 24px; border: none; border-radius: var(--border-radius); cursor: pointer; font-size: 1em; font-weight: 500; text-align: center; transition: background-color 0.2s ease, transform 0.1s ease; }
button:hover, .button:hover { background-color: var(--primary-color-dark); }
button:active, .button:active { transform: scale(0.98); }
.button-secondary { background-color: var(--text-muted-color); }
.button-secondary:hover { background-color: #5a6268; }
.button-danger { background-color: var(--danger-color); }
.button-danger:hover { background-color: #c82333; }
.button-small { padding: 6px 12px; font-size: 0.9em; }

/* 8. Tables */
.table-wrapper { width: 100%; overflow-x: auto; background: var(--surface-color); padding: 20px; border-radius: var(--border-radius); box-shadow: var(--shadow-sm); }
.data-table { width: 100%; border-collapse: collapse; margin-top: 0; }
.data-table th, .data-table td { padding: 12px 15px; border-bottom: 1px solid var(--border-color); text-align: left; white-space: nowrap; }
.data-table thead th { font-weight: 600; color: var(--text-muted-color); text-transform: uppercase; font-size: 0.85em; border-bottom-width: 2px; }
.data-table tbody tr:hover { background-color: #f1f3f5; }

/* 9. Responsive Styles */
@media (max-width: 768px) {
    .sidebar { transform: translateX(calc(-1 * var(--sidebar-width))); }
    .sidebar.open { transform: translateX(0); box-shadow: 5px 0 15px rgba(0,0,0,0.2); }
    .main-content { margin-left: 0; max-width: 100%; }
    .top-header, .menu-toggle { display: flex; }
    body { padding-top: var(--header-height); }
    .main-content { padding: 20px 15px; padding-top: 0; }
    .login-container { width: 90%; padding: 20px; }
    .dashboard-stats, .device-card-grid { grid-template-columns: 1fr; }
}
@media (min-width: 769px) {
    .sidebar { transform: translateX(0); position: sticky; }
    .main-content { margin-left: var(--sidebar-width); padding-left: 60px; /* The FIX: increased padding */ }
    body { padding-top: 0; }
}