/* Result Panel - Compact horizontal strip */
#result-panel {
    background: var(--bg-panel);
    padding: 6px 12px;
    min-height: 70px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow);
    flex-shrink: 0;
    position: relative;
}

/* Color display area (swatch + text) */
#color-display {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    flex-wrap: wrap;
}

/* Ensure color-info takes all available space */
#color-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Smaller swatch */
#color-swatch {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2.5px solid var(--text-primary);
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
    flex-shrink: 0;
    transition: background-color 0.2s;
}

#color-name {
    font-size: 20px;
    font-weight: 700;
    text-transform: capitalize;
    letter-spacing: 0.3px;
    margin: 0;
    word-break: break-word;
    overflow-wrap: anywhere;
}

#color-family {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: capitalize;
    margin: 0;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Status message - tiny, top-left overlay */
#status-message {
    position: absolute;
    top: 4px;
    left: 10px;
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: 500;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#status-message.detecting { color: var(--accent); }
#status-message.success { color: var(--success-color); }
#status-message.error { color: var(--error-color); }

/* Confidence bar - tiny, right side */
#confidence-bar-container {
    width: 60px;
    flex-shrink: 0;
    display: none; /* Hidden until detection */
}

#confidence-bar {
    width: 100%;
    height: 5px;
    background: #eee;
    border-radius: 3px;
    overflow: hidden;
}

#confidence-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.2s ease;
    border-radius: 3px;
}

/* Multi-color swatches (tiny inline) */
#multi-colors {
    display: none;
}
#multi-colors:not([hidden]) {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
}

#color-swatches-row {
    display: flex;
    gap: 6px;
}

.mini-swatch {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1.5px solid #666;
    flex-shrink: 0;
}

.mini-swatch-label {
    display: none;
}

/* Suggestions - inline row with wrapped items */
#suggestions {
    display: none;
}
#suggestions:not([hidden]) {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
    margin-left: 8px;
    padding: 2px 8px;
    background: rgba(0, 102, 204, 0.1);
    border: 1px solid rgba(0, 102, 204, 0.2);
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    height: auto;
    flex-shrink: 0;
    max-width: 160px;
}

/* Label for "Matches:" text */
.suggestion-label-text {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 11px;
    white-space: normal;
    margin-bottom: 2px;
    margin-right: 0;
}

#suggestion-swatches {
    display: flex;
    gap: 6px;
}

.suggestion-swatch {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    flex-shrink: 0;
}

.suggestion-label,
.suggestion-explanation {
    display: none;
}

#color-swatches-row {
    display: flex;
    gap: 6px;
}

.mini-swatch {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1.5px solid #666;
    flex-shrink: 0;
}

.mini-swatch-label {
    display: none;
}

/* Suggestions - inline row with wrapped items */
#suggestions {
    display: none; /* Hidden by default */
}
#suggestions:not([hidden]) {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
    margin-left: 8px;
    padding: 2px 8px;
    background: rgba(0, 102, 204, 0.1);
    border: 1px solid rgba(0, 102, 204, 0.2);
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    height: auto;
    flex-shrink: 0;
}

#suggestion-swatches {
    display: flex;
    gap: 6px;
}

.suggestion-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.suggestion-swatch {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.suggestion-label {
    display: block !important;
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.2;
    white-space: nowrap;
}

.suggestion-explanation {
    display: none !important;
}


#color-swatches-row {
    display: flex;
    gap: 6px;
}

.mini-swatch {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1.5px solid #777;
}

.mini-swatch-label {
    display: none; /* No label to save space */
}

/* Control bar - minimal height */
#controls {
    display: flex;
    gap: 8px;
    padding: 6px 10px 8px;
    background: var(--bg-panel);
    justify-content: center;
    flex-wrap: nowrap;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

button {
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

button:active { transform: scale(0.96); }
button:disabled { opacity: 0.35; pointer-events: none; box-shadow: none; }

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

.secondary-btn {
    background: #f5f5f5;
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.icon-btn {
    background: transparent;
    color: var(--text-primary);
    font-size: 18px;
    padding: 8px;
    width: 36px;
    min-width: 36px;
    border: 1px solid var(--border);
}

/* Settings panel */
#settings-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-panel);
    padding: 18px 14px 24px;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.25);
    z-index: 100;
    animation: slide-up 0.3s ease;
    border-top: 1px solid var(--border);
}

@keyframes slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

#settings-panel h2 {
    margin-bottom: 14px;
    font-size: 18px;
    font-weight: 700;
    text-align: center;
}

