/* =========================
   Foomus Cloud Styles
   ========================= */

:root {
    --primary: #1E40AF;
    --primary-hover: #1E3A8A;
    --secondary: #0F766E;
    --accent: #14B8A6;

    --success: #059669;
    --warning: #D97706;
    --danger: #B91C1C;

    --bg: #F1F5F9;
    --surface: #FFFFFF;
    --border: #E2E8F0;

    --text: #0F172A;
    --text-light: #64748B;

    --sidebar-bg: var(--secondary);
    --sidebar-text: #CBD5E1;
}

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

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

/* =========================
   Landing Page
   ========================= */

.landing-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
}

.landing-container {
    text-align: center;
    color: white;
    padding: 2rem;
    max-width: 1200px;
}

.landing-header h1 {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.landing-header p {
    font-size: 1.5rem;
    opacity: 0.9;
    margin-bottom: 3rem;
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin: 3rem 0;
}

.feature-card {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 2rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.feature-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.feature-card h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.diagram-section {
    margin: 3rem 0;
}

.diagram-section h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.diagram-section > p {
    font-size: 1.1rem;
    opacity: 0.9;
    margin-bottom: 1.5rem;
}

.diagram-card {
    display: block;
    background: #FFFFFF;
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    max-width: 900px;
    margin: 0 auto;
}

.diagram-card img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 4px;
}

.diagram-caption {
    margin-top: 0.75rem;
    font-size: 0.9rem;
    opacity: 0.75;
}

.cta-section {
    margin-top: 3rem;
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.landing-footer {
    margin-top: 4rem;
    opacity: 0.8;
}

.landing-footer a {
    color: white;
    text-decoration: none;
}

/* =========================
   Login Page
   ========================= */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
}

.login-card {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    font-size: 2rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-light);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text);
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.15);
}

.error-message {
    display: none;
    margin-top: 1rem;
    padding: 0.75rem;
    background: #FEE2E2;
    color: var(--danger);
    border-radius: 6px;
    font-size: 0.9rem;
}

.login-footer {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-light);
}

/* =========================
   Buttons
   ========================= */

.btn-primary {
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: transparent;
    color: white;
    border: 2px solid white;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
}

/* =========================
   Dashboard Layout
   ========================= */

