/* --- Components --- */

/* Title */
.title {
    font-size: clamp(1.8em, 4vw, 2.5em);
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 0.5ch;
}
.title-text {
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Buttons & Controls */
.control-btn {
    background: var(--light-surface);
    border: 1px solid var(--light-border);
    border-radius: 25px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    color: var(--light-text);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    min-height: 44px; /* Ensure minimum touch target size */
    touch-action: manipulation; /* Optimize for touch interactions */
    -webkit-tap-highlight-color: transparent; /* Remove default touch highlight */
    user-select: none; /* Prevent text selection on touch */
}
.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}

/* Touch device specific styles */
.control-btn:active {
    transform: translateY(0px) scale(0.98);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Help button specific styles for better accessibility */
#help-btn {
    position: relative;
    z-index: 100; /* Ensure it's above other elements */
    pointer-events: auto; /* Ensure it receives pointer events */
}

#help-btn:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Additional touch-friendly states for help button */
#help-btn:active {
    background: var(--primary-color);
    color: white;
    transform: translateY(0px) scale(0.95);
}

/* Ensure touch targets are accessible on smaller screens */
@media (max-width: 768px) {
    .control-btn {
        min-height: 48px; /* Larger touch target on mobile */
        padding: 10px 18px;
    }
}

/* Category Name Suggestions */
.name-input-container {
    position: relative;
    width: 100%;
}

.name-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--light-surface);
    border: 2px solid var(--light-border);
    border-top: none;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
    max-height: 240px;
    overflow-y: auto;
    z-index: 1000;
    backdrop-filter: blur(12px);
    animation: slideDownFade 0.15s ease-out;
}

@keyframes slideDownFade {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.name-suggestion-section {
    padding: 12px 0 8px 0;
    border-bottom: 1px solid var(--light-border);
}

.name-suggestion-section:last-child {
    border-bottom: none;
    padding-bottom: 12px;
}

.name-suggestion-title {
    font-size: 0.8em;
    font-weight: 700;
    color: var(--light-text);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 0 16px;
    margin-bottom: 8px;
    opacity: 0.7;
}

.name-suggestion-item {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 0.95em;
    color: var(--light-text);
    transition: all 0.15s cubic-bezier(0.4, 0.0, 0.2, 1);
    border: none;
    background: none;
    width: calc(100% - 16px);
    text-align: left;
    display: block;
    min-height: 44px; /* Mobile touch target */
    border-radius: 8px;
    margin: 2px 8px;
    line-height: 1.4;
}

.name-suggestion-item:hover {
    background: var(--primary-color);
    color: white;
    transform: translateX(4px);
    box-shadow: 0 2px 8px rgba(129, 140, 248, 0.3);
}

.name-suggestion-item:active {
    transform: translateX(2px) scale(0.98);
}

.name-suggestion-item.recent {
    color: var(--primary-color);
    font-weight: 500;
}

.name-suggestion-item.smart {
    color: var(--primary-color);
    font-weight: 600;
    background: rgba(129, 140, 248, 0.08);
    border-left: 3px solid var(--primary-color);
    padding-left: 13px;
}

.name-suggestion-item.smart:hover {
    background: var(--primary-color);
    color: white;
    border-left-color: transparent;
}

.name-suggestion-item.popular {
    color: var(--light-text-secondary);
    font-weight: 400;
}

/* Dark theme support for name suggestions */
html[data-theme="midnight"] .name-suggestions {
    background: var(--midnight-surface);
    border-color: var(--midnight-border);
}

html[data-theme="midnight"] .name-suggestion-section {
    border-bottom-color: var(--midnight-border);
}

html[data-theme="midnight"] .name-suggestion-title {
    color: var(--midnight-text);
}

html[data-theme="midnight"] .name-suggestion-item {
    color: var(--midnight-text);
}

html[data-theme="midnight"] .name-suggestion-item:hover {
    background: var(--primary-color);
    color: white;
}

html[data-theme="midnight"] .name-suggestion-item.recent {
    color: var(--primary-color);
}

html[data-theme="midnight"] .name-suggestion-item.smart {
    color: var(--primary-color);
    background: rgba(129, 140, 248, 0.12);
    border-left-color: var(--primary-color);
}

html[data-theme="midnight"] .name-suggestion-item.popular {
    color: var(--midnight-text-secondary);
}
#today-btn.active {
    background-color: var(--primary-color);
    color: white;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);
    transform: translateY(1px);
}

