:root {
    color-scheme: light;
    --background: #f5f5fb;
    --panel: #fff;
    --ink: #151631;
    --muted: #646375;
    --border: #e2e1e9;
    --accent: #6430ce;
    --accent-soft: #eee7fc;
    --error: #a22d45;
    font: 14px/1.5 "Segoe UI", system-ui, sans-serif;
    color: var(--ink);
    background: var(--background);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, select, input { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 15px; line-height: 1.25; font-weight: 690; letter-spacing: -.025em; }
h2 { font-size: clamp(16px, 1.6vw, 23px); line-height: 1.3; font-weight: 680; letter-spacing: -.015em; }
h3 { font-size: 15px; font-weight: 650; }
.muted { color: var(--muted); }
.hint { font-size: 13px; }
.shell { width: calc(100% - 24px); margin-inline: auto; }

.icon-library, .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
}

.icon {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.65;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: none;
}

.topbar { background: var(--panel); border-bottom: 1px solid var(--border); }
.topbar-content {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 58px;
    padding-block: 10px;
}
.project-title { display: flex; align-items: center; gap: 7px; }
.project-icon, .preview-icon {
    display: grid;
    place-items: center;
    flex: none;
    border-radius: 9px;
    background: var(--accent-soft);
    color: var(--accent);
}
.project-icon { width: 29px; height: 29px; background: transparent; }
.project-icon .icon { width: 24px; height: 24px; stroke-width: 1.9; }
.model-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex: none;
    padding: 5px 6px;
    border: 1px solid var(--border);
    border-radius: 16px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 650;
}
.status-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: #858497; }
.model-badge[data-state="ready"] { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.model-badge[data-state="ready"] .status-dot { display: none; }
.result-status[data-state="detecting"] .status-dot {
    width: 14px;
    height: 14px;
    border: 2px solid #d9c9f3;
    border-top-color: var(--accent);
    background: transparent;
}

@media (prefers-reduced-motion: no-preference) {
    .result-status[data-state="detecting"] .status-dot { animation: spin .8s linear infinite; }
}
@keyframes spin { to { transform: rotate(360deg); } }

main.shell { padding-block: 12px 30px; }
.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    align-items: start;
}
.sidebar { display: grid; min-width: 0; gap: 12px; }
.panel {
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 2px 6px #28204808;
}
.viewer-panel { padding: 10px; }
.icon-heading { display: flex; align-items: center; gap: 10px; }
.icon-heading .icon { color: var(--accent); width: 23px; height: 23px; }
.settings-panel .icon { color: var(--ink); }
.sample-actions { display: flex; justify-content: flex-end; margin-top: 13px; }
.text-button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 0 3px 4px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--accent);
    font-size: 15px;
    font-weight: 650;
    white-space: nowrap;
}
.text-button:hover:enabled { text-decoration: underline; }
.text-button .icon { width: 13px; height: 13px; }
.sample-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 17px; }
.sample-grid:empty { display: none; }
.sample-button {
    display: grid;
    min-width: 0;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 7px;
    overflow: hidden;
    background: var(--panel);
    text-align: left;
}
.sample-button:hover { border-color: var(--accent); color: var(--accent); }
.sample-button[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); color: var(--accent); }
.sample-button img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #ebebf0; }
.sample-caption {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 5px 6px;
    font-size: 11px;
    font-weight: 600;
}
#sample-message { margin-top: 10px; }

