:root {
    --primary: #818cf8;
    --feed: #f472b6;
    --sleep: #6366f1;
    --diaper: #34d399;
    --milestone: #fbbf24;
    --view: #38bdf8;
    --bg: #0d0d12;
    --text: #e2e8f0;
    --text-light: #6b7280;
    --white: #1a1a2a;
    --surface: #141420;
    --border: rgba(255, 255, 255, 0.08);
    --shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.45), 0 2px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 20px 30px -5px rgba(0, 0, 0, 0.55), 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --radius: 24px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

input, textarea, select {
    -webkit-user-select: auto;
    user-select: auto;
}

html {
    width: 100%;
    height: 100%;
}

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg);
    color: var(--text);
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

/* ==================== MAIN SCREEN LAYOUT ==================== */

.main-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    transition: opacity 0.3s ease, transform 0.3s ease;
    overflow: hidden;
    touch-action: none;
}

.main-screen.hidden {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
}

/* Removed Prediction Bar */

/* Grid Container */
.grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(4, 1fr);
    gap: 12px;
    padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)) 16px;
    flex: 1;
    overflow: hidden;
    touch-action: none;
    box-sizing: border-box;
}

/* Crow Column (11) */
.grid-col-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 100%;
}

.info-card {
    flex: 1;
    background: var(--white);
    border-radius: 16px;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    min-width: 0;
    position: relative;
    overflow: hidden;
}

.info-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 3px;
    border-radius: 16px 0 0 16px;
}

.info-card.next-feed::before { background: var(--feed); }
.info-card.next-diaper::before { background: var(--diaper); }
.info-card.next-nap::before { background: var(--sleep); }

.info-label {
    font-size: 8px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-light);
    margin-bottom: 2px;
}

.info-time {
    font-size: 14px;
    font-weight: 800;
    line-height: 1.1;
}

.info-card.next-feed .info-time { color: var(--feed); }
.info-card.next-diaper .info-time { color: var(--diaper); }
.info-card.next-nap .info-time { color: var(--sleep); }

.info-at {
    font-size: 9px;
    color: var(--text-light);
    white-space: nowrap;
}

.pred-loading {
    color: var(--text-light);
    font-size: 12px;
    font-weight: 600;
    opacity: 0.6;
}

.grid-container.hidden {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
}

.grid-btn {
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, background-color 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
    overflow: hidden;
    touch-action: manipulation;
    background: var(--white);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.grid-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: currentColor;
    opacity: 0.05;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.grid-btn:active {
    transform: scale(0.96);
}

.grid-btn:hover {
    box-shadow: var(--shadow-lg);
}

.grid-btn .icon {
    font-size: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.9;
}

.grid-btn .icon svg {
    width: 26px;
    height: 26px;
    stroke-width: 2.5px;
    stroke: white;
    color: white;
}

.grid-btn .icon i {
    width: 26px;
    height: 26px;
    color: white;
    stroke-width: 2.5px;
}

/* Calendar icon with day number */
.calendar-icon {
    position: relative !important;
}

.calendar-icon svg,
.calendar-icon i,
.btn-milestone .icon svg,
.btn-milestone .icon i,
.btn-sleep .icon svg,
.btn-sleep .icon i {
    stroke-width: 1px !important;
}

.calendar-day {
    position: absolute;
    font-size: 11px;
    font-weight: 700;
    color: white;
    text-align: center;
    line-height: 1;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 7px;
}

.grid-btn.pulse::before {
    opacity: 0.2;
    transition: opacity 0s;
}

/* Button Specific Colors */
.btn-add { color: var(--primary); }
.btn-view { color: var(--view); }
.btn-feed { color: var(--feed); }
.btn-sleep { color: var(--sleep); }
.btn-diaper { color: var(--diaper); }
.btn-milestone { color: var(--milestone); }
.btn-owlet { color: #ef4444; }
.btn-reports { color: var(--primary); }
.btn-walk { color: #fb923c; }

/* Icon Image Styling */
.diaper-icon,
.sock-icon,
.feed-icon {
    filter: brightness(0) invert(1);
}

/* ==================== SPLIT DIAPER BUTTON ==================== */

.diaper-split-btn {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--white);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    position: relative;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
}

.diaper-split-btn:hover {
    box-shadow: var(--shadow-lg);
}

.diaper-main {
    flex: 0 0 68%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 8px;
    color: var(--diaper);
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    touch-action: manipulation;
    transition: background 0.15s;
    border-radius: 0;
    position: relative;
}

.diaper-main::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--diaper);
    opacity: 0.05;
    pointer-events: none;
}

