:root {
  --bg: #1a1a1a;
  --bg-elevated: #242424;
  --bg-card: #2a2a2a;
  --bg-input: #1f1f1f;
  --border: #3a3a3a;
  --border-focus: #ff8c00;
  --text: #f0f0f0;
  --text-muted: #9a9a9a;
  --accent: #ff8c00;
  --accent-hover: #ffa733;
  --accent-dim: rgba(255, 140, 0, 0.15);
  --danger: #ff4d4d;
  --warning: #ffb020;
  --ok: #3ecf8e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --touch: 48px;
  --max: 480px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 40% at 50% -10%, rgba(255, 140, 0, 0.08), transparent),
    linear-gradient(180deg, #1c1c1c 0%, #151515 100%);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

.app {
  max-width: var(--max);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 12px 16px calc(16px + var(--safe-bottom));
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 12px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-brand-link {
  color: inherit;
  text-decoration: none;
}

.logo {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent-dim);
  border: 1px solid rgba(255, 140, 0, 0.35);
  font-size: 22px;
}

.header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.tagline {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.api-status {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
}

.api-status.online {
  color: var(--ok);
}

.api-status.offline {
  color: var(--danger);
}

/* Steps */
.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  min-height: var(--touch);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  opacity: 0.7;
}

.step.active {
  border-color: var(--accent);
  color: var(--text);
  opacity: 1;
  background: var(--accent-dim);
}

.step.done {
  opacity: 1;
  border-color: rgba(62, 207, 142, 0.4);
  color: var(--ok);
}

.step-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--bg-input);
  border: 1px solid currentColor;
}

.step.active .step-num {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1a1a;
}

.step-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Main */
.main {
  flex: 1;
}

.screen[hidden] {
  display: none !important;
}

.screen-title {
  margin: 0 0 6px;
  font-size: 1.4rem;
  font-weight: 700;
}

