:root {
    --bg: #f6efe6;
    --bg-accent: #fce4d6;
    --surface: rgba(255, 252, 247, 0.88);
    --surface-strong: #fffaf4;
    --surface-dark: #281f1a;
    --text-main: #221b17;
    --text-soft: #6f6258;
    --text-inverse: #fff9f5;
    --line: rgba(92, 70, 56, 0.12);
    --line-strong: rgba(92, 70, 56, 0.22);
    --primary: #ef6c4d;
    --primary-deep: #da5536;
    --secondary: #ffc857;
    --mint: #7ab8a1;
    --shadow-lg: 0 22px 50px rgba(83, 55, 32, 0.12);
    --shadow-md: 0 12px 28px rgba(83, 55, 32, 0.1);
    --shadow-sm: 0 6px 16px rgba(83, 55, 32, 0.08);
    --radius-xl: 28px;
    --radius-lg: 22px;
    --radius-md: 16px;
    --radius-sm: 12px;
    --sidebar-width: 320px;
    --header-height: 80px;
    --slot-height: 64px;
    --transition-speed: 0.28s;
}

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

html {
    height: 100%;
}

body {
    min-height: 100%;
    font-family: 'Outfit', sans-serif;
    background:
        radial-gradient(circle at top left, rgba(255, 200, 87, 0.28), transparent 30%),
        radial-gradient(circle at right center, rgba(122, 184, 161, 0.2), transparent 32%),
        linear-gradient(180deg, #fff6ef 0%, #f8efe6 52%, #f4e6db 100%);
    color: var(--text-main);
    overflow: hidden;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.ambient {
    position: fixed;
    inset: auto;
    border-radius: 999px;
    filter: blur(12px);
    pointer-events: none;
    z-index: 0;
}

.ambient-one {
    top: 72px;
    right: -48px;
    width: 180px;
    height: 180px;
    background: rgba(239, 108, 77, 0.18);
}

.ambient-two {
    bottom: 96px;
    left: -32px;
    width: 220px;
    height: 220px;
    background: rgba(122, 184, 161, 0.16);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-speed), visibility var(--transition-speed);
    z-index: 2000;
}

.sidebar-open .sidebar-overlay {
    opacity: 1;
    visibility: visible;
}

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

.sidebar {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    max-height: 80vh;
    padding: 1.5rem 1.5rem calc(1.5rem + env(safe-area-inset-bottom));
    background: #1e1a17;
    color: var(--text-inverse);
    border-radius: 30px 30px 0 0;
    transform: translateY(105%) translateZ(0);
    transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 2100;
    overflow-y: auto;
    box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.45);
    backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
}

.sidebar-open .sidebar {
    transform: translateY(0) translateZ(0);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
    font-size: 1rem;
    font-weight: 700;
    color: #fff7f0;
}

.logo svg {
    width: 20px;
    height: 20px;
    color: var(--secondary);
}

.nav-menu {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.4rem;
}

.nav-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 52px;
    padding: 0.9rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 249, 245, 0.75);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed);
}

.nav-item.active {
    background: linear-gradient(135deg, var(--primary), #f59563);
    color: white;
    border-color: transparent;
    box-shadow: 0 12px 24px rgba(239, 108, 77, 0.24);
}

.mini-calendar,
.categories {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 22px;
    padding: 1rem;
}

.mini-calendar {
    margin-bottom: 1rem;
}

.mini-cal-header,
.categories h3 {
    font-size: 0.88rem;
    font-weight: 700;
    color: rgba(255, 249, 245, 0.88);
}

.mini-cal-header {
    text-align: center;
    margin-bottom: 0.9rem;
}

.mini-cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.mini-weekday {
    text-align: center;
    font-size: 0.68rem;
    color: rgba(255, 249, 245, 0.5);
}

.mini-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font-size: 0.74rem;
    color: rgba(255, 249, 245, 0.72);
}

