/* ── Variables ─────────────────────────────────────────── */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #e0e7ff;
    --sidebar-bg: #0f172a;
    --sidebar-border: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #f1f5f9;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --success: #22c55e;
    --success-bg: #f0fdf4;
    --error: #ef4444;
    --error-bg: #fef2f2;
    --warning: #f59e0b;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -1px rgba(0,0,0,.04);
    --sidebar-width: 240px;
    --transition: 180ms ease;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, textarea, select { font-family: inherit; }
img { display: block; max-width: 100%; }

/* ── Layout ────────────────────────────────────────────── */
#app {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: 100vh;
    height: 100vh;
    overflow: hidden;
}

#app.no-sidebar {
    grid-template-columns: 1fr;
}

/* ── Sidebar ───────────────────────────────────────────── */
#sidebar {
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    overflow: hidden;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 24px;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-logo-icon {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-logo-icon svg { width: 18px; height: 18px; color: #fff; }

.sidebar-logo-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--sidebar-text-active);
    line-height: 1.2;
}

.sidebar-logo-sub {
    font-size: 11px;
    color: var(--sidebar-text);
    font-weight: 400;
}

.sidebar-section {
    padding: 20px 12px 0;
    flex: 1;
}

.sidebar-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--sidebar-text);
    padding: 0 8px;
    margin-bottom: 6px;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
    color: var(--sidebar-text);
    transition: background var(--transition), color var(--transition);
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.sidebar-nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-nav-item:hover {
    background: rgba(255,255,255,.06);
    color: var(--sidebar-text-active);
}

.sidebar-nav-item.active {
    background: rgba(99,102,241,.2);
    color: #a5b4fc;
}

.sidebar-bottom {
    padding: 16px 12px 0;
    border-top: 1px solid var(--sidebar-border);
    margin-top: auto;
}

.connection-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 10px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,.04);
    margin-bottom: 8px;
}

.connection-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.connection-dot.connected { background: var(--success); box-shadow: 0 0 0 2px rgba(34,197,94,.2); }

.connection-info {
    font-size: 12px;
    color: var(--sidebar-text);
    overflow: hidden;
}

.connection-env {
    font-weight: 600;
    color: var(--sidebar-text-active);
    font-size: 12.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Main content ──────────────────────────────────────── */
#main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100vh;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 32px;
    border-bottom: 1px solid var(--border);
    background: var(--card-bg);
    flex-shrink: 0;
}

.page-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 1px;
}

.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
    transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
    white-space: nowrap;
}

.btn svg { width: 15px; height: 15px; }

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

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

.btn-secondary {
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

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

.btn-ghost {
    color: var(--text-muted);
    padding: 9px 12px;
}

.btn-ghost:hover { background: var(--border); color: var(--text); }

.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn:disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }

.btn-lg {
    padding: 11px 20px;
    font-size: 14.5px;
    border-radius: var(--radius);
}

/* ── Forms ─────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }

label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

input[type="text"],
input[type="password"],
input[type="email"],
textarea,
select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text);
    background: var(--card-bg);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
    line-height: 1.5;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.input-row {
    display: flex;
    align-items: center;
    gap: 0;
}

.input-row input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); flex: 1; }
.input-suffix {
    padding: 9px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 13.5px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.card-body { padding: 20px; }

/* ── Connect Page ──────────────────────────────────────── */
#page-connect {
    display: none;
    min-height: 100vh;
    background: var(--bg);
    align-items: center;
    justify-content: center;
}

#page-connect.visible { display: flex; }

.connect-container {
    width: 100%;
    max-width: 920px;
    padding: 24px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}

.connect-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
}

