/* ============================================================
 * BEEROI — style.css (Fully Responsive Revision)
 * ------------------------------------------------------------
 * Breakpoints (mobile-friendly, content-driven):
 *   >= 1600px  : large desktop / TV (wider layout, bigger base text)
 *   1101-1599  : desktop (full sidebar)
 *   769-1100   : tablet (compact icon sidebar)
 *   <= 768     : phone / small tablet (bottom nav, stacked layout)
 *   <= 480     : small phones
 *   <= 360     : very small phones
 *   landscape + short height : phones sa landscape
 * Uses fluid sizing (clamp, minmax, dvh) para mag-adjust sa kahit anong screen.
 * ============================================================ */

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

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

:root {
    /* Base surfaces */
    --bg-page: #f8fafc;
    --bg-surface: #ffffff;
    --bg-subtle: #f1f5f9;
    --bg-muted: #e2e8f0;

    /* Borders */
    --border: #e2e8f0;
    --border-strong: #cbd5e1;

    /* Text */
    --text-main: #0f172a;
    --text-body: #334155;
    --text-muted: #64748b;
    --text-subtle: #94a3b8;

    /* Accent (muted amber) */
    --accent: #d97706;
    --accent-hover: #b45309;
    --accent-bg: #fef3c7;
    --accent-border: #fcd34d;

    /* Semantic */
    --success: #16a34a;
    --success-bg: #dcfce7;
    --warning: #d97706;
    --warning-bg: #fef3c7;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --info: #2563eb;
    --info-bg: #dbeafe;
    --violet: #7c3aed;
    --violet-bg: #ede9fe;

    /* Legacy aliases (keep JS-referenced names) */
    --bg-gradient: var(--bg-page);
    --glass-bg: var(--bg-surface);
    --glass-border: var(--border);
    --card-bg: var(--bg-surface);
    --input-bg: var(--bg-subtle);
    --border-color: var(--border);

    /* Type */
    --font-main: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-zesty: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", "Roboto Mono", ui-monospace, "SF Mono", Menlo, monospace;

    /* Radius + shadow */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --shadow-sm: 0 1px 2px 0 rgb(15 23 42 / 0.05);
    --shadow-md: 0 1px 3px 0 rgb(15 23 42 / 0.08), 0 1px 2px -1px rgb(15 23 42 / 0.06);
    --shadow-lg: 0 10px 25px -5px rgb(15 23 42 / 0.15), 0 8px 10px -6px rgb(15 23 42 / 0.1);

    /* Focus ring */
    --ring: 0 0 0 3px rgb(217 119 6 / 0.18);

    /* Responsive helpers */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --mobile-nav-h: 60px;
    --page-pad: clamp(14px, 2.4vw, 32px);
}