.dashboard {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h2 {
    color: white;
    font-size: 1.5rem;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.nav-item.active {
    background: rgba(20, 184, 166, 0.2);
    color: white;
    border-left: 3px solid var(--accent);
}

.nav-signout {
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(185, 28, 28, 0.9) !important;
}

.nav-signout:hover {
    background: rgba(185, 28, 28, 0.15) !important;
    color: #EF4444 !important;
}

.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.content-header h1 {
    font-size: 2rem;
    margin: 0;
}

.user-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: white;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
}

.user-badge::before {
    content: "👤";
    margin-right: 0.5rem;
}

.header-actions {
    color: var(--text-light);
    font-size: 0.9rem;
}

/* =========================
   Stats Grid
   ========================= */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.stat-icon {
    font-size: 2.5rem;
}

.stat-content {
    flex: 1;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
}

.stat-subtext {
    font-size: 0.85rem;
    color: var(--success);
}

/* =========================
   Sections
   ========================= */

.section {
    background: var(--surface);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.section h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

/* =========================
   Gateways Grid
   ========================= */

.gateways-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.gateway-card {
    background: var(--bg);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid var(--border);
}

.gateway-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.gateway-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-online {
    background: #D1FAE5;
    color: var(--success);
}

.status-offline {
    background: #FEE2E2;
    color: var(--danger);
}

.gateway-info {
    font-size: 0.9rem;
    color: var(--text-light);
}

.gateway-info div {
    margin-bottom: 0.25rem;
}

/* =========================
   Chart
   ========================= */

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.chart-header h2 {
    margin: 0;
}

.time-range-btns {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.time-btn {
    padding: 5px 12px;
    border: 1px solid #444;
    background: #2a2a2a;
    color: #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
}

.time-btn:hover {
    background: #3a3a3a;
    color: #fff;
}

.time-btn.active {
    /* secondary, not accent: accent's contrast with white text is only ~2.5:1,
       well under WCAG AA's 4.5:1 minimum for text on a solid fill */
    background: var(--secondary);
    border-color: var(--secondary);
    color: #fff;
}

.chart-container {
    position: relative;
    height: 300px;
}

.reading-chart-container h3 {
    font-size: 0.95rem;
    color: var(--text-light);
    margin-bottom: 0.5rem;
}

.reading-chart-container .chart-canvas-wrap {
    position: relative;
    height: 280px;
}

.gateway-select {
    padding: 5px 10px;
    border: 1px solid #444;
    background: #2a2a2a;
    color: #ccc;
    border-radius: 4px;
    font-size: 0.85em;
}

.ambient-charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.ph3-chart-row {
    display: grid;
    /* minmax(0, 1fr), not bare 1fr - a grid item's default min-width is
       "auto" (its content's intrinsic size), which lets a canvas's own
       sizing force this item wider than its track and overflow past the
       page's right edge on narrow viewports. Explicit 0 overrides that.
       ambient-charts-grid avoids the same trap via minmax(280px, 1fr). */
    grid-template-columns: minmax(0, 1fr);
}

/* PH3 gets a slightly taller chart than the other ambient readings, since
   it's the safety-critical fumigant gas this whole system exists to
   monitor - no left accent border, that read as a stray line, not an
   intentional design element. */
.ph3-chart-container .chart-canvas-wrap {
    height: 300px;
}

.ambient-chart-container h3 {
    font-size: 0.95rem;
    color: var(--text-light);
    margin-bottom: 0.5rem;
}

.ambient-chart-container .chart-canvas-wrap {
    position: relative;
    height: 220px;
}

/* =========================
   Alerts List
   ========================= */

.alerts-list {
    max-height: 400px;
    overflow-y: auto;
}

.alert-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 1rem;
}

.alert-item:last-child {
    border-bottom: none;
}

.alert-icon {
    font-size: 1.5rem;
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.alert-message {
    font-size: 0.9rem;
    color: var(--text-light);
}

.alert-time {
    font-size: 0.8rem;
    color: var(--text-light);
}

/* =========================
   Utility
   ========================= */

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-light);
}

/* =========================
   Mobile Menu Toggle
   ========================= */

.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 1001;
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.mobile-menu-toggle:active {
    transform: scale(0.95);
}

.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

/* =========================
   Responsive
   ========================= */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
    .sidebar {
        width: 220px;
    }

    .main-content {
        padding: 1.5rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    .content-header h1 {
        font-size: 1.75rem;
    }

    .stat-value {
        font-size: 1.75rem;
    }

    .gateways-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }

    .feature-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .landing-header h1 {
        font-size: 2.5rem;
    }

    .landing-header p {
        font-size: 1.25rem;
    }
}

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: block;
    }

    .mobile-overlay.active {
        display: block;
    }

    .dashboard {
        flex-direction: row;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.mobile-open {
        left: 0;
    }

    .main-content {
        width: 100%;
        padding: 1rem;
        padding-top: 4.5rem;
    }

    .content-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1.5rem;
    }

    .header-left {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        width: 100%;
    }

    .content-header h1 {
        font-size: 1.5rem;
        margin-top: 0.5rem;
    }

    .user-badge {
        font-size: 0.85rem;
        padding: 0.4rem 0.8rem;
    }

    .header-actions {
        font-size: 0.85rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .stat-icon {
        font-size: 2rem;
    }

    .gateways-grid {
        grid-template-columns: 1fr;
    }

    .section {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .section h2 {
        font-size: 1.25rem;
    }

    .chart-container {
        height: 250px;
    }

    /* Landing Page Mobile */
    .landing-container {
        padding: 1rem;
    }

    .landing-header h1 {
        font-size: 2rem;
    }

    .landing-header p {
        font-size: 1.1rem;
        margin-bottom: 2rem;
    }

    .feature-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        margin: 2rem 0;
    }

    .diagram-section {
        margin: 2rem 0;
    }

    .diagram-section h2 {
        font-size: 1.5rem;
    }

    .diagram-section > p {
        font-size: 1rem;
    }

    .diagram-card {
        padding: 0.5rem;
    }

    .feature-card {
        padding: 1.5rem;
    }

    .feature-icon {
        font-size: 2.5rem;
    }

    .feature-card h3 {
        font-size: 1.25rem;
    }

    .cta-section {
        flex-direction: column;
        margin-top: 2rem;
    }

    .btn-large {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
        width: 100%;
    }

    .landing-footer {
        margin-top: 2rem;
        font-size: 0.9rem;
    }

    /* Login Page Mobile */
    .login-container {
        padding: 1rem;
    }

    .login-card {
        padding: 1.5rem;
    }

    .login-header h1 {
        font-size: 1.75rem;
    }
}

/* Small Mobile (max-width: 480px) */
@media (max-width: 480px) {
    .sidebar {
        width: 260px;
    }

    .main-content {
        padding: 0.75rem;
        padding-top: 4rem;
    }

    .content-header h1 {
        font-size: 1.35rem;
    }

    .user-badge {
        font-size: 0.8rem;
        padding: 0.35rem 0.7rem;
    }

    .stat-card {
        flex-direction: column;
        text-align: center;
        gap: 0.75rem;
    }

    .stat-value {
        font-size: 1.35rem;
    }

    .gateway-card {
        padding: 0.875rem;
    }

    .gateway-name {
        font-size: 1rem;
    }

    .status-badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.6rem;
    }

    .chart-container {
        height: 200px;
    }

    .landing-header h1 {
        font-size: 1.75rem;
    }

    .landing-header p {
        font-size: 1rem;
    }

    .feature-icon {
        font-size: 2rem;
    }

    .feature-card h3 {
        font-size: 1.1rem;
    }

    .feature-card p {
        font-size: 0.9rem;
    }
}

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .chart-container {
        height: 200px;
    }

    .main-content {
        padding: 0.75rem;
        padding-top: 3.5rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* =========================
   Button Loading States
   ========================= */

.btn-loading {
    position: relative !important;
    color: transparent !important;
    pointer-events: none !important;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    top: 50%;
    left: 50%;
    margin-top: -9px;
    margin-left: -9px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: btn-spinner 0.6s linear infinite;
    z-index: 2;
}

/* Spinner colors for non-primary buttons */
button.btn-loading:not(.btn-primary):not(.btn-secondary)::after,
a.btn-loading:not(.btn-primary):not(.btn-secondary)::after {
    border-color: rgba(15, 23, 42, 0.1);
    border-top-color: var(--text);
}

@keyframes btn-spinner {
    to {
        transform: rotate(360deg);
    }
}