.connect-brand-icon {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.connect-brand-icon svg { width: 22px; height: 22px; color: #fff; }
.connect-brand-name { font-size: 17px; font-weight: 700; color: var(--text); }
.connect-brand-sub { font-size: 12px; color: var(--text-muted); }

.connect-headline { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1.3; margin-bottom: 10px; }
.connect-desc { font-size: 14.5px; color: var(--text-muted); line-height: 1.6; margin-bottom: 28px; }

.connect-features { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.connect-feature {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 13.5px;
    color: var(--text-muted);
}
.connect-feature-icon {
    width: 22px;
    height: 22px;
    background: var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}
.connect-feature-icon svg { width: 12px; height: 12px; color: var(--primary); }

/* ── Products Grid ─────────────────────────────────────── */
.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px;
}

.product-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    cursor: pointer;
    transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}

.product-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
    border-color: #c7d2fe;
}

.product-card-thumb {
    height: 160px;
    background: linear-gradient(135deg, #e0e7ff 0%, #f0f4ff 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

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

.product-card-thumb-placeholder svg {
    width: 40px;
    height: 40px;
    color: #a5b4fc;
}

.product-card-body { padding: 16px; }

.product-card-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-card-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.product-card-sku {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 11px;
    font-family: 'SF Mono', 'Consolas', monospace;
    color: var(--text-muted);
}

.product-card-dam-link {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    color: var(--text-muted);
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.15s;
}
.product-card-dam-link svg { width: 11px; height: 11px; }
.product-card:hover .product-card-dam-link { opacity: 1; }
.product-card-dam-link:hover { color: var(--primary); }

/* ── Product Detail ────────────────────────────────────── */
.product-detail-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 24px;
    align-items: start;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.breadcrumb-link {
    color: var(--primary);
    cursor: pointer;
    font-weight: 500;
}
.breadcrumb-link:hover { text-decoration: underline; }
.breadcrumb svg { width: 14px; height: 14px; }

/* ── Image Gallery ─────────────────────────────────────── */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.gallery-item {
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: opacity var(--transition);
}

.gallery-item:hover { opacity: .85; }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }

.gallery-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.gallery-empty svg {
    width: 36px;
    height: 36px;
    color: var(--border);
    margin: 0 auto 10px;
}

/* ── Quill editor ──────────────────────────────────────── */
.ql-container {
    border-bottom-left-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
}

.ql-toolbar {
    border-top-left-radius: var(--radius-sm);
    border-top-right-radius: var(--radius-sm);
    border-color: var(--border) !important;
    background: var(--bg);
}

.ql-container { border-color: var(--border) !important; min-height: 140px; }
.ql-editor { min-height: 140px; }
.ql-container.ql-snow:focus-within { border-color: var(--primary) !important; }

/* Fix Quill toolbar in dark theme */
.ql-snow.ql-toolbar,
.ql-snow .ql-toolbar { background: var(--surface); border-color: var(--border) !important; }
.ql-snow .ql-toolbar button,
.ql-snow .ql-toolbar .ql-picker { color: var(--text-muted); }
.ql-snow .ql-toolbar button:hover,
.ql-snow .ql-toolbar button.ql-active { color: var(--text); }
/* Button SVG icons */
.ql-snow .ql-toolbar button svg .ql-stroke { stroke: var(--text-muted); }
.ql-snow .ql-toolbar button:hover svg .ql-stroke,
.ql-snow .ql-toolbar button.ql-active svg .ql-stroke { stroke: var(--text); }
.ql-snow .ql-toolbar button svg .ql-fill { fill: var(--text-muted); }
/* Header picker label, dropdown arrow, and items */
.ql-snow .ql-picker.ql-header .ql-picker-label,
.ql-snow .ql-picker.ql-header .ql-picker-item { color: var(--text); }
.ql-snow .ql-picker.ql-header .ql-picker-label::before,
.ql-snow .ql-picker.ql-header .ql-picker-item::before { color: var(--text); }
.ql-snow .ql-picker.ql-header .ql-picker-label svg .ql-stroke { stroke: var(--text); }
/* Dropdown options container */
.ql-snow .ql-picker-options { background: var(--surface); border-color: var(--border); }
.ql-snow .ql-picker-item:hover { color: var(--primary) !important; }

/* ── Alerts / Toasts ───────────────────────────────────── */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    margin-bottom: 16px;
}