body {
    font-family: var(--font-main);
    background: var(--bg-page);
    color: var(--text-body);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    position: relative;
    line-height: 1.55;
    font-size: clamp(13px, 0.35vw + 12px, 15px);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.hidden {
    display: none !important;
}

img,
canvas,
video,
svg {
    max-width: 100%;
}

p,
span,
h1,
h2,
h3,
h4,
td,
div,
small,
strong {
    overflow-wrap: break-word;
    word-wrap: break-word;
}

h1,
h2,
h3,
h4 {
    font-family: var(--font-zesty);
    color: var(--text-main);
    letter-spacing: -0.01em;
    line-height: 1.25;
}

/* Tabular numbers everywhere numeric data appears */
#temp-display,
#hum-display,
#weight-display,
.stat-info p,
.conf-text,
.stat-box strong,
#graph-current,
#graph-max,
#graph-min,
#graph-avg,
.score-head strong,
#audio-level-label,
#cam-time,
#audio-ai-top,
#video-ai-top {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

:focus-visible {
    outline: none;
    box-shadow: var(--ring);
    border-radius: var(--radius-sm);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

button,
select,
input {
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

/* ---------- Brand / text accents ---------- */

.zesty-text {
    font-family: var(--font-zesty);
    font-weight: 700;
    color: var(--text-main);
    background: none;
    -webkit-text-fill-color: initial;
    filter: none;
}

.brand {
    font-family: var(--font-zesty);
    font-weight: 700;
    font-size: 18px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 6px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    letter-spacing: -0.01em;
}

/* ---------- Buttons ---------- */

.zesty-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    outline: none;
    background: var(--accent);
    color: #ffffff !important;
    font-family: var(--font-main);
    font-weight: 500;
    font-size: 13px;
    letter-spacing: 0.01em;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background-color 150ms ease, box-shadow 150ms ease;
    text-decoration: none;
    line-height: 1.2;
    text-align: center;
}

.zesty-btn:hover {
    background: var(--accent-hover);
    transform: none;
}

.zesty-btn:active {
    box-shadow: none;
}

.zesty-btn.secondary {
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    color: var(--text-main) !important;
    box-shadow: var(--shadow-sm);
}

.zesty-btn.secondary:hover {
    background: var(--bg-subtle);
    color: var(--text-main) !important;
}

.small-zesty {
    padding: 8px 14px;
    font-size: 12px;
}

.btn-upload {
    border: 1px solid var(--border-strong);
    color: var(--text-main);
    background: var(--bg-surface);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    font-family: var(--font-main);
    transition: background-color 150ms ease;
}

.btn-upload:hover {
    background: var(--bg-subtle);
}

.danger-btn {
    background: var(--danger) !important;
    border-color: var(--danger) !important;
}

.danger-btn:hover {
    background: #b91c1c !important;
}

/* ---------- Layout ---------- */

.dashboard-container {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
    position: relative;
    z-index: 1;
}

.sidebar {
    width: clamp(200px, 17vw, 260px);
    margin: 16px 0 16px 16px;
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    position: sticky;
    top: 16px;
    height: calc(100vh - 32px);
    height: calc(100dvh - 32px);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    overflow-y: auto;
}

.sidebar ul {
    list-style: none;
}

.sidebar li {
    padding: 10px 12px;
    margin: 2px 0;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
    font-weight: 500;
    align-items: center;
    font-size: 13px;
    transition: background-color 150ms ease, color 150ms ease;
    border-left: 2px solid transparent;
    white-space: nowrap;
}

.sidebar li i {
    width: 16px;
    text-align: center;
    font-size: 13px;
}

.sidebar li:hover {
    background: var(--bg-subtle);
    color: var(--text-main);
}

.sidebar li.active {
    background: var(--accent-bg);
    color: var(--accent-hover);
    font-weight: 600;
    border-left-color: var(--accent);
}

.nav-menu {
    flex: 1;
}

.nav-bottom {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: 12px;
}

.logout-btn {
    color: var(--text-muted) !important;
}

.main-content {
    flex: 1;
    padding: 24px var(--page-pad) 32px;
    position: relative;
    max-width: 1440px;
    margin: 0 auto;
    min-width: 0;
    width: 100%;
    align-self: stretch;
    max-height: 100vh;
    max-height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* ---------- Header ---------- */

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding-bottom: 20px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.greeting-box {
    min-width: 0;
    flex: 1 1 auto;
}

.greeting-box h1 {
    font-size: clamp(18px, 1.2vw + 14px, 24px);
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: -0.02em;
    margin-bottom: 2px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 13px;
}

.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
}

.header-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.action-btn {
    display: inline-flex;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 8px;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color 150ms ease, color 150ms ease;
}

.action-btn:hover {
    background: var(--bg-subtle);
    color: var(--text-main);
}

.mobile-menu-btn {
    display: none;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    width: 36px;
    height: 36px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 15px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mobile-menu-dropdown {
    position: fixed;
    top: calc(64px + var(--safe-top));
    right: max(16px, var(--safe-right));
    width: min(240px, calc(100vw - 32px));
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    padding: 6px;
}

.mobile-menu-dropdown button {
    background: none;
    border: none;
    text-align: left;
    padding: 12px;
    font-family: var(--font-main);
    font-weight: 500;
    font-size: 13px;
    color: var(--text-body);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 10px;
}

.mobile-menu-dropdown button:hover {
    background: var(--bg-subtle);
    color: var(--text-main);
}

.mobile-dashboard-dropdown {
    top: calc(64px + var(--safe-top));
    right: max(16px, var(--safe-right));
}

/* ---------- Stat cards ---------- */

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: border-color 150ms ease, box-shadow 150ms ease;
    cursor: pointer;
    overflow: hidden;
    min-width: 0;
}

.stat-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-md);
    transform: none;
}

.icon-box {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #fff;
    flex-shrink: 0;
    background: var(--text-muted);
}

.card-temp .icon-box {
    background: var(--danger);
}

.card-hum .icon-box {
    background: var(--info);
}

.card-weight .icon-box {
    background: var(--accent);
}

.card-audio .icon-box {
    background: var(--violet);
}

.card-cam .icon-box {
    background: #dc2626;
}

.stat-info {
    flex: 1;
    min-width: 0;
}

