:root {
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #e5e7eb;
    --secondary-hover: #d1d5db;
    --danger: #ef4444;
    --danger-hover: #dc2828;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    height: 70px;
    box-shadow: var(--shadow-sm);
    z-index: 10;
    position: sticky;
    top: 0;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gradient-text {
    background: linear-gradient(135deg, #4f46e5 0%, #0ea5e9 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-main);
    background: var(--secondary);
}

.tab-btn.active {
    color: var(--primary);
    background: #eef2ff;
    font-weight: 600;
}

/* Main Layout */
.app-container {
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    padding: 2rem;
}

.view-section {
    display: none;
}

.view-section.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.split-layout {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* Form Panel */
.form-panel h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #f9fafb;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.help-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

.form-actions {
    margin-top: 2rem;
}

.shortcut-tip {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.5rem;
}

/* Buttons */
.btn {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

.btn-primary:not(:disabled):hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--secondary);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: var(--secondary-hover);
}

.btn-capture {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    font-size: 1.1rem;
    box-shadow: 0 4px 14px 0 rgba(16, 185, 129, 0.39);
}

.btn-capture:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px 0 rgba(16, 185, 129, 0.39);
}

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

.btn-text {
    background: none;
    border: none;
    font-size: 0.85rem;
    cursor: pointer;
    font-weight: 500;
}

.btn-danger {
    color: var(--danger);
}

.btn-danger:not(:disabled):hover {
    color: var(--danger-hover);
    text-decoration: underline;
}

/* Camera Panel */
.camera-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.camera-select {
    padding: 0.4rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    font-size: 0.9rem;
    max-width: 250px;
}

.video-container {
    width: 100%;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 16/9;
    position: relative;
    margin-bottom: 1rem;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.loader-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2;
    font-size: 1.1rem;
}

/* Gallery */
.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 1.5rem 0 0.5rem 0;
}

.gallery-container {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 10px 0;
    min-height: 140px;
}

.thumb-item {
    width: 120px;
    height: 120px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    border: 2px solid transparent;
    transition: transform 0.2s, border-color 0.2s;
    flex-shrink: 0;
    background: #eee;
}

.thumb-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumb-item:hover {
    transform: scale(1.05);
}

.thumb-item.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.3);
}