.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.alert-error { background: var(--error-bg); color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: var(--success-bg); color: #166534; border: 1px solid #bbf7d0; }

#toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast-item {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: slideIn .2s ease;
    pointer-events: all;
    max-width: 320px;
}

.toast-success { background: #166534; color: #fff; }
.toast-error { background: #991b1b; color: #fff; }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(12px); }
    to { opacity: 1; transform: translateX(0); }
}

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

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

.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 20px 40px rgba(0,0,0,.15);
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { color: var(--text-muted); padding: 4px; border-radius: 4px; }
.modal-close:hover { background: var(--border); }
.modal-close svg { width: 18px; height: 18px; display: block; }

.modal-body {
    padding: 22px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-shrink: 0;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12.5px;
}

/* ── Dynamic field rows (settings modal) ───────────────── */
.settings-fields-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 14px;
    gap: 12px;
}

.settings-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}

.settings-section-desc {
    font-size: 12.5px;
    color: var(--text-muted);
}

.field-row {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 8px;
    background: var(--bg);
}

.field-row-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr auto auto;
    gap: 8px;
    align-items: center;
}

.field-row-inputs input,
.field-row-inputs select {
    font-size: 13px;
    padding: 6px 10px;
}

.field-row-resolved {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 6px;
    font-family: 'SF Mono', 'Consolas', monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.field-row-remove {
    color: var(--text-muted);
    font-size: 18px;
    line-height: 1;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}

.field-row-remove:hover { background: var(--error-bg); color: var(--error); }

/* ── Misc ──────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.empty-state {
    text-align: center;
    padding: 64px 32px;
    color: var(--text-muted);
}

.empty-state svg { width: 48px; height: 48px; color: var(--border); margin: 0 auto 16px; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 14px; line-height: 1.6; max-width: 320px; margin: 0 auto 20px; }

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .65s linear infinite;
    display: inline-block;
}

.spinner-dark {
    border-color: rgba(99,102,241,.2);
    border-top-color: var(--primary);
}

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

.page-section { display: none; }
.page-section.visible { display: block; }

.tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 500;
}

.tag-blue { background: var(--primary-light); color: var(--primary-dark); }

/* ── Record Link field ─────────────────────────────────────── */
.recordlink-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.recordlink-items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px;
    min-height: 56px;
}

.recordlink-empty {
    color: var(--text-muted);
    font-size: 13px;
    padding: 4px 0;
    align-self: center;
}

.rl-card {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    position: relative;
}

.rl-card-thumb {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    overflow: hidden;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

.rl-card-thumb svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.rl-card-thumb-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.rl-card-info {
    min-width: 0;
}

.rl-card-title {
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
    display: block;
}

.rl-card-id {
    font-size: 11px;
    color: var(--text-muted);
    font-family: monospace;
}

.rl-remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
    border-radius: 3px;
    flex-shrink: 0;
}

.rl-remove-btn:hover {
    background: var(--error-bg);
    color: var(--error);
}

.recordlink-add {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid var(--border);
    background: #f8fafc;
}

.recordlink-add input {
    flex: 1;
    font-size: 12px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: white;
    color: var(--text);
    font-family: monospace;
}

.recordlink-add input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ── Record Link card link styles ─────────────────────────── */
.rl-card-thumb {
    text-decoration: none;
    cursor: pointer;
}

.rl-card-thumb:hover img,
.rl-card-thumb:hover .rl-card-thumb-placeholder {
    opacity: 0.85;
}

a.rl-card-title {
    text-decoration: none;
    color: var(--text);
}

a.rl-card-title:hover {
    color: var(--primary);
    text-decoration: underline;
}

.rl-card-cdn {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 3px;
}

.rl-cdn-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.rl-cdn-copy {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 2px 4px;
    cursor: pointer;
    color: var(--text-muted);
    gap: 3px;
    font-size: 10px;
}

.rl-cdn-copy:hover {
    background: var(--primary-light, rgba(99,102,241,0.1));
    color: var(--primary);
    border-color: var(--primary);
}
