:root {
    --bg-page: #f3f5fa;
    --bg-card: #ffffff;
    --bg-subtle: #eef2ff;
    --bg-track: #e6ebf5;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-soft: #e2e8f0;
    --nav-bg: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
    --hero-awake-bg: linear-gradient(135deg, #ffffff 0%, #eef2ff 100%);
    --hero-sleep-bg: linear-gradient(135deg, #1e1b4b 0%, #3730a3 100%);
    --hero-nursing-bg: linear-gradient(135deg, #831843 0%, #be185d 100%);
    --night-color: #4338ca;
    --night-soft: #e0e7ff;
    --night-text: #312e81;
    --nap-color: #0284c7;
    --nap-soft: #e0f2fe;
    --nap-text: #075985;
    --nursing-color: #db2777;
    --nursing-soft: #fce7f3;
    --nursing-text: #9d174d;
    --shadow-card: 0 2px 10px rgba(15, 23, 42, 0.05);
}

[data-theme="dark"] {
    --bg-page: #090e1a;
    --bg-card: #111827;
    --bg-subtle: #1b2438;
    --bg-track: #1e293b;
    --text-main: #d6deeb;
    --text-muted: #94a3b8;
    --border-soft: #233047;
    --nav-bg: linear-gradient(135deg, #0b1020 0%, #171e38 100%);
    --hero-awake-bg: linear-gradient(135deg, #111827 0%, #182238 100%);
    --hero-sleep-bg: linear-gradient(135deg, #17153b 0%, #2a2460 100%);
    --hero-nursing-bg: linear-gradient(135deg, #4c0519 0%, #831843 100%);
    --night-color: #6366f1;
    --night-soft: rgba(99, 102, 241, 0.22);
    --night-text: #c7d2fe;
    --nap-color: #38bdf8;
    --nap-soft: rgba(56, 189, 248, 0.2);
    --nap-text: #bae6fd;
    --nursing-color: #f472b6;
    --nursing-soft: rgba(244, 114, 182, 0.18);
    --nursing-text: #fbcfe8;
    --shadow-card: 0 4px 14px rgba(0, 0, 0, 0.35);
}

body {
    background-color: var(--bg-page);
    color: var(--text-main);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    padding-bottom: 76px;
}

@media (min-width: 992px) {
    body {
        padding-bottom: 0;
    }
}

.navbar-sleep {
    background: var(--nav-bg);
}

.card-sleep {
    background-color: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border-soft);
    border-radius: 1rem;
    box-shadow: var(--shadow-card);
}

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

.bg-subtle-sleep {
    background-color: var(--bg-subtle);
}

.hero-awake {
    background: var(--hero-awake-bg);
    border: 1px solid var(--border-soft);
    border-radius: 1.25rem;
    box-shadow: var(--shadow-card);
}

.hero-sleeping {
    background: var(--hero-sleep-bg);
    color: #eef2ff;
    border: 1px solid rgba(165, 180, 252, 0.25);
    border-radius: 1.25rem;
    box-shadow: 0 8px 24px rgba(30, 27, 75, 0.35);
}

.hero-nursing-active {
    background: var(--hero-nursing-bg);
    color: #fdf2f8;
    border: 1px solid rgba(249, 168, 212, 0.28);
    border-radius: 1.25rem;
    box-shadow: 0 8px 24px rgba(131, 24, 67, 0.28);
}

.timer-digits {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    font-size: clamp(2.1rem, 7vw, 3rem);
    font-weight: 700;
    line-height: 1.1;
}

.timer-digits-md {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    font-size: clamp(1.75rem, 6vw, 2.4rem);
    font-weight: 700;
    line-height: 1.1;
}

.btn-tap-main {
    min-height: 56px;
    border-radius: 0.9rem;
    font-size: 1.05rem;
    font-weight: 600;
}

.btn-sleep-start {
    background: linear-gradient(135deg, #4338ca 0%, #4f46e5 100%);
    border: none;
    color: #ffffff;
}

.btn-sleep-start:hover,
.btn-sleep-start:focus {
    background: linear-gradient(135deg, #3730a3 0%, #4338ca 100%);
    color: #ffffff;
}

.btn-sleep-stop {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    border: none;
    color: #111827;
}

.btn-sleep-stop:hover,
.btn-sleep-stop:focus {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    color: #ffffff;
}

.btn-nursing-start {
    background: linear-gradient(135deg, #be185d 0%, #db2777 100%);
    border: none;
    color: #ffffff;
}

.btn-nursing-start:hover,
.btn-nursing-start:focus {
    background: linear-gradient(135deg, #9d174d 0%, #be185d 100%);
    color: #ffffff;
}

.btn-nursing-side {
    min-height: 50px;
    border-radius: 0.85rem;
    border: 1px solid var(--border-soft);
    background-color: var(--bg-subtle);
    color: var(--text-main);
    font-weight: 600;
    transition: transform 0.1s ease, border-color 0.15s ease;
}

.btn-nursing-side:hover {
    border-color: var(--nursing-color);
    color: var(--text-main);
}

.btn-side-recommended {
    background-color: var(--nursing-soft);
    border: 2px solid var(--nursing-color);
    color: var(--nursing-text);
}

.btn-side-recommended:hover {
    color: var(--nursing-text);
}

.btn-offset-pill {
    border: 1px solid var(--border-soft);
    background-color: var(--bg-card);
    color: var(--text-main);
    border-radius: 999px;
    padding: 0.45rem 0.9rem;
    font-size: 0.9rem;
    font-weight: 500;
    min-height: 40px;
}

.hero-sleeping .btn-offset-pill,
.hero-nursing-active .btn-offset-pill {
    background-color: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.24);
    color: #f8fafc;
}

.btn-offset-pill:hover {
    opacity: 0.9;
}

.kpi-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    flex-shrink: 0;
}

.badge-night {
    background-color: var(--night-soft);
    color: var(--night-text);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.badge-nap {
    background-color: var(--nap-soft);
    color: var(--nap-text);
    border: 1px solid rgba(14, 165, 233, 0.3);
}

.badge-nursing {
    background-color: var(--nursing-soft);
    color: var(--nursing-text);
    border: 1px solid rgba(219, 39, 119, 0.32);
}

.timeline-track {
    position: relative;
    height: 32px;
    border-radius: 10px;
    background-color: var(--bg-track);
    overflow: hidden;
    border: 1px solid var(--border-soft);
}

.timeline-track-sm {
    height: 20px;
    border-radius: 7px;
}

.timeline-track-nursing {
    position: relative;
    height: 12px;
    border-radius: 6px;
    background-color: var(--bg-track);
    overflow: hidden;
    border: 1px solid var(--border-soft);
    margin-top: 4px;
}

.timeline-track-nursing-sm {
    height: 8px;
    border-radius: 4px;
    margin-top: 3px;
}

.timeline-gridline {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background-color: rgba(148, 163, 184, 0.35);
    pointer-events: none;
}

.timeline-seg {
    position: absolute;
    top: 3px;
    bottom: 3px;
    border-radius: 6px;
    min-width: 4px;
    transition: opacity 0.15s ease;
}

.timeline-track-sm .timeline-seg {
    top: 2px;
    bottom: 2px;
    border-radius: 4px;
    min-width: 3px;
}

.timeline-seg-nursing {
    position: absolute;
    top: 2px;
    bottom: 2px;
    border-radius: 4px;
    min-width: 4px;
    background-color: var(--nursing-color);
}

.timeline-track-nursing-sm .timeline-seg-nursing {
    top: 1px;
    bottom: 1px;
    min-width: 3px;
}

.timeline-seg-night {
    background-color: var(--night-color);
}

.timeline-seg-nap {
    background-color: var(--nap-color);
}

.timeline-seg-active {
    animation: pulse-sleep 2s infinite ease-in-out;
}

@keyframes pulse-sleep {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.65; }
}

.timeline-now-needle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: #f59e0b;
    z-index: 3;
    pointer-events: none;
}

.timeline-axis {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.wake-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0.25rem 0 0.5rem;
    position: relative;
}

.wake-pill {
    font-size: 0.76rem;
    padding: 0.18rem 0.6rem;
    border-radius: 999px;
    background-color: var(--bg-subtle);
    color: var(--text-muted);
    border: 1px dashed var(--border-soft);
}

.stacked-bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 175px;
    padding: 8px 4px 0;
    overflow-x: auto;
}

.stacked-bar-col {
    flex: 1 0 32px;
    min-width: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
}

.stacked-bar-well {
    width: 100%;
    max-width: 36px;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    background-color: var(--bg-track);
    border-radius: 8px;
    overflow: hidden;
}

.stacked-seg-night {
    background-color: var(--night-color);
    width: 100%;
}

.stacked-seg-nap {
    background-color: var(--nap-color);
    width: 100%;
}

.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    background-color: var(--bg-card);
    border-top: 1px solid var(--border-soft);
    display: flex;
    justify-content: space-around;
    padding: 0.4rem 0.25rem calc(0.4rem + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
}

.mobile-bottom-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 500;
    padding: 0.25rem 0.65rem;
    border-radius: 0.6rem;
}

.mobile-bottom-link.active {
    color: var(--night-color);
    font-weight: 700;
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
    background-color: #0f172a;
    color: var(--text-main);
    border-color: var(--border-soft);
}

[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus {
    background-color: #0f172a;
    color: var(--text-main);
    border-color: #6366f1;
    box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.2);
}

[data-theme="dark"] .btn-outline-secondary {
    color: #cbd5e1;
    border-color: #334155;
}

[data-theme="dark"] .btn-outline-secondary:hover {
    background-color: #1e293b;
    color: #f8fafc;
}

[data-theme="dark"] .table {
    color: var(--text-main);
}

[data-theme="dark"] .border-top,
[data-theme="dark"] .border-bottom {
    border-color: var(--border-soft) !important;
}

[data-theme="dark"] .bg-white {
    background-color: var(--bg-card) !important;
}

[data-theme="dark"] .text-dark {
    color: var(--text-main) !important;
}

[data-theme="dark"] .alert-info {
    background-color: #172554;
    border-color: #1e3a8a;
    color: #dbeafe;
}

[data-theme="dark"] .alert-success {
    background-color: #064e3b;
    border-color: #065f46;
    color: #d1fae5;
}

[data-theme="dark"] .alert-warning {
    background-color: #451a03;
    border-color: #78350f;
    color: #fef3c7;
}

[data-theme="dark"] .alert-danger {
    background-color: #450a0a;
    border-color: #7f1d1d;
    color: #fee2e2;
}