.setting-group {
    margin-bottom: 14px;
}

.setting-group label {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    padding: 5px 0;
}

input[type="range"] {
    width: 100%;
    height: 40px;
    -webkit-appearance: none;
    background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 5px;
    background: #ddd;
    border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: -8.5px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

#close-settings {
    width: 100%;
    margin-top: 6px;
    padding: 14px;
    font-size: 15px;
    background: var(--accent);
    color: white;
}

/* Error */
#error-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    color: var(--text-primary);
    padding: 22px 18px;
    border-radius: 14px;
    text-align: center;
    max-width: 90%;
    z-index: 200;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    border: 1px solid var(--border);
}

#error-text {
    margin-bottom: 16px;
    font-size: 14px;
    line-height: 1.5;
}

#dismiss-error {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 22px;
    font-weight: 600;
    border-radius: 8px;
}

/* Utility */
.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

@media (orientation: landscape) and (max-height: 500px) {
    #camera-container { flex: 4; }
#result-panel {
    background: var(--bg-panel);
    padding: 6px 12px;
    min-height: 70px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow);
    flex-shrink: 0;
    position: relative;
}
    #color-swatch { width: 36px; height: 36px; }
    #color-name { font-size: 18px; max-width: 120px; }
    #color-family { font-size: 10px; max-width: 80px; }
    #status-message { font-size: 9px; top: 3px; left: 8px; }
    #confidence-bar-container { width: 50px; }
    #targeting-overlay { width: 100px; height: 100px; }
    button {
        padding: 6px 10px;
        font-size: 12px;
        min-height: 32px;
    }
    .primary-btn { flex: 1.2; }
}

@media (max-height: 600px) {
    #camera-container { flex: 4; }
    #result-panel { min-height: 80px; }
    #color-swatch { width: 40px; height: 40px; }
    #color-name { font-size: 19px; max-width: 130px; }
    button { padding: 7px 11px; font-size: 13px; min-height: 38px; }
}

@supports (padding: max(0px)) {
    #settings-panel { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
    #controls { padding-bottom: max(6px, env(safe-area-inset-bottom)); }
}


:root {
    --bg-primary: #f5f5f5;
    --bg-panel: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --accent: #0066CC;
    --accent-light: rgba(0, 102, 204, 0.15);
    --border: #e0e0e0;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100%;
}

/* CAMERA - Takes 85% of screen */
#camera-container {
    flex: 5.5;
    position: relative;
    background: #000;
    overflow: hidden;
}

#camera-feed {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Subtle targeting overlay */
#targeting-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 120px;
    height: 120px;
    pointer-events: none;
    opacity: 0.7;
}

.crosshair {
    position: absolute;
    background: var(--accent);
    opacity: 0.8;
}

.crosshair.horizontal {
    top: 50%;
    left: 8%;
    right: 8%;
    height: 2px;
    transform: translateY(-50%);
}

.crosshair.vertical {
    left: 50%;
    top: 8%;
    bottom: 8%;
    width: 2px;
    transform: translateX(-50%);
}

.target-box {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    border: 2.5px solid var(--accent);
    border-radius: 8px;
    background: var(--accent-light);
}

/* Scan border during detection */
.scan-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    border: 3px solid transparent;
    transition: border-color 0.2s;
}

.scan-overlay.active {
    border-color: var(--accent);
    box-shadow: inset 0 0 30px var(--accent-light);
}

/* RESULT PANEL - Compact strip at bottom */
#result-panel {
    background: var(--bg-panel);
    padding: 6px 12px;
    min-height: 70px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow);
    flex-shrink: 0;
    position: relative;
}

#color-display {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

/* Smaller swatch */
#color-swatch {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 3px solid var(--text-primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    flex-shrink: 0;
    transition: background-color 0.2s;
}

#color-name {
    font-size: 22px;
    font-weight: 700;
    text-transform: capitalize;
    letter-spacing: 0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

#color-family {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: capitalize;
    margin: 0;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Status message - tiny but visible */
#status-message {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

/* Confidence bar - compact */
#confidence-bar-container {
    width: 80px;
    flex-shrink: 0;
    display: none; /* Hidden by default, shown only when detection occurs */
}

#confidence-bar {
    width: 100%;
    height: 6px;
    background: #eee;
    border-radius: 3px;
    overflow: hidden;
}

#confidence-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.2s ease;
}

