/* ---
Modern UI Enhancement for Compounding Habits App
- Professional, clean, and motivating design system
- Dark mode support
- Enhanced readability and accessibility
- Subtle animations for a dynamic feel
--- */

:root {
    --primary-hue: 210;
    --secondary-hue: 230;
    --success-hue: 145;
    --warning-hue: 45;
    --danger-hue: 0;
    --info-hue: 185;
    --orange-hue: 30;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'Fira Code', 'monospace';

    /* Light Mode (Default) */
    --bg-color: #f8f9fa;
    --bg-offset-color: #ffffff;
    --font-color: #212529;
    --font-muted-color: #6c757d;
    --border-color: #dee2e6;
    --shadow-color: 220, 15%, 40%;
    --shadow: 0 2px 4px rgba(var(--shadow-color), 0.04), 0 5px 15px rgba(var(--shadow-color), 0.08);
    --primary-color: hsl(var(--primary-hue), 100%, 50%);
    --primary-hover: hsl(var(--primary-hue), 100%, 45%);
    --primary-gradient: linear-gradient(45deg, hsl(var(--primary-hue), 100%, 50%), hsl(var(--primary-hue), 100%, 60%));
}

[data-theme="dark"] {
    --bg-color: #121212;
    --bg-offset-color: #1e1e1e;
    --font-color: #e9ecef;
    --font-muted-color: #adb5bd;
    --border-color: #343a40;
    --shadow-color: 0, 0%, 0%;
    --shadow: 0 4px 12px rgba(var(--shadow-color), 0.3);
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-color);
    color: var(--font-color);
    margin: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s, color 0.3s;
}

.app-container {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 250px;
    background-color: var(--bg-offset-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.sidebar-header {
    margin-bottom: 2rem;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    color: var(--font-muted-color);
    text-decoration: none;
    font-weight: 600;
}

.nav-item.active, .nav-item:hover {
    background-color: hsla(var(--primary-hue), 100%, 50%, 0.1);
    color: var(--primary-color);
}

.sidebar-footer {
    margin-top: auto;
}

.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

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

header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0;
}

header p {
    font-size: 1rem;
    color: var(--font-muted-color);
    margin-top: 0.25rem;
}

.user-profile {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--font-muted-color);
}


#dashboard {
    max-width: 1200px;
    margin: 0 auto;
}

#dashboard-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.summary-item {
    background-color: var(--bg-offset-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
}

.summary-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.summary-label {
    font-size: 0.9rem;
    color: var(--font-muted-color);
}


#goals-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

/* --- Goal Card Redesign --- */
.goal-card {
    background-color: var(--bg-offset-color);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.goal-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 8px rgba(var(--shadow-color), 0.06), 0 8px 20px rgba(var(--shadow-color), 0.12);
}

.goal-title {
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
    font-weight: 600;
}

.goal-target {
    font-size: 1rem;
    font-weight: 500;
    color: var(--font-muted-color);
    margin: 0 0 1rem 0;
}

.goal-meta {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem 1rem;
    margin-bottom: 1rem;
    color: var(--font-muted-color);
    font-size: 0.9rem;
}

.goal-meta div {
    display: flex;
    justify-content: space-between;
}

.goal-meta span {
    font-weight: 600;
    color: var(--font-color);
}

/* --- Progress Bar --- */
.progress-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.progress-bar {
    background-color: var(--border-color);
    width: 100%;
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary-gradient);
    width: 0%;
    transition: width 0.4s ease-in-out;
    border-radius: 5px;
}

.progress-label {
    min-width: 40px;
    text-align: right;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--primary-color);
}

/* --- Action Buttons --- */
.log-section {
    display: flex;
    gap: 0.5rem;
    margin-top: auto; /* Pushes to bottom */
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
}

.log-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--bg-color);
    color: var(--font-color);
    font-family: var(--font-sans);
    font-size: 0.9rem;
}

.action-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.goal-streak, .goal-lastlogged {
    font-size: 0.85rem;
    color: var(--font-muted-color);
    margin-top: 1rem;
    margin-bottom: 0;
}

/* --- Buttons General --- */
button {
    padding: 0.6rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

button:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
    filter: brightness(1);
}

.add-button {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
    background-color: transparent;
    color: var(--primary-color);
    border: 2px dashed var(--primary-color);
}
.add-button:hover {
    background-color: hsla(var(--primary-hue), 100%, 50%, 0.1);
}

