:root {
    --radius: 15px;
    /* Palette (from comment) */
    --coral: #EF6F6C;   /* Coral Red */
    --dark-slate: #465775; /* Dark Slate Blue */
    --sandy: #F7B074;   /* Sandy Orange */
    --maize: #FFF07C;   /* Maize (warning) */
    --celadon: #ACDD91; /* Celadon Green (success) */
    --mint: #59C9A5;    /* Mint (accent) */
    --dark-cyan: #50908D; /* Info */
    --cornflower: #4A90E2; /* Cornflower Blue */
    --violet: #715D73;   /* Violet accent */
    --rose: #9B6371;     /* Rose taupe */
    --cadet: #6C7A89;    /* Muted (darkened for a11y) */

    /* Semantic variables used in the site */
    --radius-medium: 0.75rem;
    --spacing-sm: 0.5rem;
    --primary: var(--dark-slate);
    --accent: var(--coral);
    --accent-2: var(--sandy);
    --accent-3: var(--mint);
    --success: var(--celadon);
    --warning: var(--maize);
    --info: var(--dark-cyan);
    --muted: var(--cadet);
    --bg: #f7f8fb; /* slightly lighter page bg */
    --card-bg: #ffffff;
    --border-color: rgba(16,24,40,0.05);
}

/* Dark Mode Overrides */
:root.dark,
body.dark {
    --bg: #0f172a;
    --card-bg: #1e293b;
    --primary: #a5b4fc; /* Brighter Indigo */
    --muted: #94a3b8;
    --border-color: #334155;
    color: #e2e8f0;
    
    /* Tweaked accents for dark mode contrast */
    --coral: #f87171;
    --dark-slate: #575fa9;
    --violet: #c084fc;
}

:root.dark .task-item,
body.dark .task-item,
:root.dark .card,
body.dark .card,
:root.dark .stat-card,
body.dark .stat-card,
:root.dark .action-card,
body.dark .action-card,
:root.dark .smart-add-box,
body.dark .smart-add-box,
:root.dark .nav-tab.active,
body.dark .nav-tab.active {
    background: var(--card-bg);
    border-color: #334155;
    color: #f1f5f9;
}

:root.dark .smart-add-box input,
body.dark .smart-add-box input,
:root.dark input,
body.dark input { color: white; }

:root.dark .input-wrapper input,
body.dark .input-wrapper input,
:root.dark .input-wrapper select,
body.dark .input-wrapper select {
    background: #0f172a; 
    border-color: #334155;
    color: white;
}

html { background-color: var(--bg); }
body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    background-color: var(--bg);
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

*:not(input) {
    user-select: none;
}

/* Shared header row used on inner pages (calendar/tasks/etc) */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding-bottom: 1rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}
.page-header h1 { margin: 0; }
.page-header_actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
/* Card / centered container used by login/signup pages */
.card {
    width: 360px;
    max-width: calc(100% - 2rem);
    margin: 3.5rem auto;
    background: var(--card-bg);
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius);
    box-shadow: 0 6px 20px rgba(16,24,40,0.08);
    color: #101828;
}
/* .card { font-family: ... } removed - moved to body */
.lead {
    color: var(--muted);
    margin: 0 0 1rem;
}

.btn-outline { background: transparent; color: var(--primary); border: 1px solid color-mix(in srgb, var(--primary) 12%, black 2%); font-weight:600; padding: 0.75rem 1rem; }

/* Floating label input wrapper */
.input-wrapper {
    position: relative;
    margin: 0.75rem 0 1rem;
}
.input-wrapper input,
.input-wrapper select {
    width: 100%;
    height: 48px; /* fixed height to allow consistent vertical centering */
    line-height: 48px; /* vertically center single-line text */
    padding: 0 0.9rem; /* left/right padding only; vertical centering handled by line-height */
    border: 1px solid #e6e6e6;
    border-radius: var(--radius);
    background: var(--card-bg);
    font-size: 1rem;
    outline: none;
    transition: box-shadow 0.2s ease, border-color 0.2s ease, padding 0.2s ease;
    /* ensure padding doesn't cause overflow inside narrow containers (modal) */
    box-sizing: border-box;
    max-width: 100%;
}
.input-wrapper input::placeholder { color: transparent; }
.input-wrapper label {
    position: absolute;
    left: 0.9rem;
    top: 30%; /* sit slightly above center when blurred */
    transform: translateY(-50%);
    transform-origin: left center;
    color: var(--muted);
    background: transparent;
    padding: 0 0.25rem;
    pointer-events: none;
    transition: transform .16s ease, top .16s ease, color .16s ease, font-size .16s ease;
}
.input-wrapper select + label,
.input-wrapper input:focus + label,
.input-wrapper input:not(:placeholder-shown) + label {
    /* move label further up so it clears the input center — increased offset */
    top: -1.2rem;
    transform: translateY(0) scale(0.82);
    color: var(--primary);
    background: var(--card-bg);
    padding: 0 0.35rem;
    font-size: 0.82rem;
}

