/* =============================================================
   PulseWatch - Dark / Glossy Red Theme
   ============================================================= */
:root {
    --bg-0: #0a0a0d;
    --bg-1: #121216;
    --bg-2: #1a1a20;
    --bg-card: #17171d;
    --border: #2a2a32;
    --text-main: #eaeaf0;
    --text-dim: #9a9aa5;
    --red-600: #ff1f3d;
    --red-700: #d10f2a;
    --red-800: #8f0a1e;
    --red-glow: rgba(255, 31, 61, 0.45);
    --green: #24d97a;
    --amber: #ffb020;
    --radius: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', Roboto, -apple-system, sans-serif;
    background:
        radial-gradient(circle at 15% -10%, rgba(255,31,61,0.10), transparent 40%),
        radial-gradient(circle at 100% 0%, rgba(255,31,61,0.06), transparent 35%),
        var(--bg-0);
    color: var(--text-main);
    min-height: 100vh;
}

a { color: var(--red-600); text-decoration: none; }
a:hover { color: #ff5169; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px;
    background: linear-gradient(180deg, var(--bg-1), var(--bg-0));
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    flex-shrink: 0;
}

.brand {
    display: flex; align-items: center; gap: 10px;
    font-weight: 700; font-size: 19px; margin-bottom: 28px; padding: 0 6px;
}
.brand .dot {
    width: 14px; height: 14px; border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #ff8a97, var(--red-600) 55%, var(--red-800));
    box-shadow: 0 0 12px var(--red-glow);
}

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 8px; color: var(--text-dim);
    font-size: 14px; margin-bottom: 4px; cursor: pointer;
}
.nav-item:hover { background: var(--bg-2); color: var(--text-main); }
.nav-item.active {
    background: linear-gradient(90deg, rgba(255,31,61,0.18), rgba(255,31,61,0.02));
    color: #fff; border-left: 3px solid var(--red-600);
}

.main { flex: 1 1 auto; width: calc(100% - 230px); min-width: 0; padding: 26px 32px; max-width: none; }

.topbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 24px;
}
.topbar h1 { font-size: 22px; margin: 0; font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px; border-radius: 8px; border: none;
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: transform .08s ease, box-shadow .15s ease;
}
.btn-primary {
    color: #fff;
    background: linear-gradient(180deg, #ff3b54, var(--red-700));
    box-shadow: 0 4px 14px var(--red-glow), inset 0 1px 0 rgba(255,255,255,0.25);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px var(--red-glow); }
.btn-ghost {
    color: var(--text-main); background: var(--bg-2); border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--red-700); }
.btn-danger { color: #fff; background: linear-gradient(180deg, #ff4d4d, #a30f0f); }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---------- Cards ---------- */
.card {
    background: linear-gradient(180deg, var(--bg-card), var(--bg-1));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 8px 24px rgba(0,0,0,0.35);
}

.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } .main{padding:16px;} .sidebar{display:none;} }

.stat-card .label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.stat-card .value { font-size: 30px; font-weight: 700; margin-top: 6px; }
.stat-card .value.red { color: var(--red-600); text-shadow: 0 0 18px var(--red-glow); }
.stat-card .value.green { color: var(--green); }

/* ---------- Status pills ---------- */
.pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .04em;
}
.pill::before { content:''; width:8px; height:8px; border-radius:50%; }
.pill-up { background: rgba(36,217,122,0.12); color: var(--green); }
.pill-up::before { background: var(--green); box-shadow: 0 0 8px var(--green); }
.pill-down { background: rgba(255,31,61,0.14); color: #ff6b7d; }
.pill-down::before { background: var(--red-600); box-shadow: 0 0 10px var(--red-600); animation: pulse 1.4s infinite; }
.pill-unknown { background: rgba(255,176,32,0.12); color: var(--amber); }
.pill-unknown::before { background: var(--amber); }

@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.35;} }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; font-size: 14px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: rgba(255,255,255,0.02); }

/* ---------- Forms ---------- */
label { display:block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
input, select {
    width: 100%; padding: 10px 12px; border-radius: 8px;
    background: var(--bg-2); border: 1px solid var(--border); color: var(--text-main);
    font-size: 14px; margin-bottom: 16px;
}
input:focus, select:focus { outline: none; border-color: var(--red-600); box-shadow: 0 0 0 3px rgba(255,31,61,0.15); }

/* ---------- Auth pages ---------- */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
}
.auth-card { width: 380px; padding: 34px; text-align: center; }
.auth-card .brand { justify-content: center; margin-bottom: 22px; }
.otp-input { text-align: center; letter-spacing: 8px; font-size: 22px; }

