:root { --primary: #007bff; --bg: #f0f2f5; --danger: #dc3545; --success: #28a745; --accent: #ffc107; --dark: #222; }
* { box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg); margin: 0;
    display: flex; flex-direction: column;
    height: 100vh; overflow: hidden;
}

header {
    background: var(--dark); color: white; padding: 8px 16px;
    display: flex; justify-content: flex-start; align-items: center;
    z-index: 100; flex-shrink: 0;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.brand-title {
    font-size: 1rem;
    letter-spacing: 0.01em;
}

.brand-logo {
    position: relative;
    width: 28px;
    height: 28px;
    display: inline-block;
    flex-shrink: 0;
}

.brand-logo-swatch {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.25);
}

.brand-logo-swatch.s1 {
    top: 1px;
    left: 1px;
    background: #f4c430;
    transform: rotate(-8deg);
}

.brand-logo-swatch.s2 {
    top: 1px;
    right: 1px;
    background: #3aa6ff;
    transform: rotate(10deg);
}

.brand-logo-swatch.s3 {
    bottom: 1px;
    left: 8px;
    background: #2ecc71;
    transform: rotate(-4deg);
}

.brand-logo-core {
    position: absolute;
    inset: 8px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff 0%, #f0f0f0 35%, #d9d9d9 100%);
    box-shadow: 0 1px 2px rgba(0,0,0,0.35);
}

.sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.main-layout {
    display: flex; flex: 1; overflow: hidden;
    padding: 15px; gap: 15px; min-height: 0;
}

#ref-panel {
    flex: 2; display: flex; flex-direction: column;
    background: #444; border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden; position: relative; border: 2px solid transparent;
}
#ref-panel.drag-over { border-color: var(--primary); background: #555; }

.toolbar {
    padding: 10px; background: #eee; border-bottom: 1px solid #ddd;
    display: flex; gap: 10px; align-items: center; z-index: 20; color: #333;
}

#viewport {
    flex: 1; overflow: auto; position: relative;
    display: flex; align-items: flex-start; justify-content: flex-start;
    background: #333;
}

canvas#display-canvas { cursor: crosshair; display: block; transform-origin: top left; z-index: 10; }
canvas#display-canvas.sample-cursor-active { cursor: none; }
#sample-cursor {
    position: fixed;
    width: 21px;
    height: 21px;
    border: 2px solid rgba(255,255,255,0.95);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.75), inset 0 0 0 1px rgba(0,0,0,0.25);
    border-radius: 50%;
    pointer-events: none;
    z-index: 60;
    display: none;
    transform: translate(-50%, -50%);
    box-sizing: border-box;
}
#sample-cursor::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 3px;
    height: 3px;
    background: rgba(255,255,255,0.95);
    border: 1px solid rgba(0,0,0,0.75);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}
canvas.ocr-active {
    cursor: crosshair !important;
    outline: 3px dashed var(--accent);
    outline-offset: -3px;
}

#drop-instruction {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%); color: #ccc;
    text-align: center; pointer-events: none; z-index: 5;
}

.side-panels {
    flex: 1; min-width: 440px;
    display: flex; flex-direction: column;
    gap: 15px; height: 100%;
}

.panel {
    background: white; padding: 15px; border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1); display: flex; flex-direction: column;
}

.top-settings {
    margin: 8px 15px 0 15px;
    flex-shrink: 0;
    padding: 8px 12px;
}

.top-settings h3 {
    display: none;
}

.settings-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.settings-provider { width: 180px; margin-bottom: 0; }
.settings-collection { width: 190px; margin-bottom: 0; }
.settings-name { flex: 1; min-width: 160px; margin-bottom: 0; }
.settings-size-group {
    width: 210px;
    margin-bottom: 0;
}
.settings-ref-actions {
    display: flex;
    gap: 5px;
    margin-bottom: 6px;
}
.btn-ref-settings {
    flex: 1;
    width: auto;
    height: 26px;
    padding: 0 6px;
    margin-bottom: 0;
    font-size: 0.68rem;
    border-radius: 5px;
    white-space: nowrap;
}
.settings-size-group-label {
    display: block;
    white-space: nowrap;
    font-size: 0.72rem;
    font-weight: 700;
    margin-bottom: 2px;
    color: #555;
}
.settings-size-inputs {
    display: flex;
    gap: 6px;
}
.settings-size-inputs input {
    width: 92px;
}
.settings-sample-radius {
    display: flex;
    align-items: center;
    gap: 6px;
}
.settings-sample-radius input[type="range"] {
    flex: 1;
    min-width: 0;
    height: 22px;
}
.settings-sample-radius input[type="number"] {
    width: 52px;
    height: 30px;
    padding: 4px 6px;
}
.settings-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 168px;
}
.settings-actions .btn {
    width: 100%;
    height: 28px;
    padding: 0 8px;
    font-size: 0.72rem;
}