/* input focus visual */
.input-wrapper input:focus,
.input-wrapper select:focus {
    border-color: color-mix(in srgb, var(--info) 85%, black 5%);
    box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 6%, transparent 94%);
}

/* Center text when the field is not active, align left when editing */
.input-wrapper input:not(:focus) {
    text-align: center;
}
.input-wrapper input:focus {
    text-align: left;
}

/* Select specific overrides to prevent "messed up" layout */
.input-wrapper select {
    text-align: left; /* Always left align selects */
    padding-right: 2rem; /* Make room for arrow if present */
    cursor: pointer;
}

/* Make inputs inside .card ignore the older generic input rules below */
.card input[type="text"],
.card input[type="email"],
.card input[type="password"] {
    width: 100%;
    height: 48px;
    line-height: 48px;
    padding: 0 0.9rem;
    font-size: 1rem;
    margin: 0;
    border-radius: var(--radius);
    box-sizing: border-box;
}

/* small pill-style icon/button used for toggles (show/hide password) */
.icon-btn {
    background: rgba(16,24,40,0.03);
    border: 1px solid rgba(16,24,40,0.06);
    color: var(--muted);
    padding: 0.22rem 0.5rem;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    min-width: 44px;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .12s ease, color .12s ease, transform .08s ease, border-color .12s ease;
}
.icon-btn:hover {
    background: rgba(16,24,40,0.06);
    color: var(--primary);
    transform: translateY(-1px);
}
.icon-btn:focus { outline: 2px solid color-mix(in srgb, var(--primary) 18%, transparent 82%); outline-offset: 2px; }
.icon-btn[aria-pressed="true"] {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* toggle button placed inside the input area on the right */
.input-wrapper { position: relative; }
.toggle-btn {
    position: absolute;
    right: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    background: rgba(16,24,40,0.03);
    border: 1px solid rgba(16,24,40,0.06);
    padding: 0.18rem 0.5rem;
    color: var(--muted);
    font-size: 0.85rem;
    border-radius: 999px;
    cursor: pointer;
}
.toggle-btn:hover { background: rgba(16,24,40,0.06); color: var(--primary); transform: translateY(calc(-50% - 1px)); }
.toggle-btn[aria-pressed="true"] { background: var(--primary); color: white; border-color: var(--primary); }
.input-wrapper input:not(:focus) { vertical-align: middle; }

/* Shared base for all button-like elements to keep a consistent rhythm */
.btn, .btn-outline, .icon-btn, .toggle-btn, .nav-day-btn, #createTaskBtn, button:not(.btn):not(.icon-btn):not(.btn-outline):not(.toggle-btn):not(.complete-btn) {
    font-family: inherit;
    font-weight: 700;
    border-radius: var(--radius);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease, color 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    line-height: 1;
    border: none;
}

/* Primary filled button (keeps full-width behavior for form CTAs) */
.btn {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--accent);
    color: white;
    box-shadow: 0 6px 18px rgba(16,24,40,0.06);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 10px 30px rgba(16,24,40,0.10); }

/* Day navigation buttons (Prev/Next) — give them unique colors and a compact shape */
.nav-day-btn {
    padding: 0.5rem 0.85rem;
    min-width: 88px;
    font-size: 0.95rem;
    border-radius: var(--radius);
    color: white;
    box-shadow: 0 6px 18px rgba(16,24,40,0.06);
}
.nav-day-btn.prev { background: var(--mint); }
.nav-day-btn.next { background: var(--mint); }
.nav-day-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 30px rgba(16,24,40,0.12); }
.nav-day-btn:focus { outline: 2px solid color-mix(in srgb, var(--primary) 18%, transparent 82%); outline-offset: 2px; }

/* Navigation row: make prev/date/next span the full width of the container
   Prev and Next sit at the edges, date takes remaining space and is centered. */