.screen-hint {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Fields */
.field {
  display: block;
  margin-bottom: 14px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.input {
  width: 100%;
  min-height: var(--touch);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23ff8c00' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

.code-input {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
}

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--touch);
  padding: 12px 18px;
  margin-top: 10px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 1rem;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #1a1a1a;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: #555;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(255, 77, 77, 0.45);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(255, 77, 77, 0.12);
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.admin-actions .btn-sm {
  margin-top: 0;
  width: auto;
  padding: 8px 14px;
}

.btn-sm {
  min-height: 40px;
  font-size: 0.9rem;
  margin-top: 8px;
}

/* Tabs */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  margin-bottom: 16px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.tab {
  min-height: 44px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  color: var(--text-muted);
}

.tab.active {
  background: var(--accent);
  color: #1a1a1a;
}

.tab-panel[hidden] {
  display: none !important;
}

/* Upload */
.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 160px;
  padding: 20px;
  border-radius: var(--radius);
  border: 2px dashed #555;
  background: var(--bg-elevated);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.upload-icon {
  font-size: 2rem;
}

.upload-title {
  font-weight: 700;
}

.upload-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.photo-preview-wrap {
  margin-top: 12px;
  text-align: center;
}

.photo-preview-wrap img {
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  object-fit: contain;
  background: #000;
}

/* Result cards */
.result-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.result-code {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  margin: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-can_drive {
  background: rgba(62, 207, 142, 0.18);
  color: var(--ok);
  border: 1px solid rgba(62, 207, 142, 0.4);
}

.badge-limited {
  background: rgba(255, 176, 32, 0.18);
  color: var(--warning);
  border: 1px solid rgba(255, 176, 32, 0.45);
}

.badge-tow {
  background: rgba(255, 77, 77, 0.18);
  color: var(--danger);
  border: 1px solid rgba(255, 77, 77, 0.45);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 10px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.card p {
  margin: 0;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.meta-chip {
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.cause-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cause-item {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.cause-item:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.cause-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.cause-name {
  font-weight: 600;
}

.cause-pct {
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
}

.bar {
  height: 8px;
  border-radius: 999px;
  background: #1a1a1a;
  overflow: hidden;
  margin-bottom: 6px;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #cc6a00, var(--accent));
}

.cause-comment {
  margin: 0 0 6px;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.oem {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.oem code {
  color: var(--text);
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9rem;
}

.steps-list {
  margin: 0;
  padding-left: 1.2rem;
}

.steps-list li {
  margin-bottom: 8px;
  padding-left: 4px;
}

.steps-list li:last-child {
  margin-bottom: 0;
}

.ocr-block {
  margin-bottom: 14px;
}

.ocr-codes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.ocr-code-chip {
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--accent-dim);
  border: 1px solid rgba(255, 140, 0, 0.35);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.multi-diag {
  margin-bottom: 20px;
  padding-bottom: 8px;
  border-bottom: 1px dashed #444;
}

.multi-diag:last-of-type {
  border-bottom: none;
}

.result-actions {
  margin-top: 8px;
  padding-bottom: 8px;
}

/* Loading */
.loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(10, 10, 10, 0.82);
  backdrop-filter: blur(4px);
}

.loading[hidden] {
  display: none !important;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #333;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

#loading-text {
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 110;
  max-width: min(var(--max), calc(100% - 32px));
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: #333;
  border: 1px solid #555;
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 0.95rem;
  text-align: center;
}

.toast.error {
  border-color: rgba(255, 77, 77, 0.5);
  background: #3a1a1a;
}

.toast[hidden] {
  display: none !important;
}

/* Footer */
.footer {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
}

.footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.footer a:hover {
  color: var(--accent);
}

.footer code {
  color: var(--accent);
  font-size: 0.85em;
}

.req-list {
  margin: 0 0 24px;
  padding: 4px 0;
}

.req-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.req-row dt {
  margin: 0 0 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.req-row dd {
  margin: 0;
  color: var(--text);
}

.req-row a {
  color: var(--accent);
  text-decoration: none;
}

.req-row a:hover {
  color: var(--accent-hover);
}

.textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.4;
}

.comment-form {
  margin-bottom: 28px;
}

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

.comments-heading {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.comments-list {
  margin-bottom: 24px;
}

.comment-card {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.comment-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.comment-meta time {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.comment-body {
  margin: 0;
  white-space: pre-wrap;
}

.ref-gallery {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.ref-thumb {
  flex: 0 0 168px;
  width: 168px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #111;
  overflow: hidden;
  text-align: left;
  scroll-snap-align: start;
}

.ref-thumb img {
  display: block;
  width: 100%;
  height: 118px;
  object-fit: contain;
  background: #0c0c0c;
}

.ref-thumb-cap {
  display: block;
  padding: 6px 8px 8px;
  font-size: 0.72rem;
  line-height: 1.3;
  color: var(--text-muted);
  font-weight: 600;
}

.ref-thumb:hover,
.ref-thumb:focus-visible {
  border-color: var(--accent);
  outline: none;
}

body.lightbox-open {
  overflow: hidden;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 48px 24px;
  background: rgba(0, 0, 0, 0.88);
}

.lightbox[hidden] {
  display: none !important;
}

.lightbox-figure {
  margin: 0;
  max-width: min(920px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.lightbox-figure img {
  max-width: 100%;
  max-height: calc(100dvh - 140px);
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: #111;
}

.lightbox-figure figcaption {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  color: var(--text);
  font-size: 0.9rem;
}

.lightbox-counter {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.lightbox-close,
.lightbox-nav {
  position: absolute;
  color: #fff;
  background: rgba(30, 30, 30, 0.7);
  border: 1px solid #555;
  min-height: 44px;
  min-width: 44px;
  border-radius: 999px;
  font-size: 1.6rem;
  line-height: 1;
}

.lightbox-close {
  top: 12px;
  right: 12px;
}

.lightbox-prev {
  left: 8px;
}

.lightbox-next {
  right: 8px;
}

@media (min-width: 480px) {
  .app {
    padding-top: 20px;
  }
}