.top-settings .control-group { margin-bottom: 0; }
.top-settings label {
    font-size: 0.72rem;
    margin-bottom: 2px;
}
.top-settings input {
    padding: 5px 7px;
    font-size: 0.82rem;
    height: 30px;
}

.list-panel { flex: 1; min-height: 0; }
.list-panel #zip-btn { flex-shrink: 0; }
.control-group { margin-bottom: 12px; }
label { display: block; font-size: 0.8rem; font-weight: bold; margin-bottom: 4px; color: #555; }
input { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; }

#color-preview {
    height: 92px; border-radius: 6px; border: 1px solid #ddd;
    margin: 0; padding: 0 10px; min-width: 170px;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; font-size: 0.82rem; color: white; text-shadow: 0 0 3px #000;
    align-self: flex-end;
    box-sizing: border-box;
}

.image-list {
    flex: 1; overflow-y: auto; border: 1px solid #eee;
    background: #fafafa; border-radius: 4px; margin: 10px 0; padding: 0;
}

.list-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px; border-bottom: 1px solid #eee;
    background: #fff; cursor: grab;
    transition: background 0.2s;
}
.list-item.dragging { opacity: 0.4; border: 2px dashed var(--primary); }
.list-item:hover { background: #f8fbff; }
.list-item.highlighted {
    background: #fff8db;
    border: 2px solid #f0b429;
    box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.25);
    border-radius: 6px;
}
.list-item.highlighted .list-info strong {
    color: #8a5a00;
}