.drop-zone {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 6px;
    min-height: 132px;
    margin-top: 12px;
    padding: 10px 8px;
    border: 1px dashed #bcb2d7;
    border-radius: 13px;
    background: #f8f7fd;
    text-align: center;
    cursor: pointer;
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--accent); background: var(--accent-soft); }
#upload-form:focus-within .drop-zone { outline: 2px solid var(--accent); outline-offset: 3px; }
.upload-icon { width: 24px; height: 24px; color: #8251dd; }
.drop-title { color: #42415a; }
.drop-divider { display: none; }
.browse { display: flex; align-items: center; gap: 9px; padding: 8px 18px; border-radius: 10px; color: white; background: var(--accent); font-weight: 650; }
.browse .icon { width: 19px; height: 19px; }

.image-stage {
    position: relative;
    display: grid;
    place-items: center;
    aspect-ratio: 1;
    max-height: 530px;
    overflow: hidden;
    border-radius: 12px;
    background: #efeff3;
}
.image-stage img, #overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
.image-stage img { object-fit: contain; }
#overlay { pointer-events: none; }
.defect-box { filter: drop-shadow(0 0 1px #121122); }
.box-label { font-size: 13px; font-weight: 700; }
.empty-preview { display: grid; justify-items: center; gap: 12px; padding: 16px; color: var(--muted); text-align: center; }
.preview-icon { width: 54px; height: 54px; background: #e8e4f2; color: #655787; }
.preview-icon .icon { width: 26px; height: 26px; }
.viewer-footer { display: flex; justify-content: center; margin-top: 14px; }
.result-status { display: inline-flex; align-items: center; gap: 9px; padding: 6px 16px; border-radius: 20px; background: #f1f0f6; font-size: 16px; font-weight: 670; }
.result-status[data-state="empty"] { color: var(--muted); }
.result-status[data-state="found"] .status-dot {
    width: 15px;
    height: 15px;
    display: grid;
    place-items: center;
    border: 1.5px solid #148c79;
    background: transparent;
}
.result-status[data-state="found"] .status-dot::after {
    content: "";
    width: 6px;
    height: 3px;
    border-bottom: 1.5px solid #148c79;
    border-left: 1.5px solid #148c79;
    transform: translateY(-1px) rotate(-45deg);
}
.result-status[data-state="failed"], .model-badge[data-state="failed"] { color: var(--error); }
.result-status[data-state="failed"] .status-dot, .model-badge[data-state="failed"] .status-dot { background: var(--error); }
.viewer-note { margin-top: 5px; color: var(--muted); font-size: 13px; text-align: center; }
.viewer-note[data-state="failed"] { color: var(--error); }

.field { margin-top: 17px; }
.field-heading { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.field label { font-size: 15px; font-weight: 650; }
.field output {
    min-width: 40px;
    border-radius: 8px;
    padding: 1px 9px;
    background: #f1f0f7;
    text-align: center;
    font-size: 14px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}
.slider { display: flex; align-items: center; gap: 14px; margin-top: 4px; color: var(--muted); font-size: 13px; }
.range-control { position: relative; flex: 1; min-width: 0; }
.range-control::before, .range-control::after {
    content: "";
    position: absolute;
    top: calc(50% - 3px);
    left: 0;
    height: 6px;
    border-radius: 4px;
    pointer-events: none;
}
.range-control::before { width: 100%; background: #e3e1ee; }
.range-control::after { width: var(--range-value, 50%); background: var(--accent); }
.range-control input {
    position: relative;
    z-index: 1;
    display: block;
    appearance: none;
    width: 100%;
    height: 28px;
    margin: 0;
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
}
.range-control input::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--accent);
    border-radius: 50%;
    background: var(--panel);
}
.range-control input::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border: 2px solid var(--accent);
    border-radius: 50%;
    background: var(--panel);
}
.field select {
    display: block;
    width: 100%;
    margin-top: 5px;
    padding: 7px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel);
    color: var(--ink);
    font-size: 15px;
}

.prediction-list { max-height: 295px; overflow: auto; margin-top: 14px; padding: 7px 10px; border: 1px solid #e8e4f2; border-radius: 9px; background: #faf9fd; font-size: 14px; }
.details-empty { padding-block: 3px; }
.prediction-list summary { cursor: pointer; border-radius: 5px; padding: 4px 5px; color: var(--accent); font-weight: 650; }
.prediction-list summary::marker { color: var(--accent); }
.prediction-items { padding-left: 9px; }
.prediction-items details + details { margin-top: 5px; }
.prediction-items summary { background: var(--accent-soft); }
.prediction-index { margin-inline: 3px 7px; font-variant-numeric: tabular-nums; }
.prediction-details { display: grid; grid-template-columns: 1fr 1fr; margin: 3px 0 7px 7px; }
.prediction-details dt, .prediction-details dd { padding: 3px 6px; border-bottom: 1px solid #eae8f0; }
.prediction-details dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.prediction-details .class-value { display: inline-block; padding: 0 8px; border-radius: 12px; background: var(--accent-soft); }
.class-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: var(--class-color); }

.about-panel { margin-top: clamp(22px, 2.7vw, 39px); padding: clamp(18px, 2.25vw, 32px); }
.about-panel > p { margin-top: 12px; }
.class-legend { display: flex; flex-wrap: wrap; gap: 5px 16px; margin: 10px 0 0; padding: 0; list-style: none; font-size: 12px; }
.about-panel .checkpoint { margin-top: 10px; font-size: 12px; overflow-wrap: anywhere; }

dialog {
    width: min(680px, calc(100% - 28px));
    max-height: min(76dvh, 640px);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 11px;
    color: var(--ink);
    background: var(--panel);
    box-shadow: 0 10px 32px #22213224;
    overflow: hidden;
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: #23213355; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.icon-button { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 6px; background: transparent; }
.icon-button:hover { background: var(--accent-soft); }
.gallery { overflow: auto; padding: 14px 16px 18px; }
.gallery section + section { margin-top: 15px; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 7px; margin-top: 7px; }

@media (min-width: 431px) {
    .shell { width: calc(100% - 32px); }
    h1 { font-size: clamp(18px, 2vw, 29px); }
    .topbar-content { gap: 20px; min-height: 66px; padding-inline: 8px; }
    .project-title { gap: 10px; }
    .project-icon { width: 36px; height: 36px; }
    .project-icon .icon { width: 29px; height: 29px; }
    .model-badge { gap: 7px; padding-inline: 10px; font-size: 13px; }
    .sample-grid { gap: 8px; }
}

@media (min-width: 980px) {
    main.shell { padding-block: 20px 36px; }
    .workspace { grid-template-columns: minmax(0, 24fr) minmax(0, 44fr) minmax(0, 30fr); gap: 14px; }
    .sidebar { gap: 16px; }
    .panel { padding: clamp(14px, 1.55vw, 23px); }
    .viewer-panel { padding: clamp(10px, 1.1vw, 16px); }
    .image-stage { max-height: none; }
    .drop-zone { gap: 10px; min-height: clamp(180px, 18vw, 260px); margin-top: 17px; padding: 14px 8px; }
    .upload-icon { width: 35px; height: 35px; }
    .drop-divider { display: block; }
}

@media (min-width: 1101px) {
    :root { font-size: 16px; }
    .shell { width: min(100% - 44px, 1440px); }
    .topbar-content { gap: 23px; min-height: 76px; padding-inline: 16px; }
    .project-title { gap: 12px; }
    .project-icon { width: 42px; }
    .project-icon .icon { width: 32px; height: 32px; }
    .model-badge { font-size: 15px; }
    .about-panel { padding: clamp(23px, 2.25vw, 32px); }
}