.stat-info h3 {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.stat-info p {
    margin: 0 0 4px;
    font-size: clamp(17px, 0.8vw + 14px, 24px);
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.1;
    font-family: var(--font-zesty);
    letter-spacing: -0.02em;
}

.badge {
    display: inline-flex;
    align-items: center;
    font-size: 10px;
    font-weight: 600;
    background: var(--bg-subtle);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    max-width: 100%;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.badge-logonly {
    background: var(--violet-bg);
    color: var(--violet);
}

.badge-warning {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-normal {
    background: var(--success-bg);
    color: var(--success);
}

/* ---------- Status summary ---------- */

.status-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.mini-status-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    min-width: 0;
}

.mini-status-header {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mini-status-header i {
    margin-right: 6px;
    font-size: 11px;
    color: var(--text-subtle);
}

.mini-pill {
    background: var(--bg-subtle);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    padding: 3px 8px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-family: var(--font-mono);
    max-width: 55%;
    text-align: right;
}

.mini-status-body strong {
    display: block;
    font-size: 15px;
    color: var(--text-main);
    font-weight: 600;
    margin-bottom: 2px;
    letter-spacing: -0.01em;
}

.mini-status-body small {
    color: var(--text-muted);
    display: block;
    font-size: 12px;
}

/* ---------- Trigger / backend state ---------- */

.trigger-card {
    margin-bottom: 20px;
}

.trigger-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    gap: 12px;
}

.trigger-box {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
}

.trigger-label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 600;
    letter-spacing: 0.05em;
}

.trigger-box strong {
    display: block;
    font-size: 15px;
    color: var(--text-main);
    margin-bottom: 2px;
    font-weight: 600;
}

.trigger-box small {
    color: var(--text-muted);
    font-size: 12px;
}

/* ---------- Chart ---------- */

.chart-wrapper {
    padding: 18px 20px;
    height: clamp(260px, 42vh, 460px);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

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

.chart-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

.canvas-container {
    position: relative;
    height: calc(100% - 36px);
    width: 100%;
    min-width: 0;
}

.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.blink {
    width: 6px;
    height: 6px;
    background: var(--success);
    border-radius: 50%;
    display: inline-block;
    animation: live-pulse 1.6s ease-in-out infinite;
    margin-right: 2px;
}

.blink-red {
    color: var(--danger);
    animation: live-pulse-red 1.6s ease-in-out infinite;
}

@keyframes live-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.35;
    }
}

@keyframes live-pulse-red {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

/* ---------- Logs table ---------- */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

#logs-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    min-width: 640px;
    background: var(--bg-surface);
    font-size: 13px;
}

#logs-table th {
    text-align: left;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 10px 16px;
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

#logs-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-body);
    vertical-align: middle;
}

#logs-table tr:last-child td {
    border-bottom: none;
}

#logs-table tr:hover td {
    background: var(--bg-subtle);
}

#logs-table tr td:first-child {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 12px;
    white-space: nowrap;
    border-right: none;
    border-left: none;
    border-radius: 0;
}

#logs-table tr td:last-child {
    border-radius: 0;
    border-left: none;
    border-right: none;
}

.log-badge {
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: inline-block;
    min-width: 72px;
    text-align: center;
}

.log-badge.badge-normal {
    background: var(--success-bg);
    color: var(--success);
}

.log-badge.badge-warning {
    background: var(--danger-bg);
    color: var(--danger);
}

.log-badge.badge-logonly {
    background: var(--violet-bg);
    color: var(--violet);
}

.conf-text {
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--text-main);
    font-size: 12px;
}

/* ---------- Card wrapper for views ---------- */

.pro-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: clamp(14px, 2vw, 24px);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}

.pro-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.pro-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
}

/* ---------- Research paper ---------- */

.project-card {
    padding: clamp(18px, 3vw, 32px);
    max-width: 1000px;
    margin: 0 auto;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.tag {
    display: inline-block;
    background: var(--bg-subtle);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.project-content h2 {
    font-size: clamp(17px, 1.2vw + 13px, 24px);
    line-height: 1.35;
    letter-spacing: -0.02em;
    color: var(--text-main);
    font-weight: 600;
    margin-bottom: 10px;
}

.project-content h2 em {
    font-style: italic;
    color: var(--text-body);
}

.abstract-box {
    background: var(--bg-subtle);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: clamp(14px, 2vw, 20px);
    color: var(--text-body);
    font-size: 13px;
    line-height: 1.75;
    margin: 20px 0;
}

.abstract-box strong {
    color: var(--text-main);
    font-weight: 600;
}

.project-text {
    margin: 20px 0;
}

.project-text h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.project-text p {
    color: var(--text-body);
    font-size: 13px;
    line-height: 1.7;
}

.project-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 20px;
}

/* ---------- Logs view scroll ---------- */

.scrollable-card {
    max-height: calc(100vh - 140px);
    max-height: calc(100dvh - 140px);
    overflow-y: auto;
}

/* ---------- Settings ---------- */

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 14px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: background-color 150ms ease;
    min-width: 0;
}

