/* Alumtek theme — light by default, dark via data-theme="dark" */

:root,
[data-theme="light"] {
  --bg: #f4f6f9;
  --bg-elevated: #ffffff;
  --bg-input: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-hover: #eef2f7;
  --text: #1a2332;
  --muted: #5c6b7e;
  --accent: #c8102e;
  --accent-hover: #a80d26;
  --accent-soft: rgba(200, 16, 46, 0.1);
  --danger: #c62828;
  --ok: #2e7d57;
  --warn: #b8860b;
  --border: #d5dde8;
  --shadow: 0 1px 2px rgba(26, 35, 50, 0.06), 0 8px 24px rgba(26, 35, 50, 0.06);
  --banner-ok-bg: rgba(46, 125, 87, 0.1);
  --banner-ok-fg: #1b5e40;
  --banner-err-bg: rgba(198, 40, 40, 0.1);
  --banner-err-fg: #8b1a1a;
  --mark-code: #3d4f66;
  --table-hover: rgba(26, 35, 50, 0.03);
  --overlay: rgba(26, 35, 50, 0.45);
  --radius: 12px;
  --sidebar-width: 260px;
  --touch: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #1a2332;
  --bg-elevated: #243044;
  --bg-input: #2c3b52;
  --bg-sidebar: #1e2a3c;
  --bg-hover: #2c3b52;
  --text: #f2f5f8;
  --muted: #9aa8bc;
  --accent: #e11d3c;
  --accent-hover: #f03a55;
  --accent-soft: rgba(225, 29, 60, 0.18);
  --danger: #d65a5a;
  --ok: #3d9a7a;
  --warn: #d4a017;
  --border: #3a4d68;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 8px 24px rgba(0, 0, 0, 0.2);
  --banner-ok-bg: rgba(61, 154, 122, 0.2);
  --banner-ok-fg: #b7f0d8;
  --banner-err-bg: rgba(214, 90, 90, 0.18);
  --banner-err-fg: #ffc9c9;
  --mark-code: #c8d6e5;
  --table-hover: rgba(255, 255, 255, 0.03);
  --overlay: rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

:root {
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(ellipse at top left, rgba(200, 16, 46, 0.06) 0%, transparent 42%),
    radial-gradient(ellipse at bottom right, rgba(61, 154, 122, 0.05) 0%, transparent 45%),
    var(--bg);
  color: var(--text);
}

html[data-theme="dark"] body {
  background:
    radial-gradient(ellipse at top, #243044 0%, transparent 55%),
    var(--bg);
}

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

button {
  cursor: pointer;
}

img {
  max-width: 100%;
  height: auto;
}

.brand-logo {
  display: block;
  width: 72px;
  height: auto;
  object-fit: contain;
}

.brand-logo-sm {
  width: 40px;
}

.brand-logo-xs {
  width: 28px;
  flex-shrink: 0;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.brand-lockup h1 {
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

/* —— TSD shell (mobile-first) —— */

.tsd-body {
  min-height: 100dvh;
}

.app-shell {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    calc(10px + var(--safe-top))
    calc(12px + var(--safe-right))
    calc(16px + var(--safe-bottom))
    calc(12px + var(--safe-left));
  gap: 12px;
}

.tsd-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--touch);
  position: sticky;
  top: 0;
  z-index: 20;
  margin: -10px -4px 0;
  padding: 8px 4px;
  background: var(--bg);
}

.tsd-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.tsd-brand-text h1 {
  font-size: 1.05rem;
  line-height: 1.15;
}

.tsd-subtitle {
  font-size: 0.75rem;
  line-height: 1.2;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tsd-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.tsd-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.inline-form {
  display: inline;
  margin: 0;
}

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

h1,
h2,
p {
  margin: 0;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: var(--touch);
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 1rem;
  touch-action: manipulation;
  user-select: none;
}

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

.btn:active {
  transform: translateY(1px);
}

a.btn {
  text-decoration: none;
  color: white;
}

a.btn-ghost {
  color: var(--text);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

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

.btn-ghost:hover {
  background: var(--bg-hover);
}

.btn-lg {
  min-height: 52px;
  font-size: 1.05rem;
}

.btn-compact {
  width: auto;
  min-height: 40px;
  padding: 8px 10px;
  font-size: 0.85rem;
  border-radius: 10px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 10px;
  flex-shrink: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field-tight {
  margin-bottom: 10px;
}

.field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.field input:not([type="checkbox"]):not([type="radio"]),
.field select,
.input-touch,
.scan-code {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 14px;
  min-height: var(--touch);
  font-size: 16px; /* iOS: no auto-zoom */
}

.field input:not([type="checkbox"]):not([type="radio"]):focus,
.field select:focus,
.input-touch:focus,
.scan-code:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.banner {
  padding: 12px 14px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.35;
}

.banner.ok {
  background: var(--banner-ok-bg);
  border: 1px solid var(--ok);
  color: var(--banner-ok-fg);
}

.banner.err {
  background: var(--banner-err-bg);
  border: 1px solid var(--danger);
  color: var(--banner-err-fg);
}

.tsd-gap-sm {
  margin-bottom: 12px;
}

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

.route-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 12px;
  min-height: var(--touch);
  border-radius: 10px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  font-size: 0.95rem;
}

.route-list li.done {
  border-color: var(--ok);
  background: var(--banner-ok-bg);
  color: var(--banner-ok-fg);
}

.route-list li.done .muted {
  color: var(--banner-ok-fg);
  opacity: 0.85;
}

.route-list li.next {
  border-color: var(--warn);
  background: color-mix(in srgb, var(--warn) 14%, var(--bg-hover));
  box-shadow: inset 0 0 0 1px var(--warn);
  font-weight: 700;
}

.stage-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 0.85rem;
  touch-action: manipulation;
}

.theme-toggle:hover {
  background: var(--bg-hover);
}

.theme-toggle .theme-icon-moon,
html[data-theme="dark"] .theme-toggle .theme-icon-sun {
  display: none;
}

html[data-theme="dark"] .theme-toggle .theme-icon-moon {
  display: inline;
}

.theme-toggle .theme-icon-sun {
  display: inline;
}

/* —— Scan screen —— */

.scan-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.scan-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}

.scan-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px;
  border-radius: 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  position: relative;
  z-index: 2;
}

.scan-mode-btn {
  min-height: var(--touch);
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  touch-action: manipulation;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  z-index: 1;
  opacity: 0.72;
}

.scan-mode-btn:hover,
.scan-mode-btn:focus-visible {
  opacity: 1;
  background: var(--bg-elevated);
}

.scan-mode-btn.is-active {
  opacity: 1;
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow);
}