.home-year-btn {
    animation: slideIn 0.3s ease-out;
}

.home-year-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}

.home-year-btn svg {
    margin-right: 4px;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Undo toast notification */
.undo-toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    animation: slideUp 0.3s ease-out forwards;
}

.undo-content {
    background: var(--light-surface);
    border: 1px solid var(--light-border);
    border-radius: 25px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(10px);
    min-width: 280px;
}

.undo-content span {
    color: var(--light-text);
    font-weight: 500;
    flex: 1;
}

.undo-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 18px;
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.undo-btn:hover {
    background: var(--indigo-400);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(129, 140, 248, 0.4);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* * --- OPTIMIZED STAT CARD STYLES --- */
.stat-card {
    flex: 0 0 180px;
    padding: 18px;
    border-radius: 16px;
    text-align: center;
    border: 1px solid var(--light-border);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    background-color: var(--light-surface);
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 110px;
    user-select: none;
    will-change: transform;
    transition: transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                border-color 0.2s ease,
                box-shadow 0.2s ease;
}

.stat-card:not(.stat-card-add):not(.overview-card){
    cursor: grab;
}
.stat-card::before {
    content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 4px;
    background: var(--color, var(--primary-color));
}

.stat-card:hover {
    transform: scale(1.04);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
}

.stat-card.active {
    transform: scale(1.04);
    box-shadow: 0 15px 30px rgba(129, 140, 248, 0.2);
    border-color: var(--primary-color);
}

/* SortableJS Classes */
.stat-card.sortable-ghost {
    opacity: 0.4;
    background: rgba(129, 140, 248, 0.1);
    border: 2px dashed var(--primary-color);
    box-shadow: none;
}
.stat-card.sortable-chosen {
    cursor: grabbing;
    transform: scale(1.05);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

/* Category list item sortable classes */
.category-list-item.sortable-ghost {
    opacity: 0.4;
    background: rgba(129, 140, 248, 0.1);
    border: 2px dashed var(--primary-color);
}
.category-list-item.sortable-chosen {
    cursor: grabbing;
    transform: scale(1.02);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
.category-list-item.sortable-drag {
    transform: rotate(2deg);
}

/* Mobile-optimized sortable fallback classes */
.sortable-fallback {
    display: none;
}

.stat-card.sortable-fallback {
    cursor: grabbing !important;
    transform: scale(1.1) !important;
    opacity: 0.8 !important;
    z-index: 9999 !important;
    background: var(--light-surface) !important;
    border: 2px solid var(--primary-color) !important;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2) !important;
    border-radius: 15px !important;
}

.category-list-item.sortable-fallback {
    cursor: grabbing !important;
    transform: scale(1.05) rotate(3deg) !important;
    opacity: 0.9 !important;
    z-index: 9999 !important;
    background: var(--light-surface) !important;
    border: 2px solid var(--primary-color) !important;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2) !important;
}

/* Touch device specific improvements */
@media (hover: none) and (pointer: coarse) {
    .stat-card {
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }
    
    .category-list-item {
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }
    
    /* Larger touch targets for mobile */
    .stat-card {
        min-height: 60px;
        padding: 12px 16px;
    }
    
    .category-list-item {
        min-height: 50px;
        padding: 12px 15px;
    }
    
    /* Better visual feedback for touch drag initiation */
    .stat-card:active,
    .category-list-item:active {
        background-color: rgba(129, 140, 248, 0.1);
        transform: scale(0.98);
    }
}

/* Walkthrough Styles */
.walkthrough-highlight {
    position: relative;
    z-index: 9999;
    box-shadow: 0 0 0 4px var(--primary-color), 0 0 0 8px rgba(129, 140, 248, 0.3) !important;
    border-radius: 8px !important;
    animation: walkthroughPulse 2s infinite;
}

@keyframes walkthroughPulse {
    0%, 100% { box-shadow: 0 0 0 4px var(--primary-color), 0 0 0 8px rgba(129, 140, 248, 0.3); }
    50% { box-shadow: 0 0 0 4px var(--primary-color), 0 0 0 12px rgba(129, 140, 248, 0.6); }
}

.walkthrough-popup {
    background: var(--light-surface);
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    max-width: 300px;
    backdrop-filter: blur(10px);
    animation: walkthroughSlideIn 0.3s ease-out;
}

@keyframes walkthroughSlideIn {
    from { opacity: 0; transform: scale(0.9) translateY(-10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.walkthrough-popup-content {
    padding: 20px;
}

.walkthrough-popup h4 {
    margin: 0 0 10px 0;
    color: var(--primary-color);
    font-size: 1.1em;
    font-weight: 600;
}

.walkthrough-popup p {
    margin: 0 0 15px 0;
    color: var(--light-text);
    line-height: 1.5;
    font-size: 0.95em;
}

.walkthrough-popup-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.walkthrough-popup-actions > div {
    display: flex;
    align-items: center;
    gap: 10px;
}

.walkthrough-progress {
    font-size: 0.85em;
    color: var(--light-text-secondary);
    font-weight: 500;
}

.walkthrough-skip, .walkthrough-next {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--light-border);
    background: var(--light-bg);
    color: var(--light-text);
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s ease;
}

.walkthrough-next {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    font-weight: 500;
}

.walkthrough-skip:hover {
    background: var(--light-border);
}

.walkthrough-next:hover {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
    transform: translateY(-1px);
}

.walkthrough-complete-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10001;
    animation: walkthroughSlideIn 0.3s ease-out;
}

.walkthrough-toast-content {
    background: var(--success-color);
    color: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 15px;
    max-width: 400px;
}

.walkthrough-toast-content button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
}

.walkthrough-toast-content button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Dark theme support for walkthrough */
html[data-theme="midnight"] .walkthrough-popup {
    background: var(--midnight-surface);
    border-color: var(--primary-color);
}

html[data-theme="midnight"] .walkthrough-popup p {
    color: var(--midnight-text);
}

html[data-theme="midnight"] .walkthrough-skip {
    background: var(--midnight-bg);
    border-color: var(--midnight-border);
    color: var(--midnight-text);
}

html[data-theme="midnight"] .walkthrough-skip:hover {
    background: var(--midnight-border);
}

/* Emoji Picker Styles */
.emoji-picker-container {
    position: relative;
    display: flex;
    align-items: center;
    gap: 2px;
}

.emoji-input {
    flex: 1;
    font-size: 1.2em;
    min-width: 80px;
    cursor: text;
    text-align: center;
    background-color: var(--light-surface);
    border: 1px solid var(--light-border);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    letter-spacing: 2px;
}

.emoji-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.2);
    outline: none;
}