.setting-item:hover {
    background: var(--bg-subtle);
}

.setting-info {
    min-width: 0;
}

.setting-info h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 2px;
}

.setting-info p {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.setting-control {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.setting-control select,
.setting-control input[type="range"] {
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-main);
    font-family: var(--font-main);
    font-size: 12px;
    cursor: pointer;
    max-width: 100%;
}

.setting-control select:hover,
.setting-control input[type="range"]:hover {
    border-color: var(--text-muted);
}

.setting-control input[type="range"] {
    accent-color: var(--accent);
}

.range-wrap {
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
}

.range-wrap input[type="range"] {
    width: 120px;
    padding: 0;
    accent-color: var(--accent);
}

.settings-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ---------- Toggle switch ---------- */

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.switch .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: var(--border-strong);
    transition: background-color 150ms ease;
    border-radius: 22px;
}

.switch .slider::before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: #ffffff;
    transition: transform 150ms ease;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.switch input:checked+.slider {
    background-color: var(--accent);
}

.switch input:checked+.slider::before {
    transform: translateX(18px);
}

/* ---------- Reset indicator ---------- */

.reset-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font-main);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.reset-indicator .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    display: inline-block;
}

.reset-idle {
    background: var(--bg-subtle);
    color: var(--text-muted);
}

.reset-ready {
    background: var(--warning-bg);
    color: var(--warning);
}

.reset-latched {
    background: var(--danger-bg);
    color: var(--danger);
}

.reset-working {
    background: var(--success-bg);
    color: var(--success);
}

/* ---------- Decorative layer (hidden) ---------- */

.organic-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
    display: none;
}

.floating-pot,
.dashboard-bee {
    display: none;
}

/* ---------- Generic modal ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(20px, var(--safe-top)) max(20px, var(--safe-right)) max(20px, var(--safe-bottom)) max(20px, var(--safe-left));
    overflow-y: auto;
    animation: fade-in 150ms ease;
}

@keyframes fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    position: relative;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 95vw;
    max-height: 92vh;
    max-height: 92dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
}

.close-modal {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-muted);
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 150ms ease, color 150ms ease;
    font-size: 13px;
}

.close-modal:hover {
    background: var(--bg-subtle);
    color: var(--text-main);
    transform: none;
}

/* ---------- Video modal ---------- */

.video-modal-content {
    width: min(1200px, 95vw);
    height: min(760px, 90vh);
    height: min(760px, 90dvh);
}

.video-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(280px, 28vw, 360px);
    height: 100%;
    min-height: 0;
}

.video-player {
    position: relative;
    background: #0f172a;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}

.video-player img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.cam-overlay {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 52px;
    display: flex;
    justify-content: space-between;
    z-index: 2;
    pointer-events: none;
    color: #fff;
    font-family: var(--font-mono);
    font-size: 11px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.cam-rec {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(220, 38, 38, 0.9);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    letter-spacing: 0.05em;
}

.video-logs {
    background: var(--bg-surface);
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    border-left: 1px solid var(--border);
}

.logs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}

.logs-header h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}

.delete-logs-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    font-family: var(--font-main);
    transition: background-color 150ms ease, color 150ms ease;
}

.delete-logs-btn:hover {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: var(--danger-bg);
}

.ai-side-panel {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ai-panel-block {
    background: var(--bg-subtle);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}

.ai-panel-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 4px;
}

.ai-panel-big {
    font-family: var(--font-zesty);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 2px;
    letter-spacing: -0.01em;
}

.ai-panel-small {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.detection-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 180px;
    overflow-y: auto;
}

.detection-chip {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 12px;
}

.detection-chip .det-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}

.detection-chip .det-main strong {
    color: var(--text-main);
    font-weight: 600;
    font-size: 12px;
}

.detection-chip .det-main span {
    color: var(--accent-hover);
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 11px;
}

.detection-chip small {
    display: block;
    color: var(--text-muted);
    font-size: 10px;
    font-family: var(--font-mono);
}

.empty-detection {
    text-align: center;
    color: var(--text-subtle);
    font-size: 12px;
    padding: 20px 8px;
    font-style: normal;
}

.log-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}

.log-item {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    cursor: pointer;
    transition: background-color 150ms ease, border-color 150ms ease;
    font-size: 12px;
    color: var(--text-body);
}

.log-item:hover {
    background: var(--bg-subtle);
}

.log-item.active {
    border-color: var(--accent);
    background: var(--accent-bg);
    color: var(--accent-hover);
    font-weight: 500;
}

/* ---------- Detailed graph modal ---------- */

.detailed-modal-content {
    position: relative;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: min(900px, 95vw);
    max-height: 90vh;
    max-height: 90dvh;
    overflow: auto;
    border: 1px solid var(--border);
}

