/* FireAlert — Dashboard CSS */

:root {
    --color-primary:      #E65100;
    --color-primary-dark: #BF360C;
    --color-dark:         #1A1A1A;
    --color-sidebar:      #23262D;
    --color-sidebar-hover:#2D3139;
    --color-light:        #FFF8F5;
    --color-white:        #FFFFFF;
    --color-gray-100:     #F4F4F4;
    --color-gray-200:     #E8E8E4;
    --color-gray-400:     #AAAAAA;
    --color-gray-600:     #666666;
    --color-success:      #27AE60;
    --color-danger:       #DC2626;
    --color-warning:      #F59E0B;
    --color-info:         #2980B9;

    --font-base:    'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --radius:       6px;
    --shadow:       0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg:    0 4px 20px rgba(0,0,0,0.12);
    --sidebar-w:    240px;
    --header-h:     60px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
    font-family: var(--font-base);
    color: var(--color-dark);
    background: var(--color-gray-100);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
ul { list-style: none; }

/* Layout */
.dash-layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--color-sidebar);
    color: rgba(255,255,255,0.85);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    overflow-y: auto;
    z-index: 50;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    text-decoration: none;
}
.sidebar-logo img { width: 34px; height: 34px; }
.sidebar-logo__text { color: var(--color-white); font-weight: 800; font-size: 1.05rem; }
.sidebar-logo__text span { color: var(--color-primary); }
.auth-card .sidebar-logo__text { color: var(--color-dark); }

.sidebar-nav { flex: 1; padding: 0.75rem 0; }
.sidebar-nav__section {
    padding: 0.75rem 1.25rem 0.25rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.35);
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 1.25rem;
    color: rgba(255,255,255,0.75);
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover {
    background: var(--color-sidebar-hover);
    color: var(--color-white);
    text-decoration: none;
}
.sidebar-nav a.active {
    background: rgba(230,81,0,0.15);
    color: var(--color-primary);
    border-left-color: var(--color-primary);
}
.sidebar-nav .icon { font-size: 1rem; width: 18px; text-align: center; }

.sidebar-user {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.07);
    font-size: 0.82rem;
}
.sidebar-user__name { font-weight: 700; color: var(--color-white); margin-bottom: 0.15rem; }
.sidebar-user__role { color: rgba(255,255,255,0.45); font-size: 0.75rem; }
.sidebar-user__links { margin-top: 0.5rem; display: flex; gap: 0.75rem; }
.sidebar-user__links a { color: rgba(255,255,255,0.5); font-size: 0.8rem; }
.sidebar-user__links a:hover { color: var(--color-white); }