.mini-day.today {
    background: white;
    color: var(--surface-dark);
    font-weight: 700;
}

.category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.category-list {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.category-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    color: rgba(255, 249, 245, 0.88);
}

.cat-item-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
}

.add-cat-btn,
.delete-cat-btn,
.close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: rgba(255, 249, 245, 0.78);
    cursor: pointer;
}

.add-cat-btn {
    width: 32px;
    height: 32px;
    border-radius: 10px;
}

.delete-cat-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    min-height: 100vh;
    padding: max(1rem, env(safe-area-inset-top)) 1rem calc(7rem + env(safe-area-inset-bottom));
    overflow: auto;
}

.mobile-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toolbar-btn,
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.72);
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

.toolbar-badge,
.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.toolbar-badge {
    padding: 0.7rem 0.95rem;
    border-radius: 999px;
    color: var(--primary-deep);
    background: rgba(255, 255, 255, 0.72);
    box-shadow: var(--shadow-sm);
}

.clear-all-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.6rem 0.8rem;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border-radius: 999px;
    border: none;
    font-size: 0.65rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.clear-all-btn:hover {
    background: #ef4444;
    color: white;
}

.clear-all-btn svg {
    width: 14px;
    height: 14px;
}

.eyebrow {
    color: var(--primary-deep);
    margin-bottom: 0.3rem;
    font-size: 0.55rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.toggle-icon {
    width: 10px;
    height: 10px;
    transition: transform 0.3s ease;
}

.main-header.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.header-collapsible {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease, margin 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.main-header.collapsed .header-collapsible {
    max-height: 0;
    opacity: 0;
    margin: 0;
    pointer-events: none;
}

.main-header {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1rem;
    border-radius: var(--radius-lg);
    background: linear-gradient(145deg, rgba(255, 250, 244, 0.92), rgba(255, 243, 234, 0.82));
    border: 1px solid rgba(255, 255, 255, 0.65);
    box-shadow: var(--shadow-md);
    transition: all 0.3s ease;
}

.main-header.collapsed {
    padding-bottom: 0.5rem;
}

.current-date-info h1 {
    font-size: 0.95rem;
    line-height: 1.2;
    letter-spacing: -0.01em;
    font-weight: 700;
}

.current-date-info p {
    margin-top: 0.15rem;
    color: var(--text-soft);
    font-size: 0.68rem;
}

.header-actions {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.view-navigation {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem;
    padding: 0.35rem;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.62);
    border: 1px solid rgba(255, 255, 255, 0.8);
}

.view-navigation .icon-btn {
    flex: 0 0 46px;
}

.view-navigation .btn-secondary {
    flex: 1 1 120px;
}

.sync-status {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0.55rem 0.85rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.62);
    border: 1px solid rgba(92, 70, 56, 0.08);
    color: var(--text-soft);
    font-size: 0.74rem;
    font-weight: 600;
}

.sync-status[data-state="pending"] {
    color: #9a6700;
    background: rgba(255, 200, 87, 0.16);
}

.sync-status[data-state="saving"] {
    color: #8a4a19;
    background: rgba(239, 108, 77, 0.14);
}

.sync-status[data-state="success"] {
    color: #0f7a57;
    background: rgba(122, 184, 161, 0.18);
}

.sync-status[data-state="error"] {
    color: #c2410c;
    background: rgba(239, 68, 68, 0.12);
}

.btn-primary,
.btn-secondary {
    min-height: 40px;
    padding: 0.6rem 0.9rem;
    border-radius: 14px;
    border: none;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.88rem;
    transition: transform var(--transition-speed), background var(--transition-speed), border-color var(--transition-speed);
}

.btn-primary svg, .btn-secondary svg, .icon-btn svg {
    width: 16px;
    height: 16px;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    background: linear-gradient(135deg, var(--primary), #f08f57);
    color: white;
    box-shadow: 0 8px 16px rgba(239, 108, 77, 0.18);
}

.btn-primary:hover,
.btn-primary:focus-visible {
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.65);
    color: var(--text-main);
    border: 1px solid rgba(92, 70, 56, 0.1);
}

.btn-secondary:disabled,
.btn-primary:disabled,
.icon-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
    min-height: 40px;
    padding: 0.6rem 0.9rem;
    border-radius: 14px;
    font-weight: 700;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all var(--transition-speed);
}

