/* ── PXCatalog Theme — Cream & Deep Brown ────────────────── */
:root {
    --bg-dark: #FAF6F1;
    --bg-card: #FFFFFF;
    --bg-input: #F0EBE3;
    --accent: #8B4513;
    --accent-hover: #6B3410;
    --danger: #C0392B;
    --success: #27AE60;
    --text: #2C1810;
    --text-muted: #8C7B6B;
    --border: #D4C5B4;
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ──────────────────────────────────────────────── */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: #3C2415;
    border-bottom: 2px solid #2C1810;
    color: #FAF6F1;
    position: sticky;
    top: 0;
    z-index: 800;
}

.app-header h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: #FAF6F1;
}

.app-header .catalog-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 16px;
}

.app-header .catalog-name {
    color: #C4A882;
    font-size: 15px;
    font-weight: 400;
}

.app-header #catalog-dropdown {
    background: #2C1810;
    color: #FAF6F1;
    border: 1px solid #5C4A3A;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 14px;
}

.app-header .header-left {
    display: flex;
    align-items: center;
}

.app-header nav {
    display: flex;
    gap: 16px;
    align-items: center;
}

.app-header nav a {
    color: #D4B892;
    font-size: 16px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.app-header nav a:hover,
.app-header nav a.active {
    color: #FAF6F1;
    background: rgba(255, 255, 255, 0.12);
    text-decoration: none;
}

/* ── Segmented buttons (header controls) ─────────────────── */
.seg-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: #C4A882;
    padding: 3px 10px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.seg-btn:first-child { border-radius: 4px 0 0 4px; }
.seg-btn:last-child { border-radius: 0 4px 4px 0; }
.seg-btn:only-child { border-radius: 4px; }
.seg-btn:hover { background: rgba(255,255,255,0.2); color: #FAF6F1; }
.seg-btn.seg-active { background: rgba(255,255,255,0.25); color: #FAF6F1; font-weight: 600; }

/* ── User menu ───────────────────────────────────────────── */
.user-menu {
    position: relative;
}
.user-menu-btn {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.2);
    color: #D4B892;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-menu-btn:hover { color: #FAF6F1; }
.user-menu-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    min-width: 200px;
    z-index: 2000;
    padding: 4px 0;
}
.user-menu.open .user-menu-dropdown { display: block; }
.user-menu-email {
    padding: 8px 14px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
.user-menu-item {
    display: block;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--text) !important;
    cursor: pointer;
}
.user-menu-item:hover {
    background: var(--bg-input);
    text-decoration: none !important;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

.container-wide {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* ── Cards & Panels ──────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.card h2 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--text);
}

/* ── Forms ────────────────────────────────────────────────── */
label {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
}

textarea {
    min-height: 80px;
    resize: vertical;
}

.form-row {
    margin-bottom: 12px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* ── Editor sidebar ──────────────────────────────────────── */
.editor-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 480px;
    height: 100vh;
    background: var(--bg-card);
    box-shadow: -4px 0 24px rgba(0,0,0,0.15);
    z-index: 900;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
    pointer-events: none;
}
.editor-sidebar.open { transform: translateX(0); pointer-events: auto; }

.sidebar-inner {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

/* Close button — always visible */
.sidebar-close {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
.sidebar-close:hover { color: var(--text); }

/* Sticky footer */
.sidebar-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    flex-shrink: 0;
}

/* Photo editor panel — sits to the left of the sidebar */
.photo-editor-panel {
    position: fixed;
    top: 0;
    right: 480px;
    width: 500px;
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    box-shadow: -2px 0 12px rgba(0,0,0,0.1);
    z-index: 899;
    transform: translateX(100%);
    opacity: 0;
    transition: transform 0.25s ease, opacity 0.25s ease;
    display: flex;
    flex-direction: column;
    padding: 20px;
    pointer-events: none;
}
.photo-editor-panel.open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}
.photo-editor-panel .crop-container {
    flex: 0 1 auto;
    min-height: 0;
    max-height: calc(100vh - 140px);
    width: 100%;
    /* aspect-ratio set dynamically by JS via updateCropAspectButtons */
}
.photo-editor-panel .crop-controls {
    padding-top: 12px;
    flex-shrink: 0;
}
body.crop-open .container-wide {
    margin-right: 990px;
}

/* Sidebar form adjustments */
.editor-sidebar .form-grid {
    grid-template-columns: 1fr;
}
.editor-sidebar .photo-slots {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

/* Main content shifts when sidebar is open */
body.sidebar-open .container-wide {
    margin-right: 490px;
    transition: margin-right 0.25s ease;
}

/* ── Markdown editor ─────────────────────────────────────── */
.md-editor {
    position: relative;
}
.md-preview {
    min-height: 60px;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.5;
    cursor: text;
    color: var(--text);
}
.md-preview:empty::before {
    color: var(--text-muted);
    opacity: 0.5;
    font-style: italic;
}
.md-preview p { margin: 0 0 8px 0; }
.md-preview p:last-child { margin-bottom: 0; }
.md-preview h1, .md-preview h2, .md-preview h3 { margin: 8px 0 4px; font-size: 15px; }
.md-preview ul, .md-preview ol { margin: 4px 0; padding-left: 20px; }
.md-preview code { background: var(--border); padding: 1px 4px; border-radius: 3px; font-size: 13px; }
.md-preview a { color: var(--accent); }
.md-toolbar {
    display: flex;
    gap: 2px;
    padding: 4px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
}
.md-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    width: 30px;
    height: 26px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
}
.md-btn:hover { background: var(--bg-input); border-color: var(--accent); }
.md-textarea {
    display: none;
    width: 100%;
    min-height: 60px;
    resize: none;
    overflow: hidden;
}
.md-editor.editing .md-preview { display: none; }
.md-editor.editing .md-textarea { display: block; }
.md-editor.editing .md-toolbar { display: flex !important; }
.md-editor.editing .md-textarea {
    border-radius: 0 0 var(--radius) var(--radius);
}

/* Auto-expand textareas in sidebar */
.editor-sidebar textarea {
    resize: none;
    overflow: hidden;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: white; }
.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* ── Grid (items) ────────────────────────────────────────── */
.items-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.item-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
}

.item-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.item-card-image {
    width: 100%;
    aspect-ratio: 1/1;
    background: var(--bg-input);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.item-card-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-orientation: from-image;
}

.item-card-image .placeholder {
    color: var(--text-muted);
    font-size: 32px;
}

/* Modal back button */
.modal-back {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 26px;
    font-weight: bold;
    cursor: pointer;
    padding: 4px 12px;
    flex-shrink: 0;
    transition: color 0.15s;
}
.modal-back:hover { color: var(--text); }

/* Crop focus ring — disabled on grid cards (shows cropped thumbnail already) */
.card-crop-ring {
    display: none;
}

.item-card-body {
    padding: 12px;
}

.item-card-body h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-card-body .meta {
    font-size: 13px;
    color: #5C4A3A;
    word-spacing: 1px;
    letter-spacing: 0.2px;
}

/* ── Table view ──────────────────────────────────────────── */
.items-table {
    width: 100%;
    border-collapse: collapse;
}

.items-table th,
.items-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.items-table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.items-table tr:hover td {
    background: var(--bg-input);
}

/* ── Pagination ──────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 20px;
}

.pagination button {
    padding: 6px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
}

.pagination button:hover { border-color: var(--accent); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .page-info { color: var(--text-muted); font-size: 13px; }

/* ── Toolbar ─────────────────────────────────────────────── */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.toolbar .search-input {
    flex: 1;
    min-width: 200px;
}

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-header h2 { font-size: 18px; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
}

.modal-close:hover { color: var(--text); }

/* ── Photo slots ─────────────────────────────────────────── */
.photo-slots {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.photo-slot {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.photo-slot .slot-image {
    aspect-ratio: 4/3;
    background: var(--bg-input);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: border-color 0.15s;
}

.photo-slot .slot-image:hover { border-color: var(--accent); }
.photo-slot.drag-over .slot-image { border-color: var(--accent); background: rgba(59, 130, 246, 0.15); }
.photo-slot.primary .slot-image { border-color: var(--success); border-style: solid; }
.photo-slot.has-photo .slot-image { border-style: solid; }

.photo-slot .slot-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.photo-slot .slot-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 24px;
}

.photo-slot .slot-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
}

.photo-slot.primary .slot-label {
    color: var(--success);
}

.photo-slot .slot-actions {
    display: none;
    gap: 4px;
    margin-left: auto;
}

.photo-slot.has-photo:hover .slot-actions { display: flex; }

.slot-actions .btn {
    padding: 2px 8px;
    font-size: 11px;
}

/* Drag-and-drop reorder */
.photo-slot[draggable="true"] .slot-image { cursor: grab; }
.photo-slot[draggable="true"]:active .slot-image { cursor: grabbing; }
.photo-slot.dragging { opacity: 0.3; }

/* Arrow buttons for photo reorder */
.slot-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.55);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 22px;
    line-height: 32px;
    text-align: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 3;
    padding: 0;
}
.photo-slot:hover .slot-arrow { opacity: 0.8; }
.slot-arrow:hover { opacity: 1 !important; background: rgba(0,0,0,0.8); }
.slot-arrow-left { left: 6px; }
.slot-arrow-right { right: 6px; }