/* CONTROL BAR - Ultra compact */
#controls {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-panel);
    justify-content: center;
    flex-wrap: nowrap;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

button {
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    padding: 10px 14px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

button:active {
    transform: scale(0.96);
}

button:disabled {
    opacity: 0.35;
    pointer-events: none;
    box-shadow: none;
}

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

.primary-btn:hover:not(:disabled) {
    filter: brightness(1.1);
}

.secondary-btn {
    background: #f0f0f0;
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.secondary-btn:hover:not(:disabled) {
    background: #e8e8e8;
    border-color: var(--accent);
}

.icon-btn {
    background: transparent;
    color: var(--text-primary);
    font-size: 20px;
    padding: 10px;
    width: 40px;
    min-width: 40px;
    border: 1px solid var(--border);
}

.icon-btn:hover {
    background: var(--accent-light);
}

/* SETTINGS PANEL */
#settings-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-panel);
    padding: 20px 16px 28px;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
    z-index: 100;
    animation: slide-up 0.3s ease;
    border-top: 1px solid var(--border);
}

@keyframes slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

#settings-panel h2 {
    margin-bottom: 16px;
    font-size: 20px;
    font-weight: 700;
    text-align: center;
}

.setting-group {
    margin-bottom: 16px;
}

.setting-group label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    padding: 6px 0;
}

input[type="range"] {
    width: 100%;
    height: 44px;
    -webkit-appearance: none;
    background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: -9px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
}

#close-settings {
    width: 100%;
    margin-top: 8px;
    padding: 14px;
    font-size: 15px;
    background: var(--accent);
    color: white;
    border: none;
}

/* ERROR */
#error-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    color: var(--text-primary);
    padding: 24px 20px;
    border-radius: 16px;
    text-align: center;
    max-width: 90%;
    z-index: 200;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    border: 1px solid var(--border);
}

#error-text {
    margin-bottom: 16px;
    font-size: 15px;
    line-height: 1.5;
}

#dismiss-error {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 24px;
    font-weight: 600;
}

/* Suggestions display fixes */
.suggestion-label {
    display: block !important;
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.2;
    white-space: nowrap;
}

.suggestion-explanation {
    display: none !important;
}

.suggestion-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

/* UTILITY */
.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

@media (orientation: landscape) and (max-height: 500px) {
    #camera-container { flex: 4; }
    #result-panel {
        min-height: 70px;
        padding: 6px 10px;
        gap: 8px;
    }
    #color-swatch { width: 36px; height: 36px; }
    #color-name { font-size: 18px; }
    #color-family { font-size: 10px; }
    #status-message { font-size: 10px; max-width: 100px; }
    #confidence-bar-container { width: 60px; }
    button {
        padding: 8px 10px;
        font-size: 13px;
        min-height: 36px;
    }
    #targeting-overlay { width: 100px; height: 100px; }
}
    #color-swatch { width: 36px; height: 36px; }
    #color-name { font-size: 18px; }
    #color-family { font-size: 10px; }
    #status-message { font-size: 10px; max-width: 100px; }
    #confidence-bar-container { width: 60px; }
    button {
        padding: 8px 10px;
        font-size: 13px;
        min-height: 36px;
    }
    #targeting-overlay { width: 100px; height: 100px; }
}

@media (max-height: 600px) {
    #camera-container { flex: 4; }
    #result-panel { min-height: 100px;                                                                                                                                                                                                                                                                                                                                                                            
/* === Mobile layout overrides for Matches section === */
#result-panel {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 6px !important;
    justify-content: initial !important;
}

#color-display {
    flex: 0 0 auto !important;
    width: 100% !important;
}

#suggestions,
#suggestions:not([hidden]) {
    flex-direction: column !important;
    width: 100% !important;
    max-width: none !important;
    margin-left: 0 !important;
    padding: 6px 10px !important;
}

#suggestion-swatches {
    flex-direction: column !important;
    gap: 3px !important;
    width: 100% !important;
}

.suggestion-item {
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px !important;
}

.suggestion-label {
    white-space: normal !important;
    font-size: 11px !important;
    color: var(--text-primary) !important;
    text-align: left !important;
    word-break: break-word !important;
}

#multi-colors,
#confidence-bar-container {
    width: 100% !important;
}

#suggestions, #suggestions:not([hidden]) {
    white-space: normal !important;
}

#suggestions, #suggestions:not([hidden]) {
    align-items: stretch !important;
    flex-shrink: 0 !important;
}

#multi-colors {
    margin-left: 0 !important;
}