.emoji-input::placeholder {
    opacity: 0.6;
    font-size: 0.9em;
}

.emoji-picker-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--light-surface);
    border: 1px solid var(--light-border);
    border-radius: 4px;
    padding: 4px;
    cursor: pointer;
    color: var(--primary-color);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.emoji-picker-btn svg {
    width: 16px;
    height: 16px;
    stroke-width: 2;
}

.emoji-picker-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    transform: translateY(-50%) scale(1.05);
}

/* Template Picker Button */
.name-input-with-template {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.name-input-with-template .name-input {
    flex: 1;
}

.template-picker-btn {
    background: var(--light-surface);
    border: 1px solid var(--light-border);
    border-radius: 4px;
    padding: 8px;
    cursor: pointer;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    transition: all 0.2s ease;
}

.template-picker-btn svg {
    width: 16px;
    height: 16px;
    stroke-width: 2;
}

.template-picker-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

.emoji-picker-popup {
    position: fixed;
    background: var(--light-surface);
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(16px);
    animation: emojiPickerSlideIn 0.3s ease-out;
    width: 380px;
    height: 450px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Template Picker Popup */
.template-picker-popup {
    position: fixed;
    background: var(--light-surface);
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(16px);
    animation: emojiPickerSlideIn 0.3s ease-out;
    width: 420px;
    max-height: 500px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 1000;
}

.template-picker-header {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--light-border);
    background: var(--light-bg);
}

.template-picker-header span {
    font-weight: 600;
    color: var(--light-text);
    font-size: 14px;
}

.template-picker-search {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--light-border);
    border-radius: 6px;
    background: var(--light-surface);
    color: var(--light-text);
    font-size: 13px;
}