.log-button {
    background: var(--primary-gradient);
    color: white;
}
.apply-button {
    background-color: hsl(var(--success-hue), 55%, 45%);
    color: white;
}
.info-button {
    background-color: hsl(var(--info-hue), 60%, 50%);
    color: white;
}
.edit-button {
    background-color: hsl(var(--warning-hue), 100%, 50%);
    color: #212529;
}
.delete-button {
    background-color: hsl(var(--danger-hue), 70%, 50%);
    color: white;
}
.reset-button {
    background-color: hsl(var(--secondary-hue), 15%, 50%);
    color: white;
}


/* --- Modal Redesign --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}
.modal-overlay[style*="display: flex;"] {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: var(--bg-offset-color);
    padding: 2rem;
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.95);
    transition: transform 0.3s;
}

.modal-overlay[style*="display: flex;"] .modal-content {
    transform: scale(1);
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--font-muted-color);
    background: none;
    border: none;
    padding: 0.5rem;
    line-height: 1;
}

#new-goal-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem 1.5rem;
}

#new-goal-form h3 {
    grid-column: span 2;
    text-align: center;
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

#new-goal-form label {
    font-weight: 600;
    grid-column: span 1;
}

#new-goal-form input[type="text"],
#new-goal-form input[type="number"] {
    grid-column: span 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    background-color: var(--bg-color);
    color: var(--font-color);
}

#new-goal-form .radio-group {
    grid-column: span 2;
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

#new-goal-form button[type="submit"] {
    grid-column: span 2;
    background: var(--primary-gradient);
    color: white;
    padding: 0.8rem;
    font-size: 1.1rem;
    margin-top: 1rem;
}

/* --- Info Modal --- */
.info-modal-header {
    text-align: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.info-modal-header h3 {
    margin: 0;
    font-size: 1.75rem;
}

.info-modal-header p {
    margin: 0.25rem 0 0;
    color: var(--font-muted-color);
    font-size: 1rem;
}

.info-modal-body {
    padding: 0 1rem;
}

#info-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
    text-align: center;
}

.info-stat-item {
    background-color: var(--bg-color);
    padding: 1.25rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.info-stat-label {
    display: block;
    font-size: 0.9rem;
    color: var(--font-muted-color);
    margin-bottom: 0.5rem;
}

.info-stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
}

.info-modal-footer {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}
.graph-area {
    width: 100%;
    margin: 0 auto;
}

#goal-graph {
    width: 100%;
    height: 300px; /* Adjust as needed */
    border-radius: 8px;
}

.motivational {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 0;
    padding: 1.25rem;
    background: linear-gradient(45deg, hsla(var(--primary-hue), 100%, 50%, 0.05), hsla(var(--success-hue), 60%, 50%, 0.05));
    border-radius: 8px;
    color: var(--font-muted-color);
    text-align: center;
    font-style: italic;
    font-size: 1rem;
}

.motivational[style*="display: flex;"] {
    display: flex !important;
}

.motivational i {
    color: hsl(var(--orange-hue), 90%, 55%);
    width: 24px;
    height: 24px;
}

/* Modal projection preview */
.modal-projection {
    grid-column: span 2;
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 8px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
}
#modal-projection-chart {
    height: 100px !important;
}

.projection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}
.projection-header strong {
    font-size: 1rem;
}
.projection-stats {
    text-align: right;
    font-size: 0.9rem;
    color: var(--font-muted-color);
}
.radio-group label {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* --- Theme Switcher --- */
.theme-switcher {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-toggle-checkbox {
    display: none;
}

.theme-toggle-label {
    display: block;
    position: relative;
    width: 50px;
    height: 26px;
    border-radius: 13px;
    background-color: var(--primary-color);
    cursor: pointer;
    transition: background-color 0.3s;
}

.theme-toggle-label::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: white;
    transition: transform 0.3s;
}

.theme-toggle-checkbox:checked + .theme-toggle-label {
    background-color: var(--font-muted-color);
}

.theme-toggle-checkbox:checked + .theme-toggle-label::after {
    transform: translateX(24px);
}

/* --- Empty State --- */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
    background-color: var(--bg-offset-color);
    border: 2px dashed var(--border-color);
    border-radius: 12px;
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-top: 0;
}

.empty-state p {
    color: var(--font-muted-color);
    margin-bottom: 0;
}

