:root {
    --primary: #818cf8;
    --feed: #f472b6;
    --sleep: #6366f1;
    --diaper: #34d399;
    --milestone: #fbbf24;
    --view: #38bdf8;
    --bg: #fafaf9;
    --text: #334155;
    --text-light: #94a3b8;
    --white: #ffffff;
    --shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.05), 0 2px 6px -1px rgba(0, 0, 0, 0.02);
    --shadow-lg: 0 20px 30px -5px rgba(0, 0, 0, 0.06), 0 10px 15px -3px rgba(0, 0, 0, 0.03);
    --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;
}

.grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(4, 1fr);
    gap: 16px;
    padding: 16px;
    padding-top: 50px;
    height: 100vh;
    height: 100dvh;
    transition: opacity 0.3s ease, transform 0.3s ease;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    touch-action: none;
    box-sizing: border-box;
}

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

.grid-btn {
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    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: 12px;
    position: relative;
    overflow: hidden;
    touch-action: manipulation;
    background: var(--white);
    box-shadow: var(--shadow);
}

.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: 56px;
    height: 56px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.9;
}

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

.grid-btn .icon i {
    width: 28px;
    height: 28px;
    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; } /* Soft Red/Rose */

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

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    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 rgba(0,0,0,0.03);
}

.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 #f1f5f9;
    background: #f8fafc;
    border-radius: 16px;
    font-size: 16px;
    font-family: inherit;
    color: var(--text);
    transition: all 0.2s ease;
}

.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.1);
}

.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: var(--white);
    box-shadow: 0 4px 12px rgba(129, 140, 248, 0.3);
}

.btn-secondary {
    background: #f1f5f9;
    color: var(--text);
}

/* 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);
    }
}

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

/* iOS specific adjustments for PWA mode */
@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);
    /* box-shadow: var(--shadow); */
    flex-shrink: 0;
    z-index: 100;
}

.back-btn {
    background: var(--white);
    border: 1px solid rgba(0,0,0,0.04);
    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.25);
    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.35);
}

.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 rgba(0,0,0,0.02);
}

#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: var(--white);
    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: #f8fafc;
    padding: 8px 12px;
    border-radius: 8px;
}

.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 Notification */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(200px);
    background: rgba(30, 41, 59, 0.9);
    backdrop-filter: blur(4px);
    color: var(--white);
    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;
}

.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 Grid */
.milestones-grid {
    max-width: 600px;
    margin: 0 auto;
    min-height: calc(100vh - 120px);
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* grid-template-rows: 1fr 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 rgba(0,0,0,0.02);
}

.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: #fef3c7;
    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: #78350f;
    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 #e2e8f0;
    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.05);
    color: var(--primary);
    transform: translateY(-3px);
}

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

/* Day Timeline Styles */
.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;
}

.date-nav-btn {
    background: #f1f5f9;
    color: var(--text);
    border: none;
    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: white;
    border-radius: 20px;
    padding: 20px;
    border: 1px solid rgba(0,0,0,0.02);
    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: #1e293b;
}

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

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

/* Mobile optimizations for timeline chart */
@media (max-width: 480px) {
    .timeline-chart-container {
        padding: 8px;
        /* Height 280px is fine on mobile too */
    }
    
    .timeline-chart-title {
        font-size: 14px;
        margin-bottom: 12px;
    }
}

.timeline-horizontal {
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 100%;
    background: #f8fafc;
    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: #e2e8f0;
    z-index: 1;
}

.hour-tick:first-child::after,
.hour-tick:last-child::after {
    background: #cbd5e1;
    /*height: 115px;*/
}

.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.05);
}

.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: #334155;
    border-radius: 2px;
    z-index: 10;
    transform: translateX(-1.5px);
}

/*.event-marker::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    width: 9px;
    height: 9px;
    background: #1e293b;
    border-radius: 50%;
    z-index: 11;
}*/

.event-marker-icon {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 32px;
    background: var(--white);
    border: 2px solid #e2e8f0;
    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: #334155;
    color: #334155;
}

.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: #94a3b8;
    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: #94a3b8;
    border-radius: 50%;
    z-index: 9;
}

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

.timeline-track {
    position: relative;
    height: 40px;
    background: #f1f5f9;
    border-radius: 0 !important;
    margin: 20px 5px;
    overflow: hidden;
}

.timeline-click-info {
    position: fixed;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    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;
    /* border-radius: 12px; */
}

.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);
}

/* Desktop version - 4 columns on larger screens */
@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: #f8fafc;
    border-radius: 16px;
    transition: transform 0.2s ease;
    min-height: 64px;
}

/* Mobile adjustments */
@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;
}

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

/* Owlet View 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;
}

/* owlet-history-content handled by parent wrapper */

/* 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 #e2e8f0;
    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.08);
    transform: translateY(-2px);
}

.history-hourly-card.has-data {
    background: linear-gradient(135deg, #f0f4ff 0%, #faf5ff 100%);
    border-color: #c7d2fe;
}

.history-hourly-card.no-data {
    opacity: 0.5;
    background: #f8fafc;
}

.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 #e2e8f0;
    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: #94a3b8;
    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;
}

/* Form Input Classes */
/* Styles already applied via .form-group select/input/textarea */

/* Day Timeline Stats View */
#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: none !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;
}

.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: #f8fafc;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
}

.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 #e2e8f0;
}

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

/* Prediction Cards */
.prediction-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    border-left: 4px solid var(--primary);
}

.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: #f0f4f8;
    padding: 8px;
    border-radius: 6px;
    margin-bottom: 8px;
}

.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 #e2e8f0;
}

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

/* Insight Cards */
.insight-card {
    background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    border-left: 4px solid #9C27B0;
}

.insight-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 10px;
}

.insight-main {
    font-size: 24px;
    font-weight: 700;
    color: #9C27B0;
    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: #5E35B1;
    background: rgba(156, 39, 176, 0.1);
    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: white;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.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, #f3e5f5 0%, #ede7f6 100%);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    border-left: 4px solid #7B1FA2;
}

.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: #7B1FA2;
    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, #fff3e0 0%, #ffe0b2 100%);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    border-left: 4px solid #f44336;
}

.anomaly-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

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

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

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

/* Hybrid Sleep Analysis Card */
.hybrid-sleep-card {
    background: linear-gradient(135deg, #e1f5fe 0%, #b3e5fc 100%);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    border-left: 4px solid #01579B;
}

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

.hybrid-stat {
    background: white;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #B3E5FC;
    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: #01579B;
}

.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.1);
    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.1);
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 8px;
}

.owlet-confidence strong {
    color: #01579B;
}

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

.event-validation strong {
    color: #2E7D32;
}

.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.1);
    color: var(--primary-dark);
    transform: scale(1.1);
}

.period-action-btn svg {
    width: 16px;
    height: 16px;
}

/* Loading spinner animation */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

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