.detailed-graph-container {
    padding: clamp(16px, 3vw, 24px);
}

.detailed-graph-container h2 {
    font-size: clamp(16px, 1vw + 12px, 20px);
    font-weight: 600;
    margin-bottom: 16px;
    padding-right: 40px;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

.canvas-container-detailed {
    position: relative;
    height: clamp(220px, 42vh, 400px);
    margin-bottom: 20px;
}

.graph-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 10px;
}

.stat-box {
    background: var(--bg-subtle);
    border-radius: var(--radius-sm);
    padding: 12px;
    text-align: center;
}

.stat-box span {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.stat-box strong {
    display: block;
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
}

/* ---------- Audio modal ---------- */

.audio-modal-content {
    width: min(1200px, 95vw);
    height: min(760px, 90vh);
    height: min(760px, 90dvh);
}

.audio-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(260px, 27vw, 340px);
    height: 100%;
    min-height: 0;
}

.spectrogram-section {
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.spectrogram-section>h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    padding-right: 36px;
}

.spectrogram-display {
    position: relative;
    background: #0f172a;
    border-radius: var(--radius-md);
    height: clamp(160px, 30vh, 280px);
    flex-shrink: 0;
    overflow: hidden;
    border: 1px solid var(--border);
}

.spectrogram-display canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.audio-zoom-toolbar {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--text-muted);
}

.audio-zoom-toolbar label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-weight: 500;
    flex: 1;
    min-width: min(140px, 100%);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.audio-zoom-toolbar input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.audio-score-board {
    background: var(--bg-subtle);
    border-radius: var(--radius-md);
    padding: 12px;
    max-height: 200px;
    overflow-y: auto;
    flex-shrink: 0;
}

.score-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.score-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.score-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-main);
}

.score-head strong {
    font-family: var(--font-mono);
    color: var(--accent-hover);
    font-weight: 600;
}

.score-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.score-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 150ms ease;
}

.audio-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.audio-controls #audio-level-label {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    flex: 1;
    min-width: 0;
    letter-spacing: 0.02em;
}

.audio-logs-section {
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.audio-events-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
}

.audio-event-item {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 12px;
}

.audio-event-item .timestamp {
    font-family: var(--font-mono);
    color: var(--text-subtle);
    font-size: 10px;
    margin-bottom: 4px;
    letter-spacing: 0.02em;
}

.audio-event-item .event-type {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
    font-weight: 500;
}

.stress-indicator {
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stress-normal {
    background: var(--success-bg);
    color: var(--success);
}

.stress-high {
    background: var(--danger-bg);
    color: var(--danger);
}

/* ---------- Alert modal ---------- */

.alert-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(3px);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(20px, var(--safe-top)) max(20px, var(--safe-right)) max(20px, var(--safe-bottom)) max(20px, var(--safe-left));
    overflow-y: auto;
    animation: fade-in 150ms ease;
}

.alert-modal-content {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 32px 28px 24px;
    width: min(480px, 95vw);
    max-height: 100%;
    overflow-y: auto;
    margin: auto;
    text-align: center;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    border-top: 3px solid var(--danger);
    animation: alert-in 200ms ease;
}

@keyframes alert-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.alert-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--danger-bg);
    color: var(--danger);
    font-size: 22px;
    margin-bottom: 14px;
}

.alert-modal-content h2 {
    font-family: var(--font-zesty);
    font-size: 18px;
    color: var(--text-main);
    margin-bottom: 8px;
    text-transform: none;
    letter-spacing: -0.01em;
    font-weight: 600;
}

.alert-modal-content p {
    color: var(--text-body);
    font-size: 14px;
    margin-bottom: 18px;
    line-height: 1.55;
}

.alert-state-strip {
    background: var(--danger-bg);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--danger);
    margin-bottom: 18px;
    text-transform: none;
    letter-spacing: 0.02em;
}

.alert-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.alert-actions button {
    flex: 1;
    min-width: 110px;
    padding: 9px 14px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    font-family: var(--font-main);
    font-weight: 500;
    font-size: 12px;
    text-transform: none;
    letter-spacing: 0.01em;
    transition: background-color 150ms ease, border-color 150ms ease;
}

.alert-actions button:hover {
    transform: none;
}

.alert-close-btn {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.alert-close-btn:hover {
    background: var(--accent-hover);
}

.alert-view-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-strong) !important;
    color: var(--text-main);
}

.alert-view-btn:hover {
    background: var(--bg-subtle);
}