/* Mobile responsive adjustments (only affect small screens) */
@media (max-width: 900px) {
    body {
        padding: 1rem;
    }

    .app-container {
        display: block;
    }

    .sidebar {
        display: none; /* hide sidebar on small screens to preserve desktop layout */
    }

    .main-content {
        margin: 0;
        width: 100%;
    }

    header {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
    }

    header h1 { font-size: 1.4rem; }
    header p { font-size: 0.95rem; }

    #goals-container {
        grid-template-columns: 1fr; /* single column cards on phones */
        gap: 1rem;
    }

    .goal-card {
        padding: 1rem;
        border-radius: 10px;
    }

    /* Mobile: compact goal card improvements */
    .goal-card .goal-title {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem;
        font-size: 1.05rem;
        margin-bottom: 0.25rem;
    }

    .goal-target {
        font-size: 0.95rem;
        color: var(--font-muted-color);
        margin-bottom: 0.5rem;
    }

    /* make meta rows tighter and stacked */
    .goal-meta {
        grid-template-columns: 1fr;
        gap: 0.25rem 0.5rem;
        margin-bottom: 0.75rem;
    }
    .goal-meta div { font-size: 0.9rem; }

    /* highlight rate as a small badge */
    .goal-rate {
        display: inline-block;
        background: linear-gradient(90deg, rgba(0,123,255,0.12), rgba(0,123,255,0.08));
        color: var(--primary-color);
        padding: 0.25rem 0.5rem;
        border-radius: 8px;
        font-weight: 700;
        font-size: 0.85rem;
    }

    /* larger progress bar for touch */
    .progress-container { gap: 0.5rem; }
    .progress-bar { height: 12px; }
    .progress-fill { border-radius: 8px; }
    .progress-label { font-size: 0.9rem; }

    /* Actions: make primary actions full-width but keep a compact action row for secondary actions */
    .log-section { display: flex; gap: 0.5rem; align-items: center; }
    .log-input { flex: 1; }
    .log-section .log-button, .log-section .apply-button { flex: 0 0 auto; }

    .action-row { display: flex; gap: 0.5rem; justify-content: space-between; margin-top: 0.6rem; }
    .action-row button { flex: 1; padding: 0.6rem; font-size: 0.95rem; }

    /* compact icon buttons if present */
    .icon-button { width: 44px; height: 44px; padding: 0; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; }

    .goal-streak, .goal-lastlogged { font-size: 0.82rem; color: var(--font-muted-color); }

    /* ensure dropdowns and menus are touch-friendly */
    .dropdown-content { min-width: 120px; }

    .goal-meta {
        grid-template-columns: 1fr;
    }

    .progress-container { gap: 0.5rem; }
    .progress-bar { height: 12px; }
    .progress-label { min-width: 34px; font-size: 0.85rem; }

    .log-section {
        flex-direction: column;
        gap: 0.5rem;
        padding-top: 0.75rem;
    }

    .log-input { width: 100%; }
    .log-section button { width: 100%; }

    .action-row { flex-direction: column; gap: 0.5rem; }
    .action-row button { width: 100%; }

    .goal-streak, .goal-lastlogged { font-size: 0.8rem; }

    /* Modal adjustments for small screens */
    .modal-content {
        width: calc(100% - 2rem);
        max-width: 100%;
        padding: 1rem;
        border-radius: 8px;
        max-height: 85vh;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    /* Make Add/Edit modal slightly narrower than full-width on mobile for improved focus */
    #add-goal-modal .modal-content {
        width: calc(100% - 3rem);
        max-width: 480px; /* cap width on small devices */
        margin: 0 1rem;
    }

    /* Apply centered, breathable modal style for Add Goal on mobile (similar to Info modal) */
    #add-goal-modal {
        align-items: center; /* center vertically */
        justify-content: center;
    }
    #add-goal-modal .modal-content.add-goal-modal {
        width: clamp(320px, 90%, 520px);
        max-width: 94%;
        max-height: 78vh; /* keep it compact */
        padding: 0.75rem 0.85rem;
        border-radius: 12px;
        display: flex;
        flex-direction: column;
    }
    /* Reduce header weight/size for mobile add modal */
    #add-goal-modal .modal-content.add-goal-modal h3 {
        font-size: 1.15rem;
        font-weight: 600;
        margin: 0.75rem 0;
    }
    /* Make the form scroll independently inside the modal content */
    #add-goal-modal #new-goal-form {
        overflow-y: auto;
        max-height: calc(78vh - 120px);
        padding: 0.5rem 0.5rem 0.75rem 0.5rem;
        display: block;
    }
    /* Slightly smaller inputs on mobile to balance the layout */
    #add-goal-modal input[type="text"],
    #add-goal-modal input[type="number"] {
        padding: 0.6rem;
        font-size: 0.95rem;
    }
    /* Compact submit button but keep it tappable */
    #add-goal-modal button[type="submit"] {
        position: static;
        width: 100%;
        margin-top: 0.75rem;
        padding: 0.75rem;
        border-radius: 8px;
    }

    /* Center Info modal on small screens and make it breathing/responsive */
    #info-modal {
        align-items: center; /* override potential global top-alignment */
        justify-content: center;
    }
    #info-modal .modal-content {
        /* breathable width between small phones and larger devices */
        width: clamp(320px, 88%, 520px);
        max-width: 92%;
        max-height: 75vh; /* reduce height to keep it compact */
        padding: 0.5rem 0.75rem;
        border-radius: 12px;
        box-shadow: var(--shadow);
    }

    /* Reduce header font-size/weight and tighten spacing for mobile Info modal */
    #info-modal .info-modal-header { padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--border-color); }
    #info-modal .info-modal-header h3 { font-size: 1.15rem; font-weight: 600; margin: 0 0 0.15rem 0; }
    #info-modal .info-modal-header p { font-size: 0.9rem; margin: 0; color: var(--font-muted-color); }

    /* Make chart area smaller and more compact on mobile */
    #info-modal .info-modal-body .graph-area { height: 200px; }
    #info-modal #goal-graph { height: 100% !important; }

    /* Reduce stat font sizes/weights for better balance and readability */
    #info-stats-grid .info-stat-label { font-size: 0.85rem; }
    #info-stats-grid .info-stat-value { font-size: 1.05rem; font-weight: 600; color: var(--primary-color); }

    /* Keep close button reachable on small screens */
    .modal-content > .close-btn {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
        z-index: 6;
        background: transparent;
        padding: 0.5rem;
        border-radius: 6px;
    }

    /* Make the form area grow so modal header stays visible */
    #new-goal-form { flex: 1 1 auto; overflow: visible; }

    /* Make projection area larger and touch-friendly */
    .modal-projection { padding: 0.75rem; display: block; }
    .projection-chart-wrap { height: 140px; }
    #modal-projection-chart { width: 100% !important; height: 140px !important; }

    /* Info modal: sticky header and scrollable body to keep charts visible */
    /* Scoped to the Info modal so desktop behavior remains unchanged */
    #info-modal .modal-content { padding: 0; max-width: 520px; width: calc(100% - 1rem); border-radius: 12px; display: flex; flex-direction: column; }
    #info-modal .info-modal-header { position: sticky; top: 0; z-index: 8; background: var(--bg-offset-color); padding: 1rem; border-bottom: 1px solid var(--border-color); }
    #info-modal .info-modal-header h3 { margin-bottom: 0.25rem; }
    #info-modal .info-modal-header p { margin: 0; }

    /* Make the body scroll independently and reserve space for header/footer */
    #info-modal .info-modal-body { padding: 0.75rem 1rem 1rem; overflow-y: auto; max-height: calc(85vh - 140px); }
    #info-modal .info-modal-body { padding: 0.75rem 1rem 1rem; overflow-y: auto; max-height: calc(85vh - 140px); display: block; }
    #info-modal .info-modal-body .graph-area { width: 100%; margin: 0 0 0.75rem 0; height: 260px; }
    #info-modal .info-modal-body { flex: 1 1 auto; }
    #info-modal #goal-graph { width: 100% !important; height: 100% !important; display: block; }

    /* Footer pinned to bottom of modal, but not covering content (transparent gradient) */
    #info-modal .info-modal-footer { position: sticky; bottom: 0; z-index: 9; background: linear-gradient(180deg, rgba(0,0,0,0.00), rgba(0,0,0,0.03)); padding: 0.75rem 1rem; border-top: 1px solid var(--border-color); }

    /* Info stats: grid of small stat cards for touch */
    #info-stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.6rem; margin-top: 0.75rem; }
    #info-stats-grid .info-stat-item { background: var(--bg-offset-color); border: 1px solid var(--border-color); padding: 0.9rem; border-radius: 8px; }
    #info-stats-grid .info-stat-value { margin-top: 0.35rem; font-size: 1.15rem; color: var(--primary-color); font-weight: 700; }
    /* Legend and small layout tweaks for touch */
    .graph-legend { display: flex; gap: 0.75rem; justify-content: center; align-items: center; flex-wrap: wrap; margin-bottom: 0.5rem; }
    .legend-item { font-size: 0.95rem; color: var(--font-muted-color); display: inline-flex; gap: 0.5rem; align-items: center; }
    .legend-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; }
    .legend-swatch.actual { background: #ff7f0e; }
    .legend-swatch.expected { background: #4dabf7; }

    @media (max-width: 480px) {
        #info-stats-grid { grid-template-columns: 1fr; }
        #goal-graph { height: 180px; }
        .projection-chart-wrap { height: 110px; }
        #modal-projection-chart { height: 110px !important; }
        /* make add-goal modal narrower on very small screens */
        #add-goal-modal .modal-content { max-width: 380px; width: calc(100% - 2rem); }
        /* Make info modal stats slightly larger and more readable on tiny screens */
        #info-stats-grid .info-stat-item { padding: 1rem; }
        #info-stats-grid .info-stat-label { font-size: 0.95rem; }
        #info-stats-grid .info-stat-value { font-size: 1.15rem; font-weight: 600; }

        /* Ensure Info modal remains centered on very small screens */
        #info-modal { align-items: center; }
        #info-modal .modal-content { width: clamp(300px, 94%, 420px); max-height: 72vh; }
    }

    #new-goal-form { grid-template-columns: 1fr; }
    #new-goal-form h3, #new-goal-form label, #new-goal-form .radio-group {
        grid-column: span 1;
    }
    #new-goal-form .radio-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .modal-projection { grid-column: span 1; }
    .projection-chart-wrap { height: 120px; }
    #modal-projection-chart { width: 100% !important; height: 120px !important; }

    /* Info modal layout tweaks */
    .info-modal-body { display: block; }
    .graph-area { width: 100%; }
    #goal-graph { height: 220px; }

    .info-modal-footer { padding-top: 1rem; }

    /* Make buttons and controls slightly larger/tappable */
    button { padding: 0.8rem; font-size: 1rem; }
}
/* --- Add Goal Modal Mobile UI Improvements --- */
@media (max-width: 768px) {
    /* Center the modal on small devices and make it compact (not full-screen) */
    .modal-overlay {
        align-items: center;
        justify-content: center;
        padding: 1rem;
    }

    .modal-content.add-goal-modal {
        width: clamp(320px, 92%, 520px);
        max-width: 94%;
        max-height: 80vh;
        border-radius: 12px;
        background-color: var(--bg-offset-color);
        display: flex;
        flex-direction: column;
        padding: 0.75rem;
        box-shadow: var(--shadow);
    }

    /* Make the form scroll inside the modal; header should scroll naturally (not sticky) */
    #add-goal-modal #new-goal-form {
        padding: 0.5rem 0.5rem 0.75rem 0.5rem;
        overflow-y: auto;
        flex: 1 1 auto;
        display: block;
        gap: 0.5rem;
    }

    /* Header is part of the scrollable content (non-sticky) and centered */
    #add-goal-modal h3 {
        position: relative;
        top: auto;
        background: transparent;
        padding: 0.5rem 0;
        margin: 0 0 0.5rem 0;
        text-align: center;
        font-size: 1.15rem;
        font-weight: 600;
    }

    /* Keep the submit button inside the modal flow (not fixed) so it appears below the form */
    #add-goal-modal button[type="submit"] {
        position: static;
        margin-top: 0.5rem;
        width: 100%;
        padding: 0.75rem;
        border-radius: 8px;
        box-shadow: none;
    }

    /* Inputs and labels: stacked full-width for clarity on small screens */
    #add-goal-modal label { display: block; margin-bottom: 0.25rem; font-weight: 600; }
    #add-goal-modal input[type="text"],
    #add-goal-modal input[type="number"] { width: 100%; box-sizing: border-box; }
}