.diaper-main:active {
    transform: scale(0.96);
}

.diaper-poop {
    flex: 0 0 32%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 6px;
    color: #f59e0b;
    border: none;
    border-left: 1px solid var(--border);
    background: rgba(245, 158, 11, 0.06);
    cursor: pointer;
    font-size: 11px;
    font-weight: 700;
    font-family: inherit;
    touch-action: manipulation;
    border-radius: 0;
    position: relative;
    transition: background 0.15s;
}

.diaper-poop:active {
    background: rgba(245, 158, 11, 0.15);
    transform: scale(0.96);
}

.diaper-poop .poop-icon {
    font-size: 22px;
    line-height: 1;
}

.diaper-main .icon {
    font-size: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--diaper);
    opacity: 0.9;
}

/* ==================== MODAL STYLES ==================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1000;
    touch-action: auto;
}

.modal.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: var(--white);
    border-radius: 32px;
    padding: 32px;
    max-width: 400px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-header {
    margin-bottom: 28px;
    text-align: center;
}

.modal-header h2 {
    font-size: 24px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.modal-header p {
    color: var(--text-light);
    font-size: 15px;
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: 700;
    color: var(--text);
    font-size: 14px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.form-group select,
.form-group input,
.form-group textarea {
    width: 100%;
    padding: 16px 20px;
    border: 2px solid var(--border);
    background: var(--surface);
    border-radius: 16px;
    font-size: 16px;
    font-family: inherit;
    color: var(--text);
    transition: all 0.2s ease;
}

.form-group select option {
    background: var(--white);
    color: var(--text);
}

.form-group select:focus,
.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--white);
    box-shadow: 0 0 0 4px rgba(129, 140, 248, 0.15);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

.modal-actions {
    display: flex;
    gap: 16px;
    margin-top: 32px;
}

.btn {
    flex: 1;
    padding: 16px;
    border: none;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(129, 140, 248, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    border: 1px solid var(--border);
}

/* ==================== EVENTS VIEW ==================== */

.events-view {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 999;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

/* Standalone PWA mode adjustments */
@media all and (display-mode: standalone) {
    .events-header {
        padding-top: max(40px, env(safe-area-inset-top) + 40px);
    }
}

@media all and (display-mode: fullscreen) {
    .events-header {
        padding-top: max(40px, env(safe-area-inset-top) + 40px);
    }
}

@supports (-webkit-touch-callout: none) {
    @media all and (display-mode: standalone) {
        .events-header {
            padding-top: max(50px, env(safe-area-inset-top) + 50px);
        }
    }
}

.events-view.active {
    transform: translateX(0);
}

.events-header {
    display: flex;
    align-items: center;
    padding: 24px;
    padding-top: max(24px, env(safe-area-inset-top) + 24px);
    background: var(--bg);
    flex-shrink: 0;
    z-index: 100;
}

.back-btn {
    background: var(--white);
    border: 1px solid var(--border);
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-right: 20px;
    box-shadow: var(--shadow);
    transition: all 0.2s ease;
    color: var(--text);
}

.back-btn svg {
    stroke: var(--text);
    color: var(--text);
}

.back-btn:active {
    transform: scale(0.92);
}

.events-header h2 {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    flex: 1;
    letter-spacing: -0.5px;
}

.add-event-btn {
    background: var(--white);
    color: var(--milestone);
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: 15px;
    box-shadow: 0 4px 12px rgba(251, 191, 36, 0.2);
    transition: all 0.2s ease;
    font-size: 24px;
    font-weight: 600;
}

.add-event-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(251, 191, 36, 0.3);
}

.add-event-btn svg {
    stroke: var(--milestone);
    color: var(--milestone);
    width: 24px;
    height: 24px;
}

.add-event-btn:active {
    transform: scale(0.92);
}

.event-list {
    max-width: 600px;
    margin: 0 auto;
    min-height: calc(100vh - 120px);
    flex: 1;
    padding: 24px;
    overflow-y: visible;
    width: 100%;
}