.template-picker-search:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(46, 125, 253, 0.1);
}

.template-picker-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.template-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
}

.template-picker-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--light-border);
    border-radius: 6px;
    background: var(--light-surface);
    cursor: pointer;
    transition: all 0.2s ease;
}

.template-picker-card:hover {
    border-color: var(--primary-color);
    background: var(--primary-color-light, rgba(59, 130, 246, 0.05));
    transform: translateY(-1px);
}

.template-picker-card-emoji {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.template-picker-card-name {
    flex: 1;
    font-size: 12px;
    font-weight: 500;
    color: var(--light-text);
    line-height: 1.2;
}

.template-picker-card-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.1);
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
}

.template-search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--light-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    transition: background-color 0.2s ease, color 0.2s ease;
    padding: 0;
}

.template-search-clear:hover {
    background: var(--light-border);
    color: var(--light-text);
}

@keyframes emojiPickerSlideIn {
    from { opacity: 0; transform: scale(0.9) translateY(-10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.emoji-picker-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}


.emoji-picker-header {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--light-border);
    background: var(--light-bg);
}

.emoji-picker-header h4 {
    margin: 0;
    color: var(--primary-color);
    font-size: 1.1em;
    font-weight: 600;
}


.emoji-picker-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--light-text-secondary);
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.emoji-picker-close:hover {
    background: var(--danger-color);
    color: white;
}

.emoji-section {
    padding: 10px 15px;
    flex-shrink: 0;
}

.emoji-section:last-child {
    border-bottom: none;
}

.emoji-section-title {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--secondary-color);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    max-height: none;
}

.emoji-btn {
    background: none;
    border: 1px solid transparent;
    padding: 10px;
    border-radius: 8px;
    font-size: 1.5em; /* Increased from 1.2em */
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    min-width: 48px; /* Added minimum size */
    min-height: 48px;
}

.emoji-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    transform: scale(1.1);
}

.emoji-picker-tabs-container {
    display: flex;
    align-items: center;
    background: var(--light-bg);
    border-top: 1px solid var(--light-border);
    border-bottom: 1px solid var(--light-border);
    flex-shrink: 0;
}

.emoji-picker-tabs {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    flex: 1;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.emoji-nav-btn {
    background: var(--light-surface);
    border: none;
    width: 30px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    color: var(--primary-color);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.emoji-nav-btn:hover:not(:disabled) {
    background: var(--primary-color);
    color: white;
}

.emoji-nav-btn:disabled {
    cursor: not-allowed;
    color: var(--light-text-secondary);
}

.emoji-picker-tabs::-webkit-scrollbar {
    display: none;
}

.emoji-tab-item {
    background: none;
    border: none;
    padding: 8px 12px;
    font-size: 0.8em;
    font-weight: 500;
    cursor: pointer;
    color: var(--light-text-secondary);
    transition: all 0.2s ease;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    flex-shrink: 0;
}

.emoji-tab-item:hover {
    color: var(--primary-color);
    background: rgba(129, 140, 248, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(129, 140, 248, 0.2);
}

.emoji-tab-item.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: var(--light-surface);
}


.emoji-picker-categories {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.emoji-category {
    display: none;
    padding: 15px;
}

.emoji-category.active {
    display: block;
}

/* Emoji Search Styles */
.emoji-search-container {
    position: relative;
    padding: 10px 15px;
    border-bottom: 1px solid var(--light-border);
    flex-shrink: 0;
}

.emoji-search-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--light-border);
    border-radius: 6px;
    background: var(--light-surface);
    color: var(--light-text);
    font-size: 13px;
    box-sizing: border-box;
}

.emoji-search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(46, 125, 253, 0.1);
}