/* Extra-small screens */
@media (max-width: 480px) {
    body { padding: 0.5rem; }
    header h1 { font-size: 1.1rem; }
    header p { font-size: 0.9rem; }
    .modal-content { padding: 0.75rem; }
    .progress-bar { height: 14px; }
    #goal-graph { height: 200px; }
}

/* --- Card Footer & Actions --- */
.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
}

.log-section {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    border-top: none;
    padding-top: 0;
}

.action-menu {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.icon-button {
    background: transparent;
    color: var(--font-muted-color);
    padding: 0.5rem;
    border-radius: 50%;
}
.icon-button:hover {
    background-color: var(--border-color);
    color: var(--font-color);
}
.icon-button i {
    width: 18px;
    height: 18px;
}

.dropdown {
    position: relative;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 5px);
    background-color: var(--bg-offset-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    z-index: 10;
    width: 120px;
    overflow: hidden;
}

.dropdown-content.show {
    display: block;
}

.dropdown-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    color: var(--font-color);
}
.dropdown-item:hover {
    background-color: var(--border-color);
}

.info-button { color: hsl(var(--info-hue), 80%, 50%); }
.edit-button { color: hsl(var(--warning-hue), 90%, 50%); }
.delete-button { color: hsl(var(--danger-hue), 70%, 50%); }
.reset-button { color: hsl(var(--secondary-hue), 20%, 50%); }