.alert-box { padding: 12px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: rgba(255,31,61,0.12); color: #ff8a97; border: 1px solid rgba(255,31,61,0.35); }
.alert-success { background: rgba(36,217,122,0.1); color: var(--green); border: 1px solid rgba(36,217,122,0.3); }

.badge-role { padding: 2px 8px; border-radius: 6px; background: var(--bg-2); font-size: 11px; color: var(--text-dim); }

.section-title { font-size: 15px; font-weight: 600; margin: 26px 0 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }

footer.appfoot { color: var(--text-dim); font-size: 12px; margin-top: 40px; text-align: center; }

/* PulseWatch final UI refinements */
.settings-stack{display:flex;flex-direction:column;gap:18px;width:100%;max-width:none}.settings-stack>.card{width:100%;min-width:0}.settings-help{margin:-8px 0 16px;font-size:12px}.settings-rule{border:0;border-top:1px solid var(--border);margin:20px 0}.check-row{display:flex;align-items:center;gap:8px;margin-bottom:12px}.check-row input{width:auto;margin:0}.recipient-row{display:grid;grid-template-columns:1fr auto auto;gap:10px;align-items:center;padding:10px 0;border-bottom:1px solid var(--border)}.recipient-row form{display:flex;gap:6px}.inline-add{display:flex;gap:10px;align-items:center;margin-top:16px}.inline-add input{margin:0;flex:1}.user-actions{display:flex;gap:6px;flex-wrap:wrap;align-items:center}.user-actions form{display:flex;gap:6px;flex-wrap:wrap}.user-panel{margin-top:12px;padding:14px;border:1px solid var(--border);border-radius:10px;background:rgba(255,255,255,.02)}.password-reset{display:grid;grid-template-columns:1fr 1fr auto;gap:10px;align-items:end}.password-reset input{margin-bottom:0}.site-picker{margin:10px 0;padding:10px;border:1px solid var(--border);border-radius:8px;max-height:140px;overflow:auto}.site-picker .check-row{font-size:12px}.report-print-heading{display:none}.report-section-head{display:flex;justify-content:space-between;align-items:center;gap:10px}.report-section-head h3{margin:0}.report-time-note{margin-top:10px;color:var(--text-dim);font-size:12px}.chart-wrap{height:360px;margin-top:18px}.availability-chart{width:100%;height:100%;display:block;background:var(--bg-2);border-radius:10px}.chart-axis{stroke:currentColor;opacity:.28}.chart-grid{stroke:currentColor;opacity:.10}.chart-text{fill:var(--text-dim);font-size:12px}.chart-line{fill:none;stroke:var(--red-600);stroke-width:3;stroke-linejoin:round;stroke-linecap:round}.chart-point{fill:var(--red-600);stroke:var(--bg-2);stroke-width:1}.report-empty{min-height:280px;display:flex;align-items:center;justify-content:center;color:var(--text-dim);border:1px dashed var(--border);border-radius:10px;margin-top:18px;text-align:center;padding:20px}.auth-submit{justify-content:center}.report-generate{justify-content:center}
@media(max-width:800px){.password-reset{grid-template-columns:1fr}.recipient-row{grid-template-columns:1fr}.inline-add{flex-direction:column;align-items:stretch}.inline-add input{width:100%}}
@media print{body{background:#fff!important;color:#111!important}.sidebar,.topbar,.report-filters,.report-actions,.btn,.appfoot{display:none!important}.app-shell,.main{display:block!important;max-width:none!important;padding:0!important;margin:0!important}.card{background:#fff!important;color:#111!important;border:1px solid #ccc!important;box-shadow:none!important;break-inside:avoid}.report-print-heading{display:block!important;margin-bottom:16px}.report-print-heading h2{margin:0 0 5px;color:#111}.report-print-heading p{margin:0;color:#555}.report-stats{grid-template-columns:repeat(4,1fr)!important}.chart-wrap{height:360px}.availability-chart{background:#fff!important}.chart-text{fill:#444}.chart-grid,.chart-axis{stroke:#888}.chart-line,.chart-point{stroke:#111;fill:#111}.report-chart-card{break-inside:avoid}.report-chart-card .muted{color:#555}.report-chart-card{color:#111}.report-time-note{display:none}}
.auth-card .btn{justify-content:center}.auth-card form{width:100%}
.site-alert-row{display:grid;grid-template-columns:minmax(220px,1fr) repeat(4,auto) auto;gap:10px;align-items:center;padding:10px 0;border-bottom:1px solid var(--border)}
.site-alert-row label{font-size:12px;white-space:nowrap}.site-alert-row input[type=email]{margin:0}.site-alert-row input[type=checkbox]{width:auto;margin:0}
@media(max-width:900px){.site-alert-row{grid-template-columns:1fr 1fr}.site-alert-row input[type=email]{grid-column:1/-1}}

/* Shared layout repair: keep all application pages full-width and prevent child content from being clipped. */
.app-shell { width: 100%; min-height: 100vh; }
.main { width: calc(100% - 230px); max-width: none !important; min-width: 0; overflow-x: hidden; }
.settings-stack { width: 100% !important; max-width: none !important; }
.settings-stack > .card { width: 100% !important; }
.card { min-width: 0; }
@media (max-width:700px){ .main { width:100%; } }

/* =============================================================
   PulseWatch - Mobile Phone Optimization
   Desktop layout remains unchanged.
   ============================================================= */

@media (max-width: 700px) {
    html, body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
        -webkit-text-size-adjust: 100%;
    }

    body {
        min-width: 0;
    }

    .app-shell {
        display: flex;
        flex-direction: column;
        width: 100%;
        min-height: 100vh;
    }

    /* Mobile navigation: keep the menu usable instead of hiding it. */
    .sidebar {
        position: sticky;
        top: 0;
        z-index: 1000;
        width: 100% !important;
        max-width: 100%;
        height: auto;
        max-height: none;
        padding: 12px 10px 10px;
        display: flex !important;
        flex-wrap: nowrap;
        align-items: center;
        gap: 6px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        background: linear-gradient(180deg, var(--bg-1), var(--bg-0));
    }

    .brand {
        flex: 0 0 auto;
        margin: 0 8px 0 2px;
        padding: 0 6px;
        font-size: 17px;
        white-space: nowrap;
    }

    .brand .dot {
        width: 12px;
        height: 12px;
    }

    .nav-section {
        flex: 0 0 auto;
        margin: 0 !important;
        padding: 0 8px !important;
        font-size: 10px !important;
        white-space: nowrap;
    }

    .nav-item {
        flex: 0 0 auto;
        min-height: 42px;
        margin: 0 !important;
        padding: 10px 13px;
        font-size: 13px;
        white-space: nowrap;
        border-radius: 8px;
    }

    .nav-item.active {
        border-left: 3px solid var(--red-600);
    }

    .main {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        padding: 16px 12px 24px !important;
        overflow-x: hidden;
    }

    .topbar {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 16px;
    }

    .topbar h1 {
        font-size: 21px;
        line-height: 1.25;
        word-break: break-word;
    }

    .page-user,
    .badge-role {
        max-width: 100%;
        white-space: normal !important;
        overflow-wrap: anywhere;
    }

    /* Cards and grids */
    .grid,
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .card {
        width: 100%;
        padding: 15px;
        border-radius: 10px;
        overflow-x: auto;
    }

    .stat-card .value {
        font-size: 27px;
    }

    /* Forms */
    input,
    select,
    textarea,
    button,
    .btn {
        max-width: 100%;
    }

    input,
    select,
    textarea {
        min-height: 44px;
        font-size: 16px; /* prevents iOS Safari zoom */
    }

    .btn {
        min-height: 44px;
        padding: 10px 15px;
    }

    form .btn,
    form button {
        width: 100%;
        justify-content: center;
    }

    .inline-add,
    .recipient-row,
    .site-alert-row,
    .user-actions,
    .user-actions form,
    .password-reset {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100%;
        gap: 9px;
    }

    .inline-add input,
    .recipient-row input,
    .site-alert-row input[type=email] {
        width: 100%;
    }

    .check-row {
        align-items: flex-start;
        line-height: 1.45;
    }

    .check-row input[type=checkbox] {
        flex: 0 0 auto;
        width: 20px;
        height: 20px;
        margin-top: 1px;
    }

    /* Reports */
    .report-filters form,
    .report-filters .grid {
        grid-template-columns: 1fr !important;
    }

    .report-section-head {
        flex-direction: column;
        align-items: flex-start;
    }

    .report-section-head h3 {
        font-size: 18px;
    }

    .chart-wrap {
        height: 280px;
        min-width: 0;
        margin-top: 14px;
    }

    .availability-chart {
        min-width: 0;
        width: 100%;
    }

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

    /* Tables remain readable through horizontal scrolling. */
    .card > table,
    .card > div > table,
    .data-table {
        min-width: 680px;
    }

    th,
    td {
        padding: 10px 11px;
        font-size: 13px;
        white-space: nowrap;
    }

    th {
        font-size: 11px;
    }

    /* Sites / user management rows */
    .site-picker {
        max-height: 220px;
    }

    .user-panel {
        padding: 12px;
    }

    /* Auth / OTP */
    .auth-wrap {
        width: 100%;
        min-height: calc(100vh - 20px);
        padding: 16px 12px;
    }

    .auth-card {
        width: 100% !important;
        max-width: 420px;
        padding: 24px 18px;
    }

    .auth-card .brand {
        justify-content: center;
        margin: 0 auto 18px;
    }

    .otp-input {
        width: 100%;
        font-size: 21px;
        letter-spacing: 7px;
        text-align: center;
    }

    /* Footer */
    footer.appfoot {
        margin-top: 24px;
        padding: 0 6px;
        line-height: 1.5;
    }
}

/* Very small phones */
@media (max-width: 390px) {
    .sidebar {
        padding-left: 7px;
        padding-right: 7px;
    }

    .brand {
        font-size: 16px;
        margin-right: 4px;
    }

    .nav-item {
        padding-left: 11px;
        padding-right: 11px;
        font-size: 12px;
    }

    .main {
        padding-left: 9px !important;
        padding-right: 9px !important;
    }

    .card {
        padding: 13px;
    }

    .stat-card .value {
        font-size: 25px;
    }

    .chart-wrap {
        height: 250px;
    }
}
