/* --- Basic Setup --- */
:root {
    --bg-color: #f4f7f6;
    --column-bg: #fff;
    --border-color: #e0e0e0;
    --text-color: #333;
    --accent-color: #4a9d7f;
    --accent-hover: #3d8268;
    --danger-color: #dc3545;
    --input-bg: #fff;
    --input-border: #ccc;
    --tab-bg: #fafafa;
    --tab-hover-bg: #f0f0f0;
    --item-bg: #fff;
    --item-border: #eee;
    --item-number-color: #888;
    --header-bg: #333;
    --button-bg: #555;
    --button-hover-bg: #777;
    --offline-bg: #d9534f;
    --disabled-bg: #e8e8e8;
    --disabled-text: #999;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --column-bg: #2d2d2d;
        --border-color: #444;
        --text-color: #e0e0e0;
        --accent-color: #6aab96;
        --input-bg: #3a3a3a;
        --input-border: #555;
        --tab-bg: #1f1f1f;
        --tab-hover-bg: #3a3a3a;
        --item-bg: #363636;
        --item-border: #444;
        --item-number-color: #888;
        --header-bg: #0a0a0a;
        --button-bg: #444;
        --button-hover-bg: #555;
        --offline-bg: #a73a3a;
        --disabled-bg: #252525;
        --disabled-text: #666;
    }
}

/* Dark mode when user explicitly sets it */
body.dark-mode {
    --bg-color: #1a1a1a;
    --column-bg: #2d2d2d;
    --border-color: #444;
    --text-color: #e0e0e0;
    --accent-color: #6aab96;
    --accent-hover: #4a9d7f;
    --input-bg: #3a3a3a;
    --input-border: #555;
    --tab-bg: #1f1f1f;
    --tab-hover-bg: #3a3a3a;
    --item-bg: #363636;
    --item-border: #444;
    --item-number-color: #888;
    --header-bg: #0a0a0a;
    --button-bg: #444;
    --button-hover-bg: #555;
    --offline-bg: #a73a3a;
    --disabled-bg: #252525;
    --disabled-text: #666;
}

/* Light mode when user explicitly sets it */
body.light-mode {
    --bg-color: #f4f7f6;
    --column-bg: #fff;
    --border-color: #e0e0e0;
    --text-color: #333;
    --accent-color: #4a9d7f;
    --accent-hover: #3d8268;
    --input-bg: #fff;
    --input-border: #ccc;
    --tab-bg: #fafafa;
    --tab-hover-bg: #f0f0f0;
    --item-bg: #fff;
    --item-border: #eee;
    --item-number-color: #888;
    --header-bg: #333;
    --button-bg: #555;
    --button-hover-bg: #777;
    --offline-bg: #d9534f;
    --disabled-bg: #e8e8e8;
    --disabled-text: #999;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding-bottom: 3rem;
    position: relative;
}

/* --- Hero Background --- */
.hero-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
    overflow: hidden;
}

.hero-background-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center top;
    background-repeat: no-repeat;
    filter: blur(20px);
    transform: scale(1.1); /* Prevent blur edge artifacts */
    opacity: 0;
    transition: opacity 0.8s ease-in-out, background-image 0.8s ease-in-out;
}

.hero-background-image.active {
    opacity: 0.3;
}

body.dark-mode .hero-background-image.active {
    opacity: 0.2;
}

.hero-background-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        var(--bg-color) 100%
    );
}

.container {
    display: flex;
    justify-content: center;
    padding: 1rem;
    max-width: 1200px;
    margin: 0 auto;
}
header {
    background-color: var(--header-bg);
    color: white;
    padding: 1rem 2rem;
    text-align: center;
    position: relative;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
header h1 { margin: 0; }

/* --- Help Button --- */
.help-btn {
    position: absolute;
    top: 50%;
    left: 1.5rem;
    transform: translateY(-50%);
    background: var(--accent-color);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    transition: background 0.3s ease, transform 0.2s ease;
    line-height: 1;
}

.help-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-50%) scale(1.1);
}