.emoji-search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--light-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    transition: background-color 0.2s ease, color 0.2s ease;
    padding: 0;
}

.emoji-search-clear:hover {
    background: var(--light-border);
    color: var(--light-text);
}

.emoji-search-results {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.emoji-no-results {
    text-align: center;
    color: var(--light-text-secondary);
    padding: 24px 16px;
    line-height: 1.5;
}

.emoji-no-results > div:first-child {
    font-weight: 500;
    margin-bottom: 8px;
}

.emoji-search-hint {
    font-size: 0.85em;
    color: var(--light-text-secondary);
    font-style: italic;
    opacity: 0.8;
}

.emoji-search-results .emoji-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    padding: 4px;
}

.emoji-search-results .emoji-btn {
    padding: 10px;
    transition: all 0.2s ease;
    position: relative;
}

.emoji-search-results .emoji-btn:hover {
    background: rgba(129, 140, 248, 0.1);
    border-color: var(--primary-color);
    transform: scale(1.05);
}

/* Dark theme support */
html[data-theme="midnight"] .emoji-picker-btn {
    background: var(--midnight-surface);
    border-color: var(--midnight-border);
    color: var(--primary-color);
}

html[data-theme="midnight"] .template-picker-btn {
    background: var(--midnight-surface);
    border-color: var(--midnight-border);
    color: var(--primary-color);
}

html[data-theme="midnight"] .emoji-picker-popup {
    background: var(--midnight-surface);
    border-color: var(--primary-color);
}

html[data-theme="midnight"] .template-picker-popup {
    background: var(--midnight-surface);
    border-color: var(--primary-color);
}

html[data-theme="midnight"] .template-picker-header {
    background: var(--midnight-bg);
    border-bottom-color: var(--midnight-border);
}

html[data-theme="midnight"] .template-picker-header span {
    color: var(--midnight-text);
}

html[data-theme="midnight"] .template-picker-search {
    background: var(--midnight-surface);
    border-color: var(--midnight-border);
    color: var(--midnight-text);
}

html[data-theme="midnight"] .template-picker-card {
    background: var(--midnight-surface);
    border-color: var(--midnight-border);
}

html[data-theme="midnight"] .template-picker-card-name {
    color: var(--midnight-text);
}

html[data-theme="midnight"] .template-search-clear:hover {
    background: var(--midnight-border);
    color: var(--midnight-text);
}

/* Template Picker Modal */
.template-picker-modal-content {
    max-width: 600px;
    max-height: 80vh;
}

.template-picker-modal-content .modal-body {
    padding: 20px;
    overflow-y: auto;
}

.template-picker-modal-content .template-picker-content {
    max-height: 400px;
    overflow-y: auto;
}

/* Emoji Picker Modal */
.emoji-picker-modal-content {
    max-width: 500px;
    max-height: 80vh;
}

.emoji-picker-modal-content .modal-body {
    padding: 20px;
    overflow-y: auto;
}

.emoji-picker-modal-content .emoji-picker-categories {
    max-height: 350px;
    overflow-y: auto;
}

html[data-theme="midnight"] .emoji-picker-header {
    background: var(--midnight-bg);
    border-bottom-color: var(--midnight-border);
}

