/**
 * Habit Tracker Styles
 * Supports both light and dark modes
 */

/* Remove max-width from editor-page when habit tracker is active */
body.note-type-habit .editor-page {
    max-width: none;
    padding-left: 40px;
    padding-right: 40px;
}

.habit-tracker-wrapper {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    background: var(--content-bg);
    color: var(--text-primary);
}

/* Header Section */
.habit-tracker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.habit-tracker-title-section {
    display: flex;
    align-items: center;
    gap: 16px;
}

.habit-tracker-title {
    font-size: 24px;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.habit-add-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.habit-add-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.habit-add-btn:active {
    transform: translateY(0);
}

/* Week Navigation */
.habit-week-nav {
    display: flex;
    align-items: center;
    gap: 12px;
}

.habit-nav-btn,
.habit-today-btn {
    padding: 8px 12px;
    background: var(--content-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.habit-nav-btn:hover,
.habit-today-btn:hover {
    background: var(--hover-bg, #f5f5f5);
    border-color: var(--accent-color);
}

.habit-today-btn {
    font-weight: 500;
    padding: 8px 16px;
}

/* Dark mode overrides for navigation */
body.dark .habit-nav-btn:hover,
body.dark .habit-today-btn:hover {
    background: var(--hover-bg, #2a2a2a);
}

/* Empty State */
.habit-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-secondary);
    text-align: center;
}

.habit-empty-state i {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.habit-empty-state p {
    margin: 8px 0;
    font-size: 16px;
}

.habit-empty-subtitle {
    font-size: 14px;
    opacity: 0.7;
}

/* Habit Grid */
.habit-grid-container {
    position: relative;
}

.habit-grid {
    background: var(--content-bg);
    border-radius: 8px;
    overflow-x: visible;
    overflow-y: hidden;
    border: 1px solid var(--border-color);
}

/* Scrollbar styling */
.habit-grid::-webkit-scrollbar {
    height: 8px;
}

.habit-grid::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

.habit-grid::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    transition: background 0.2s;
}

.habit-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

body.dark .habit-grid::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

body.dark .habit-grid::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

body.dark .habit-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.habit-grid-header {
    display: grid;
    grid-template-columns: 250px repeat(7, 1fr) 100px;
    gap: 1px;
    background: var(--border-color);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.habit-name-header,
.habit-day-header,
.habit-streak-header {
    background: var(--sidebar-bg, #f8f8f8);
    padding: 12px;
    text-align: center;
    color: var(--text-secondary);
}

.habit-name-header {
    text-align: left;
}

.habit-day-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 8px;
}

.habit-day-header.today {
    background: var(--accent-color);
    color: white;
}

.habit-day-name {
    font-size: 11px;
}

.habit-day-num {
    font-size: 16px;
    font-weight: 600;
}

.habit-month-year {
    font-size: 9px;
    opacity: 0.7;
    margin-top: 2px;
}

/* Dark mode grid header */
body.dark .habit-name-header,
body.dark .habit-day-header,
body.dark .habit-streak-header {
    background: #252525;
}

body.dark .habit-day-header.today {
    background: var(--accent-color);
}

/* Habit Rows */
.habit-row {
    display: grid;
    grid-template-columns: 250px repeat(7, 1fr) 100px;
    gap: 1px;
    background: var(--border-color);
}

/* Days container - desktop shows as grid cells, mobile shows as grid */
.habit-days-container {
    display: contents; /* On desktop, children act as direct grid items */
}

/* Hide day labels on desktop (shown in header instead) */
.habit-day-label,
.habit-day-date {
    display: none;
}

.habit-name-cell,
.habit-day-cell,
.habit-streak-cell {
    background: var(--content-bg);
    padding: 12px;
}

/* Name Cell */
.habit-name-cell {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

.habit-name-cell:hover .habit-actions {
    opacity: 1;
}

.habit-color-indicator {
    width: 4px;
    height: 32px;
    border-radius: 2px;
    flex-shrink: 0;
}

.habit-name-text {
    flex: 1;
    font-weight: 500;
    font-size: 15px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.habit-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.habit-action-btn {
    padding: 6px 8px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
}

.habit-action-btn:hover {
    background: var(--hover-bg, #f0f0f0);
    color: var(--text-primary);
}

body.dark .habit-action-btn:hover {
    background: #2a2a2a;
}

/* Day Cells */
.habit-day-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 12px 8px;
}

.habit-day-cell.future {
    opacity: 0.3;
}

/* Habit Checkbox */
.habit-checkbox {
    width: 36px;
    height: 36px;
    border: 2px solid;
    border-radius: 8px;
    background: transparent;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.habit-checkbox:not(.checked):hover {
    transform: scale(1.1);
    opacity: 0.7;
}

.habit-checkbox.checked {
    transform: scale(1);
}

.habit-checkbox:disabled {
    cursor: not-allowed;
    opacity: 0.2;
}

.habit-checkbox i {
    font-size: 16px;
}

/* Streak Cell */
.habit-streak-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 60px; /* Prevent content shift when trophy appears */
}

.habit-streak-current {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 18px;
    font-weight: 600;
    color: var(--accent-color);
    height: 28px; /* Fixed height to prevent shift */
}

.habit-streak-current i {
    font-size: 20px;
}

.habit-streak-best {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1;
    height: 18px; /* Fixed height - always reserves space */
}

.habit-streak-best i {
    font-size: 12px;
    color: #fbbf24;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
}

/* Stats Footer */
.habit-stats-footer {
    display: flex;
    justify-content: space-around;
    margin-top: 24px;
    margin-bottom: 24px;
    padding: 20px;
    background: var(--sidebar-bg, #f8f8f8);
    border-radius: 8px;
    gap: 16px;
    flex-wrap: wrap;
}

body.dark .habit-stats-footer {
    background: #252525;
}

.habit-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.habit-stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.habit-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent-color);
}

/* Responsive Design */
@media (max-width: 1200px) {
    .habit-grid-header,
    .habit-row {
        grid-template-columns: 250px repeat(7, 1fr) 100px;
    }

    .habit-tracker-title {
        font-size: 20px;
    }
}

@media (max-width: 900px) {
    body.note-type-habit .editor-page {
        padding-left: 24px;
        padding-right: 24px;
    }
}

@media (max-width: 780px) {
    /* Switch to card-based layout on mobile */
    .habit-grid {
        display: flex;
        flex-direction: column;
        gap: 12px;
        overflow-x: visible;
        border: none;
        background: transparent;
    }

    .habit-grid-header {
        display: none; /* Hide header on mobile */
    }

    .habit-row {
        display: flex;
        flex-direction: column;
        background: var(--content-bg);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 16px;
        gap: 12px;
    }

    .habit-name-cell {
        padding: 0;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 12px;
    }

    .habit-name-text {
        font-size: 16px;
    }

    /* Days grid within each habit card */
    .habit-days-container {
        display: grid;
        grid-template-columns: repeat(7, 1fr);
        gap: 8px;
    }

    .habit-day-cell {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        padding: 8px 4px;
        background: transparent;
    }

    .habit-day-label {
        display: block; /* Show on mobile */
        font-size: 11px;
        color: var(--text-secondary);
        font-weight: 600;
        text-transform: uppercase;
    }

    .habit-day-date {
        display: block; /* Show on mobile */
        font-size: 10px;
        color: var(--text-secondary);
    }

    .habit-checkbox {
        width: 36px;
        height: 36px;
    }

    .habit-streak-cell {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        padding: 12px 0 0 0;
        border-top: 1px solid var(--border-color);
    }

    .habit-stats-footer {
        flex-direction: column;
        gap: 12px;
        margin-bottom: 20px;
    }

    .habit-stat {
        flex-direction: row;
        justify-content: space-between;
        width: 100%;
    }
}

@media (max-width: 600px) {
    body.note-type-habit .editor-page {
        padding-left: 12px;
        padding-right: 12px;
    }

    .habit-tracker-wrapper {
        padding: 0 0 80px 0; /* Add bottom padding for mobile */
    }

    .habit-tracker-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-bottom: 16px;
        padding: 12px 12px 0;
    }

    .habit-tracker-title-section {
        flex-direction: column;
        align-items: stretch;
    }

    .habit-add-btn {
        justify-content: center;
        width: 100%;
        padding: 12px 16px;
        font-size: 15px;
    }

    .habit-week-nav {
        justify-content: center;
    }

    .habit-nav-btn,
    .habit-today-btn {
        padding: 10px 16px;
        font-size: 15px;
    }

    .habit-grid-container {
        margin: 0;
    }

    .habit-grid {
        gap: 10px;
    }

    .habit-row {
        padding: 12px;
    }

    .habit-name-cell {
        gap: 8px;
        padding-bottom: 10px;
    }

    .habit-name-text {
        font-size: 15px;
    }

    .habit-name-input {
        font-size: 14px;
        padding: 6px 8px;
    }

    .habit-color-indicator {
        width: 3px;
        height: 28px;
    }

    .habit-actions {
        opacity: 1; /* Always show on mobile */
    }

    .habit-action-btn {
        padding: 6px 8px;
        font-size: 12px;
    }

    .habit-days-container {
        gap: 6px;
    }

    .habit-day-cell {
        padding: 6px 2px;
    }

    .habit-day-label {
        display: block; /* Ensure shown on small mobile */
        font-size: 10px;
    }

    .habit-day-date {
        display: block; /* Ensure shown on small mobile */
        font-size: 9px;
    }

    .habit-checkbox {
        width: 32px;
        height: 32px;
    }

    .habit-streak-cell {
        padding-top: 10px;
        gap: 8px;
    }

    .habit-streak-current {
        font-size: 14px;
    }

    .habit-streak-current i {
        font-size: 16px;
    }

    .habit-streak-current {
        height: 22px; /* Smaller fixed height for mobile */
    }

    .habit-streak-best {
        font-size: 11px;
        height: 16px; /* Fixed height for mobile */
    }

    .habit-streak-best i {
        width: 11px;
        height: 11px;
        font-size: 11px;
    }

    .habit-stats-footer {
        flex-direction: column;
        gap: 12px;
        padding: 16px 12px;
        margin: 16px 0 20px;
    }

    .habit-stat {
        flex-direction: row;
        justify-content: space-between;
        width: 100%;
        padding: 4px 0;
    }

    .habit-stat-label {
        font-size: 12px;
    }

    .habit-stat-value {
        font-size: 20px;
    }

    .habit-empty-state {
        padding: 60px 20px;
    }

    .habit-empty-state i {
        font-size: 48px;
    }

    .habit-empty-state p {
        font-size: 15px;
    }

    .habit-empty-subtitle {
        font-size: 13px;
    }
}

/* Animations */
@keyframes habitCheckIn {
    0% {
        transform: scale(0.8);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* Only apply animation when specifically triggered, not on every render */
.habit-checkbox.checking-in {
    animation: habitCheckIn 0.3s ease;
}

/* Inline Editing */
.habit-name-input {
    flex: 1;
    font-weight: 500;
    font-size: 15px;
    color: var(--text-primary);
    border: 1px solid transparent;
    background: transparent;
    padding: 6px 8px;
    border-radius: 4px;
    outline: none;
    transition: all 0.2s ease;
}

.habit-name-input:hover {
    background: var(--hover-bg, #f5f5f5);
    border-color: var(--border-color);
}

.habit-name-input:focus {
    background: white;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(80, 202, 89, 0.1);
}

body.dark .habit-name-input:hover {
    background: #2a2a2a;
}

body.dark .habit-name-input:focus {
    background: #1d1d1d;
    box-shadow: 0 0 0 2px rgba(80, 202, 89, 0.2);
}

/* Modal Styles */
.habit-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.habit-modal-content {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 480px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    max-height: 90vh;
    overflow-y: auto;
}

.habit-modal-content.habit-modal-sm {
    max-width: 400px;
}

.habit-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color, #f0f0f0);
}

.habit-modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.habit-modal-close {
    background: transparent;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.habit-modal-close:hover {
    background: var(--hover-bg, #f0f0f0);
    color: var(--text-primary);
}

.habit-modal-body {
    padding: 24px;
}

.habit-modal-body p {
    margin: 0;
    color: var(--text-primary);
    line-height: 1.6;
}

.habit-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color, #f0f0f0);
}

.habit-form-group {
    margin-bottom: 20px;
}

.habit-form-group:last-child {
    margin-bottom: 0;
}

.habit-form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.habit-form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 6px;
    font-size: 15px;
    color: var(--text-primary);
    background: var(--content-bg);
    outline: none;
    transition: all 0.2s ease;
}

.habit-form-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(80, 202, 89, 0.1);
}

.habit-color-picker {
    margin-top: 8px;
}

.habit-color-presets {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.habit-color-preset {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.habit-color-preset:hover {
    transform: scale(1.1);
}

.habit-color-preset.selected {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
}

.habit-btn-primary,
.habit-btn-secondary,
.habit-btn-danger {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.habit-btn-primary {
    background: var(--accent-color);
    color: white;
}

.habit-btn-primary:hover {
    background: var(--accent-hover, #3da449);
    transform: translateY(-1px);
}

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

.habit-btn-secondary:hover {
    background: var(--hover-bg, #f5f5f5);
}

.habit-btn-danger {
    background: #e74c3c;
    color: white;
}

.habit-btn-danger:hover {
    background: #c0392b;
    transform: translateY(-1px);
}

/* Dark mode modal styles */
body.dark .habit-modal-content {
    background: #1d1d1d;
}

body.dark .habit-modal-header {
    border-bottom-color: #353535;
}

body.dark .habit-modal-footer {
    border-top-color: #353535;
}

body.dark .habit-modal-close:hover {
    background: #252525;
}

body.dark .habit-form-input {
    background: #252525;
    border-color: #353535;
    color: #d4d4d4;
}

body.dark .habit-form-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(80, 202, 89, 0.2);
}

body.dark .habit-btn-secondary {
    background: transparent;
    border-color: #353535;
    color: #d4d4d4;
}

body.dark .habit-btn-secondary:hover {
    background: #252525;
}

/* Dark mode specific adjustments */
body.dark .habit-tracker-wrapper {
    background: var(--content-bg);
}

body.dark .habit-grid {
    border-color: #2a2a2a;
}

body.dark .habit-grid-header,
body.dark .habit-row {
    background: #2a2a2a;
}

body.dark .habit-name-cell,
body.dark .habit-day-cell,
body.dark .habit-streak-cell {
    background: #1d1d1d;
}

/* Dark mode: Mobile card layout */
@media (max-width: 780px) {
    body.dark .habit-row {
        background: #1d1d1d;
        border-color: #2a2a2a;
    }

    body.dark .habit-name-cell {
        border-bottom-color: #2a2a2a;
    }

    body.dark .habit-streak-cell {
        border-top-color: #2a2a2a;
    }

    body.dark .habit-day-cell {
        background: transparent;
    }
}