.help-btn:active {
    transform: translateY(-50%) scale(0.95);
}

/* --- Settings Button (Admin only) --- */
.settings-btn {
    position: absolute;
    top: 50%;
    left: 4.5rem;
    transform: translateY(-50%);
    background: var(--button-bg);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease, transform 0.2s ease;
    text-decoration: none;
}

.settings-btn:hover {
    background: var(--button-hover-bg);
    transform: translateY(-50%) scale(1.1);
}

.settings-btn:active {
    transform: translateY(-50%) scale(0.95);
}

.settings-btn svg {
    width: 20px;
    height: 20px;
}

.logout-btn {
    position: absolute;
    top: 50%;
    right: 4.5rem;
    transform: translateY(-50%);
    color: white;
    text-decoration: none;
    background: var(--button-bg);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.9rem;
}
.logout-btn:hover { background: var(--button-hover-bg); }

/* --- Theme Toggle Button --- */
.theme-toggle-btn {
    position: absolute;
    top: 50%;
    right: 1.5rem;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
}
.theme-toggle-btn:hover {
    opacity: 0.8;
}

/* --- Offline Banner --- */
#offline-banner {
    background-color: var(--offline-bg);
    color: white;
    text-align: center;
    padding: 0.5rem;
    font-weight: 500;
    display: none; /* Hidden by default */
}

/* --- Update Toast --- */
.update-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: var(--accent-color);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.95rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 9999;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    text-align: center;
    max-width: 90%;
}