.scan-user {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.scan-user strong {
  font-size: 1rem;
  line-height: 1.2;
}

.scan-user .muted {
  font-size: 0.8rem;
}

.scan-entry {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: stretch;
}

.scan-entry .btn {
  width: auto;
  min-width: 72px;
  padding-inline: 18px;
}

.scan-code {
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  letter-spacing: 0.01em;
}

.scan-reader {
  width: 100%;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #000;
  min-height: 220px;
}

.scan-reader[hidden] {
  display: none !important;
}

.scan-reader video {
  width: 100% !important;
  border-radius: 12px;
}

.scan-message {
  position: sticky;
  top: calc(52px + var(--safe-top));
  z-index: 15;
}

.scan-feedback {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.scan-feedback-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.scan-feedback-option input {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.part-card h2 {
  font-size: 1.15rem;
  word-break: break-word;
}

.part-card .mark-code {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--mark-code);
  word-break: break-all;
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
}

.part-status {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 10px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
}

.part-status-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.part-status-row strong {
  text-align: right;
  font-size: 0.95rem;
}

#part-next-stage {
  color: var(--warn);
}

#part-last-stage {
  color: var(--banner-ok-fg);
}

.part-finished {
  margin-top: 12px;
}

.tsd-login-card h2 {
  font-size: 1.25rem;
}

.tsd-login-hint {
  margin: 6px 0 16px;
  font-size: 0.9rem;
}

/* Very narrow TSD / phone portrait */
@media (max-width: 380px) {
  .tsd-subtitle {
    display: none;
  }

  .btn-compact {
    padding: 8px;
    font-size: 0.8rem;
  }

  .scan-entry {
    grid-template-columns: 1fr;
  }

  .scan-entry .btn {
    width: 100%;
  }
}

/* Landscape handheld */
@media (max-height: 480px) and (orientation: landscape) {
  .app-shell {
    max-width: 720px;
    padding-top: calc(6px + var(--safe-top));
    gap: 8px;
  }

  .tsd-header {
    position: static;
    margin: 0;
    padding: 0;
    min-height: 36px;
  }

  .scan-reader {
    min-height: 160px;
  }
}

/* Wider phones / tablets keep the same mobile column */
@media (min-width: 520px) {
  .app-shell {
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: calc(24px + var(--safe-bottom));
    gap: 16px;
  }

  .card {
    padding: 16px;
  }
}