html[data-theme="midnight"] .emoji-section {
    border-bottom-color: rgba(255,255,255,0.1);
}

html[data-theme="midnight"] .emoji-picker-tabs-container {
    background: var(--midnight-bg);
    border-top-color: var(--midnight-border);
    border-bottom-color: var(--midnight-border);
}

html[data-theme="midnight"] .emoji-nav-btn {
    background: var(--midnight-surface);
    color: var(--primary-color);
}

html[data-theme="midnight"] .emoji-nav-btn:hover:not(:disabled) {
    background: var(--primary-color);
    color: white;
}

html[data-theme="midnight"] .emoji-nav-btn:disabled {
    color: var(--midnight-text-secondary);
}

html[data-theme="midnight"] .emoji-tab-item {
    color: var(--midnight-text-secondary);
}

html[data-theme="midnight"] .emoji-tab-item:hover {
    color: var(--primary-color);
    background: rgba(129, 140, 248, 0.15);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(129, 140, 248, 0.3);
}

html[data-theme="midnight"] .emoji-tab-item.active {
    color: var(--primary-color);
    background: var(--midnight-surface);
    border-bottom-color: var(--primary-color);
}

html[data-theme="midnight"] .emoji-search-container {
    border-bottom-color: var(--midnight-border);
}

html[data-theme="midnight"] .emoji-search-input {
    background: var(--midnight-bg);
    border-color: var(--midnight-border);
    color: var(--midnight-text);
}

html[data-theme="midnight"] .emoji-search-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.2);
}

html[data-theme="midnight"] .emoji-search-clear:hover {
    background: var(--midnight-border);
    color: var(--midnight-text);
}

html[data-theme="midnight"] .emoji-no-results {
    color: var(--midnight-text-secondary);
}

html[data-theme="midnight"] .emoji-search-hint {
    color: var(--midnight-text-secondary);
}

html[data-theme="midnight"] .emoji-search-results .emoji-btn:hover {
    background: rgba(129, 140, 248, 0.15);
    border-color: var(--primary-color);
}


/* --- NEW: Stat Card Edit Button for Touch Devices --- */
.edit-stat-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background-color: rgba(255, 255, 255, 0.8);
    border: 1px solid var(--light-border);
    border-radius: 50%;
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    transition: all 0.2s ease;
}
.edit-stat-btn:hover {
    transform: scale(1.1);
    background-color: white;
}
.edit-stat-btn svg {
    width: 16px;
    height: 16px;
    color: var(--primary-color);
    stroke-width: 2.5;
}
/* Conditional visibility for touch devices */
body.is-touch-device .stat-card.active:not(.overview-card) .edit-stat-btn {
    display: flex;
}