.event-item {
    background: var(--white);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: transform 0.2s ease;
    border: 1px solid var(--border);
}

#dayEventList {
    margin-top: 20px;
}

#dayEventList .event-item {
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.event-icon {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #fff;
    flex-shrink: 0;
}

.event-icon svg {
    width: 26px;
    height: 26px;
    stroke-width: 2.5px;
    stroke: white;
    color: white;
}

.event-icon.feed { background: var(--feed); box-shadow: 0 4px 12px rgba(244, 114, 182, 0.3); }
.event-icon.sleep { background: var(--sleep); box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3); }
.event-icon.diaper { background: var(--diaper); box-shadow: 0 4px 12px rgba(52, 211, 153, 0.3); }
.event-icon.milestone { background: var(--milestone); box-shadow: 0 4px 12px rgba(251, 191, 36, 0.3); }
.event-icon.custom { background: var(--primary); box-shadow: 0 4px 12px rgba(129, 140, 248, 0.3); }

.event-details {
    flex: 1;
}

.event-type {
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
    font-size: 17px;
}

.event-time {
    color: var(--text-light);
    font-size: 14px;
    font-weight: 500;
}

.event-notes {
    margin-top: 8px;
    color: var(--text);
    font-size: 15px;
    line-height: 1.4;
    background: var(--surface);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.empty-state .icon {
    font-size: 60px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state .icon svg {
    stroke: currentColor;
    color: currentColor;
}

/* ==================== TOAST ==================== */

.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(200px);
    background: rgba(15, 15, 25, 0.92);
    backdrop-filter: blur(8px);
    color: var(--text);
    padding: 16px 24px;
    border-radius: 50px;
    box-shadow: var(--shadow-lg);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 2000;
    max-width: 300px;
    text-align: center;
    font-weight: 600;
    border: 1px solid var(--border);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ==================== ANIMATIONS ==================== */

@keyframes slideInUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(100px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes slideOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(100px); }
}

.event-item {
    animation: slideInUp 0.3s ease;
}

/* ==================== MILESTONES ==================== */

.milestones-grid {
    max-width: 600px;
    margin: 0 auto;
    min-height: calc(100vh - 120px);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 16px;
}

.milestone-box {
    background: var(--white);
    border-radius: 20px;
    padding: 24px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    min-height: 140px;
    border: 1px solid var(--border);
}

.milestone-box:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.milestone-box:active {
    transform: scale(0.96);
}

.milestone-box .milestone-icon {
    font-size: 32px;
    margin-bottom: 12px;
    color: var(--milestone);
    background: rgba(251, 191, 36, 0.15);
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.milestone-box .milestone-icon svg {
    width: 24px;
    height: 24px;
    stroke: var(--milestone);
    color: var(--milestone);
}

.milestone-box .milestone-icon img {
    width: 24px;
    height: 24px;
}

.milestone-box .milestone-type {
    font-weight: 600;
    color: #d4a860;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.milestone-box .milestone-title {
    font-weight: 700;
    color: var(--text);
    font-size: 14px;
    margin-bottom: 6px;
    min-height: 20px;
}

.milestone-box .milestone-date {
    color: var(--text-light);
    font-size: 13px;
    font-weight: 500;
}

.milestone-box.empty {
    border: 2px dashed rgba(255, 255, 255, 0.15);
    background: transparent;
    color: var(--text-light);
    transition: all 0.3s ease;
    box-shadow: none;
}

.milestone-box.empty:hover {
    border-color: var(--primary);
    border-style: dashed;
    background: rgba(129, 140, 248, 0.08);
    color: var(--primary);
    transform: translateY(-3px);
}

.milestone-box.empty:active {
    transform: scale(0.96);
}

/* ==================== DAY TIMELINE ==================== */

.timeline-container {
    width: 100%;
    margin: 0;
    padding: 0;
    flex: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
}

.timeline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 20px 16px 25px 16px;
    background: var(--white);
    padding: 16px 20px;
    border-radius: 20px;
    box-shadow: var(--shadow);
    flex-shrink: 0;
    z-index: 20;
    border: 1px solid var(--border);
}

.date-nav-btn {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    transition: transform 0.2s ease;
}

.date-nav-btn svg {
    stroke: var(--text);
    color: var(--text);
}

.date-nav-btn:active {
    transform: scale(0.92);
}

.current-date {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
}

.timeline {
    background: var(--white);
    border-radius: 20px;
    padding: 20px;
    border: 1px solid var(--border);
    position: relative;
    overflow: visible;
    min-height: 340px;
    margin: 0 16px 16px 16px;
    box-shadow: var(--shadow);
}

.timeline-chart-title {
    margin: 0 0 16px 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.timeline-chart-container {
    position: relative;
    width: 100%;
    height: 280px;
    margin-bottom: 16px;
    background: var(--surface);
    border-radius: 16px;
    padding: 16px;
    box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
}

.timeline-chart-canvas {
    max-height: 280px;
}

@media (max-width: 480px) {
    .timeline-chart-container {
        padding: 8px;
    }
    .timeline-chart-title {
        font-size: 14px;
        margin-bottom: 12px;
    }
}

.timeline-horizontal {
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 100%;
    background: var(--surface);
    border-radius: 0 !important;
    padding: 12px;
}

.timeline-hours-container {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    padding: 0 5px;
}

.hour-tick {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 11px;
    color: var(--text-light);
    font-weight: 600;
    flex: 1;
    position: relative;
}

.hour-tick::after {
    content: '';
    position: absolute;
    top: 25px;
    width: 1px;
    height: 92px;
    background: rgba(255, 255, 255, 0.08);
    z-index: 1;
}

.hour-tick:first-child::after,
.hour-tick:last-child::after {
    background: rgba(255, 255, 255, 0.14);
}

.timeline-colored-section {
    position: absolute;
    top: 2px;
    height: calc(100% - 4px);
    border-radius: 0 !important;
    opacity: 0.9;
    z-index: 3;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.timeline-colored-section:hover {
    opacity: 1;
    transform: scaleY(1.1);
    z-index: 5;
}

.timeline-colored-section.sleep { background: var(--sleep); }
.timeline-colored-section.feed  { background: var(--feed); }
.timeline-colored-section.other { background: var(--primary); }

.event-marker {
    position: absolute;
    top: -5px;
    width: 2px;
    height: 50px;
    background: var(--text);
    border-radius: 2px;
    z-index: 10;
    transform: translateX(-1.5px);
}

.event-marker-icon {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 32px;
    background: var(--white);
    border: 2px solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    box-shadow: var(--shadow);
    z-index: 12;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.event-marker-icon svg {
    width: 16px;
    height: 16px;
    stroke: var(--text);
    color: var(--text);
}

.event-marker-icon:hover {
    transform: translateX(-50%) scale(1.15);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.instant-event-marker {
    position: absolute;
    top: -2px;
    width: 2px;
    height: 44px;
    background: var(--text-light);
    border-radius: 1px;
    z-index: 8;
    transform: translateX(-1px);
}

.instant-event-marker::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    width: 6px;
    height: 6px;
    background: var(--text-light);
    border-radius: 50%;
    z-index: 9;
}

.instant-event-marker .event-marker-icon {
    top: 45px;
    border-color: var(--border);
    width: 26px;
    height: 26px;
    font-size: 12px;
}

.timeline-track {
    position: relative;
    height: 40px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 0 !important;
    margin: 20px 5px;
    overflow: hidden;
}

.timeline-click-info {
    position: fixed;
    background: rgba(20, 20, 32, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px 16px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    max-width: 200px;
    min-width: 140px;
    font-size: 13px;
    pointer-events: none;
    opacity: 0;
    transform: translateY(8px) scale(0.94);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.timeline-click-info.show {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0) scale(1);
}

.timeline-click-info h4 {
    margin: 0 0 4px 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.01em;
    line-height: 1.3;
}

.timeline-click-info .event-item {
    margin: 0;
    padding: 0;
    border: none;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-weight: 600;
    line-height: 1.4;
    background: transparent;
    box-shadow: none;
}

.timeline-click-info .event-item span:first-child {
    font-size: 16px;
    flex-shrink: 0;
}

.timeline-click-info .event-item span:last-child {
    font-size: 13px;
    color: var(--text);
    opacity: 0.9;
}

.no-events-timeline {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 120px;
    color: var(--text-light);
    text-align: center;
    margin: 30px 0;
}

.no-events-timeline .icon {
    font-size: 48px;
    margin-bottom: 10px;
    opacity: 0.5;
}

.no-events-timeline .icon svg {
    stroke: currentColor;
    color: currentColor;
}

.timeline-legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 0 16px;
    padding: 16px;
    background: transparent;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-light);
    font-weight: 600;
}

.legend-color {
    width: 20px;
    height: 8px;
    border-radius: 4px;
}

.legend-color.sleep { background: var(--sleep); }
.legend-color.feed  { background: var(--feed); }

/* Daily Stats */
.daily-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 12px;
    margin: 0 16px;
    padding: 16px;
    background: var(--white);
    border-radius: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

@media (min-width: 768px) {
    .daily-stats {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: 1fr;
    }
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--surface);
    border-radius: 16px;
    transition: transform 0.2s ease;
    min-height: 64px;
    border: 1px solid var(--border);
}

@media (max-width: 767px) {
    .stat-item {
        gap: 10px;
        padding: 10px;
        min-height: 60px;
    }
}

.stat-item:hover {
    transform: translateY(-2px);
}

.stat-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    color: white;
}

.stat-icon svg {
    width: 18px;
    height: 18px;
    stroke: white;
    color: white;
}

.stat-icon.sleep { background: var(--sleep); }
.stat-icon.feed  { background: var(--feed); }
.stat-icon.diaper { background: var(--diaper); }
.stat-icon.other { background: var(--primary); }

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

.stat-duration {
    font-weight: 800;
    font-size: 15px;
    color: var(--text);
    margin: 0;
    line-height: 1.2;
}

.stat-label {
    font-size: 11px;
    color: var(--text-light);
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.2;
    font-weight: 700;
}

@media (max-width: 767px) {
    .stat-duration { font-size: 14px; }
    .stat-label    { font-size: 10px; }
}

/* ==================== OWLET STYLES ==================== */

.owlet-container {
    padding: 20px;
    overflow-y: auto;
    height: calc(100% - 60px);
    box-sizing: border-box;
}

.owlet-status { margin-bottom: 20px; }

.btn-history { margin-left: auto; }

.history-icon { font-size: 20px; }

.owlet-history-content-wrapper {
    padding: 0 20px 20px 20px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Timeline Legend and Daily Stats - Hidden by default */
.timeline-legend { display: none; }
.daily-stats { display: none; }
.timeline-legend.show { display: flex; }
.daily-stats.show { display: grid; }

/* History Hourly Averages Section */
.history-hourly-section { margin-top: 24px; margin-bottom: 20px; }

.history-hourly-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 12px;
}

.history-hourly-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    width: 100%;
}

