:root {
    --background: #f6f5f2;
    --surface: #ffffff;
    --text: #1d2a2f;
    --muted: #647075;
    --primary: #6f3c18;
    --primary-hover: #563015;
    --border: rgba(29, 42, 47, 0.15);
    --danger: #8f2929;
    --focus: rgba(111, 60, 24, 0.28);
    --shadow: 0 8px 24px rgba(29, 42, 47, 0.07);
}

* {
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-width: 0;
    min-height: 100vh;
    overflow-x: hidden;
    color: var(--text);
    background: var(--background);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

body.modal-open {
    overflow: hidden;
}

button,
input {
    font: inherit;
}

button {
    min-height: 48px;
    border: 1px solid var(--primary);
    border-radius: 10px;
    padding: 11px 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: var(--primary);
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    transition: background-color 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

button:hover:not(:disabled) {
    border-color: var(--primary-hover);
    background: var(--primary-hover);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.secondary-action {
    color: var(--primary);
    background: transparent;
}

.secondary-action:hover:not(:disabled) {
    color: #fff;
}

.app-shell {
    width: min(100% - 28px, 660px);
    margin: 0 auto;
    padding: clamp(40px, 9vh, 88px) 0 48px;
    transition: width 180ms ease, padding 180ms ease;
}

.search-stage {
    transition: padding 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

.page-header {
    padding: 0 2px 24px;
    text-align: center;
    transition: padding 180ms ease, text-align 180ms ease;
}

.home-title-button {
    width: 100%;
    min-height: 0;
    border: 0;
    padding: 0;
    color: inherit;
    background: transparent;
    cursor: pointer;
}

.home-title-button:hover:not(:disabled) {
    color: var(--primary);
    background: transparent;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(2rem, 7vw, 2.55rem);
    line-height: 1.15;
    letter-spacing: -0.03em;
    transition: font-size 180ms ease;
}

h2 {
    margin-bottom: 16px;
    font-size: 1.2rem;
}

h3 {
    font-size: 1.05rem;
}

p {
    color: var(--muted);
}

.public-search-panel,
.result-card,
.admin-card {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
}

.public-search-panel {
    padding: 22px;
    box-shadow: var(--shadow);
    transition: padding 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.result-search-prompt {
    display: none;
    margin-bottom: 10px;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

form {
    display: grid;
    gap: 10px;
}

.search-label {
    font-weight: 700;
}

.code-search-row {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

input[type="text"] {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 13px;
    color: var(--text);
    background: #fff;
}

.or-divider {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 4px;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.12em;
}

.or-divider::before,
.or-divider::after {
    height: 1px;
    flex: 1;
    background: var(--border);
    content: "";
}

.photo-search-controls {
    display: grid;
    gap: 8px;
}

.photo-search-controls button {
    width: 100%;
}

.primary-photo-action {
    min-height: 54px;
    font-weight: 800;
}

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

.photo-preview {
    min-width: 0;
    margin-top: 14px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    text-align: center;
}

.photo-preview img {
    display: block;
    width: 100%;
    max-height: 220px;
    object-fit: contain;
    border-radius: 8px;
}

.result-card {
    margin-top: 12px;
    padding: 22px;
    scroll-margin-top: 152px;
}

.result-card[hidden],
.photo-preview[hidden],
.modal-overlay[hidden],
button[hidden] {
    display: none;
}

.result-title {
    margin-bottom: 16px;
    font-size: 1.35rem;
}

.result-fields {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 0 0 18px;
    padding: 14px;
    border-radius: 12px;
    background: var(--background);
}

.result-fields div {
    min-width: 0;
}

.result-fields dt {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.result-fields dd {
    margin: 2px 0 0;
    overflow-wrap: anywhere;
    font-size: 1.04rem;
    font-weight: 750;
}

.catalog-image {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: 760px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
}

.catalog-link,
.text-link,
.new-search-link {
    display: inline-block;
    margin-top: 10px;
    color: var(--primary);
    font-weight: 750;
    text-underline-offset: 3px;
}

.result-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
}

.candidate-list {
    display: grid;
    gap: 10px;
    margin: 16px 0;
}

.candidate-card {
    min-width: 0;
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 12px;
    padding: 11px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
}

.candidate-card img {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 8px;
    background: var(--background);
}

.candidate-code {
    margin-bottom: 2px;
    font-weight: 800;
}

.candidate-meta {
    margin: 0;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.photo-search-help {
    margin: 12px 0 0;
    color: #64748b;
    font-size: 0.9rem;
    text-align: center;
}

.family-image {
    display: block;
    width: min(100%, 520px);
    max-height: 420px;
    margin: 20px auto;
    object-fit: contain;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    background: #f8fafc;
}

.family-options,
.family-swatches {
    margin-top: 24px;
}

.family-option-groups {
    display: grid;
    gap: 14px;
}

.family-option-group {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
}

.family-option-group h4 {
    margin: 0;
    padding: 10px 14px;
    background: #f8fafc;
}

.family-option-group ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.family-option-group li {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 14px;
    border-top: 1px solid #e2e8f0;
}

.family-option-group li:first-child {
    border-top: 0;
}

.family-option-group strong {
    white-space: nowrap;
}

.swatch-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.swatch-chip {
    max-width: 100%;
    padding: 7px 10px;
    overflow-wrap: anywhere;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    background: #f8fafc;
    color: #334155;
    font-size: 0.88rem;
}

.show-all-swatches {
    margin-top: 14px;
}

@media (max-width: 640px) {
    .family-option-group li {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .family-option-group strong {
        white-space: normal;
    }
}

.error-message {
    color: var(--danger);
}

.loading-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    font-weight: 700;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(111, 60, 24, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 800ms linear infinite;
}

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

body.results-mode .app-shell {
    width: min(100% - 28px, 760px);
    padding-top: 0;
}

body.results-mode .search-stage {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 -14px;
    padding: 10px 14px 12px;
    border-bottom: 1px solid var(--border);
    background: rgba(246, 245, 242, 0.96);
    box-shadow: 0 4px 12px rgba(29, 42, 47, 0.05);
    backdrop-filter: blur(10px);
}

body.results-mode .page-header {
    padding: 0 0 8px;
    text-align: left;
}

body.results-mode h1 {
    font-size: 1.02rem;
    letter-spacing: -0.01em;
}

body.results-mode .home-title-button {
    width: auto;
    text-align: left;
}

body.results-mode .public-search-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 8px;
    padding: 0;
    border-color: transparent;
    background: transparent;
    box-shadow: none;
}

body.results-mode .result-search-prompt {
    display: block;
    grid-column: 1 / -1;
}

body.results-mode .search-label,
body.results-mode .or-divider,
body.results-mode .photo-search-help {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

body.results-mode .photo-search-controls {
    margin-top: 0;
    grid-template-columns: 1fr;
}

body.results-mode .photo-search-controls button {
    min-height: 42px;
    padding-block: 8px;
}

body.results-mode.has-selected-photo .photo-preview,
body.results-mode.has-selected-photo .photo-search-controls {
    grid-column: 1 / -1;
}

body.results-mode.has-selected-photo .photo-preview {
    margin-top: 2px;
    padding: 6px;
}

body.results-mode.has-selected-photo .photo-preview img {
    max-height: 150px;
}

body.results-mode.has-selected-photo .photo-search-controls {
    grid-template-columns: 1fr;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    background: rgba(17, 24, 28, 0.42);
}

.photo-sheet {
    width: min(100%, 520px);
    display: grid;
    gap: 10px;
    padding: 12px 16px 16px;
    border-radius: 18px 18px 14px 14px;
    background: var(--surface);
    box-shadow: 0 16px 40px rgba(17, 24, 28, 0.2);
    animation: sheet-in 180ms ease-out;
}

.photo-sheet h2 {
    margin: 2px 0 4px;
    text-align: center;
}

.sheet-handle {
    width: 42px;
    height: 4px;
    margin: 0 auto 2px;
    border-radius: 99px;
    background: var(--border);
}

.sheet-cancel {
    color: var(--text);
    border-color: transparent;
    background: transparent;
}

.sheet-cancel:hover:not(:disabled) {
    color: var(--text);
    border-color: var(--border);
    background: var(--background);
}

@keyframes sheet-in {
    from { transform: translateY(18px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.admin-shell {
    width: min(100% - 28px, 1100px);
    margin: 0 auto;
    padding: 24px 0 48px;
}

.admin-shell .page-header {
    text-align: left;
}

.admin-grid {
    display: grid;
    gap: 20px;
}

.admin-card {
    padding: 20px;
    box-shadow: var(--shadow);
}

.admin-card + .admin-card {
    margin-top: 20px;
}

.admin-result {
    margin-top: 16px;
}

.automatic-import-actions {
    display: grid;
    min-width: 220px;
    gap: 0.45rem;
}

.automatic-import-actions button,
.automatic-import-actions a {
    font-size: 0.8rem;
}

.candidate-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}

.candidate-image {
    width: 100%;
    max-height: 280px;
    object-fit: contain;
    border-radius: 10px;
    background: #f3f4f6;
}

.variant-pricing {
    margin: 20px 0;
}

.variant-pricing h3 {
    margin-bottom: 10px;
}

.variant-pricing ul {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.variant-pricing li {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

.available-finishes {
    margin-top: 1rem;
}

@media (max-width: 480px) {
    .variant-pricing li {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
}

th,
td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
    font-size: 0.9rem;
}

th {
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
}

@media (max-width: 768px) {
    .app-shell {
        padding-top: clamp(24px, 7vh, 56px);
    }

    .result-fields {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    body.results-mode .app-shell {
        padding-top: 0;
    }
}

@media (max-width: 430px) {
    .app-shell,
    .admin-shell,
    body.results-mode .app-shell {
        width: min(100% - 20px, 760px);
    }

    .public-search-panel,
    .result-card,
    .admin-card {
        padding: 16px;
        border-radius: 14px;
    }

    .code-search-row {
        grid-template-columns: minmax(0, 1fr) 88px;
    }

    .code-search-row button {
        padding-inline: 10px;
    }

    h1 {
        font-size: 1.8rem;
    }

    body.results-mode .search-stage {
        margin-inline: -10px;
        padding-inline: 10px;
    }

    body.results-mode h1 {
        font-size: 0.96rem;
    }

    body.results-mode .public-search-panel {
        grid-template-columns: 1fr;
    }

    .photo-search-controls {
        grid-template-columns: 1fr;
    }

    .candidate-card {
        grid-template-columns: 64px minmax(0, 1fr);
    }

    .candidate-card img {
        width: 64px;
        height: 64px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.review-header,
.page-navigation,
.candidate-card header,
.candidate-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.review-header {
    margin-bottom: 1rem;
}

.review-header h1 {
    margin: 0.35rem 0 0;
}

.run-metrics,
.confidence-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 0.75rem;
}

.run-metrics div,
.confidence-grid div {
    display: grid;
    gap: 0.2rem;
}

.run-metrics span,
.confidence-grid dt {
    color: var(--muted);
    font-size: 0.78rem;
}

.page-navigation {
    min-height: 48px;
    margin-bottom: 1rem;
}

.review-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
    gap: 1rem;
    align-items: start;
}

.catalog-overlay-panel {
    position: sticky;
    top: 1rem;
}

.catalog-overlay-frame {
    position: relative;
    width: 100%;
    line-height: 0;
}

.catalog-overlay-frame img {
    width: 100%;
    height: auto;
    border-radius: 12px;
}

.bbox {
    position: absolute;
    min-height: 0;
    padding: 0.2rem;
    border: 2px solid #22c55e;
    border-radius: 4px;
    background: rgb(34 197 94 / 18%);
    color: #fff;
    font-weight: 800;
    line-height: 1;
    text-align: left;
}

.bbox:hover,
.bbox.is-active {
    border-color: #fbbf24;
    background: rgb(251 191 36 / 28%);
}

.candidate-list {
    display: grid;
    gap: 1rem;
}

.candidate-card {
    display: grid;
    gap: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
}

.candidate-card.is-active {
    outline: 3px solid rgb(37 99 235 / 28%);
}

.candidate-card > img {
    width: 100%;
    max-height: 260px;
    object-fit: contain;
    background: #f3f4f6;
    border-radius: 8px;
}

.candidate-card label {
    display: grid;
    gap: 0.35rem;
    font-weight: 650;
}

.candidate-card textarea {
    min-height: 76px;
    resize: vertical;
}

.candidate-actions .secondary {
    color: var(--primary);
    background: transparent;
}

.candidate-card pre {
    max-height: 180px;
    overflow: auto;
    white-space: pre-wrap;
}

.status-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    background: #eef2ff;
    font-size: 0.75rem;
}

.warning-message {
    color: #92400e;
    background: #fffbeb;
    padding: 0.75rem;
    border-radius: 8px;
}

@media (max-width: 900px) {
    .review-layout {
        grid-template-columns: 1fr;
    }

    .catalog-overlay-panel {
        position: static;
    }
}

@media (max-width: 600px) {
    .review-header,
    .candidate-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .candidate-actions button {
        width: 100%;
    }
}

.catalog-pages {
    margin-top: 1.25rem;
}

.catalog-page-list {
    display: grid;
    gap: 1rem;
}

.catalog-page-card {
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 16px;
    padding: 1rem;
    background: var(--surface-color, #fff);
}

.catalog-page-card h4 {
    margin: 0 0 0.75rem;
}
