:root {
  --bg: #0f172a;
  --bg-elevated: #1a2540;
  --bg-card: #16213f;
  --border: #2a3a5f;
  --text: #e8ecf5;
  --text-muted: #93a3c2;
  --accent: #4f8cff;
  --accent-hover: #6ea0ff;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 16px 0;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand-logo {
  width: 32px;
  height: 32px;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
}

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

.tabs {
  display: flex;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  padding: 10px 8px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.hint {
  font-size: 0.9rem;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 0 0 16px;
}

.btn {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.btn.primary:hover { background: var(--accent-hover); }

.btn.secondary {
  background: var(--bg-card);
  color: var(--text);
}
.btn.secondary:hover { border-color: var(--accent); }

.btn.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn.danger:hover { background: var(--danger); color: white; }

.file-label { position: relative; }

.scan-source {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.camera-wrap {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto 16px;
  border-radius: var(--radius);
  overflow: hidden;
  background: black;
  aspect-ratio: 4 / 3;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge.warning { background: var(--warning); color: #1a1200; }
.badge.danger { background: var(--danger); }

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

.warnings {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 0.85rem;
}

.warnings ul { margin: 4px 0 0; padding-left: 18px; }

.field-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 10px 0 4px;
}

textarea, input[type="text"], input[type="email"], select {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: var(--font);
  resize: vertical;
}

textarea:focus, input:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.details {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.details dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0; }
.details dt { font-weight: 600; color: var(--text); }

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.gen-type-select {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.gen-form { margin-bottom: 12px; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.gen-options {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
}
.gen-options input[type="range"] { flex: 1; }

.gen-result {
  margin-top: 20px;
  text-align: center;
}

#gen-canvas {
  max-width: 100%;
  background: white;
  border-radius: 8px;
  padding: 12px;
}

.history-subtabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.subtab-btn {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.subtab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

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

.history-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

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

.history-item .h-content {
  font-size: 0.85rem;
  word-break: break-word;
  color: var(--text-muted);
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 24px;
}

.app-footer {
  text-align: center;
  padding: 14px;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.auth-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 32px 20px;
  min-height: 100vh;
}

.auth-screen .brand-logo { width: 56px; height: 56px; }
.auth-screen h1 { margin: 0; }
.auth-screen .hint { max-width: 360px; }
.auth-screen a.btn { text-decoration: none; }

.user-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.admin-table th, .admin-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.admin-table th { color: var(--text-muted); font-weight: 600; }

.admin-table select, .admin-table input[type="checkbox"] {
  width: auto;
}

@media (min-width: 640px) {
  .app-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
  }
  .tabs { width: auto; }
  .tab-btn { flex: none; padding: 10px 20px; }
  .user-bar { padding-bottom: 0; }
}