/* Main content area */
.dash-main {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.dash-header {
    height: var(--header-h);
    background: var(--color-white);
    border-bottom: 1px solid var(--color-gray-200);
    display: flex;
    align-items: center;
    padding: 0 1.75rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 40;
}
.dash-header__title { font-weight: 700; font-size: 1.05rem; flex: 1; }
.dash-header__actions { display: flex; gap: 0.5rem; align-items: center; }

.dash-content { flex: 1; padding: 1.75rem; }

/* Page header */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.page-header h1 { font-size: 1.5rem; }
.page-header p  { color: var(--color-gray-600); font-size: 0.9rem; margin-top: 0.25rem; }
.page-header__actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

/* Cards */
.card {
    background: var(--color-white);
    border-radius: 8px;
    border: 1px solid var(--color-gray-200);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}
.card-header h2, .card-header h3 { font-size: 1rem; font-weight: 700; }
.card-body  { padding: 1.25rem; }
.card-footer {
    padding: 0.85rem 1.25rem;
    border-top: 1px solid var(--color-gray-200);
    background: var(--color-gray-100);
    font-size: 0.85rem;
}

/* Tables */
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
    background: var(--color-gray-100);
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--color-gray-600);
    padding: 0.7rem 1rem;
    text-align: left;
    white-space: nowrap;
    border-bottom: 2px solid var(--color-gray-200);
}
tbody td {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--color-gray-200);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-gray-100); }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.22rem 0.65rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    white-space: nowrap;
}
.badge-success  { background: #d4edda; color: #155724; }
.badge-danger   { background: #f8d7da; color: #721c24; }
.badge-warning  { background: #fff3cd; color: #856404; }
.badge-info     { background: #d1ecf1; color: #0c5460; }
.badge-secondary{ background: var(--color-gray-200); color: var(--color-gray-600); }
.badge-primary  { background: rgba(230,81,0,0.15); color: var(--color-primary-dark); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    border: none;
    text-align: center;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: var(--color-primary); color: var(--color-white) !important; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-gray-200); color: var(--color-dark) !important; }
.btn-secondary:hover { background: #ddd; }
.btn-danger    { background: var(--color-danger); color: var(--color-white) !important; }
.btn-danger:hover { background: #b91c1c; }
.btn-success   { background: var(--color-success); color: var(--color-white) !important; }
.btn-success:hover { background: #1e8449; }
.btn-outline   { background: transparent; border: 1.5px solid var(--color-gray-400); color: var(--color-dark) !important; }
.btn-outline:hover { border-color: var(--color-dark); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-block { display: flex; width: 100%; justify-content: center; }

/* Tabs */
.tab-nav { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; }
.tab-link {
    display: inline-block;
    padding: 0.5rem 1.2rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-dark) !important;
    text-decoration: none !important;
    background: var(--color-white);
    border: 1.5px solid var(--color-gray-200);
    transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
    white-space: nowrap;
    cursor: pointer;
}
.tab-link:hover { border-color: var(--color-gray-400); background: var(--color-gray-100); }
.tab-link.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-white) !important;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(230,81,0,0.25);
}

/* Forms */
.form-group { margin-bottom: 1.1rem; }
.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
    color: var(--color-dark);
}
.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.55rem 0.8rem;
    border: 1.5px solid var(--color-gray-200);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: var(--font-base);
    color: var(--color-dark);
    background: var(--color-white);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(230,81,0,0.12);
}
.form-group .help-text { font-size: 0.78rem; color: var(--color-gray-600); margin-top: 0.25rem; }
.form-group .error-text { font-size: 0.78rem; color: var(--color-danger); margin-top: 0.25rem; }
.form-group textarea    { resize: vertical; min-height: 100px; }

/* Disabled / readonly form fields */
input:disabled, input[readonly],
textarea:disabled, textarea[readonly],
select:disabled, select[readonly],
.input:disabled, .input[readonly],
button:disabled {
    background: var(--color-gray-100) !important;
    color: var(--color-gray-400) !important;
    border-color: var(--color-gray-200) !important;
    cursor: not-allowed;
    opacity: 0.7;
    box-shadow: none !important;
}
input[type="checkbox"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.form-group--consent { margin-top: 1.4rem; }
.consent-label {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--color-gray-700);
    line-height: 1.5;
    font-weight: normal;
}
.consent-label input[type="checkbox"] {
    margin-top: 0.2rem;
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
    accent-color: var(--color-primary);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-label__link { float: right; font-size: 0.82rem; font-weight: 400; color: var(--color-primary); }

/* Alerts */
.alert {
    padding: 0.8rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.1rem;
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}
.alert-success  { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-danger   { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-warning  { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.alert-info     { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* Toast notifications */
#toast-container {
    position: fixed;
    top: 1.1rem;
    right: 1.1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    min-width: 240px;
    max-width: 360px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.14);
    pointer-events: all;
    opacity: 0;
    transform: translateX(1.5rem);
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.toast-in { opacity: 1; transform: translateX(0); }
.toast.toast-out { opacity: 0; transform: translateX(1.5rem); }
.toast-success { background: #1a7a3c; color: #fff; border: 1px solid #166432; }
.toast-danger { background: #c0392b; color: #fff; border: 1px solid #a93226; }

/* Auth pages */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--color-dark) 0%, #2a1510 100%);
    padding: 2rem 1rem;
}
.auth-card {
    background: var(--color-white);
    border-radius: 12px;
    padding: 2.25rem;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
}
.auth-card--wide { max-width: 520px; }
.auth-card__header { text-align: center; margin-bottom: 1.5rem; }
.auth-card__title { font-size: 1.3rem; margin-bottom: 0.35rem; }
.auth-card__subtitle { color: var(--color-gray-600); font-size: 0.88rem; margin: 0; }
.auth-card__footer {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.85rem;
    color: var(--color-gray-600);
}
.required { color: var(--color-danger); }
.form-hint { font-size: 0.78rem; color: var(--color-gray-600); margin-top: 0.25rem; display: block; }

/* Device detail */
.device-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.device-meta__label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--color-gray-600);
    margin-bottom: 0.15rem;
}
.device-meta__value { font-weight: 600; font-size: 0.95rem; }
#map { height: 300px; border-radius: 8px; }

/* Pagination */
.pagination {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    justify-content: center;
    padding: 1rem 0;
}
.pagination a, .pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    border: 1px solid var(--color-gray-200);
    color: var(--color-dark);
    transition: background 0.15s;
}
.pagination a:hover { background: var(--color-gray-100); text-decoration: none; }
.pagination span.current {
    background: var(--color-primary);
    color: var(--color-white);
    border-color: var(--color-primary);
}

/* Stats row */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--color-white);
    border: 1px solid var(--color-gray-200);
    border-radius: 8px;
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow);
}
.stat-card__label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--color-gray-600);
    margin-bottom: 0.4rem;
}
.stat-card__value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--color-dark);
    line-height: 1;
}