.nav-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
}
.nav-row #currentDateDisplay {
    flex: 1 1 auto;
    text-align: center;
    font-weight: 600;
}
.nav-row .nav-day-btn {
    flex: 0 0 auto;
}

.helper { font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; }
.muted-link { color: var(--violet); text-decoration: none; font-weight:600 }
.muted-link:hover { text-decoration: underline; color: var(--dark-slate); }
.row { display:flex; justify-content:space-between; align-items:center; }
.checkbox { display:flex; align-items:center; gap:0.5rem; }
.checkbox input { /* keep native input for accessibility but visually hide it while keeping it interactive */
    position: absolute;
    left: 0;
    width: 1.1rem;
    height: 1.1rem;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}
.checkbox { position: relative; display:flex; align-items:center; gap:0.5rem; }
.checkbox-custom {
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 0.35rem;
    border: 1px solid #d0d5db;
    background: white;
    display: inline-grid;
    place-items: center;
    transition: background .12s ease, border-color .12s ease, transform .12s ease;
}
.checkbox input:checked + .checkbox-custom {
    background: var(--success);
    border-color: color-mix(in srgb, var(--success) 80%, black 5%);
}
.checkbox input:checked + .checkbox-custom::after {
    content: '✓';
    color: white;
    font-size: 0.85rem;
    line-height: 1;
}

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: rgba(2, 6, 23, 0.45);
    backdrop-filter: blur(10px);
    z-index: 2020;

    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 140ms ease, visibility 0ms linear 140ms;
}

.modal.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 140ms ease;
}

.modal_panel {
    width: 520px;
    max-width: 100%;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: 0 24px 60px rgba(2, 6, 23, 0.28);
    overflow-x: hidden;

    max-height: calc(100vh - 2.5rem);
    display: flex;
    flex-direction: column;
    min-height: 0;

    opacity: 0;
    transform: translateY(10px) scale(0.98);
    transition: opacity 160ms ease, transform 160ms ease;
}

.modal.is-open .modal_panel {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.modal_panel--wide {
    width: 760px;
    max-width: 100%;
}

.modal_panel--narrow {
    width: 380px;
    max-width: 100%;
}

@media (prefers-reduced-motion: reduce) {
    .modal,
    .modal_panel {
        transition: none;
    }

    .modal_panel {
        transform: none;
    }
}

.modal_header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.modal_title {
    margin: 0;
    font-size: 1.25rem;
    line-height: 1.2;
    color: var(--primary);
}

.modal_subtitle {
    margin: 0.35rem 0 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.modal_close {
    min-width: 40px;
    height: 40px;
    border-radius: 999px;
    font-size: 1.25rem;
    line-height: 1;
}

.modal_body {
    padding: 1rem 1.25rem;
    display: grid;
    gap: 1rem;
    overflow: auto;
    min-height: 0;
}

.modal_body .input-wrapper {
    margin-bottom: .5rem;
}

.modal_footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
}

.modal_footer--split {
    justify-content: space-between;
    align-items: center;
}

.modal_footer .btn,
.modal_footer .btn-outline {
    width: auto;
}

.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 28px;
}

.switch input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.switch_track {
    width: 100%;
    height: 100%;
    border-radius: 999px;
    background: color-mix(in srgb, var(--muted) 30%, transparent 70%);
    border: 1px solid var(--border-color);
    transition: background 0.15s ease, border-color 0.15s ease;
}

.switch_thumb {
    position: absolute;
    left: 4px;
    top: 50%;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    transform: translateY(-50%);
    background: var(--card-bg);
    box-shadow: 0 6px 18px rgba(2, 6, 23, 0.12);
    transition: transform 0.15s ease;
    cursor: pointer;
}

.switch input:checked ~ .switch_track {
    background: var(--primary);
    border-color: color-mix(in srgb, var(--accent) 35%, var(--border-color) 65%);
}

.switch input:checked ~ .switch_thumb {
    transform: translate(20px, -50%);
}

