:root {
  --bg: #080a0d;
  --panel: #101318;
  --panel-soft: #151a21;
  --panel-border: rgba(255, 255, 255, 0.1);

  --text: #f6f7fb;
  --muted: #9aa4b2;
  --muted-2: #697386;

  --primary: #14b8a6;
  --primary-2: #38bdf8;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;

  --radius-lg: 8px;
  --radius-md: 8px;
  --radius-sm: 6px;

  --shadow: 0 18px 60px rgba(0, 0, 0, 0.34);
  --page-max: 1320px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background: linear-gradient(180deg, #0b0f14 0%, var(--bg) 42%, #06080b 100%);
}

button,
input,
a {
  font: inherit;
}

button,
a {
  cursor: pointer;
}

img {
  max-width: 100%;
  display: block;
}

.app-shell {
  min-height: 100vh;
  max-width: var(--page-max);
  margin: 0 auto;
}

/* Sidebar */

.sidebar {
  position: sticky;
  top: 0;
  height: auto;
  padding: 18px 32px;
  background: rgba(8, 10, 13, 0.86);
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(18px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  z-index: 20;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--primary), #2563eb);
  color: white;
  font-weight: 900;
  letter-spacing: -0.04em;
}

.brand h2,
.mobile-header h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.04em;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary-2);
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.nav {
  display: flex;
  gap: 8px;
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  transition: 180ms ease;
}

.nav-link:hover,
.nav-link.active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
}

.sidebar-card {
  padding: 16px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-md);
}

.sidebar-footer {
  color: var(--muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Main */

.main {
  padding: 34px 32px 48px;
  display: grid;
  gap: 28px;
}

.mobile-header {
  display: none;
}

/* Panels */

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: 24px;
  align-items: start;
}

.panel {
  padding: 24px;
  border: 1px solid var(--panel-border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.025)),
    var(--panel);
  box-shadow: var(--shadow);
  border-radius: var(--radius-lg);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.panel-header.compact {
  margin-bottom: 14px;
}

.panel-header h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.04em;
}

.section-divider {
  height: 1px;
  margin: 24px 0;
  background: var(--panel-border);
}

.small-label {
  margin: 0 0 10px;
  color: var(--muted-2);
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.muted-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 8px 11px;
  color: #dbeafe;
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.26);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.neutral {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--panel-border);
}

.badge.success {
  color: #bbf7d0;
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.3);
}

.badge.danger {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
}

/* Inputs */

.input {
  width: 100%;
  min-height: 44px;
  padding: 0 13px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  outline: none;
  transition: 180ms ease;
}

.input:focus {
  border-color: rgba(6, 182, 212, 0.6);
  box-shadow: 0 0 0 4px rgba(6, 182, 212, 0.12);
}

/* Buttons */

.primary-btn,
.secondary-btn,
.danger-btn,
.icon-btn {
  border: 0;
  border-radius: var(--radius-md);
  min-height: 46px;
  padding: 0 18px;
  font-weight: 800;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 180ms ease,
    opacity 180ms ease,
    background 180ms ease,
    border 180ms ease;
}

.primary-btn {
  color: white;
  background: linear-gradient(135deg, var(--primary), #2563eb);
}

.secondary-btn {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-border);
}

.danger-btn {
  color: white;
  background: rgba(239, 68, 68, 0.9);
}

.icon-btn {
  width: 46px;
  padding: 0;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.primary-btn:hover,
.secondary-btn:hover,
.danger-btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
}

.primary-btn:disabled,
.secondary-btn:disabled,
.danger-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.full-width {
  width: 100%;
  margin-top: 12px;
}

/* Webcam Capture */

.webcam-shell {
  display: grid;
  gap: 16px;
}

.webcam-frame,
.captured-preview {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.035);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.025);
}

.webcam-frame {
  aspect-ratio: 16 / 9;
  min-height: 280px;
}

.webcam-frame video,
.captured-preview img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.webcam-frame video {
  background: #05070d;
}

.webcam-overlay {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  justify-content: flex-start;
  pointer-events: none;
}

.camera-status-pill {
  max-width: 100%;
  padding: 8px 11px;
  color: #dbeafe;
  background: rgba(7, 10, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  backdrop-filter: blur(12px);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}

.captured-preview {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 18px;
  align-items: center;
  padding: 16px;
}

.captured-preview img {
  width: 180px;
  height: 130px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  background: #05070d;
}

.captured-meta {
  min-width: 0;
}

.captured-meta strong {
  display: block;
  overflow-wrap: anywhere;
}

.webcam-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.webcam-controls .primary-btn,
.webcam-controls .secondary-btn {
  flex: 1 1 180px;
}

/* Templates */

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr));
  gap: 16px;
}

.template-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
  text-align: left;
  color: var(--text);
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.025)),
    rgba(255, 255, 255, 0.03);
  overflow: hidden;
  isolation: isolate;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease,
    opacity 180ms ease,
    filter 180ms ease;
}

.template-card::after {
  content: none;
}

.template-card:hover {
  border-color: rgba(6, 182, 212, 0.55);
  transform: translateY(-2px);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
}