/* Invisible contenteditable overlay so right-click shows Paste */
.slot-paste-target {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 1;
    overflow: hidden;
}
.slot-paste-target:focus { outline: none; }

/* Photo metadata hover popup */
.photo-meta-popup {
    display: none;
    position: fixed;
    z-index: 1500;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text);
    max-width: 300px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    pointer-events: none;
}
.photo-meta-popup .meta-label { color: var(--text-muted); }
.photo-meta-popup a { pointer-events: auto; color: var(--accent); font-size: 11px; }
.photo-slot.drop-before::before,
.photo-slot.drop-after::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent);
    border-radius: 2px;
    z-index: 10;
}
.photo-slot.drop-before::before { left: -6px; }
.photo-slot.drop-after::after { right: -6px; }
.photo-slot { position: relative; }

/* ── Crop editor ─────────────────────────────────────────── */
.crop-container {
    max-width: 100%;
    max-height: 450px;
    margin: 0 auto;
    background: #1a1a1a;
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
    user-select: none;
}

.crop-container img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none;
}

/* Dimming overlays around the selection */
.crop-dim {
    position: absolute;
    background: rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

/* Selection rectangle */
.crop-selection {
    position: absolute;
    border: 2px dashed rgba(255, 255, 255, 0.8);
    cursor: move;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0);
}