.stat-number {
    font-size: clamp(1.5em, 3vw, 2.2em);
    font-weight: 800;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
}
.stat-emoji { font-size: 0.9em; }
.stat-value { color: var(--light-text); }
.stat-label {
    color: var(--light-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.stat-card-add {
    display: flex; justify-content: center; align-items: center; font-size: 3em;
    color: var(--light-text-secondary); border: 2px dashed var(--light-border);
    background-color: transparent; box-shadow: none;
}
.stat-card-add:hover {
    background-color: rgba(129, 140, 248, 0.1);
    color: var(--primary-color); border-color: var(--primary-color);
}

/* --- UPDATED: STYLES FOR THE "WORKDAYS" PILL --- */
.exclude-icon {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7em;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 6px;
    background-color: var(--light-bg);
    color: var(--light-text-secondary);
}
.exclude-icon svg {
    width: 8px;
    height: 8px;
    stroke-width: 2.5;
    stroke: currentColor;
}

/* Calendar */
.month-container {
    background: var(--light-surface); border-radius: 16px;
    padding: 16px; border: 1px solid var(--light-border);
}
.month-header {
    text-align: center; font-size: clamp(1.4em, 3vw, 1.8em); font-weight: 700;
    color: white; margin-bottom: 16px; padding: 12px; border-radius: 12px;
}
.month-header.gradient-1 { background: linear-gradient(135deg, #fdc830, #f37335); }
.month-header.gradient-2 { background: linear-gradient(135deg, #4facfe, #00f2fe); }
.month-header.gradient-3 { background: linear-gradient(135deg, #e66465, #9198e5); }
.month-header.gradient-4 { background: linear-gradient(135deg, #43e97b, #38f9d7); }

.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.day-header {
    text-align: center; font-weight: 600; font-size: 0.9em;
    color: var(--light-text-secondary); padding-bottom: 8px;
}
.day {
    display: flex; flex-direction: column; align-items: center;
    background: transparent; position: relative; cursor: pointer;
    border-radius: 10px; padding: 6px 4px 12px; min-height: 90px;
    border: 1px solid var(--light-border);
}
.day:hover { background: rgba(129, 140, 248, 0.1); border-color: var(--primary-color); }
.day.other-month { opacity: 0.6; }
.day.weekend { background-image: var(--weekend-bg-light); }
.day.weekend .day-number { color: var(--weekend-text-light); font-weight: 700; }
.day.filtered-out { opacity: 0.3; filter: grayscale(0.5); }
.day-number {
    font-size: clamp(1em, 2vw, 1.2em); z-index: 2; line-height: 1;
    transition: all 0.2s ease; font-weight: 700;
}
.day-emojis {
    font-size: clamp(1em, 2vw, 1.4em); z-index: 2; line-height: 1;
    flex-grow: 1; display: flex; align-items: center;
}
.day.today .day-number {
    background-color: var(--primary-color); color: white !important;
    border-radius: 50%; width: 1.8em; height: 1.8em;
    display: flex; align-items: center; justify-content: center;
}

.activities-bar {
    position: absolute; bottom: 4px; left: 5px; right: 5px;
    height: 4px; display: flex; border-radius: 4px;
    overflow: hidden; gap: 1px;
}
.activity-segment { flex: 1; height: 100%; }
#calendar-placeholder {
    text-align: center; padding: 40px; background: var(--light-surface);
    border-radius: 16px; grid-column: 1 / -1;
}

/* Category List Styles */
#category-list-container { flex-grow: 1; overflow-y: auto; padding-right: 4px; }
.category-list-item {
    display: flex; align-items: center; padding: 10px; background: var(--light-bg);
    border-radius: 10px; border: 1px solid var(--light-border); color: var(--light-text);
    margin-bottom: 10px; position: relative;
}
.category-list-item-content { flex-grow: 1; font-weight: 600; }
.category-list-item-actions { display: flex; gap: 5px; opacity: 0; visibility: hidden; transition: opacity 0.2s ease, visibility 0.2s ease; }
.category-list-item:hover .category-list-item-actions { opacity: 1; visibility: visible; }
.category-list-item.dragging { opacity: 0.5; background: var(--primary-color); }
.category-list-item.drag-placeholder { background: rgba(129, 140, 248, 0.1); border: 2px dashed var(--primary-color); height: 52px; }

.import-preview-card {
    background: var(--light-surface); border: 1px solid var(--light-border);
    border-radius: 12px; padding: 12px; margin-bottom: 10px; transition: all 0.3s ease;
}
.import-preview-card.is-duplicate { border-left: 5px solid var(--danger-color); }
.import-preview-card-header { display: flex; align-items: center; gap: 10px; }
.import-preview-card-header input[type="checkbox"] { width: 20px; height: 20px; flex-shrink: 0; }
.import-preview-card-header .color-dot { width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0; }
.import-preview-card-header .name-display { font-weight: 600; flex-grow: 1; }
.import-preview-card-header .import-card-actions { display: flex; gap: 5px; } /* Container for new buttons */
.import-dates-preview { 
    margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--light-border);
    font-size: 0.9em; color: var(--light-text-secondary); 
}
.import-dates-preview strong { color: var(--light-text-primary); }
#import-select-all-container { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
#import-confirmation-summary { flex-grow: 1; }
#import-confirmation-summary > label { 
    display: flex; align-items: center; gap: 8px; margin-bottom: 15px; 
    padding: 10px; background: var(--light-bg); border-radius: 8px; 
    border: 1px solid var(--light-border); font-weight: 600;
}
#import-confirmation-summary > label input[type="checkbox"] { 
    width: 18px; height: 18px; margin: 0; 
}
#import-error-message, #editor-error-message, .import-duplicate-warning {
    display: none; color: var(--danger-color); font-weight: 600; margin-bottom: 10px;
    background-color: rgba(239, 68, 68, 0.1); padding: 10px; border-radius: 8px;
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.import-duplicate-warning { margin-top: 10px; margin-bottom: 0; }
.import-preview-card.is-duplicate .import-duplicate-warning { display: block; }

/* Animation for invalid input */
@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-3px, 0, 0); }
  40%, 60% { transform: translate3d(3px, 0, 0); }
}
.shake {
  animation: shake 0.6s cubic-bezier(.36,.07,.19,.97) both;
}

/* Styles for custom date input from newdate.html */
.date-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    flex-grow: 1;
}
.date-display-input {
     padding-right: 3rem !important; /* Make space for the icon */
}
.native-date-input {
    /* sr-only equivalent */
    border: 0;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    white-space: nowrap;
}
.calendar-button {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 3rem; /* 48px */
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--light-text-secondary);
    cursor: pointer;
    background: transparent;
    border: none;
    padding: 0;
    /* iOS touch optimizations */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    /* Ensure reliable event handling on iOS */
    pointer-events: auto;
    z-index: 10;
}
.calendar-button svg {
    width: 20px;
    height: 20px;
    transition: all 0.15s ease;
}

.calendar-button:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--primary-color);
}