.alert-reset-btn {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.alert-reset-btn:hover {
    background: #b91c1c;
}

#alert-notification {
    position: fixed;
    bottom: max(20px, var(--safe-bottom));
    right: max(20px, var(--safe-right));
    background: var(--bg-surface);
    color: var(--text-main);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-weight: 500;
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--danger);
    z-index: 9500;
    max-width: min(360px, calc(100vw - 40px));
    animation: slide-in 200ms ease;
}

@keyframes slide-in {
    from {
        transform: translateX(20px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ---------- Mobile nav ---------- */

.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.06);
    z-index: 3000;
    padding: 6px max(0px, var(--safe-right)) max(6px, var(--safe-bottom)) max(0px, var(--safe-left));
    justify-content: space-around;
}

.mobile-nav div {
    flex: 1;
    text-align: center;
    padding: 12px;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    transition: color 150ms ease;
    position: relative;
    min-height: 44px;
}

.mobile-nav div.active {
    color: var(--accent);
}

.mobile-nav div.active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 2px;
    background: var(--accent);
    border-radius: 2px;
}

/* ---------- Scrollbars ---------- */

.main-content::-webkit-scrollbar,
.log-list::-webkit-scrollbar,
.audio-events-list::-webkit-scrollbar,
.detection-list::-webkit-scrollbar,
.spectrogram-section::-webkit-scrollbar,
.score-list::-webkit-scrollbar,
.scrollable-card::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.main-content::-webkit-scrollbar-track,
.log-list::-webkit-scrollbar-track,
.audio-events-list::-webkit-scrollbar-track,
.detection-list::-webkit-scrollbar-track,
.spectrogram-section::-webkit-scrollbar-track,
.score-list::-webkit-scrollbar-track,
.scrollable-card::-webkit-scrollbar-track {
    background: transparent;
}

.main-content::-webkit-scrollbar-thumb,
.log-list::-webkit-scrollbar-thumb,
.audio-events-list::-webkit-scrollbar-thumb,
.detection-list::-webkit-scrollbar-thumb,
.spectrogram-section::-webkit-scrollbar-thumb,
.score-list::-webkit-scrollbar-thumb,
.scrollable-card::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}

.main-content::-webkit-scrollbar-thumb:hover,
.log-list::-webkit-scrollbar-thumb:hover,
.audio-events-list::-webkit-scrollbar-thumb:hover,
.detection-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-subtle);
}

/* ============================================================
 * RESPONSIVE BREAKPOINTS
 * ============================================================ */

/* ---------- Large desktop / TV (>= 1600px) ---------- */
@media (min-width: 1600px) {
    .main-content {
        max-width: 1680px;
    }

    .sidebar {
        width: 270px;
    }

    .cards-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

/* ---------- Tablet / small laptop (<= 1100px): compact icon sidebar ---------- */
@media (max-width: 1100px) and (min-width: 769px) {
    .sidebar {
        width: 68px;
        padding: 16px 8px;
        align-items: stretch;
    }

    /* hide text labels, keep icons */
    .sidebar li,
    .brand {
        font-size: 0;
        justify-content: center;
        gap: 0;
        border-left: none;
    }

    .sidebar li {
        padding: 12px 0;
    }

    .sidebar li i {
        width: auto;
        font-size: 16px;
    }

    .sidebar li.active {
        border-left: none;
        box-shadow: inset 0 0 0 1px var(--accent-border);
    }

    .brand {
        padding: 4px 0 16px;
    }

    .brand i {
        font-size: 20px;
    }
}

/* ---------- Modals stack (<= 1024px) ---------- */
@media (max-width: 1024px) {

    .video-modal-content,
    .audio-modal-content {
        height: min(900px, 94vh);
        height: min(900px, 94dvh);
        overflow-y: auto;
    }

    .video-layout,
    .audio-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        height: auto;
        min-height: 100%;
    }

    .video-player {
        aspect-ratio: 16 / 9;
        width: 100%;
    }

    .video-logs,
    .audio-logs-section {
        border-left: none;
        border-top: 1px solid var(--border);
        max-height: none;
    }

    .log-list,
    .audio-events-list {
        max-height: 260px;
    }

    .spectrogram-section {
        overflow-y: visible;
    }
}