.update-toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Dark mode toast adjustment */
body.dark-mode .update-toast {
    background-color: var(--accent-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

/* --- Help Modal --- */
.help-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.help-modal.active {
    display: flex;
}

.help-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.help-modal-content {
    background: var(--column-bg);
    border-radius: 8px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 2rem;
    position: relative;
    margin: 1rem;
    z-index: 1;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.help-modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-color);
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.help-modal-close:hover {
    background: var(--tab-hover-bg);
}

.help-modal-content h2 {
    margin-top: 0;
    margin-bottom: 1.5rem;
    color: var(--text-color);
    padding-right: 2rem;
}

.help-section {
    margin-bottom: 1.5rem;
}

.help-section h3 {
    color: var(--accent-color);
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.help-section p {
    margin: 0.5rem 0;
    line-height: 1.6;
    color: var(--text-color);
}

.help-section ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
    line-height: 1.6;
}

.help-section li {
    margin: 0.25rem 0;
    color: var(--text-color);
}

/* --- Tabs Wrapper --- */
.tabs-wrapper {
    background: var(--column-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 600px;
}

/* --- Tab Header --- */
.tabs-header {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    background: var(--tab-bg);
}

.tab-button {
    flex: 1;
    padding: 1rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: #666;
    transition: all 0.3s ease;
    position: relative;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
}

.tab-button:hover {
    color: var(--text-color);
    background: var(--tab-hover-bg);
}

.tab-button.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
    background: var(--column-bg);
}

/* --- Tab Content --- */
.tab-content {
    display: none;
    flex: 1;
    min-height: 300px;
    animation: fadeIn 0.3s ease-in-out;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* --- List Columns --- */
.list-column {
    background: var(--column-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    flex: 1;
    min-width: 320px;
    max-width: 500px;
    display: flex;
    flex-direction: column;
}

/* --- Add Item Button --- */
.add-item-btn {
    display: block;
    width: calc(100% - 2rem);
    margin: 1rem;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 6px;
    background: var(--accent-color);
    color: white;
    font-size: 1rem;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: background 0.15s ease;
}

.add-item-btn:hover {
    background: var(--accent-hover);
}

.add-item-btn:active {
    background: var(--accent-color);
    transform: scale(0.98);
}

/* --- List Items --- */
.list-container {
    list-style: none;
    margin: 0;
    padding: 1rem;
    min-height: 200px;
    /* This creates the numbering */
    counter-reset: item-counter; 
}
.list-item {
    display: flex;
    align-items: center;
    background: var(--item-bg);
    border: 1px solid var(--item-border);
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    cursor: default;
}
.list-item:before {
    /* The item number */
    counter-increment: item-counter;
    content: counter(item-counter) ".";
    font-weight: bold;
    color: var(--item-number-color);
    margin-right: 0.4rem;
    min-width: 25px;
}

/* Drag Handle */
.drag-handle {
    cursor: grab;
    padding: 0.5rem;
    margin-right: 0.25rem;
    color: var(--item-number-color);
    font-size: 1.2rem;
    user-select: none;
    touch-action: none;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: -0.5rem;
}

.list-item span {
    flex-grow: 1;
    word-break: break-word;
}

/* Edit Button */
.edit-btn {
    border: none;
    background: none;
    color: var(--accent-color);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.5rem;
    opacity: 0.3;
    margin-left: 0.25rem;
    flex-shrink: 0;
}

.list-item:hover .edit-btn {
    opacity: 1;
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: var(--column-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    min-width: 150px;
    overflow: hidden;
}

.context-menu-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.2s ease;
}

.context-menu-item:hover {
    background: var(--tab-hover-bg);
}

.context-menu-item:last-child {
    border-bottom: none;
}

.context-menu-item.danger {
    color: var(--danger-color);
}

/* Inline Editing */
.editing-input {
    flex-grow: 1;
    border: 2px solid var(--accent-color);
    border-radius: 4px;
    padding: 0.5rem;
    font-size: 1rem;
    background: var(--input-bg);
    color: var(--text-color);
    font-family: inherit;
}

.editing-input:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

/* Desktop: entire item draggable, subtle handle */
@media (pointer: fine) {
    .list-item {
        cursor: grab;
    }
    .drag-handle {
        opacity: 0.3;
    }
    .list-item:hover .drag-handle {
        opacity: 1;
    }
}

/* Mobile: only handle draggable, always visible */
@media (pointer: coarse) {
    .drag-handle {
        opacity: 1;
    }
}

/* SortableJS drag effect */
.list-item.sortable-ghost {
    opacity: 0.4;
    background: #cde;
}
.list-item.sortable-chosen {
    cursor: grabbing;
}

/* Disabled state for offline */
.offline-mode .add-item-btn,
.offline-mode .edit-btn {
    opacity: 0.5;
    background-color: var(--disabled-bg);
    color: var(--disabled-text);
    pointer-events: none;
}
.offline-mode .list-item {
    cursor: not-allowed;
}

/* --- Responsive Design --- */

/* Medium screens (tablets, landscape phones) */
@media (max-width: 768px) {
    header {
        padding: 1rem;
    }
    
    header h1 {
        font-size: 1.5rem;
        padding: 0 8rem;
    }
    
    .help-btn {
        left: 1rem;
        width: 32px;
        height: 32px;
        font-size: 1.2rem;
    }
    
    .logout-btn {
        right: 4rem;
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }
    
    .theme-toggle-btn {
        right: 1.25rem;
        font-size: 1.3rem;
    }
    
    .container {
        padding: 0.75rem;
    }
    
    .tabs-wrapper {
        max-width: 100%;
    }
    
    .help-modal-content {
        max-width: 90%;
        padding: 1.5rem;
    }
}

/* Small screens (portrait phones) */
@media (max-width: 480px) {
    header {
        padding: 0.75rem 0.5rem;
    }
    
    header h1 {
        font-size: 1.2rem;
        padding: 0 6rem;
    }
    
    .help-btn {
        left: 0.5rem;
        width: 28px;
        height: 28px;
        font-size: 1rem;
    }
    
    .logout-btn {
        right: 3rem;
        padding: 0.35rem 0.65rem;
        font-size: 0.75rem;
    }
    
    .theme-toggle-btn {
        right: 0.75rem;
        font-size: 1.1rem;
        padding: 0.3rem;
    }
    
    .container {
        padding: 0.5rem;
    }
    
    .list-item {
        padding: 0.25rem;
        font-size: 0.9rem;
        align-items: center;
    }
    
    .list-item:before {
        min-width: 20px;
        margin-right: 0.3rem;
        font-size: 0.85rem;
    }
    
    .list-item span {
        font-size: 0.85rem;
        line-height: 1.1;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
    }
    
    .drag-handle {
        min-width: auto;
        width: auto;
        min-height: 2.2em;
        height: auto;
        padding: 0.25rem;
        margin-right: 0.2rem;
        margin-left: -0.25rem;
        font-size: 1rem;
    }
    
    .edit-btn {
        font-size: 1rem;
        padding: 0.25rem;
        min-height: 2.2em;
        height: auto;
        display: flex;
        align-items: center;
    }
    
    .add-item-btn {
        margin: 0.75rem;
        width: calc(100% - 1.5rem);
        padding: 0.65rem 0.75rem;
        font-size: 0.9rem;
    }
    
    .tab-button {
        font-size: 0.9rem;
        padding: 0.8rem 0.5rem;
    }
    
    .help-modal-content {
        padding: 1.25rem;
        max-width: 95%;
        max-height: 85vh;
    }
    
    .help-section h3 {
        font-size: 1rem;
    }
}

/* Extra small screens */
@media (max-width: 360px) {
    header h1 {
        font-size: 1rem;
        padding: 0 5rem;
    }
    
    .help-btn {
        left: 0.25rem;
        width: 26px;
        height: 26px;
        font-size: 0.9rem;
    }
    
    .logout-btn {
        right: 2.5rem;
        padding: 0.3rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .theme-toggle-btn {
        right: 0.5rem;
        font-size: 1rem;
    }
    
    .tab-button {
        font-size: 0.85rem;
        padding: 0.7rem 0.4rem;
    }
    
    .list-item {
        font-size: 0.85rem;
        padding: 0.2rem;
    }
    
    .list-item:before {
        font-size: 0.8rem;
        min-height: 2em;
    }
    
    .list-item span {
        font-size: 0.8rem;
        min-height: 2em;
    }
    
    .drag-handle {
        min-height: 2em;
        font-size: 0.9rem;
    }
    
    .edit-btn {
        min-height: 2em;
        font-size: 0.9rem;
    }
}

/* =============================================================================
   WATCHER STYLES
   ============================================================================= */

/* --- Watcher Badge Base --- */
.watcher-badge {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: bold;
    text-transform: uppercase;
    user-select: none;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.watcher-badge:hover {
    transform: scale(1.1);
}

.watcher-badge:active {
    transform: scale(0.95);
}

/* --- Watcher Badge Small (for list items) --- */
.watcher-badge.small {
    width: 26px;
    height: 26px;
}

.watcher-badge.small .watcher-initial {
    font-size: 1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.watcher-badge.small .watcher-name {
    display: none;
}

/* --- Watcher Badge Large (for modal) --- */
.watcher-badge.large {
    width: 72px;
    height: 72px;
}

.watcher-badge.large .watcher-initial {
    font-size: 1.75rem;
    line-height: 1;
    margin-top: -4px;
}

.watcher-badge.large .watcher-name {
    font-weight: 600;
    max-width: 64px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
    text-transform: none;
    text-align: center;
    padding: 0 4px;
    box-sizing: border-box;
}

/* --- Watcher Badge States --- */
.watcher-badge.active {
    box-shadow: 0 0 0 3px var(--accent-color), 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 1;
}

/* Inactive state: muted, smaller, with diagonal stripes overlay */
.watcher-badge.inactive {
    filter: grayscale(60%) brightness(0.8);
    transform: scale(0.85);
    opacity: 0.7;
}

.watcher-badge.inactive::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 3px,
        rgba(0, 0, 0, 0.15) 3px,
        rgba(0, 0, 0, 0.15) 6px
    );
    border-radius: 50%;
    pointer-events: none;
}

.watcher-badge.inactive:hover {
    filter: grayscale(30%) brightness(0.9);
    opacity: 0.85;
    transform: scale(0.92);
}

/* --- Watcher Add Button (Plus Icon) --- */
.watcher-badge.add-watcher {
    background: var(--tab-bg);
    border: 2px dashed var(--border-color);
    color: var(--text-color);
}

.watcher-badge.add-watcher:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.watcher-badge.add-watcher .watcher-initial {
    font-size: 2rem;
    font-weight: 300;
    margin-top: 0;
}

/* --- Watcher Container in List Items --- */
.item-watchers {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    max-width: 100px;
    max-height: 60px;
    overflow: hidden;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.item-watchers-row {
    display: flex;
    justify-content: center;
    gap: 3px;
}

.item-watchers .watcher-badge.small {
    cursor: default;
}

.item-watchers .watcher-badge.small:hover {
    transform: none;
}

/* Overflow indicator */
.watcher-overflow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--tab-bg);
    border: 1px solid var(--border-color);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-color);
    flex-shrink: 0;
}

/* --- Watchers Modal --- */
.watchers-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.watchers-modal.active {
    display: flex;
}

.watchers-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
}

.watchers-modal-content {
    background: var(--column-bg);
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    padding: 1.5rem;
    position: relative;
    z-index: 1;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.watchers-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.watchers-modal-header h3 {
    margin: 0;
    color: var(--text-color);
    font-size: 1.25rem;
}

.watchers-modal-close {
    background: none;
    border: none;
    font-size: 1.75rem;
    cursor: pointer;
    color: var(--text-color);
    line-height: 1;
    padding: 0.25rem;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.watchers-modal-close:hover {
    background: var(--tab-hover-bg);
}

/* --- Watchers Grid (Centered Hexagonal Layout) --- */
.watchers-grid {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 0;
}

.watchers-grid-row {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}

/* --- Watcher Edit Form (inline in modal) --- */
.watcher-edit-form {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2100;
    align-items: center;
    justify-content: center;
}

.watcher-edit-form.active {
    display: flex;
}

.watcher-edit-form-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.watcher-edit-form-content {
    background: var(--column-bg);
    border-radius: 12px;
    padding: 1.5rem;
    position: relative;
    z-index: 1;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    min-width: 280px;
    max-width: 90%;
}

.watcher-edit-form-content h4 {
    margin: 0 0 1rem 0;
    color: var(--text-color);
}

.watcher-edit-form-content label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-color);
    font-size: 0.9rem;
}

.watcher-edit-form-content input[type="text"] {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 1rem;
    margin-bottom: 1rem;
    box-sizing: border-box;
}

.watcher-edit-form-content input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

/* Color picker wrapper */
.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.color-picker-wrapper input[type="color"] {
    width: 50px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    cursor: pointer;
    background: var(--input-bg);
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch {
    border-radius: 2px;
    border: none;
}

.color-preview {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Form buttons */
.watcher-form-buttons {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.watcher-form-buttons button {
    flex: 1;
    padding: 0.75rem;
    border: none;
    border-radius: 4px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.watcher-form-buttons .btn-save {
    background: var(--accent-color);
    color: white;
}

.watcher-form-buttons .btn-save:hover {
    background: var(--accent-hover);
}

.watcher-form-buttons .btn-cancel {
    background: var(--tab-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.watcher-form-buttons .btn-cancel:hover {
    background: var(--tab-hover-bg);
}

.watcher-form-buttons .btn-delete {
    background: var(--danger-color);
    color: white;
    flex: 0 0 auto;
    padding: 0.75rem 1rem;
}

.watcher-form-buttons .btn-delete:hover {
    background: #c82333;
}

/* --- Responsive Watcher Styles --- */
@media (max-width: 480px) {
    .watcher-badge.large {
        width: 56px;
        height: 56px;
    }
    
    .watcher-badge.large .watcher-initial {
        font-size: 1.25rem;
        margin-top: -2px;
    }
    
    .watcher-badge.large .watcher-name {
        max-width: 48px;
    }
    
    .item-watchers {
        max-width: 70px;
    }
    
    .watcher-badge.small {
        width: 22px;
        height: 22px;
    }
    
    .watcher-badge.small .watcher-initial {
        font-size: 0.85rem;
    }
    
    .watcher-overflow {
        width: 22px;
        height: 22px;
        font-size: 0.6rem;
    }
    
    .watchers-modal-content {
        padding: 1rem;
    }
    
    .watchers-grid {
        gap: 0.5rem;
    }
    
    .watchers-grid-row {
        gap: 0.5rem;
    }
}

@media (max-width: 360px) {
    .item-watchers {
        max-width: 55px;
    }
    
    .watcher-badge.small {
        width: 20px;
        height: 20px;
    }
    
    .watcher-badge.small .watcher-initial {
        font-size: 0.75rem;
    }
    
    .watcher-overflow {
        width: 20px;
        height: 20px;
        font-size: 0.55rem;
    }
    
    .watcher-badge.large {
        width: 50px;
        height: 50px;
    }
    
    .watcher-badge.large .watcher-initial {
        font-size: 1.1rem;
    }
    
    .watcher-badge.large .watcher-name {
        max-width: 42px;
    }
}

/* =============================================================================
   ITEM MODAL (Add/Edit)
   ============================================================================= */

.item-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.item-modal.active {
    display: flex;
}

.item-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
}

.item-modal-content {
    background: var(--column-bg);
    border-radius: 12px;
    max-width: 480px;
    width: 90%;
    height: auto;
    max-height: 85vh;
    min-height: 320px;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

/* Fixed header */
.item-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.item-modal-header h3 {
    margin: 0;
    color: var(--text-color);
    font-size: 1.25rem;
}

.item-modal-close {
    background: none;
    border: none;
    font-size: 1.75rem;
    cursor: pointer;
    color: var(--text-color);
    line-height: 1;
    padding: 0.25rem;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.item-modal-close:hover {
    background: var(--tab-hover-bg);
}

/* Fixed input area */
.search-input-container {
    padding: 1rem 1.25rem;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
}

.search-input-container label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-color);
    font-size: 0.9rem;
    font-weight: 500;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input-wrapper input {
    width: 100%;
    padding: 0.75rem;
    padding-right: 2.5rem;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input-wrapper input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

/* --- Search Spinner --- */
.search-spinner {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: none;
}

.search-spinner.active {
    display: block;
}

@keyframes spin {
    to { transform: translateY(-50%) rotate(360deg); }
}

/* Scrollable results/content area - takes remaining space */
.item-modal-body {
    flex: 1;
    overflow-y: auto;
    min-height: 120px;
}

/* Search results list (replaces dropdown) */
.search-results-list {
    display: none;
}

.search-results-list.active {
    display: block;
}

/* --- Search Result Items --- */
.search-result-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s ease;
    gap: 0.75rem;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover,
.search-result-item.selected {
    background: var(--tab-hover-bg);
}

.search-result-poster {
    width: 40px;
    height: 60px;
    background: var(--tab-bg);
    border-radius: 4px;
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--item-number-color);
    font-size: 0.7rem;
}

.search-result-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.search-result-info {
    flex: 1;
    min-width: 0;
}

.search-result-title {
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Logo display in search results (TV shows) */
.search-result-logo {
    max-height: 1.5em;
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    vertical-align: middle;
}

.search-result-meta {
    font-size: 0.8rem;
    color: var(--item-number-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* --- Lazy Loading Poster Transitions --- */
.search-result-poster img.lazy-poster {
    filter: blur(4px);
    transform: scale(1.1);
    transition: filter 0.3s ease, transform 0.3s ease;
}

.search-result-poster img.loading {
    filter: blur(4px);
    transform: scale(1.1);
}

.search-result-poster img:not(.lazy-poster):not(.loading) {
    filter: none;
    transform: scale(1);
    transition: filter 0.3s ease, transform 0.3s ease;
}

/* --- Search Status Messages --- */
.search-status {
    padding: 1.5rem 1.25rem;
    text-align: center;
    color: var(--item-number-color);
    font-size: 0.9rem;
}

.search-status.error {
    color: var(--danger-color);
}

.search-status-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    display: block;
}

/* Empty state when not searching and no metadata */
.item-modal-empty {
    padding: 2rem 1.25rem;
    text-align: center;
    color: var(--item-number-color);
    font-size: 0.9rem;
}

.item-modal-empty-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

/* --- Metadata Display (in modal body) --- */
.item-metadata-display {
    padding: 1.25rem;
    display: none;
}

.item-metadata-display.active {
    display: block;
}

.metadata-card {
    background: var(--tab-bg);
    border-radius: 8px;
    padding: 1rem;
}

.metadata-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.metadata-poster {
    width: 60px;
    height: 90px;
    background: var(--column-bg);
    border-radius: 4px;
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--item-number-color);
    font-size: 0.8rem;
}

.metadata-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Lazy loading transitions for metadata poster */
.metadata-poster img.lazy-poster {
    filter: blur(4px);
    transform: scale(1.1);
    transition: filter 0.3s ease, transform 0.3s ease;
}

.metadata-poster img.loading {
    filter: blur(4px);
    transform: scale(1.1);
}

.metadata-poster img:not(.lazy-poster):not(.loading) {
    filter: none;
    transform: scale(1);
    transition: filter 0.3s ease, transform 0.3s ease;
}

.metadata-info {
    flex: 1;
}

.metadata-title {
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.25rem;
}

/* Logo display in metadata panel (TV shows) */
.metadata-logo {
    max-height: 2em;
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.metadata-year {
    font-size: 0.85rem;
    color: var(--item-number-color);
    margin-bottom: 0.5rem;
}

/* --- Rating Display --- */
.metadata-rating {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.rating-stars {
    display: flex;
    gap: 2px;
}

.rating-star {
    color: var(--border-color);
    font-size: 0.9rem;
}

.rating-star.filled {
    color: #fbbf24;
}

.rating-star.half {
    position: relative;
    color: var(--border-color);
}

.rating-star.half::before {
    content: '\2605';
    position: absolute;
    left: 0;
    width: 50%;
    overflow: hidden;
    color: #fbbf24;
}

.rating-value {
    font-size: 0.8rem;
    color: var(--item-number-color);
    margin-left: 0.25rem;
}

/* --- Unlink Button --- */
.metadata-unlink {
    margin-top: 0.75rem;
    text-align: right;
}

.btn-unlink {
    background: none;
    border: none;
    color: var(--danger-color);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.25rem 0;
    text-decoration: underline;
}

.btn-unlink:hover {
    opacity: 0.8;
}

/* Fixed footer with buttons */
.item-modal-buttons {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--column-bg);
}

.item-modal-buttons button {
    flex: 1;
    padding: 0.75rem;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.item-modal-buttons .btn-primary {
    background: var(--accent-color);
    color: white;
}

.item-modal-buttons .btn-primary:hover {
    background: var(--accent-hover);
}

.item-modal-buttons .btn-secondary {
    background: var(--tab-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.item-modal-buttons .btn-secondary:hover {
    background: var(--tab-hover-bg);
}

/* --- Mobile: Full-screen modal --- */
@media (max-width: 600px) {
    .item-modal {
        align-items: stretch;
        justify-content: stretch;
    }
    
    .item-modal-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        min-height: 100%;
        border-radius: 0;
    }
    
    .item-modal-body {
        min-height: 0;
    }
    
    .search-result-poster {
        width: 35px;
        height: 52px;
    }
    
    .metadata-poster {
        width: 50px;
        height: 75px;
    }
    
    .item-modal-buttons {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }
}