/* Catalog Master-Detail Layout */
.catalog-master-detail {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 0;
    height: calc(100vh - 70px - 4rem);
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

/* LEFT PANEL — Search + List */
.catalog-list-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.catalog-search-bar {
    display: flex;
    gap: 6px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    background: #f9fafb;
}

.catalog-search-bar input {
    flex: 1;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.88rem;
}

.catalog-search-bar .btn {
    width: auto;
    padding: 0.5rem 0.8rem;
    font-size: 0.9rem;
}

.search-type {
    padding: 0.5rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.82rem;
    min-width: 80px;
    background: #fff;
}

.catalog-list {
    flex: 1;
    overflow-y: auto;
}

.list-placeholder {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem 1rem;
    font-size: 0.9rem;
}

/* Compact list row */
.list-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

.list-row:hover {
    background: #f5f3ff;
}

.list-row.active {
    background: #eef2ff;
    border-left: 3px solid var(--primary);
}

.list-row-thumb {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    object-fit: cover;
    background: #e5e7eb;
    flex-shrink: 0;
}

.list-row-info {
    flex: 1;
    min-width: 0;
}

.list-row-vendor {
    font-size: 0.72rem;
    color: var(--primary);
    font-weight: 600;
    text-transform: uppercase;
}

.list-row-title {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-row-id {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* RIGHT PANEL — Detail */
.catalog-detail-panel {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.detail-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 10px;
}

.detail-empty-icon {
    font-size: 3rem;
}

.detail-content {
    padding: 1.5rem;
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.2rem;
}

.detail-id {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.detail-title {
    font-size: 1.4rem;
    font-weight: 700;
}

.detail-vendor {
    font-size: 0.85rem;
    color: var(--primary);
    font-weight: 600;
    margin-top: 2px;
}

.detail-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.btn-edit-detail {
    padding: 7px 14px;
    background: rgba(79, 70, 229, .1);
    border: 1px solid rgba(79, 70, 229, .3);
    color: var(--primary);
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all .2s;
}

.btn-edit-detail:hover {
    background: rgba(79, 70, 229, .2);
}

.btn-delete-detail {
    padding: 7px 12px;
    background: rgba(239, 68, 68, .08);
    border: 1px solid rgba(239, 68, 68, .3);
    color: var(--danger);
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all .2s;
}

.btn-delete-detail:hover {
    background: rgba(239, 68, 68, .18);
}

/* Photo gallery in detail */
.detail-gallery-section {
    margin-bottom: 1.2rem;
}

.detail-gallery-main {
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
}

.detail-gallery-main img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.detail-gallery-thumbs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.detail-thumb {
    width: 70px;
    height: 70px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color .15s, opacity .15s;
    opacity: .7;
}

.detail-thumb:hover,
.detail-thumb.active {
    border-color: var(--primary);
    opacity: 1;
}

/* Detail fields */
.detail-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.detail-field {
    background: #f9fafb;
    border-radius: 8px;
    padding: 10px 14px;
}

.detail-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.detail-value {
    font-size: 0.9rem;
    color: var(--text-main);
    line-height: 1.5;
    white-space: pre-wrap;
}

.detail-value.mono {
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Edit form inside detail */
.detail-edit-form {
    margin-top: 0.5rem;
}

.detail-edit-actions {
    display: flex;
    gap: 10px;
    margin-top: 1rem;
}

.detail-edit-actions .btn {
    flex: 1;
    padding: 0.65rem;
    font-size: 0.9rem;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
}

.btn-confirm {
    background: var(--primary);
    color: #fff;
}

.btn-confirm:hover {
    background: var(--primary-hover);
}

.btn-cancel-modal {
    background: var(--secondary);
    color: var(--text-main);
}

.btn-cancel-modal:hover {
    background: var(--secondary-hover);
}

/* Loading */
.global-loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, .8);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--secondary);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

/* ---- Detail gallery photo actions ---- */
.detail-gallery-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.detail-gallery-thumbs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    flex: 1;
    min-height: 74px;
}

.detail-thumb {
    width: 70px;
    height: 70px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color .15s, opacity .15s;
    opacity: .7;
}

.detail-thumb:hover,
.detail-thumb.active {
    border-color: var(--primary);
    opacity: 1;
}

.photo-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
    padding-top: 2px;
}

.photo-action-btn {
    padding: 6px 10px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid;
    white-space: nowrap;
    transition: all .18s;
}

.btn-add-photo {
    background: rgba(16, 185, 129, .1);
    border-color: rgba(16, 185, 129, .4);
    color: #059669;
}

.btn-add-photo:hover {
    background: rgba(16, 185, 129, .2);
}

.btn-del-photo {
    background: rgba(239, 68, 68, .08);
    border-color: rgba(239, 68, 68, .3);
    color: var(--danger);
}

.btn-del-photo:hover:not(:disabled) {
    background: rgba(239, 68, 68, .18);
}

.btn-del-photo:disabled {
    opacity: .4;
    cursor: not-allowed;
}

/* Camera button in photo-actions */
.btn-cam-photo {
    background: rgba(79, 70, 229, .1);
    border-color: rgba(79, 70, 229, .35);
    color: var(--primary);
}

.btn-cam-photo:hover {
    background: rgba(79, 70, 229, .2);
}

/* ---- Camera capture modal ---- */
.camera-modal {
    max-width: 820px;
    width: 95vw;
}

.camera-modal-body {
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 1rem;
    margin-top: 1rem;
}

.camera-modal-video-wrap {
    position: relative;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 16/9;
}

.camera-modal-video-wrap video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-modal-shots {
    display: flex;
    flex-direction: column;
}

.camera-modal-shots-label {
    font-size: .82rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 600;
}

.camera-modal-thumbs {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    flex: 1;
    max-height: 260px;
    padding-right: 4px;
}

.cam-shot-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f9fafb;
    border-radius: 6px;
    padding: 4px;
    border: 1px solid var(--border);
}

.cam-shot-thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.cam-shot-del {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 6px;
    border-radius: 4px;
    transition: background .15s;
}

.cam-shot-del:hover {
    background: rgba(239, 68, 68, .1);
}