.switch input:focus-visible ~ .switch_track {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.switch-row {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    user-select: none;
}

.switch-row_text {
    font-weight: 650;
    color: var(--primary);
}
.error { color: var(--accent); font-size:0.95rem; margin-top:0.5rem; }
/*footer {
    background-color: #465775;
    color: azure;
    text-align: center;
    padding: 10px 0;
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    z-index: 1000;
}*/
/* Use a column flex layout so the footer sits at the bottom when content is short,
    but remains in the normal flow (not fixed/sticky) so users can scroll away. */
footer {
    background: var(--dark-slate);
    color: white;
    text-align: center;
    width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    margin-top: auto;
}
h1{
    color: var(--violet);
    text-align: center;
    margin-top: 20px;
    font-weight: 700;
}
/* Generic page buttons — avoid overriding component buttons like .btn, .icon-btn, .btn-outline */
button:not(.btn):not(.icon-btn):not(.btn-outline):not(.toggle-btn):not(.complete-btn) {
    display: block;
    margin: 20px auto;
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 20px;
    cursor: pointer;
    font-size: 16px;
    border-radius: var(--radius);
}
button:not(.btn):not(.icon-btn):not(.btn-outline):not(.toggle-btn):not(.complete-btn):hover { filter: brightness(.95); transform: translateY(-1px); }
label {
    display: block;
    margin: 10px 0;
    font-weight: bold;
    align-content: center;
}
/* Removed broad input styling that conflicted with .input-wrapper and .card input rules. */
section {
    max-width: 80%;
    margin: 0 auto;
    padding: 20px;
    /*background-color: white;*/
    border-radius: var(--radius);
}

/* Larger card used by the app pages so content can fill ~80% of the viewport */
.card.calendar-large {
    width: 80vw;          /* target 80% of the viewport width */
    max-width: 1200px;    /* don't get absurdly wide on very large screens */
    margin: 2rem auto;    /* center and give vertical spacing */
    box-sizing: border-box; /* include padding in width */
}

/* Responsive: Stack layout for mobile */
@media (max-width: 640px) {
    /* Full screen usage on mobile */
    .card, .card.calendar-large {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        min-height: 100vh;
        box-shadow: none !important;
        border: none !important;
        padding: 0.5rem;
    }

    footer {
        margin-top: 1rem;
    }
    
    /* Ensure body doesn't add scroll if card does */
    body {
        margin: 0;
        background: var(--card-bg); /* Seamless transition */
    }
}

/* --- Loading Spinner --- */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}
.btn-loading:after {
    content: "";
    position: absolute;
    top: 50%; left: 50%;
    width: 16px; height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(255,255,255,0.5);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s infinite linear;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* --- Toast Notifications --- */
#toast-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 10000;
}
.toast {
    background: white;
    color: #333;
    padding: 8px 12px;
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 250px;
    max-width: 350px;
    animation: slideIn 0.3s ease-out forwards;
    border-left: 4px solid var(--primary);
    font-size: 0.9rem;
}
.toast.success { border-left-color: var(--celadon); }
.toast.error { border-left-color: var(--coral); }
.toast.info { border-left-color: var(--dark-cyan); }
.toast.fade-out { animation: fadeOut 0.3s ease-in forwards; }

/* Dark mode toast polish */
:root.dark #toast-container,
body.dark #toast-container {
    left: auto;
    right: 20px;
}
:root.dark .toast,
body.dark .toast {
    background: #0f172a;
    color: #e2e8f0;
    box-shadow: 0 14px 40px rgba(0,0,0,0.55);
    border: 1px solid rgba(255,255,255,0.08);
}
:root.dark .toast.success,
body.dark .toast.success { border-left-color: #4ade80; }
:root.dark .toast.error,
body.dark .toast.error { border-left-color: #fb7185; }
:root.dark .toast.info,
body.dark .toast.info { border-left-color: #38bdf8; }
:root.dark .toast button,
body.dark .toast button {
    border-color: rgba(255,255,255,0.35) !important;
    color: #e2e8f0 !important;
    background: rgba(255,255,255,0.06) !important;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.04);
}

@keyframes slideIn {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
    to { opacity: 0; transform: translateY(10px); }
}

/* --- Accessibility & Focus --- */
button:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}



/* Confetti */
.confetti { position: fixed; width: 8px; height: 8px; z-index: 9999; pointer-events: none; opacity: 0.8; }
@keyframes fall { to { transform: translateY(100vh) rotate(720deg); opacity: 0; } }

/* Keyboard Keys */
kbd { background: #eee; border-radius: 3px; border: 1px solid #b4b4b4; box-shadow: 0 1px 1px rgba(0,0,0,.2); color: #333; display: inline-block; font-size: .85em; font-weight: 700; line-height: 1; padding: 2px 4px; white-space: nowrap; }
body.dark kbd { background: #333; border-color: #555; color: #eee; }