/* Resize handles */
.crop-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: white;
    border: 1px solid var(--accent);
    border-radius: 2px;
}
.crop-handle[data-handle="nw"] { top: -5px; left: -5px; cursor: nw-resize; }
.crop-handle[data-handle="ne"] { top: -5px; right: -5px; cursor: ne-resize; }
.crop-handle[data-handle="sw"] { bottom: -5px; left: -5px; cursor: sw-resize; }
.crop-handle[data-handle="se"] { bottom: -5px; right: -5px; cursor: se-resize; }
.crop-handle[data-handle="n"] { top: -5px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.crop-handle[data-handle="s"] { bottom: -5px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.crop-handle[data-handle="e"] { top: 50%; right: -5px; transform: translateY(-50%); cursor: e-resize; }
.crop-handle[data-handle="w"] { top: 50%; left: -5px; transform: translateY(-50%); cursor: w-resize; }


/* ── Lookup management ───────────────────────────────────── */
.lookup-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.lookup-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-input);
    border-radius: var(--radius);
}

.lookup-item .name { font-weight: 500; }
.lookup-item .count { color: var(--text-muted); font-size: 13px; }

/* ── Auth (login page) ───────────────────────────────────── */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
    width: 100%;
    max-width: 400px;
}

.auth-box h1 {
    font-size: 28px;
    margin-bottom: 4px;
}