.btn-danger:hover {
    background: #ef4444;
    color: white;
}

.modal-footer {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-top: 1.8rem;
}

.footer-right {
    display: flex;
    gap: 0.6rem;
    width: 100%;
}

.footer-right button,
.modal-footer .btn-danger {
    width: 100%;
    justify-content: center;
}

.calendar-container {
    min-height: 0;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.55rem;
}

.weekday {
    padding: 0.7rem 0.25rem;
    text-align: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-soft);
}

.day-cell {
    min-height: 96px;
    padding: 0.7rem 0.55rem;
    border-radius: 20px;
    background: rgba(255, 252, 247, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.82);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 0.42rem;
    transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}

.day-cell:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.day-cell.other-month {
    opacity: 0.42;
}

.day-cell.today {
    background: linear-gradient(180deg, rgba(255, 228, 214, 0.92), rgba(255, 248, 241, 0.96));
    border-color: rgba(239, 108, 77, 0.22);
}

.day-number {
    font-size: 0.85rem;
    font-weight: 700;
}

.today .day-number {
    color: var(--primary-deep);
}

.event-chip {
    padding: 0.38rem 0.45rem;
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: rgba(239, 108, 77, 0.08);
}

.event-chip-more {
    background: rgba(34, 27, 23, 0.06);
    color: var(--text-soft);
    border-left: none !important;
}

.daily-view {
    height: min(72vh, 840px);
    padding: 0.4rem;
    border-radius: 30px;
    background: linear-gradient(180deg, rgba(255, 252, 247, 0.96), rgba(255, 248, 242, 0.88));
    border: 1px solid rgba(255, 255, 255, 0.75);
    box-shadow: var(--shadow-lg);
    overflow: auto;
}

.timeline-grid {
    position: relative;
    min-height: calc(48 * var(--slot-height));
    padding-right: 0.35rem;
}

.time-slot {
    display: flex;
    min-height: var(--slot-height);
    border-bottom: 1px dashed rgba(92, 70, 56, 0.12);
}

.time-slot.hour-mark {
    border-bottom-color: rgba(92, 70, 56, 0.18);
}

.time-label {
    width: 50px;
    padding: 0.5rem 0.4rem 0 0;
    text-align: right;
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--text-soft);
    border-right: 1px solid var(--line);
    flex-shrink: 0;
}

.slot-content {
    position: relative;
    flex: 1;
}

.daily-event {
    position: absolute;
    left: 62px;
    right: 12px;
    padding: 0.5rem;
    border-radius: 18px;
    color: white;
    box-shadow: 0 16px 26px rgba(71, 42, 25, 0.18);
    cursor: grab;
    z-index: 4;
    user-select: none;
    overflow: hidden;
    touch-action: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.daily-event:active {
    cursor: grabbing;
}

.event-content {
    width: 100%;
    padding: 0 2rem; /* Give space for actions on edges if needed */
}

.daily-event h4 {
    margin-bottom: 0.2rem;
    font-size: 1.15rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.02em;
}

.daily-event span {
    font-size: 0.73rem;
    opacity: 0.92;
}

.event-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 0.35rem;
    opacity: 1;
    z-index: 10;
}

.edit-btn,
.delete-event-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.resize-handle {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: ns-resize;
}

.resize-handle::after {
    content: '';
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.42);
}

