:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --danger-color: #ef4444;
    --success-color: #10b981;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Views */
.view {
    display: none;
    height: 100%;
}

.view.active {
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* Login View */
#login-view {
    align-items: center;
    justify-content: center;
    text-align: center;
}

.login-container {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    max-width: 400px;
    width: 90%;
}

.login-container h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.login-container p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* Buttons */
button {
    cursor: pointer;
    border: none;
    border-radius: 0.375rem;
    padding: 0.5rem 1rem;
    font-weight: 500;
    transition: background-color 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    width: 100%;
}

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

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

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

/* App View Layout */
header {
    background: var(--card-bg);
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.header-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.month-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-weight: 600;
}

.month-nav button {
    background: transparent;
    font-size: 1.25rem;
    padding: 0.25rem 0.5rem;
}

.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar h2 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#habit-list {
    list-style: none;
    flex: 1;
    margin-bottom: 1rem;
}


/* Sidebar Habit Toggle */
.habit-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    /* Compact padding */
    background: var(--bg-color);
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    /* Reduced margin */
    gap: 0.75rem;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}

/* Control Area (Checkbox only) */
.habit-control {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    /* Reduced width */
    padding-right: 0;
}

.habit-checkbox {
    width: 20px;
    /* Standard size */
    height: 20px;
    cursor: pointer;
    accent-color: var(--success-color);
}

.habit-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    justify-content: center;
}

.habit-name {
    font-weight: 600;
    font-size: 0.95rem;
    /* Slightly smaller */
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.text-muted {
    color: var(--text-secondary);
    font-weight: 400;
}

.text-xs {
    font-size: 0.75rem;
}

.habit-stats {
    font-size: 0.7rem;
    /* Compact stats */
    color: var(--text-secondary);
    display: flex;
    gap: 0.5rem;
    margin-top: 0.1rem;
}

#add-habit-form {
    display: flex;
    gap: 0.5rem;
}

#habit-name-input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
}

#add-habit-btn {
    background: var(--primary-color);
    color: white;
    font-size: 1.25rem;
    padding: 0 1rem;
}

/* Calendar */
.calendar-container {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
}

.calendar-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    background: var(--card-bg);
    padding: 1rem 0;
    border-radius: 0.5rem 0.5rem 0 0;
    border-bottom: 1px solid var(--border-color);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border-color);
    border: 1px solid var(--border-color);
}

.calendar-day {
    background: var(--card-bg);
    min-height: 80px;
    /* Reduced since no habits inside */
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Center date */
    justify-content: center;
}

.calendar-day.today {
    border: 2px solid var(--primary-color);
    /* Highlight today border */
}

/* Removed simple .completed-today in favor of inline style for progressive */
.calendar-day.text-white .day-number,
.text-white {
    color: white !important;
}

.day-number {
    font-weight: 600;
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.day-habit {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
    cursor: pointer;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
}

.day-habit:hover {
    background-color: var(--bg-color);
}

.day-habit.completed {
    text-decoration: line-through;
    color: var(--text-secondary);
    opacity: 0.7;
}

.day-habit input[type="checkbox"] {
    cursor: pointer;
}

/* Feature: Weekly Summary (Global) */
.weekly-summary {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 0.5rem;
    margin-top: 1rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.summary-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: none;
}

.summary-label {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.9rem;
    text-align: center;
    margin-top: 0.5rem;
}

.progress-bar-bg {
    background-color: #d1d5db;
    height: 16px;
    border-radius: 8px;
    overflow: hidden;
    width: 100%;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.progress-bar-fill {
    background: linear-gradient(90deg, var(--success-color), #34d399);
    height: 100%;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 8px;
    min-width: 0;
}

/* Feature: Missed Day (Global) */
.calendar-day.missed-day {
    background-color: #fee2e2;
    /* Light Red */
}

/* Responsive */
@media (max-width: 768px) {
    .main-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        max-height: 300px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .calendar-container {
        padding: 1rem;
    }

    .calendar-day {
        min-height: 80px;
        padding: 0.25rem;
    }

    .day-habit span {
        display: none;
        /* Hide habit name on small screens, show color dot/checkbox only? */
    }

    /* Better solution for mobile calendar habits: maybe just a dot */
    .day-habit {
        justify-content: center;
    }

    /* Feature: Weekly Summary */
    .weekly-summary {
        background: var(--card-bg);
        padding: 1rem;
        border-radius: 0.5rem;
        margin-top: 1rem;
        /* Added margin since it is now below */
        box-shadow: var(--shadow);
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .summary-text {
        font-size: 0.9rem;
        color: var(--text-secondary);
        display: none;
    }

    .summary-label {
        font-weight: 600;
        color: var(--primary-color);
        font-size: 0.9rem;
        text-align: center;
        /* Center text */
    }

    .progress-bar-bg {
        background-color: #d1d5db;
        /* Darker gray for visibility */
        height: 16px;
        /* Taller */
        border-radius: 8px;
        overflow: hidden;
        width: 100%;
        box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
        /* Inner shadow */
    }

    .progress-bar-fill {
        background: linear-gradient(90deg, var(--success-color), #34d399);
        /* Gradient fill */
        height: 100%;
        transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
        /* Smooth transition */
        border-radius: 8px;
        min-width: 0;
    }



    /* Feature: Form & Targets */
    #add-habit-form {
        flex-direction: column;
        /* Changed from row */
    }

    .form-row {
        display: flex;
        gap: 0.5rem;
        width: 100%;
    }

    #habit-target-type {
        padding: 0.5rem;
        border: 1px solid var(--border-color);
        border-radius: 0.375rem;
        background: white;
        font-size: 0.85rem;
    }

    .habit-target-input {
        width: 60px;
        padding: 0.25rem;
        border: 1px solid var(--border-color);
        border-radius: 0.25rem;
        text-align: center;
    }

    /* Hide checkbox when number input is present */
    /* Checkbox always allowed now */
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 0.5rem;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.modal-content h3 {
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.modal-content p {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-form label {
    font-weight: 500;
    font-size: 0.9rem;
}

.modal-form select,
.modal-form input {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    width: 100%;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1rem;
}