.history-hourly-card {
    background: var(--white);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.history-hourly-card:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transform: translateY(-2px);
}

.history-hourly-card.has-data {
    background: rgba(129, 140, 248, 0.08);
    border-color: rgba(129, 140, 248, 0.3);
}

.history-hourly-card.no-data {
    opacity: 0.4;
    background: var(--surface);
}

.history-hourly-time {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-hourly-values {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-hourly-value {
    font-size: 11px;
    color: var(--text-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-hourly-value strong {
    color: var(--text);
    font-weight: 600;
}

/* History Charts Section */
.history-charts-section { margin-top: 24px; margin-bottom: 24px; }

.history-charts-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 12px;
}

.history-chart-container {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 12px;
    min-height: 250px;
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    touch-action: auto;
    -webkit-user-select: none;
    user-select: none;
}

.history-chart-container.zoomed { cursor: grab; }
.history-chart-container.zoomed:active { cursor: grabbing; }

.history-chart-inner {
    position: relative;
    display: inline-block;
    min-width: 100%;
}

.history-chart {
    width: 100% !important;
    height: auto !important;
    touch-action: auto;
    display: block;
    pointer-events: auto;
}

.history-chart-zoom-hint {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 8px;
    padding: 4px 0;
    text-align: center;
}

/* History Stats Grid */
.history-stats-grid { margin-bottom: 20px; }
.history-stat-card { box-shadow: var(--shadow); }
.history-stat-label { text-transform: uppercase; letter-spacing: 0.5px; }
.history-stat-value { line-height: 1.2; }
.history-stat-minmax { display: flex; justify-content: space-between; gap: 2px; }

/* ==================== DAY TIMELINE STATS ==================== */

#dayTimelineStatsView { display: none; }
#dayTimelineStatsView.active { display: flex; flex-direction: column; }

.btn-stats {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 8px 12px !important;
    background: var(--white) !important;
    color: var(--primary) !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
}

.btn-stats:active { opacity: 0.8 !important; }

.stats-container { flex: 1; overflow-y: auto; padding-bottom: 20px; }

.stats-sections { display: flex; flex-direction: column; gap: 24px; }

.stats-section {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stats-section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    margin-bottom: 4px;
}

/* Pattern Cards */
.pattern-card {
    background: var(--white);
    border-radius: 12px;
    padding: 14px;
    box-shadow: var(--shadow);
    margin-bottom: 10px;
    border: 1px solid var(--border);
}

.pattern-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
}

.pattern-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 10px;
}

.pattern-stat {
    background: var(--surface);
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    border: 1px solid var(--border);
}

.pattern-stat-label {
    font-size: 11px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-weight: 600;
    margin-bottom: 4px;
}

.pattern-stat-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
}