/* ---------- Phones / small tablets (<= 768px) ---------- */
@media (max-width: 768px) {
    :root {
        --page-pad: 14px;
    }

    body {
        overflow: auto;
        height: auto;
        min-height: 100dvh;
    }

    .dashboard-container {
        flex-direction: column;
    }

    .sidebar {
        display: none;
    }

    html,
    body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    .dashboard-container {
        width: 100%;
        max-width: 100%;
        align-items: stretch;
    }

    /* FIX: "margin: 0 auto" sa flex-column ang nagpapalapad ng page lampas sa screen */
    .main-content {
        margin: 0;
        align-self: stretch;
        width: 100%;
        min-width: 0;
        max-width: 100%;
        padding: calc(14px + var(--safe-top)) max(var(--page-pad), var(--safe-right)) calc(var(--mobile-nav-h) + 32px + var(--safe-bottom)) max(var(--page-pad), var(--safe-left));
        max-height: none;
        overflow-x: hidden;
        overflow-y: visible;
    }

    .view-section,
    .pro-card,
    .project-card,
    header {
        min-width: 0;
        max-width: 100%;
    }

    /* Table scrolls sideways INSIDE the card, hindi na lalabas sa screen */
    .table-responsive {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #logs-table {
        min-width: 560px;
    }

    .scrollable-card h3 {
        margin-bottom: 12px;
    }

    header {
        flex-wrap: nowrap;
        gap: 10px;
        padding-bottom: 14px;
        margin-bottom: 16px;
    }

    .greeting-box h1 {
        font-size: 18px;
    }

    .subtitle {
        font-size: 12px;
    }

    .desktop-actions {
        display: none;
    }

    .mobile-menu-btn {
        display: inline-flex;
    }

    .cards-grid {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
        gap: 10px;
    }

    .stat-card {
        padding: 14px;
        gap: 10px;
    }

    .icon-box {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .status-summary-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .chart-wrapper {
        height: clamp(230px, 38vh, 320px);
        padding: 14px;
    }

    .mobile-nav {
        display: flex;
    }

    /* Modals become full-screen sheets */
    .modal-overlay {
        padding: 0;
        align-items: stretch;
    }

    .video-modal-content,
    .audio-modal-content,
    .detailed-modal-content {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        max-width: 100vw;
        border-radius: 0;
        border: none;
    }

    .close-modal {
        top: calc(10px + var(--safe-top));
        right: max(10px, var(--safe-right));
        width: 38px;
        height: 38px;
        background: rgba(255, 255, 255, 0.92);
    }

    .cam-overlay {
        top: calc(14px + var(--safe-top));
        right: 60px;
    }

    .spectrogram-section {
        padding: calc(14px + var(--safe-top)) 14px 14px;
    }

    .detailed-graph-container {
        padding-top: calc(16px + var(--safe-top));
        padding-bottom: calc(16px + var(--safe-bottom));
    }

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

    .alert-modal-content {
        padding: 24px 18px;
    }

    .alert-modal-content h2 {
        font-size: 16px;
    }

    .alert-actions button {
        min-width: 100%;
        padding: 12px 14px;
    }

    #alert-notification {
        right: max(12px, var(--safe-right));
        left: max(12px, var(--safe-left));
        max-width: none;
        bottom: calc(var(--mobile-nav-h) + 12px + var(--safe-bottom));
    }

    /* Settings: stack label above control */
    .setting-item {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .setting-control {
        justify-content: space-between;
        width: 100%;
    }

    .setting-control select {
        width: 100%;
    }

    .setting-control input[type="range"],
    .range-wrap input[type="range"] {
        flex: 1;
        width: 100%;
    }

    /* toggle rows: keep label left, switch right */
    .setting-item:has(.switch) {
        flex-direction: row;
        align-items: center;
    }

    .setting-item:has(.switch) .setting-control {
        width: auto;
    }

    .settings-actions {
        justify-content: stretch;
    }

    .settings-actions .btn-upload {
        flex: 1 1 100%;
        padding: 12px;
    }

    .project-actions .zesty-btn {
        flex: 1 1 100%;
    }

    .scrollable-card {
        max-height: none;
        overflow-y: visible;
    }

    .audio-controls .zesty-btn {
        flex: 1 1 100%;
    }

    .audio-controls #audio-level-label {
        flex: 1 1 100%;
    }
}

/* ---------- Small phones (<= 480px) ---------- */
@media (max-width: 480px) {
    .cards-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    /* 5th card (odd one) spans full width */
    .cards-grid .stat-card:last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-info p {
        font-size: 16px;
    }

    .zesty-btn {
        padding: 10px 14px;
        font-size: 12px;
    }

    .small-zesty {
        padding: 8px 10px;
        font-size: 11px;
    }

    .project-card {
        padding: 16px;
    }

    .abstract-box {
        font-size: 12.5px;
        line-height: 1.7;
    }

    #logs-table th,
    #logs-table td {
        padding: 10px 12px;
    }

    .mini-pill {
        max-width: 60%;
    }
}