.auth-box .subtitle {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 14px;
}

.auth-box .form-row { margin-bottom: 16px; }
.auth-box .btn { width: 100%; justify-content: center; margin-top: 8px; }
.btn-row .btn { width: auto; margin-top: 0; }

.auth-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 13px;
    color: var(--danger);
    margin-bottom: 12px;
    display: none;
}

.auth-success {
    background: rgba(39, 174, 96, 0.12);
    border: 1px solid var(--success);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 13px;
    color: var(--success);
    margin-bottom: 12px;
}

/* ── Change password modal ────────────────────────────────── */
#change-pw-modal {
    display: flex;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9000;
    padding: 24px;
}

/* ── Filter row (compact single line) ────────────────────── */
.filter-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.search-wrap {
    position: relative;
    flex: 0 0 auto;
}
.search-wrap input {
    width: 160px;
    padding: 7px 28px 7px 12px;
    font-size: 16px;
}
.search-clear {
    display: none;
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 18px;
    padding: 2px 6px;
    line-height: 1;
}
.search-clear:hover { color: var(--text); }
.search-wrap input:not(:placeholder-shown) ~ .search-clear { display: block; }

.filter-row select {
    padding: 7px 8px;
    font-size: 16px;
    min-width: 0;
    flex: 1;
}

/* ── Multi-select filter dropdown ────────────────────────── */
.multi-select {
    position: relative;
    flex: 1;
    min-width: 0;
}
.multi-select-btn {
    width: 100%;
    padding: 7px 28px 7px 8px;
    font-size: 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238C7B6B'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}
.multi-select-btn.has-selection { font-weight: 600; color: var(--accent); }
.multi-select-panel {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 100%;
    max-height: 280px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    z-index: 500;
    padding: 4px 0;
}
.multi-select.open .multi-select-panel { display: block; }
.multi-select-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
}
.multi-select-item:hover { background: var(--bg-input); }
.multi-select-item input[type="checkbox"] { flex-shrink: 0; }

/* ── Stats + sort row ────────────────────────────────────── */
.stats-sort-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.stats-bar {
    display: flex;
    gap: 14px;
    font-size: 16px;
    color: #5C4A3A;
    flex-wrap: wrap;
}

.stats-bar a {
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
}

.stats-bar a:hover { color: var(--text); }

.stats-bar strong {
    color: var(--accent);
    font-weight: 700;
    font-size: 18px;
}

/* ── Sort pills ──────────────────────────────────────────── */
.sort-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    font-size: 15px;
    color: #5C4A3A;
}

.sort-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    cursor: pointer;
    font-size: 14px;
    color: #3C2415;
    user-select: none;
    transition: border-color 0.15s;
}

.sort-pill:hover { border-color: var(--accent); }
.sort-pill.active { border-color: var(--accent); background: rgba(139, 69, 19, 0.1); }

.sort-pill .sort-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    font-size: 10px;
    font-weight: 700;
}

.sort-pill .sort-dir { font-size: 10px; opacity: 0.7; }

.sort-pill.drag-left { box-shadow: -3px 0 0 0 var(--accent); }
.sort-pill.drag-right { box-shadow: 3px 0 0 0 var(--accent); }

.sort-then { color: var(--text-muted); font-size: 11px; }

/* ── Sortable table headers ──────────────────────────────── */
.items-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.items-table th.sortable:hover {
    color: var(--accent);
}

/* ── Tag input (mediums autocomplete) ────────────────────── */
.tag-input-wrapper {
    position: relative;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    cursor: text;
}

.tag-input-wrapper:focus-within { border-color: var(--accent); }

.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--accent);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    white-space: nowrap;
}

.tag-chip .tag-text:hover {
    text-decoration: underline;
}

.tag-chip .tag-remove {
    cursor: pointer;
    opacity: 0.7;
    font-size: 14px;
    line-height: 1;
}