.template-card.active {
  border-color: var(--primary-2);
  box-shadow:
    0 0 0 1px rgba(6, 182, 212, 0.45),
    0 18px 44px rgba(0, 0, 0, 0.34);
}

.template-image-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: #05070d;
  border-bottom: 1px solid var(--panel-border);
}

.template-image-wrapper img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transform: scale(1);
  transition:
    transform 260ms ease,
    filter 180ms ease,
    opacity 180ms ease;
}

.template-card:hover .template-image-wrapper img {
  transform: scale(1.055);
}

.template-card-content {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 6px;
  padding: 10px 12px 12px;
}

.template-card-content strong {
  display: block;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.template-card-content span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.template-card:disabled,
.template-card[disabled] {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
  filter: grayscale(0.24) saturate(0.72);
}

.template-card:disabled:hover,
.template-card[disabled]:hover {
  border-color: var(--panel-border);
  transform: none;
  box-shadow: none;
}

.template-card:disabled .template-image-wrapper img,
.template-card[disabled] .template-image-wrapper img {
  transform: none;
  filter: grayscale(0.55) saturate(0.55) brightness(0.82);
}

.template-card:disabled::after,
.template-card[disabled]::after {
  opacity: 0.28;
}

/* Processing */

.process-panel {
  position: sticky;
  top: 96px;
}

.processing-card {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 112px;
}

.processing-card h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.processing-card h2.success {
  color: var(--success);
}

.processing-card h2.danger {
  color: #fecaca;
}

.wait-spinner {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--primary-2);
  animation: spin 900ms linear infinite;
  animation-play-state: paused;
}

.is-processing .wait-spinner,
.processing-result .wait-spinner {
  animation-play-state: running;
}

.wait-spinner.large {
  width: 58px;
  height: 58px;
  border-width: 4px;
}

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

.progress-wrap {
  margin-top: 12px;
}

.progress-bar {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.progress-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  transition: width 250ms ease;
}

.timeline {
  margin-top: 26px;
  display: grid;
  gap: 16px;
}

.timeline-item {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.timeline-item span {
  width: 13px;
  height: 13px;
  border-radius: 999px;
  border: 2px solid var(--muted-2);
}

.timeline-item p {
  margin: 0;
}

.timeline-item.done {
  color: var(--text);
}

.timeline-item.done span {
  border-color: var(--success);
  background: var(--success);
}

.timeline-item.active {
  color: var(--text);
}

.timeline-item.active span {
  border-color: var(--primary-2);
  box-shadow: 0 0 0 6px rgba(6, 182, 212, 0.14);
}

.api-message {
  margin-top: 24px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.28);
  color: #fecaca;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

/* Result */

.result-panel {
  min-height: 440px;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.empty-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.07);
  color: var(--primary-2);
  font-size: 20px;
  font-weight: 900;
}

.empty-result,
.processing-result {
  min-height: 320px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  text-align: center;
  border: 1px dashed var(--panel-border);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.025);
}

.empty-result h3 {
  margin: 0;
  font-size: 20px;
}

.processing-result h3 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.empty-result p {
  margin: 8px 0 0;
  color: var(--muted);
}

.result-box {
  display: grid;
  gap: 18px;
}

.result-box img {
  width: 100%;
  max-height: 720px;
  object-fit: contain;
  border-radius: var(--radius-lg);
  background: #05070d;
  border: 1px solid var(--panel-border);
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  color: var(--muted);
}

.result-meta p {
  margin: 0;
}

.result-meta strong {
  color: var(--text);
}

/* State Helpers */

.hidden {
  display: none !important;
}

.error-text {
  margin: 10px 0 0;
  color: #fecaca;
  font-size: 14px;
}

.status-dot {
  width: 11px;
  height: 11px;
  display: inline-block;
  border-radius: 999px;
  background: var(--muted-2);
}

.status-dot.ok {
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.12);
}

.status-dot.bad {
  background: var(--danger);
  box-shadow: 0 0 0 5px rgba(239, 68, 68, 0.12);
}

.status-dot.warn {
  background: var(--warning);
  box-shadow: 0 0 0 5px rgba(245, 158, 11, 0.12);
}

.status-dot.muted {
  background: var(--muted-2);
}

/* Responsive */

@media (max-width: 1100px) {
  .mobile-header {
    display: none;
  }

  .sidebar {
    padding: 16px 22px;
  }

  .main {
    padding: 22px;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .process-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 16px;
  }

  .panel {
    padding: 18px;
    border-radius: var(--radius-lg);
  }

  .panel-header {
    flex-direction: column;
  }

  .webcam-frame {
    aspect-ratio: 4 / 3;
    min-height: 260px;
  }

  .captured-preview {
    grid-template-columns: 1fr;
  }

  .captured-preview img {
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
  }

  .sidebar {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav {
    width: 100%;
  }

  .nav-link {
    flex: 1;
    text-align: center;
  }

  .webcam-controls,
  .result-actions {
    display: grid;
  }

  .secondary-btn,
  .primary-btn,
  .danger-btn {
    width: 100%;
  }
}
