/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-bg: #f8f9fa;
    --color-surface: #ffffff;
    --color-primary: #4a90d9;
    --color-primary-hover: #357abd;
    --color-text: #212529;
    --color-text-muted: #6c757d;
    --color-border: #dee2e6;
    --color-error: #dc3545;
    --color-error-bg: #f8d7da;
    --color-success: #28a745;
    --color-muted-bg: #f0f0f0;
    --color-muted-border: #d0d0d0;
    --color-muted-text: #888;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== Dashboard ===== */
.dashboard {
    max-width: 960px;
    margin: 0 auto;
    padding: 1rem;
}

.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--color-border);
}

.dashboard-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

/* ===== Buttons ===== */
.btn-add-habit {
    background: var(--color-primary);
    color: #fff;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    min-width: 44px;
    transition: background 0.15s;
}

.btn-add-habit:hover,
.btn-add-habit:focus-visible {
    background: var(--color-primary-hover);
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

button:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ===== Loading / Empty / Error ===== */
.loading {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
    font-size: 1.1rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: var(--color-text-muted);
    font-size: 1.1rem;
}

.error-banner {
    background: var(--color-error-bg);
    color: var(--color-error);
    border: 1px solid var(--color-error);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-weight: 500;
}

.card-error {
    background: var(--color-error-bg);
    color: var(--color-error);
    border-radius: 4px;
    padding: 0.5rem;
    margin: 0.5rem 0;
    font-size: 0.85rem;
}

/* ===== Current Month Section ===== */
.current-month h2 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: var(--color-text);
}

.habits-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* ===== Habit Card ===== */
.habit-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow);
}

.habit-card-muted {
    background: var(--color-muted-bg);
    border-color: var(--color-muted-border);
    opacity: 0.85;
}

.habit-card-muted .habit-name {
    color: var(--color-muted-text);
}

.habit-card-muted .habit-description {
    color: var(--color-muted-text);
}

.habit-card-muted .habit-goal {
    color: var(--color-muted-text);
}

.habit-header {
    margin-bottom: 0.75rem;
}

.habit-name {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.habit-description {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.habit-goal {
    color: var(--color-text-muted);
    font-size: 0.85rem;
    font-style: italic;
}

/* ===== Day Grid ===== */
.day-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-top: 0.5rem;
}

.day-checkbox-wrapper,
.day-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.day-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.1s;
    min-width: 36px;
    min-height: 36px;
    justify-content: center;
}

.day-label:hover {
    background: rgba(74, 144, 217, 0.08);
}

.day-number {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: 2px;
    user-select: none;
}

.day-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--color-primary);
    cursor: pointer;
}

.day-label input[type="checkbox"]:disabled {
    cursor: default;
    opacity: 0.4;
}

.day-label input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Muted day indicators (previous months) */
.day-indicator .day-label {
    cursor: default;
}

.day-indicator .day-label:hover {
    background: transparent;
}

.day-indicator input[type="checkbox"] {
    accent-color: var(--color-muted-text);
}

/* ===== Previous Months ===== */
.previous-months {
    margin-top: 2rem;
}

.prev-months-heading {
    font-size: 1.2rem;
    color: var(--color-text-muted);
    margin-bottom: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}

.month-group {
    margin-bottom: 1.5rem;
}

.month-heading {
    font-size: 1.1rem;
    color: var(--color-text-muted);
    margin-bottom: 0.75rem;
}

/* ===== Add Habit Form ===== */
.add-habit-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}

.add-habit-form {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.add-habit-form h2 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

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

.form-field label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

.form-field input,
.form-field textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.15s;
}

.form-field input:focus,
.form-field textarea:focus {
    border-color: var(--color-primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

.form-field textarea {
    min-height: 60px;
    resize: vertical;
}

.form-error {
    background: var(--color-error-bg);
    color: var(--color-error);
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.form-actions button {
    flex: 1;
    padding: 0.6rem 1rem;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    min-height: 44px;
    transition: background 0.15s;
}

.form-actions button[type="submit"] {
    background: var(--color-primary);
    color: #fff;
    border: none;
}

.form-actions button[type="submit"]:hover {
    background: var(--color-primary-hover);
}

.form-actions button[type="submit"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-bg);
}

/* ===== Login Page ===== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-container {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
    text-align: center;
}

.login-container h1 {
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.login-subtitle {
    color: var(--color-text-muted);
    margin-bottom: 1.5rem;
    font-size: 1.1rem;
}

.login-form h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    text-align: left;
}

.login-form .form-field {
    text-align: left;
}

.login-form .form-actions {
    margin-top: 1.25rem;
}

.login-form .form-actions button {
    width: 100%;
}

.login-toggle {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.login-toggle a {
    color: var(--color-primary);
    text-decoration: none;
}

.login-toggle a:hover {
    text-decoration: underline;
}

/* ===== Header Actions ===== */
.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn-logout {
    background: transparent;
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
    padding: 0.6rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
    min-height: 44px;
    transition: background 0.15s, color 0.15s;
}

.btn-logout:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
    .dashboard {
        padding: 0.75rem;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .dashboard-header h1 {
        font-size: 1.25rem;
    }

    .day-grid {
        grid-template-columns: repeat(7, 1fr);
        gap: 2px;
    }

    .day-label {
        min-width: 28px;
        min-height: 28px;
        padding: 2px;
    }

    .day-number {
        font-size: 0.65rem;
    }

    .day-label input[type="checkbox"] {
        width: 16px;
        height: 16px;
    }

    .habit-card {
        padding: 0.75rem;
    }

    .add-habit-form {
        padding: 1rem;
    }
}

@media (min-width: 768px) {
    .dashboard {
        padding: 2rem;
    }

    .dashboard-header h1 {
        font-size: 1.75rem;
    }
}