.tag-chip .tag-remove:hover { opacity: 1; }

.tag-input-wrapper input {
    border: none;
    background: transparent;
    outline: none;
    padding: 4px 0;
    font-size: 13px;
    color: var(--text);
    flex: 1;
    min-width: 80px;
}
.tag-input-wrapper input.tag-unresolved {
    color: var(--danger);
    border-bottom: 2px solid var(--danger);
}

.tag-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 180px;
    overflow-y: auto;
    z-index: 100;
    margin-top: 2px;
}

.tag-dropdown.visible { display: block; }

.tag-dropdown-item {
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text);
}

.tag-dropdown-item:hover,
.tag-dropdown-item.highlighted { background: var(--bg-input); }

.tag-dropdown-item.add-new {
    color: var(--accent);
    font-style: italic;
    border-top: 1px solid var(--border);
}

/* ── Invite banner ───────────────────────────────────────── */
.invite-banner {
    background: rgba(139, 69, 19, 0.1);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 10px 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 14px;
}

.invite-banner .invite-info { flex: 1; }
.invite-banner .invite-actions { display: flex; gap: 6px; }

/* ── Photo picker modal ─────────────────────────────────── */
.photo-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 4px;
}

.photo-picker-thumb {
    aspect-ratio: 4/3;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
}

.photo-picker-thumb:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.photo-picker-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.photo-picker-thumb .picker-info {
    font-size: 10px;
    color: var(--text-muted);
    padding: 2px 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.photo-picker-search {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    align-items: center;
}

.photo-picker-search input {
    flex: 1;
}

.photo-picker-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 32px;
    font-size: 14px;
}

/* ── Photo slot context menu ────────────────────────────── */
.slot-menu {
    position: absolute;
    z-index: 1100;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 4px 0;
    min-width: 160px;
}

.slot-menu-item {
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.slot-menu-item:hover {
    background: var(--bg-input);
}

/* ── Item editor modal ──────────────────────────────────── */
.item-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 900;
    align-items: center;
    justify-content: center;
}
.item-modal-overlay.active { display: flex; }

.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.4);
    color: rgba(255,255,255,0.7);
    border: none;
    font-size: 48px;
    line-height: 1;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    z-index: 910;
    transition: background 0.2s, color 0.2s;
}
.modal-nav:hover { background: rgba(0,0,0,0.7); color: #fff; }
.modal-nav:disabled { opacity: 0.2; pointer-events: none; }
.modal-nav-prev { left: 8px; }
.modal-nav-next { right: 8px; }

.item-modal {
    background: var(--bg-card);
    border-radius: 12px;
    width: 92vw;
    height: 90vh;
    max-width: 1600px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 40px rgba(0,0,0,0.3);
    animation: modalSlideIn 0.25s ease-out;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

.item-modal-header {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}

.header-title-input {
    flex: 1;
    border: 1px solid var(--border) !important;
    background: var(--bg-input) !important;
    font-size: 16px !important;
    font-weight: 600;
    color: var(--text) !important;
    padding: 6px 10px !important;
    min-width: 0;
    border-radius: var(--radius);
}

.item-modal-id {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
    margin-left: auto;
}

.item-modal-status {
    font-size: 11px;
    color: var(--text-muted);
}

.item-modal-header .modal-close {
    flex-shrink: 0;
}

.item-modal-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Left side: photos */
.item-modal-photos {
    flex: 0 0 auto;
    width: 45%;
    display: flex;
    flex-direction: column;
    padding: 0 12px 12px 12px;
    background: #1a1a1a;
    border-radius: 0 0 0 12px;
}

.primary-photo-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    max-height: calc(90vh - 200px); /* bound height so portraits don't dominate */
}

.primary-photo-wrap img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

.primary-photo-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.3);
    font-size: 18px;
}