.pattern-detail {
    font-size: 12px;
    color: var(--text);
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.pattern-detail strong { color: var(--text); }

/* Prediction Cards (in stats view) */
.prediction-card {
    background: linear-gradient(135deg, rgba(26, 26, 42, 0.8) 0%, rgba(20, 20, 32, 0.9) 100%);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    border-left: 4px solid var(--primary);
    border-top: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.prediction-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
}

.prediction-main {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.prediction-time {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 10px;
}

.prediction-window {
    font-size: 12px;
    color: var(--text);
    background: var(--surface);
    padding: 8px;
    border-radius: 6px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
}

.prediction-window span { font-weight: 600; color: var(--text); }

.prediction-meta {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-light);
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.prediction-meta span { display: flex; align-items: center; }

/* Insight Cards */
.insight-card {
    background: linear-gradient(135deg, rgba(25, 40, 65, 0.8) 0%, rgba(35, 25, 55, 0.8) 100%);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    border-left: 4px solid #9C27B0;
    border-top: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.insight-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 10px; }
.insight-main  { font-size: 24px; font-weight: 700; color: #ce93d8; margin-bottom: 4px; }
.insight-time  { font-size: 13px; color: var(--text-light); margin-bottom: 8px; }
.insight-observation { font-size: 13px; color: var(--text); margin-bottom: 8px; }

.insight-suggestion {
    font-size: 12px;
    color: #ce93d8;
    background: rgba(156, 39, 176, 0.15);
    padding: 8px;
    border-radius: 6px;
    margin-top: 8px;
}

.insight-meta {
    font-size: 11px;
    color: var(--text-light);
    padding-top: 8px;
    border-top: 1px solid rgba(156, 39, 176, 0.2);
    margin-top: 8px;
}

/* Totals Grid */
.totals-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 12px;
}

.total-item {
    display: flex;
    flex-direction: column;
    background: var(--white);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.total-label {
    font-size: 11px;
    color: var(--text-light);
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 6px;
}

.total-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.total-progress { font-size: 11px; color: var(--text-light); }

/* Routine Details */
.routine-details { font-size: 13px; color: var(--text); line-height: 1.6; }
.routine-details div { margin-bottom: 8px; }
.routine-details strong { color: var(--text); font-weight: 600; }

/* Correlation Cards */
.correlation-card {
    background: linear-gradient(135deg, rgba(35, 25, 55, 0.8) 0%, rgba(25, 20, 50, 0.8) 100%);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    border-left: 4px solid #7B1FA2;
    border-top: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.correlation-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 10px; display: flex; align-items: center; }
.correlation-main  { font-size: 20px; font-weight: 700; color: #ce93d8; margin-bottom: 8px; }
.correlation-strength { font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.correlation-detail { font-size: 12px; color: var(--text); margin-bottom: 6px; padding-left: 12px; }
.correlation-detail strong { color: var(--text); font-weight: 600; }

/* Anomaly Cards */
.anomaly-card {
    background: linear-gradient(135deg, rgba(50, 30, 15, 0.8) 0%, rgba(45, 25, 10, 0.8) 100%);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    border-left: 4px solid #f44336;
    border-top: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.anomaly-title { font-size: 14px; font-weight: 600; margin-bottom: 10px; color: var(--text); }
.anomaly-description { font-size: 13px; color: var(--text); margin-bottom: 10px; line-height: 1.4; }

.anomaly-action {
    font-size: 12px;
    color: #ef9a9a;
    background: rgba(244, 67, 54, 0.15);
    padding: 8px;
    border-radius: 6px;
    margin-top: 8px;
}

.anomaly-action strong { color: #ef9a9a; font-weight: 600; }

/* Hybrid Sleep Analysis Card */
.hybrid-sleep-card {
    background: linear-gradient(135deg, rgba(1, 40, 70, 0.85) 0%, rgba(0, 30, 55, 0.85) 100%);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    border-left: 4px solid #01579B;
    border-top: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.hybrid-header {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.hybrid-stat {
    background: rgba(255, 255, 255, 0.06);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid rgba(1, 87, 155, 0.3);
    display: flex;
    flex-direction: column;
    text-align: center;
}

.hybrid-label {
    font-size: 11px;
    color: var(--text-light);
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 6px;
}

.hybrid-value { font-size: 16px; font-weight: 700; color: #4fc3f7; }

.reliability-bar {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(1, 87, 155, 0.2);
}

.reliability-label { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 8px; display: block; }

.reliability-bar-bg {
    width: 100%;
    height: 24px;
    background: rgba(1, 87, 155, 0.15);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 8px;
}

.reliability-bar-fill { height: 100%; transition: width 0.3s ease; border-radius: 12px; }

.reliability-status { font-size: 12px; font-weight: 600; text-align: center; }

.owlet-confidence {
    font-size: 12px;
    color: var(--text);
    background: rgba(1, 87, 155, 0.12);
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 8px;
}

.owlet-confidence strong { color: #4fc3f7; }

.event-validation {
    font-size: 12px;
    color: var(--text);
    background: rgba(76, 175, 80, 0.12);
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 8px;
}

.event-validation strong { color: #81c784; }

.sleep-periods-detail {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(1, 87, 155, 0.2);
}

.sleep-periods-detail strong { display: block; margin-bottom: 8px; color: var(--text); font-size: 12px; }

.period-detail {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text);
    padding: 6px 0;
    border-bottom: 1px solid rgba(1, 87, 155, 0.1);
}

.period-detail:last-child { border-bottom: none; }
.period-confidence { font-weight: 600; font-size: 11px; }

.period-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    transition: all 0.2s ease;
    border-radius: 4px;
    flex-shrink: 0;
}

.period-action-btn:hover { background-color: rgba(1, 87, 155, 0.12); transform: scale(1.1); }
.period-action-btn svg { width: 16px; height: 16px; }

/* ==================== REPORTS VIEW ==================== */

.reports-period-bar {
    display: flex;
    gap: 6px;
    padding: 0 24px 16px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.period-btn {
    padding: 8px 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-light);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.period-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.period-btn:active { transform: scale(0.95); }

.reports-content {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px 24px;
    -webkit-overflow-scrolling: touch;
}

.reports-summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.report-summary-card {
    background: var(--white);
    border-radius: 16px;
    padding: 14px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.report-summary-card .rsc-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 6px;
}

.report-summary-card .rsc-icon svg {
    width: 16px;
    height: 16px;
    stroke: #fff;
}

.report-summary-card.feed .rsc-icon    { background: var(--feed); }
.report-summary-card.diaper .rsc-icon  { background: var(--diaper); }
.report-summary-card.sleep .rsc-icon   { background: var(--sleep); }
.report-summary-card.poop .rsc-icon    { background: #f59e0b; }

.rsc-value {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    line-height: 1.1;
}

.rsc-label {
    font-size: 11px;
    color: var(--text-light);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.rsc-sub {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 2px;
}

.reports-chart-section {
    background: var(--white);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.reports-chart-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
}

.reports-chart-canvas {
    max-height: 180px;
}

.reports-avg-table {
    background: var(--white);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.reports-avg-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
}

.avg-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.avg-row:last-child { border-bottom: none; }

.avg-row-label { color: var(--text-light); font-weight: 600; }
.avg-row-value { color: var(--text); font-weight: 700; }

.reports-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-light);
    gap: 12px;
}

/* ==================== LOADING SPINNER ==================== */

@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

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

@media (max-width: 600px) {
    .pattern-grid { grid-template-columns: 1fr; }
    .prediction-main { font-size: 20px; }
}