.calendar-button:active {
    background-color: rgba(0, 0, 0, 0.1);
    transform: scale(0.95);
}

/* iOS Safari specific enhancements */
@supports (-webkit-touch-callout: none) {
    .calendar-button {
        /* Additional iOS-specific touch optimizations */
        -webkit-appearance: none;
        border-radius: 0;
    }
    
    .calendar-button:active {
        /* More pronounced feedback on iOS */
        background-color: rgba(129, 140, 248, 0.1);
        color: var(--primary-color);
    }
}
.editor-input.border-red-500 { border-color: var(--danger-color) !important; }
.editor-input.border-green-500 { border-color: var(--success-color) !important; }

#group-categories-container, .group-categories-container {
    max-height: 200px; overflow-y: auto; border: 1px solid var(--light-border);
    border-radius: 8px; padding: 12px; background: var(--light-bg);
    display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px;
}
.group-category-item { display: flex; align-items: center; gap: 10px; }
.group-category-item input[type="checkbox"] { flex-shrink: 0; width: 1.2em; height: 1.2em; margin: 0; }
.date-buttons-wrapper { display: flex; gap: 10px; margin-top: 15px; flex-wrap: wrap; }

/* --- Smart Category Input --- */
.smart-category-input {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.smart-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.suggestion-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.suggestion-label {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--light-text-secondary);
    min-width: 60px;
    flex-shrink: 0;
}
.suggestion-chips {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.suggestion-chip {
    background: var(--light-surface);
    border: 1px solid var(--light-border);
    border-radius: 12px;
    padding: 4px 8px;
    font-size: 0.8em;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--light-text);
}
.suggestion-chip:hover {
    background: var(--light-hover);
    border-color: var(--primary-color);
}
.suggestion-chip.template-chip {
    background: linear-gradient(135deg, var(--light-surface), var(--light-hover));
    border-color: var(--primary-color);
    color: var(--primary-color);
}
.suggestion-chip.template-chip:hover {
    background: var(--primary-color);
    color: white;
}
.suggestion-chip-emoji {
    font-size: 1em;
}
.suggestion-chip-name {
    font-weight: 500;
}