/* Crop ring: solid subtle ring always visible, dashed + handles on hover */
.primary-photo-wrap .crop-selection {
    border: 2px solid rgba(255, 255, 255, 0.6);
    transition: border 0.2s ease;
}
.primary-photo-wrap .crop-handle {
    opacity: 0;
    transition: opacity 0.2s ease;
}
.primary-photo-wrap .crop-dim {
    opacity: 0.3;
    transition: opacity 0.2s ease;
}
.primary-photo-wrap:hover .crop-selection,
.primary-photo-wrap.crop-active .crop-selection {
    border: 2px dashed rgba(255, 255, 255, 0.9);
}
.primary-photo-wrap:hover .crop-handle,
.primary-photo-wrap.crop-active .crop-handle {
    opacity: 1;
}
.primary-photo-wrap:hover .crop-dim,
.primary-photo-wrap.crop-active .crop-dim {
    opacity: 0.5;
}

/* Photo filename — always visible below image */
.photo-toolbar-row {
    display: flex;
    align-items: center;
    padding: 4px 0;
    gap: 12px;
}
.photo-toolbar-filename {
    font-size: 13px;
    color: #C4A882;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.photo-toolbar-filename:hover { text-decoration: underline; color: #FAF6F1; }
/* Photo toolbar — right of filename, visible on hover */
.photo-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.item-modal-photos:hover .photo-toolbar,
.photo-toolbar:hover { opacity: 1; pointer-events: auto; }
.photo-mode-toggle { display: flex; }
.photo-toolbar > .seg-btn { border-radius: 4px; }
.seg-btn-dark {
    background: var(--bg-card);
    border-color: var(--border);
    color: var(--text-muted);
}
.seg-btn-dark:hover { background: var(--bg-hover); color: var(--text); }
.seg-btn-dark.seg-active { background: var(--accent); color: white; border-color: var(--accent); }
.seg-btn-dark:disabled { opacity: 0.35; pointer-events: none; }
.seg-btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    border-radius: 4px;
}
.seg-btn-primary:hover { background: var(--accent-hover); }
.photo-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}
.photo-toolbar-actions .seg-btn { border-radius: 4px; }

/* Reduce dim overlay intensity for inline crop */
.primary-photo-wrap .crop-dim {
    background: rgba(0, 0, 0, 0.3);
}

.secondary-thumbs {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    flex-shrink: 0;
    justify-content: flex-start;
}

.secondary-thumb {
    flex: 0 1 calc(25% - 5px);
    max-width: calc(25% - 5px);
    aspect-ratio: 1/1;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.2);
    transition: border-color 0.15s;
}

.secondary-thumb { position: relative; }
.secondary-thumb:hover { border-color: rgba(255,255,255,0.6); }
.secondary-thumb.active { border-color: var(--accent); border-width: 3px; }

.secondary-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: rgba(0,0,0,0.3);
}

.secondary-thumb .thumb-arrows {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 3px;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 3;
    pointer-events: none;
}
.secondary-thumb:hover .thumb-arrows { opacity: 1; }
.thumb-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 14px;
    line-height: 18px;
    text-align: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    padding: 0;
    z-index: 2;
}
.thumb-remove:hover { background: rgba(180,0,0,0.8); }
.secondary-thumb:hover .thumb-remove { opacity: 1; }
.thumb-arrow {
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 20px;
    line-height: 28px;
    text-align: center;
    cursor: pointer;
    padding: 0;
    pointer-events: auto;
}
.thumb-arrow:hover { background: rgba(0,0,0,0.85); }