/* ---------- Very small phones (<= 360px) ---------- */
@media (max-width: 360px) {
    .cards-grid {
        grid-template-columns: 1fr;
    }

    .stat-info h3 {
        font-size: 10px;
    }

    .greeting-box h1 {
        font-size: 16px;
    }

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

/* ---------- Phones in landscape / very short screens ---------- */
@media (max-height: 520px) and (orientation: landscape) {
    .modal-overlay {
        padding: 0;
    }

    .video-modal-content,
    .audio-modal-content,
    .detailed-modal-content {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        max-width: 100vw;
        border-radius: 0;
        border: none;
    }

    /* keep side-by-side layout in landscape if there is room width-wise */
    .video-layout {
        grid-template-columns: minmax(0, 1fr) 260px;
        grid-template-rows: none;
        height: 100%;
        min-height: 0;
    }

    .video-player {
        aspect-ratio: auto;
    }

    .video-logs {
        border-left: 1px solid var(--border);
        border-top: none;
        overflow-y: auto;
    }

    .audio-layout {
        grid-template-columns: minmax(0, 1fr) 240px;
        grid-template-rows: none;
        height: 100%;
        min-height: 0;
    }

    .audio-logs-section {
        border-left: 1px solid var(--border);
        border-top: none;
    }

    .spectrogram-section {
        overflow-y: auto;
        padding-top: 14px;
    }

    .spectrogram-display {
        height: 140px;
    }

    .canvas-container-detailed {
        height: 180px;
    }

    .alert-modal-content {
        padding: 16px;
    }

    .alert-icon {
        width: 40px;
        height: 40px;
        font-size: 16px;
        margin-bottom: 8px;
    }
}

/* ---------- Touch devices: bigger tap targets ---------- */
@media (pointer: coarse) {

    .action-btn,
    .mobile-menu-btn {
        width: 44px;
        height: 44px;
    }

    .close-modal {
        width: 40px;
        height: 40px;
    }

    .delete-logs-btn {
        padding: 8px 12px;
    }

    .switch {
        width: 46px;
        height: 26px;
    }

    .switch .slider::before {
        height: 20px;
        width: 20px;
    }

    .switch input:checked+.slider::before {
        transform: translateX(20px);
    }

    .log-item {
        padding: 12px;
    }
}

/* ---------- Respect reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================================
 * ACTIVITY LOG — phone layout (walang left-right scroll)
 * Ang bawat row ay nagiging maliit na card:
 *   [ Timestamp .................. Status ]
 *   [ Event description ...................]
 *   [ T/H/W Sensors ............ ML Conf. ]
 * ============================================================ */
@media (max-width: 768px) {
    .table-responsive {
        overflow: visible;
        border: none;
        border-radius: 0;
    }

    #logs-table {
        display: block;
        width: 100%;
        min-width: 0;
        background: transparent;
    }

    #logs-table thead {
        display: none;
    }

    #logs-table tbody {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    #logs-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "time status"
            "event event"
            "sensors conf";
        gap: 8px 12px;
        padding: 12px 14px;
        background: var(--bg-surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-sm);
    }

    #logs-table tr:hover td {
        background: transparent;
    }

    #logs-table tr td {
        display: block;
        padding: 0;
        border: none;
        min-width: 0;
        background: transparent;
    }

    #logs-table tr td:nth-child(1) {
        grid-area: time;
        align-self: center;
        font-size: 12px;
    }

    #logs-table tr td:nth-child(2) {
        grid-area: event;
        color: var(--text-main);
        font-size: 13px;
        line-height: 1.45;
    }

    #logs-table tr td:nth-child(3),
    #logs-table tr td:nth-child(4) {
        padding-top: 8px;
        border-top: 1px solid var(--border);
        font-size: 12px;
        font-family: var(--font-mono);
        color: var(--text-main);
    }

    #logs-table tr td:nth-child(3) {
        grid-area: sensors;
    }

    #logs-table tr td:nth-child(4) {
        grid-area: conf;
        text-align: right;
    }

    #logs-table tr td:nth-child(5) {
        grid-area: status;
        justify-self: end;
        align-self: center;
    }

    #logs-table tr td:nth-child(3)::before,
    #logs-table tr td:nth-child(4)::before {
        display: block;
        margin-bottom: 2px;
        font-family: var(--font-main);
        font-size: 10px;
        font-weight: 600;
        letter-spacing: 0.05em;
        text-transform: uppercase;
        color: var(--text-muted);
    }

    #logs-table tr td:nth-child(3)::before {
        content: "Temp / Hum / Weight";
    }

    #logs-table tr td:nth-child(4)::before {
        content: "ML Conf.";
    }

    /* "No data" / single-cell rows */
    #logs-table tr td:only-child {
        grid-area: auto;
        grid-column: 1 / -1;
        padding: 12px 0;
        text-align: center;
        border-top: none;
        font-family: var(--font-main);
    }

    #logs-table tr td:only-child::before {
        content: none;
    }
}