/* ==============================
   Habits & Calendar Page
   ============================== */
.habits-layout {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 24px;
    align-items: start;
}

.habits-view-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.habits-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 16px;
}

.habit-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

/* Habit Card */
.habit-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 16px;
    transition: all var(--transition-normal);
    animation: fadeIn 0.5s ease;
}
.habit-card:hover {
    border-color: var(--green-500);
    box-shadow: var(--shadow-blue);
}
.habit-card.habit-failed {
    opacity: 0.55;
    border-color: var(--red-500);
}
.habit-card.habit-failed:hover {
    box-shadow: none;
    border-color: var(--red-500);
}
.habit-card.habit-complete {
    border-color: var(--gold-400);
}
.habit-card.habit-complete:hover {
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.2);
}

.habit-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.habit-card-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 600;
}
.habit-card-name .habit-emoji {
    font-size: 1.2rem;
}
.habit-streak {
    font-size: 0.8rem;
    color: var(--orange-400);
    font-weight: 600;
}

/* Habit Meta (status + progress) */
.habit-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 8px;
}
.habit-status-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    letter-spacing: 0.5px;
}
.habit-status-badge.active {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red-400);
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.habit-status-badge.danger {
    background: rgba(239, 68, 68, 0.25);
    color: #ff6b6b;
    border: 1px solid rgba(239, 68, 68, 0.5);
    animation: pulse 2s ease-in-out infinite;
}
.habit-status-badge.failed {
    background: rgba(239, 68, 68, 0.2);
    color: var(--red-400);
    border: 1px solid var(--red-500);
}
.habit-status-badge.complete {
    background: rgba(251, 191, 36, 0.15);
    color: var(--gold-400);
    border: 1px solid rgba(251, 191, 36, 0.3);
}
.habit-progress-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ===== Calendar View ===== */
.habit-calendar {
    margin-bottom: 12px;
    background: rgba(10, 14, 25, 0.5);
    border-radius: var(--radius-md);
    padding: 12px;
    border: 1px solid var(--border-subtle);
}
.cal-header {
    text-align: center;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--purple-400);
    margin-bottom: 10px;
    letter-spacing: 1px;
}
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
}
.cal-day-label {
    text-align: center;
    font-size: 0.6rem;
    color: var(--text-muted);
    font-weight: 600;
    padding: 4px 0;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.cal-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    border-radius: 4px;
    color: var(--text-secondary);
    background: rgba(74, 158, 255, 0.05);
    border: 1px solid rgba(74, 158, 255, 0.08);
    transition: all 0.2s;
    position: relative;
}
.cal-cell.empty {
    background: transparent;
    border: none;
}
.cal-cell.inactive {
    opacity: 0.25;
}
.cal-cell.today {
    border-color: var(--blue-400);
    box-shadow: 0 0 8px rgba(74, 158, 255, 0.3);
    font-weight: 700;
    color: var(--blue-400);
}
.cal-cell.done {
    background: rgba(34, 197, 94, 0.2);
    border-color: rgba(34, 197, 94, 0.4);
    font-size: 0.75rem;
}
.cal-cell.missed {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
    font-size: 0.75rem;
}
.cal-cell.disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* Habit Done Button */
.habit-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.habit-done-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid var(--green-500);
    border-radius: var(--radius-sm);
    color: var(--green-400);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-body);
    flex: 1;
}
.habit-done-btn:hover {
    background: rgba(34, 197, 94, 0.3);
    box-shadow: var(--green-glow);
}
.habit-done-btn.checked {
    background: var(--green-500);
    color: #000;
}
.habit-done-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.habit-delete-btn {
    padding: 6px 10px;
    background: none;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.habit-delete-btn:hover {
    border-color: var(--red-500);
    color: var(--red-400);
    background: rgba(239, 68, 68, 0.1);
}

/* ===== Habit Goals Sidebar ===== */
.habit-goals {
    padding: 20px;
    position: sticky;
    top: 120px;
}
.habit-goals h3 {
    margin-bottom: 16px;
    font-size: 1.1rem;
}

.habit-goals-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 500px;
    overflow-y: auto;
}

.habit-goal-card {
    background: rgba(20, 25, 35, 0.6);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 14px;
    transition: border-color var(--transition-fast);
}
.habit-goal-card:hover {
    border-color: var(--blue-400);
}
.habit-goal-card.goal-failed {
    opacity: 0.55;
    border-color: var(--red-500);
}

.habit-goal-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 6px;
}
.habit-goal-days {
    font-size: 0.8rem;
    color: var(--orange-400);
    margin-bottom: 8px;
}
.habit-goal-rewards {
    font-size: 0.8rem;
    margin-bottom: 8px;
}

/* Miss Bar */
.habit-goal-miss-bar {
    margin-bottom: 8px;
}
.miss-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 4px;
}
.miss-bar-track {
    height: 6px;
    background: rgba(74, 158, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
}
.miss-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--orange-400), var(--red-400));
    border-radius: 3px;
    transition: width 0.5s ease;
}
.miss-bar-fill.danger {
    background: linear-gradient(90deg, var(--red-400), #ff3333);
    animation: pulse 1.5s ease-in-out infinite;
}

.habit-goal-status {
    font-size: 0.8rem;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-subtle);
    font-weight: 600;
}
.habit-goal-status.won { color: var(--gold-400); }
.habit-goal-status.lost { color: var(--red-400); }
.habit-goal-status.active { color: var(--blue-400); }
.habit-goal-status.neutral { color: var(--text-muted); }

@media (max-width: 900px) {
    .habits-layout {
        grid-template-columns: 1fr;
    }
    .habit-goals {
        position: static;
    }
    .habit-grid {
        grid-template-columns: 1fr;
    }
}

/* ==============================
   Gym Habit Specific Styles
   ============================== */
.gym-habit {
    border-color: rgba(249, 115, 22, 0.4);
}
.gym-badge {
    display: inline-block;
    padding: 1px 8px;
    background: linear-gradient(135deg, var(--orange-500), var(--red-500));
    color: #fff;
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 2px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
}

.rest-days-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid var(--border-subtle);
}

/* Excuse Buttons (Gym Closed / Rest Day) */
.habit-excuse-btn {
    padding: 6px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-body);
    white-space: nowrap;
}
.gym-closed-btn:hover {
    background: rgba(251, 191, 36, 0.15);
    border-color: var(--gold-400);
    color: var(--gold-400);
}
.rest-day-btn:hover {
    background: rgba(156, 163, 175, 0.15);
    border-color: #9ca3af;
    color: #9ca3af;
}

/* Excused button state */
.habit-done-btn.excused {
    background: rgba(251, 191, 36, 0.15);
    border-color: var(--gold-400);
    color: var(--gold-400);
    cursor: default;
}

/* Calendar: Excused day cells */
.cal-cell.excused-closed {
    background: rgba(251, 191, 36, 0.2);
    color: var(--gold-400);
    border-color: var(--gold-500);
    font-size: 0.7rem;
}
.cal-cell.excused-rest {
    background: rgba(156, 163, 175, 0.15);
    color: #9ca3af;
    border-color: #4b5563;
    font-size: 0.7rem;
}