.thumb-label {
    position: absolute;
    bottom: 2px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 10px;
    font-weight: 600;
    color: white;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.add-photo-thumb {
    width: 120px;
    height: 100px;
    border-radius: 6px;
    border: 2px dashed rgba(255,255,255,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.4);
    font-size: 24px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
    flex-shrink: 0;
    caret-color: transparent;
    -webkit-user-modify: read-write-plaintext-only;
}
.add-photo-thumb:focus { outline: none; }

.add-photo-thumb:hover {
    border-color: rgba(255,255,255,0.6);
    color: rgba(255,255,255,0.7);
}

/* Right side: fields */
.item-modal-fields {
    flex: 1;
    padding: 12px 20px;
    overflow-y: auto;
    min-width: 0;
}

.item-modal-fields .form-row {
    margin-bottom: 4px;
}

.item-modal-fields label {
    font-size: 12px;
    margin-bottom: 1px;
}

.item-modal-fields input[type="text"],
.item-modal-fields textarea,
.item-modal-fields .tag-input-wrapper,
.item-modal-fields .tag-input-wrapper input,
.item-modal-fields .md-preview,
.item-modal-fields .md-textarea {
    font-size: 14px;
    padding: 6px 10px;
}

/* Tag wrappers in modal match plain input height */
.item-modal-fields .tag-input-wrapper {
    min-height: 0;
    height: 31px;
    box-sizing: border-box;
    padding: 3px 8px;
    flex-wrap: nowrap;
}

/* Dimmer placeholder text across all modal fields */
.item-modal-fields input::placeholder,
.item-modal-fields textarea::placeholder,
.item-modal-fields .tag-input-wrapper input::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
    font-style: italic;
}

/* Quill WYSIWYG editors in modal */
.item-modal-fields .ql-container {
    font-size: 14px;
    font-family: inherit;
    border-color: var(--border);
    background: var(--bg-input);
    color: var(--text);
    border-radius: 0 0 var(--radius) var(--radius);
}
.item-modal-fields .ql-toolbar {
    border-color: var(--border);
    background: var(--bg-card);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 4px;
    display: none;
}
.item-modal-fields .ql-toolbar.ql-active {
    display: flex;
}
.item-modal-fields .ql-container.ql-no-toolbar {
    border-radius: var(--radius);
}
.item-modal-fields .ql-toolbar button {
    width: 26px;
    height: 24px;
}
.item-modal-fields .ql-editor {
    min-height: 36px;
    padding: 6px 10px;
    max-height: 120px;
    overflow-y: auto;
}
.item-modal-fields .ql-editor.ql-blank::before {
    color: var(--text-muted);
    opacity: 0.5;
    font-style: italic;
}
.item-modal-fields .ql-editor p { margin: 0 0 4px 0; }
.item-modal-fields .ql-editor p:last-child { margin-bottom: 0; }
.item-modal-fields .ql-snow .ql-stroke { stroke: var(--text); }
.item-modal-fields .ql-snow .ql-fill { fill: var(--text); }
.item-modal-fields .ql-snow .ql-picker { color: var(--text); }
.item-modal-fields .ql-snow .ql-picker-options { background: var(--bg-card); border-color: var(--border); }

.fields-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 4px;
}

/* Uncertain pill (inside tag inputs, right-justified) */
.uncertain-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 12px;
    font-size: 12px;
    padding: 2px 8px;
    margin-left: auto;
    white-space: nowrap;
    cursor: default;
}
.uncertain-pill .tag-remove {
    cursor: pointer;
    opacity: 0.7;
    font-size: 14px;
    line-height: 1;
}
.uncertain-pill .tag-remove:hover { opacity: 1; }

/* Year field uncertain pill (sits beside the input) */
.year-uncertain-pill {
    margin-left: 4px;
    flex-shrink: 0;
}

/* Uncertain toggle button (legacy, kept for compat) */
.uncertain-toggle {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 11px;
    padding: 4px 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.uncertain-toggle:hover {
    border-color: var(--accent);
}

.uncertain-toggle.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ── Build number ────────────────────────────────────────── */
.build-number {
    position: fixed;
    bottom: 8px;
    right: 12px;
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.4;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .app-header { flex-direction: column; gap: 8px; }
    .form-grid { grid-template-columns: 1fr; }
    .photo-slots { grid-template-columns: repeat(2, 1fr); }
    .items-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .filter-row { flex-wrap: wrap; }
    .filter-row select { max-width: none; flex: 1; min-width: 100px; }
    .editor-sidebar { width: 100%; }
    body.sidebar-open .container-wide { margin-right: 0; display: none; }
}