.list-thumb { width: 40px; height: 40px; border: 1px solid #ccc; border-radius: 4px; flex-shrink: 0; }
.list-info { flex: 1; pointer-events: none; }
.list-actions { display: flex; gap: 5px; }

.btn { padding: 10px; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.btn-blue { background: var(--primary); color: white; width: 100%; }
.btn-green { background: var(--success); color: white; width: 100%; }
.btn-red { background: var(--danger); color: white; }
.btn-orange { background: #fd7e14; color: white; }
.btn-grey { background: #6c757d; color: white; }
.btn-action { padding: 6px; font-size: 0.8rem; min-width: 32px; }

.btn-zoom { padding: 5px 10px; background: white; border: 1px solid #ccc; font-size: 0.8rem; }
.btn-zoom.active { background: var(--primary); color: white; }
.btn-sort { background: #6f42c1; color: white; padding: 4px 10px; font-size: 0.75rem; }

.list-panel-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.list-panel-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-left: auto;
}

.list-sort-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}
.list-sort-label {
    font-size: 0.68rem;
    font-weight: 600;
    color: #667085;
    line-height: 1;
    text-transform: none;
}
.list-sort-buttons {
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-add-list {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 72px;
    height: 36px;
    padding: 0 14px;
    border: none;
    border-radius: 8px;
    background: #28a745;
    color: #fff;
    font-weight: 800;
    box-shadow: 0 2px 0 #1e7e34;
    cursor: pointer;
}
.btn-add-list:hover:not(:disabled) {
    background: #218838;
}
.btn-add-list:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
}
.btn-add-list .add-btn-label {
    font-size: 0.82rem;
    line-height: 1;
    font-weight: 900;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.btn-add-list .add-btn-count {
    min-width: 1.4em;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(255,255,255,0.25);
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
}



.btn-ocr { background: white; border: 1px solid #ccc; border-radius: 4px; cursor: pointer; padding: 4px 10px; font-size: 0.8rem; font-weight: bold; }
.btn-ocr.active { background: var(--accent); border-color: #e0a800; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.6; } }

#modal-overlay, #ref-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.8);
    display: none; align-items: center; justify-content: center; z-index: 1000;
}
#info-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.8);
    display: none; align-items: center; justify-content: center; z-index: 1000;
}
#saved-lists-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.8);
    display: none; align-items: center; justify-content: center; z-index: 1000;
}
.modal { background: white; padding: 20px; border-radius: 12px; max-width: 500px; width: 95%; position: relative; max-height: 90vh; overflow-y: auto; }
.modal-large { max-width: 1000px; }
#modal-preview-rect {
    width: 100%; height: 120px; border-radius: 8px; margin-bottom: 10px; border: 1px solid #ddd;
    display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; text-shadow: 0 0 4px #000;
}

.search-container { margin: 15px 0; }
.search-input { width: 100%; padding: 10px; border: 2px solid #ddd; border-radius: 6px; font-size: 1rem; }
.ref-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.ref-table th, .ref-table td { border: 1px solid #ddd; padding: 8px; text-align: left; }
.ref-table th { background: #f4f4f4; position: sticky; top: 0; }
.ref-table input { border: none; width: 100%; background: transparent; padding: 4px; }

#ocr-loading { position: fixed; bottom: 20px; left: 20px; background: #333; color: white; padding: 10px 20px; border-radius: 50px; display: none; z-index: 200; }
kbd { background: #eee; border-radius: 3px; padding: 2px 4px; font-size: 0.7rem; border: 1px solid #ccc; }

.ral-tag { display: inline-block; background: #333; color: #fff; padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; font-weight: bold; margin-top: 5px; }
.ral-tag-classic { background: #0056b3; }
.ral-tag-design { background: #6f42c1; }
.delta-badge {
    display: inline-block;
    margin-top: 0;
    font-size: 0.72rem;
    font-weight: 700;
    color: #333;
    background: #eef2f7;
    border: 1px solid #d7dee8;
    border-radius: 10px;
    padding: 2px 8px;
    white-space: nowrap;
}

.match-line {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 6px;
    margin: 2px 0;
    white-space: nowrap;
    line-height: 1.35;
}

.match-text {
    white-space: nowrap;
}

.confidence-badge {
    display: inline-block;
    margin-left: 0;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    flex-shrink: 0;
}
.conf-excellent { background: #1f8f3a; }
.conf-good { background: #2ea44f; }
.conf-fair { background: #d4a017; color: #222; }
.conf-weak { background: #b02a37; }

.info-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}

.info-pill {
    background: #f3f6fb;
    border: 1px solid #dde5ef;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.85rem;
}

.info-table-wrap {
    max-height: 56vh;
    overflow-y: auto;
    border: 1px solid #ddd;
}

.color-chip {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: 1px solid #bbb;
}

.saved-lists-container {
    max-height: 60vh;
    overflow-y: auto;
    border: 1px solid #e5e9ef;
    border-radius: 8px;
}

.saved-list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px;
    border-bottom: 1px solid #eef2f7;
}

.saved-list-row:last-child {
    border-bottom: none;
}

.saved-list-title {
    font-weight: 700;
    color: #222;
}

.saved-list-meta {
    font-size: 0.78rem;
    color: #667085;
    margin-top: 2px;
}

.palette-print-controls {
    margin: 0 0 12px 0;
    padding: 10px 12px;
    background: #f7f9fc;
    border: 1px solid #e3e8ef;
    border-radius: 8px;
}
.palette-print-controls-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}
.palette-print-controls select {
    padding: 6px 8px;
    border: 1px solid #ccd5e0;
    border-radius: 6px;
    font-size: 0.85rem;
    min-width: 200px;
}

.palette-print-sheet {
    margin: 0 0 14px 0;
    padding: 12px;
    border: 1px solid #e5e9ef;
    border-radius: 8px;
    background: #fff;
}
.palette-header h3 {
    margin: 0 0 4px 0;
    font-size: 1.05rem;
}
.palette-subheader {
    color: #667085;
    font-size: 0.8rem;
    margin-bottom: 10px;
}
.palette-grid {
    display: grid;
    grid-template-columns: repeat(var(--palette-cols, 6), minmax(0, 1fr));
    gap: 10px 8px;
}
.palette-card {
    text-align: center;
    min-width: 0;
}
.palette-swatch {
    width: 100%;
    height: var(--palette-swatch-h, 72px);
    border-radius: 6px;
    border: 1px solid #c9d0d8;
    box-sizing: border-box;
}
.palette-name {
    margin-top: 5px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #222;
    line-height: 1.2;
    word-break: break-word;
}
.palette-ral {
    margin-top: 2px;
    font-size: 0.68rem;
    color: #555;
    line-height: 1.15;
}
.palette-empty {
    color: #777;
    font-size: 0.85rem;
    text-align: center;
    padding: 12px;
}

@media print {
    @page {
        size: A4;
        margin: 8mm;
    }

    body {
        background: #fff !important;
        overflow: visible !important;
        height: auto !important;
    }

    header,
    .top-settings,
    .main-layout,
    #modal-overlay,
    #ref-modal-overlay,
    #saved-lists-modal-overlay,
    #color-search-modal-overlay,
    #ral-search-modal-overlay,
    #ral-edit-modal-overlay,
    #ocr-loading {
        display: none !important;
    }

    #info-modal-overlay {
        position: static !important;
        inset: auto !important;
        background: transparent !important;
        display: block !important;
        align-items: initial !important;
        justify-content: initial !important;
        z-index: auto !important;
        padding: 0 !important;
    }

    #info-modal-overlay .modal {
        max-width: none !important;
        width: 100% !important;
        max-height: none !important;
        overflow: visible !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
    }

    .no-print {
        display: none !important;
    }

    .info-table-wrap {
        max-height: none !important;
        overflow: visible !important;
        border: 1px solid #bbb !important;
    }

    .ref-table th,
    .ref-table td {
        font-size: 10px !important;
        padding: 5px !important;
        vertical-align: top !important;
    }

    .match-line {
        display: block !important;
        white-space: nowrap !important;
        page-break-inside: avoid !important;
        margin: 1px 0 !important;
    }

    .match-text,
    .confidence-badge,
    .delta-badge {
        display: inline !important;
        white-space: nowrap !important;
        margin-right: 4px !important;
    }

    body.print-mode-info .palette-print-sheet {
        display: none !important;
    }
    body.print-mode-info .print-info-only {
        display: block !important;
    }

    body.print-mode-palette .print-info-only {
        display: none !important;
    }
    body.print-mode-palette .palette-print-sheet {
        display: block !important;
        border: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    body.print-mode-palette .info-meta {
        display: none !important;
    }
    body.print-mode-palette .palette-header h3 {
        font-size: 14pt !important;
        margin-bottom: 2mm !important;
    }
    body.print-mode-palette .palette-subheader {
        font-size: 9pt !important;
        margin-bottom: 4mm !important;
    }
    body.print-mode-palette .palette-grid {
        gap: 3mm 2.5mm !important;
    }
    body.print-mode-palette .palette-swatch {
        height: var(--palette-swatch-h, 18mm) !important;
        border-radius: 2px !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    body.print-mode-palette .palette-name {
        font-size: 7.5pt !important;
        margin-top: 1.2mm !important;
    }
    body.print-mode-palette .palette-ral {
        font-size: 6.5pt !important;
    }
    body.print-mode-palette .palette-card {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }
}

#color-search-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.8);
    display: none; align-items: center; justify-content: center; z-index: 1000;
}
.color-search-bar {
    display: flex;
    gap: 8px;
    align-items: stretch;
    margin-bottom: 12px;
}
.color-search-bar .search-input {
    flex: 1;
}
.color-search-results {
    max-height: 55vh;
    overflow-y: auto;
    border: 1px solid #eee;
    border-radius: 8px;
    background: #fafafa;
}
.color-search-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    background: #fff;
}
.color-search-row:last-child { border-bottom: none; }
.color-search-swatch {
    width: 42px;
    height: 42px;
    border-radius: 6px;
    border: 1px solid #ccc;
    flex-shrink: 0;
}
.color-search-info { flex: 1; min-width: 0; }
.color-search-title {
    font-weight: 700;
    font-size: 0.92rem;
    color: #1f2937;
}
.color-search-meta {
    font-size: 0.78rem;
    color: #667085;
    margin-top: 2px;
}

.modal-edit-color {
    max-width: 640px;
}
.edit-color-matches {
    margin-top: 12px;
    display: grid;
    gap: 10px;
}
.edit-match-block {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px 12px;
    background: #fafbfc;
}
.edit-match-block h4 {
    margin: 0 0 8px 0;
    font-size: 0.82rem;
    color: #374151;
}
.edit-match-meta {
    font-size: 0.78rem;
    color: #667085;
    margin-bottom: 8px;
}
.edit-color-values {
    display: grid;
    gap: 6px;
}
.color-value-row {
    display: grid;
    grid-template-columns: 42px 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
}
.color-value-label {
    font-size: 0.72rem;
    font-weight: 800;
    color: #667085;
}
.color-value-text {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8rem;
    color: #111827;
    cursor: pointer;
    user-select: all;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.color-value-text:hover {
    color: #175cd3;
}
.color-value-copy {
    border: 1px solid #d0d5dd;
    background: #f8fafc;
    color: #344054;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
}
.color-value-copy:hover {
    background: #eef2f7;
}
.color-value-copy.copied {
    background: #dcfae6;
    border-color: #abefc6;
    color: #027a48;
}
.edit-color-matches .match-line {
    white-space: normal;
    flex-wrap: wrap;
}

.ref-modal-body {
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 12px;
    align-items: stretch;
    min-height: 0;
}
.ref-table-wrap {
    max-height: 50vh;
    overflow-y: auto;
    border: 1px solid #ddd;
}
.sector-order-panel {
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fafbfc;
    padding: 10px;
    max-height: 50vh;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.sector-order-header {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
}
.sector-order-header strong {
    font-size: 0.85rem;
    color: #1f2937;
}
.sector-order-header span {
    font-size: 0.72rem;
    color: #667085;
}
.sector-order-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    min-height: 0;
}
.sector-order-item {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 6px 8px;
    cursor: grab;
    user-select: none;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.sector-order-item.dragging {
    opacity: 0.45;
    cursor: grabbing;
}
.sector-order-item.drag-over {
    border-color: #6f42c1;
    background: #f5f0ff;
    box-shadow: inset 0 0 0 1px rgba(111, 66, 193, 0.25);
}
.sector-order-handle {
    color: #98a2b3;
    font-size: 0.75rem;
    letter-spacing: -1px;
    cursor: grab;
    line-height: 1;
    padding: 0 2px;
}
.sector-order-item .sector-order-name {
    flex: 1;
    font-size: 0.78rem;
    font-weight: 600;
    color: #374151;
    min-width: 0;
    word-break: break-word;
}
.sector-order-item .sector-order-index {
    font-size: 0.7rem;
    color: #98a2b3;
    width: 1.2em;
    text-align: right;
}
.sector-order-btns {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sector-order-btns button {
    width: 26px;
    height: 18px;
    padding: 0;
    border: 1px solid #d0d5dd;
    border-radius: 4px;
    background: #f2f4f7;
    color: #344054;
    font-size: 0.65rem;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
}
.sector-order-btns button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
@media (max-width: 900px) {
    .ref-modal-body {
        grid-template-columns: 1fr;
    }
}

#ral-search-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.8);
    display: none; align-items: center; justify-content: center; z-index: 1000;
}
.ral-search-modal {
    max-width: 1080px;
    width: min(1080px, 96vw);
}
.ral-search-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}
.ral-search-help {
    margin: 4px 0 0 0;
    font-size: 0.8rem;
    color: #667085;
}
.ral-search-close {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    color: #667085;
    padding: 2px 6px;
}
.ral-source-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}
.ral-pill {
    border: 1px solid #d0d5dd;
    background: #fff;
    color: #344054;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
}
.ral-pill.active {
    background: #1f2937;
    border-color: #1f2937;
    color: #fff;
}
.ral-search-input {
    margin-bottom: 12px;
}
.ral-search-body {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.05fr);
    gap: 14px;
    align-items: start;
}
.ral-panel-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: #667085;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 6px;
}
.ral-panel-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}
.ral-panel-label-row .ral-panel-label {
    margin-bottom: 0;
}
.ral-clear-btn {
    width: auto !important;
    height: 28px;
    padding: 0 10px;
    font-size: 0.72rem;
}
.ral-search-results {
    max-height: 58vh;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fafafa;
}
.ral-search-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-bottom: 1px solid #eee;
    background: #fff;
    cursor: pointer;
}
.ral-search-row:hover { background: #f3f8ff; }
.ral-search-row.in-compare { background: #eefbf3; }
.ral-search-row:last-child { border-bottom: none; }
.ral-search-swatch {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: 1px solid #ccc;
    flex-shrink: 0;
}
.ral-search-meta { min-width: 0; flex: 1; }
.ral-search-code {
    font-weight: 700;
    font-size: 0.86rem;
    color: #1f2937;
}
.ral-search-name {
    font-size: 0.74rem;
    color: #667085;
}
.ral-search-badge {
    font-size: 0.66rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    color: #fff;
    flex-shrink: 0;
}
.ral-search-badge.classic { background: #0056b3; }
.ral-search-badge.design { background: #6f42c1; }
.ral-search-badge.lists { background: #0f766e; }
.ral-search-badge.sampled { background: #b54708; }
.ral-search-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}
.ral-action-btn {
    border: 1px solid #d0d5dd;
    background: #fff;
    border-radius: 6px;
    padding: 3px 7px;
    font-size: 0.68rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    color: #344054;
}
.ral-action-btn.ral-action-compare {
    color: #027a48;
    border-color: #abefc6;
    background: #f6fef9;
}
.ral-action-btn.ral-action-list {
    color: #175cd3;
    border-color: #b2ccff;
    background: #f5f8ff;
}
.ral-slot-tolist {
    width: 100% !important;
    margin-top: 8px;
    height: 30px;
    padding: 0 8px;
    font-size: 0.72rem;
}
.ral-list-feedback {
    margin-top: 8px;
    min-height: 1.2em;
    font-size: 0.78rem;
    font-weight: 700;
    color: #027a48;
    opacity: 0;
    transition: opacity 0.2s;
}
.ral-list-feedback.show {
    opacity: 1;
}
.ral-compare-board {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.ral-slot {
    border: 1px dashed #d0d5dd;
    border-radius: 10px;
    background: #fafbfc;
    min-height: 150px;
    padding: 8px;
    position: relative;
    box-sizing: border-box;
}
.ral-slot.filled {
    border-style: solid;
    border-color: #e5e7eb;
    background: #fff;
}
.ral-slot-empty {
    height: 100%;
    min-height: 134px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #98a2b3;
    font-size: 0.8rem;
    text-align: center;
    padding: 8px;
}
.ral-slot-swatch {
    width: 100%;
    height: 88px;
    border-radius: 8px;
    border: 1px solid #c9d0d8;
}
.ral-slot-name {
    margin-top: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    color: #1f2937;
    word-break: break-word;
}
.ral-slot-meta {
    margin-top: 2px;
    font-size: 0.7rem;
    color: #667085;
    word-break: break-word;
}
.ral-slot-remove {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: rgba(0,0,0,0.55);
    color: #fff;
    font-size: 0.75rem;
    cursor: pointer;
    line-height: 1;
}
.ral-compare-deltas {
    margin-top: 10px;
    display: grid;
    gap: 6px;
}
.ral-delta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    background: #f7f9fc;
    border: 1px solid #e3e8ef;
    font-size: 0.8rem;
}
.ral-delta-hint {
    margin-top: 8px;
    font-size: 0.72rem;
    color: #98a2b3;
}
@media (max-width: 900px) {
    .ral-search-body {
        grid-template-columns: 1fr;
    }
}

#ral-edit-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.8);
    display: none; align-items: center; justify-content: center; z-index: 1100;
}
.ral-edit-modal { max-width: 460px; }
.ral-edit-warning {
    margin: 0 0 12px 0;
    padding: 8px 10px;
    border-radius: 8px;
    background: #fff7ed;
    border: 1px solid #fdba74;
    color: #9a3412;
    font-size: 0.8rem;
}
.ral-edit-rgb-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}
.ral-edit-preview {
    margin-top: 10px;
    height: 70px;
    border-radius: 8px;
    border: 1px solid #d0d5dd;
}
.ral-action-btn.ral-action-edit {
    color: #b54708;
    border-color: #f9dbaf;
    background: #fffaf5;
}
.ral-search-row.ral-overridden .ral-search-code::after {
    content: " • mod";
    color: #b54708;
    font-size: 0.7rem;
}