.time-indicator {
    position: absolute;
    left: 50px;
    right: 0;
    height: 2px;
    background: #ef4444;
    z-index: 10;
    pointer-events: none;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.past-dimmer {
    position: absolute;
    left: 50px;
    right: 0;
    background: rgba(30, 20, 10, 0.12);
    z-index: 2;
    pointer-events: none;
}

.time-indicator::before {
    content: '';
    position: absolute;
    left: -6px;
    top: -5px;
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: #df4a3a;
    box-shadow: 0 0 0 6px rgba(223, 74, 58, 0.1);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
    background: rgba(28, 20, 14, 0.38);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-speed), visibility var(--transition-speed);
    z-index: 40;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content.glass {
    width: min(100%, 560px);
    max-height: 88vh;
    overflow-y: auto;
    padding: 1.25rem;
    border-radius: 28px;
    background: rgba(255, 250, 244, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.78);
    box-shadow: var(--shadow-lg);
    transform: translateY(22px);
    transition: transform var(--transition-speed);
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-header,
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
}

.modal-header {
    margin-bottom: 1.4rem;
}

.modal-header h2 {
    font-size: 1.1rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.45rem;
    color: var(--text-soft);
    font-size: 0.84rem;
    font-weight: 700;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.95rem 1rem;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: white;
    color: var(--text-main);
    outline: none;
}

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

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: rgba(239, 108, 77, 0.48);
    box-shadow: 0 0 0 4px rgba(239, 108, 77, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.9rem;
}

.modal-footer {
    margin-top: 1.5rem;
    flex-direction: column-reverse;
}

.modal-footer .btn-primary,
.modal-footer .btn-secondary {
    width: 100%;
}

.fab-add {
    position: fixed;
    right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom));
    width: 62px;
    height: 62px;
    border: none;
    border-radius: 22px;
    background: linear-gradient(135deg, var(--primary), #f08955);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 20px 32px rgba(239, 108, 77, 0.26);
    z-index: 10;
    cursor: pointer;
}

.fab-add svg {
    width: 24px;
    height: 24px;
}

.active-interaction {
    opacity: 0.94;
}

@media (min-width: 700px) {
    .main-content {
        padding-left: 1.4rem;
        padding-right: 1.4rem;
    }

    .header-actions {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .view-navigation {
        width: min(100%, 560px);
    }

    .btn-primary {
        min-width: 144px;
    }

    .utility-btn {
        min-width: 148px;
    }

    .form-row {
        grid-template-columns: 1fr 1fr;
    }

    .modal-footer {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .footer-right {
        width: auto;
    }

    .modal-footer .btn-danger,
    .footer-right button {
        width: auto;
    }
}

@media (min-width: 1024px) {
    body {
        overflow: hidden;
    }

    .sidebar-overlay,
    .mobile-toolbar,
    .fab-add {
        display: none;
    }

    .sidebar {
        position: sticky;
        top: 1.4rem;
        left: auto;
        inset: auto;
        width: var(--sidebar-width);
        max-height: calc(100vh - 2.8rem);
        margin: 1.4rem 0 1.4rem 1.4rem;
        border-radius: 30px;
        transform: none;
        padding: 1.5rem;
    }

    .nav-menu {
        grid-template-columns: 1fr;
    }

    .main-content {
        padding: 1.4rem 1.4rem 1.4rem 1rem;
    }

    .main-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding: 1.2rem 1.5rem;
    }

    .header-collapsible {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        gap: 2rem;
    }

    .header-actions {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }

    .current-date-info {
        cursor: default;
    }

    .current-date-info h1 {
        font-size: 1.0rem;
    }

    .daily-view {
        height: calc(100vh - 230px);
    }

    .calendar-grid {
        gap: 0.8rem;
    }

    .day-cell {
        min-height: 132px;
        padding: 0.9rem 0.8rem;
    }

    .modal-overlay {
        align-items: center;
    }

    .modal-content.glass {
        padding: 1.6rem;
    }
}