/* Responsive */
/* -------------------------------------------------------
   Page loading overlay
------------------------------------------------------- */
#page-loader {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.7);
    z-index: 9000;
    justify-content: center;
    align-items: center;
}
#page-loader.active { display: flex; }
.loader-spinner {
    width: 40px; height: 40px;
    border: 4px solid var(--color-gray-200);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------------------------------------------
   Tooltip (info) icons
------------------------------------------------------- */
.info-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--color-gray-200);
    color: var(--color-gray-600);
    font-size: 0.65rem;
    font-weight: 700;
    cursor: help;
    margin-left: 4px;
    vertical-align: middle;
    flex-shrink: 0;
}
.info-tooltip .info-tooltip__text {
    display: none;
    position: fixed;
    background: var(--color-dark);
    color: #fff;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 400;
    line-height: 1.45;
    white-space: pre-line;
    width: 280px;
    max-height: 50vh;
    overflow-y: auto;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    text-transform: none;
    letter-spacing: 0;
}

/* -------------------------------------------------------
   Mobile hamburger toggle
------------------------------------------------------- */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 0.25rem;
    flex-shrink: 0;
}
.sidebar-toggle span {
    display: block;
    width: 22px;
    height: 2.5px;
    background: var(--color-dark);
    border-radius: 2px;
    margin: 4px 0;
    transition: transform 0.2s, opacity 0.2s;
}
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 45;
}
.sidebar-close {
    display: none;
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    color: rgba(255,255,255,0.6);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
}
.sidebar-close:hover { color: #fff; }

/* -------------------------------------------------------
   Responsive: Tablet (768px)
------------------------------------------------------- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: block; }
    .sidebar-overlay.active { display: block; }
    .sidebar-close { display: block; }

    .dash-main { margin-left: 0; }
    .dash-header { padding: 0 1rem; }
    .dash-content { padding: 1rem; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .form-row { grid-template-columns: 1fr; }

    /* Bigger touch targets */
    .btn { min-height: 44px; padding: 0.6rem 1.2rem; }
    .btn--small, .btn-sm { min-height: 36px; padding: 0.4rem 0.8rem; }
    .input, .form-group input, .form-group select, .form-group textarea {
        min-height: 44px;
        font-size: 16px; /* prevents iOS zoom on focus */
    }
    .pagination a, .pagination span { width: 40px; height: 40px; }

    /* Stat cards */
    .stats-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; }
    .stat-card { padding: 0.85rem 1rem; }
    .stat-card__value { font-size: 1.4rem; }

    /* Sensor cards */
    .sensor-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)) !important; }

    /* Charts and maps */
    .chart-container { min-height: 220px; }

    /* Tables: smaller font, tighter cells */
    table { font-size: 0.78rem; }
    table th, table td { padding: 0.5rem 0.6rem; }
}

/* -------------------------------------------------------
   Responsive: Mobile (480px)
------------------------------------------------------- */
@media (max-width: 480px) {
    .dash-header { padding: 0 0.75rem; gap: 0.5rem; }
    .dash-header__title { font-size: 0.92rem; }
    .dash-content { padding: 0.75rem; }

    .stats-row { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .stat-card { padding: 0.65rem 0.75rem; }
    .stat-card__label { font-size: 0.65rem; }
    .stat-card__value { font-size: 1.15rem; }
    .stat-24h { font-size: 0.6rem; }

    .sensor-grid { grid-template-columns: 1fr !important; }

    .card-header { padding: 0.75rem 1rem; flex-direction: column; align-items: flex-start !important; gap: 0.5rem; }
    .card-body { padding: 0.75rem 1rem; }

    table { font-size: 0.72rem; }
    table th, table td { padding: 0.35rem 0.45rem; white-space: nowrap; }

    /* Chart toolbar: stack vertically */
    #chartToolbar { flex-direction: column; align-items: stretch !important; gap: 0.35rem; }
    #chartToolbar .btn { width: auto; }

    /* Sensor header */
    .sensor-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .sensor-header h1 { font-size: 1.1rem; }
}

/* -------------------------------------------------------
   Responsive: Small phone (375px)
------------------------------------------------------- */
@media (max-width: 375px) {
    .stats-row { grid-template-columns: 1fr; }
    .stat-card__value { font-size: 1rem; }
    .dash-header__title { font-size: 0.85rem; }
}
