/* ===== Image Manager - Main Styles ===== */
:root {
    --primary: #1a5276;
    --primary-light: #2980b9;
    --accent: #c0392b;
    --bg: #f4f6f8;
    --panel-bg: #ffffff;
    --border: #dce1e6;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --success: #27ae60;
    --warning: #f39c12;
    --selected: #d4e6f1;
    --hover: #eaf2f8;
    --toolbar-bg: #ecf0f1;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== Header / Toolbar ===== */
.header {
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
}

.header h1 {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
}

.header .topbar-shop-name {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    color: #fff;
}

.header .change-shop-link {
    font-size: 12px;
    color: #9db9ff;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.header .change-shop-link:hover {
    text-decoration: underline;
}

.header .user-info {
    font-size: 12px;
    opacity: 0.8;
    margin-left: auto;
}

/* ===== Control Bar ===== */
.control-bar {
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.control-bar label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.control-bar select,
.control-bar input {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    background: white;
    color: var(--text);
    outline: none;
}

.control-bar select:focus,
.control-bar input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 2px rgba(41,128,185,0.15);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.separator {
    width: 1px;
    height: 28px;
    background: var(--border);
    margin: 0 4px;
}

/* ===== View Tabs ===== */
.view-tabs {
    display: flex;
    gap: 2px;
}

.view-tab {
    padding: 7px 18px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    background: white;
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.view-tab:disabled {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
}

.view-tab:hover {
    background: var(--hover);
}

.view-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.view-tab.active-red {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ===== Action Buttons ===== */
.btn {
    padding: 9px 22px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    background: white;
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn:hover { background: var(--hover); }
.btn:active { transform: scale(0.98); }
.btn:disabled {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-light); }

.btn-danger {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.btn-danger:hover { background: #e74c3c; }

.btn-success {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

/* ===== Image Actions Bar (shown when in RO view) ===== */
.ro-actions-bar {
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border);
    padding: 6px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ro-actions-bar.hidden {
    display: none;
}

.image-actions-bar {
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border);
    padding: 6px 16px;
    display: none;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.image-actions-bar.visible {
    display: flex;
}

.image-filter-tabs {
    display: flex;
    gap: 2px;
}

.image-filter-tab {
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 13px;
    font-weight: 600;
    background: white;
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s ease;
}

.image-filter-tab:hover { background: var(--hover); }
.image-filter-tab.active {
    background: var(--primary-light);
    color: white;
    border-color: var(--primary-light);
}

/* ===== Status Bar ===== */
.status-bar {
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    font-size: 12px;
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
}

.status-bar .count {
    font-weight: 600;
    color: var(--text);
}

.status-bar .selected-count {
    color: var(--primary);
    font-weight: 600;
}

.status-bar #viewLabel {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    pointer-events: none;
}

/* ===== Main Content - Thumbnail Grid ===== */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.thumbnail-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-content: flex-start;
}

/* ===== Thumbnail Item ===== */
.thumb-item {
    width: calc(var(--thumb-size, 150px) + 30px);
    border: 2px solid var(--border);
    border-radius: 6px;
    background: white;
    cursor: pointer;
    transition: all 0.15s ease;
    overflow: hidden;
    user-select: none;
}

.thumb-item:hover {
    border-color: var(--primary-light);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.thumb-item.selected {
    border-color: var(--primary);
    background: var(--selected);
    box-shadow: 0 0 0 2px rgba(41,128,185,0.3);
}

.thumb-image-wrap {
    width: 100%;
    height: var(--thumb-size, 150px);
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    overflow: hidden;
    position: relative;
}

.thumb-image-wrap img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.thumb-image-wrap .no-image {
    color: #bdc3c7;
    font-size: 40px;
}

.thumb-select-check {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 20px;
    height: 20px;
    border: 2px solid white;
    border-radius: 3px;
    background: rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: white;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.thumb-item:hover .thumb-select-check,
.thumb-item.selected .thumb-select-check {
    opacity: 1;
}

.thumb-item.selected .thumb-select-check {
    background: var(--primary);
    border-color: var(--primary);
}

.thumb-info {
    padding: 6px 8px;
    font-size: 11px;
    line-height: 1.4;
    border-top: 1px solid var(--border);
}

.thumb-info .ro-number {
    font-weight: 700;
    font-size: 12px;
    color: var(--primary);
}

.thumb-info .ro-name {
    color: var(--text);
    font-weight: 600;
}

.thumb-info .ro-date,
.thumb-info .ro-claim {
    color: var(--text-light);
    font-size: 10px;
}

.thumb-info .ro-writer {
    color: var(--primary-light);
    font-size: 10px;
}

.thumb-info .badge {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-archived {
    background: #f39c12;
    color: white;
}

.badge-deleted {
    background: var(--accent);
    color: white;
}

/* ===== Full-size Image Viewer Overlay ===== */
.image-viewer-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.85);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

.image-viewer-overlay.visible {
    display: flex;
}

.image-viewer-overlay img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 4px;
    position: relative;
    z-index: 1;
    transform-origin: center center;
    will-change: transform;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.image-viewer-overlay .viewer-controls {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 10;
}

.image-viewer-overlay .viewer-zoom-slider {
    width: 120px;
    height: 6px;
    accent-color: #fff;
    cursor: pointer;
    background: rgba(255,255,255,0.25);
    border-radius: 4px;
    padding: 6px 10px;
    box-sizing: content-box;
    backdrop-filter: blur(4px);
}

.image-viewer-overlay .viewer-btn {
    padding: 8px 14px;
    background: rgba(255,255,255,0.15);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    backdrop-filter: blur(4px);
}

.image-viewer-overlay .viewer-btn:hover {
    background: rgba(255,255,255,0.25);
}

.image-viewer-overlay .viewer-info {
    color: white;
    font-size: 13px;
    margin-top: 10px;
    text-align: center;
    opacity: 0.8;
    position: relative;
    z-index: 10;
}

.image-viewer-overlay .nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    padding: 16px 12px;
    background: rgba(255,255,255,0.1);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 28px;
    border-radius: 4px;
    backdrop-filter: blur(4px);
    z-index: 10;
}

.nav-arrow:hover { background: rgba(255,255,255,0.2); }
.nav-arrow.prev { left: 12px; }
.nav-arrow.next { right: 12px; }

/* ===== Search Panel ===== */
.search-panel {
    display: none;
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    gap: 10px;
    align-items: flex-end;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.search-panel.visible {
    display: flex;
}

.search-panel .form-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.search-panel label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
}

.search-panel input,
.search-panel select {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
}

/* ===== Loading Spinner ===== */
.loading-overlay {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.8);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.loading-overlay.visible {
    display: flex;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Empty State ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-light);
    gap: 8px;
    padding: 40px;
}

.empty-state .icon { font-size: 48px; opacity: 0.4; }
.empty-state .message { font-size: 16px; font-weight: 600; }
.empty-state .sub-message { font-size: 13px; }

/* ===== Responsive adjustments ===== */
@media (max-width: 768px) {
    .control-bar { padding: 6px 10px; gap: 8px; }
    .thumb-item { width: 140px; }
    .thumb-image-wrap { height: 120px; }
    .separator { display: none; }
}

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

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

.modal-box {
    background: white;
    border-radius: 8px;
    padding: 20px 24px;
    width: 420px;
    max-width: 90vw;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-box h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.form-row label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-row input,
.form-row select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    outline: none;
}

.form-row input:focus,
.form-row select:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 2px rgba(41,128,185,0.15);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* ===== Move Target List ===== */
.move-target-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-top: 6px;
}

.move-target-item {
    padding: 8px 10px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.1s ease;
}

.move-target-item:hover {
    background: var(--hover);
}

.move-target-item.selected {
    background: var(--selected);
    font-weight: 600;
}

.move-target-item .ro-num {
    font-weight: 700;
    color: var(--primary);
}

.move-selected-target {
    margin-top: 8px;
    padding: 8px 10px;
    background: var(--selected);
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
}

/* ===== Context Menu ===== */
.context-menu {
    display: none;
    position: fixed;
    z-index: 3000;
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    min-width: 180px;
    padding: 4px 0;
}

.context-menu.visible {
    display: block;
}

.context-menu-item {
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.1s ease;
}

.context-menu-item:hover {
    background: var(--hover);
}

.context-menu-item.danger {
    color: var(--accent);
}

.context-menu-separator {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* ===== Toast Notification ===== */
.toast {
    display: none;
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 5000;
    transition: opacity 0.3s ease;
}

.toast.visible {
    display: block;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--accent); }

/* Permission Denied slide-out banner (slides down from top) */
.perm-banner {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translate(-50%, -120%);
    background: var(--accent);
    color: #fff;
    padding: 12px 44px 12px 18px;
    border-radius: 0 0 8px 8px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 6px 20px rgba(0,0,0,0.28);
    z-index: 6000;
    max-width: 90vw;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
    pointer-events: none;
}
.perm-banner.visible {
    transform: translate(-50%, 0);
    pointer-events: auto;
}
.perm-banner .perm-banner-icon {
    font-size: 16px;
    line-height: 1;
}
.perm-banner .perm-banner-close {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.85;
    padding: 0;
}
.perm-banner .perm-banner-close:hover { opacity: 1; }

/* ===== Upload Dropzone ===== */
.upload-dropzone {
    padding: 8px 16px 0;
}

.upload-area {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #fafbfc;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary-light);
    background: var(--hover);
}

.upload-icon { font-size: 28px; margin-bottom: 4px; }
.upload-text { font-size: 13px; color: var(--text); }
.upload-sub { font-size: 11px; color: var(--text-light); margin-top: 2px; }
.upload-link { color: var(--primary-light); cursor: pointer; text-decoration: underline; font-weight: 600; }

.upload-progress {
    margin-top: 8px;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
    height: 28px;
    position: relative;
}

.upload-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--primary-light);
    transition: width 0.3s ease;
}

.upload-progress-text {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
}

/* ===== Login Overlay ===== */
.login-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}
.login-box {
    background: white;
    border-radius: 12px;
    padding: 32px;
    width: 360px;
    max-width: 90vw;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
}
.login-box h2 {
    font-size: 20px;
    color: var(--primary);
    margin-bottom: 4px;
}
.login-subtitle {
    font-size: 13px;
    color: #666;
    margin-bottom: 12px;
    text-align: center;
}
.login-field {
    width: 100%;
    margin-bottom: 12px;
}
.login-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #555;
}
.login-field input,
.login-field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}
.login-field input:focus,
.login-field select:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(41,128,185,0.2);
}
.login-btn {
    width: 100%;
    padding: 10px;
    font-size: 14px;
}
.login-error {
    width: 100%;
    color: #e74c3c;
    font-size: 12px;
    min-height: 18px;
    margin-bottom: 8px;
    text-align: center;
}

/* ===== Settings Tabs ===== */
.settings-tab {
    padding: 8px 20px;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 600;
    color: #888;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}
.settings-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.settings-tab:hover { color: var(--primary); }

/* ===== Users Table ===== */
.users-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.users-table th { background: #f0f3f6; padding: 6px 8px; text-align: left; font-weight: 600; position: sticky; top: 0; }
.users-table td { padding: 5px 8px; border-bottom: 1px solid #eee; }
.users-table tr:hover td { background: #f8f9fa; }
.users-table .inactive { opacity: 0.5; }

/* ===== Permission Checkboxes ===== */
.perm-check {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    cursor: pointer;
    margin-bottom: 6px;
    break-inside: avoid;
}

