:root {
  --bg: oklch(24% 0.03 238);
  --surface: oklch(97% 0.015 90);
  --surface-2: oklch(92% 0.025 88);
  --ink: oklch(18% 0.02 245);
  --muted: oklch(46% 0.025 245);
  --line: oklch(79% 0.03 88);
  --accent: oklch(73% 0.16 74);
  --accent-dark: oklch(35% 0.08 70);
  --danger: oklch(55% 0.18 25);
  --code-bg: oklch(18% 0.025 236);
  --code-fg: oklch(91% 0.02 118);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Manrope", sans-serif;
  background:
    linear-gradient(135deg, oklch(21% 0.03 238), oklch(31% 0.045 210) 58%, oklch(26% 0.035 160)),
    var(--bg);
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.055;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.login-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: oklch(13% 0.025 238 / 78%);
  backdrop-filter: blur(10px);
}

.login-card {
  width: min(420px, 100%);
  padding: 22px;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 48px;
}

.hero {
  color: var(--surface);
  margin-bottom: 28px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 820px;
  margin-bottom: 10px;
  font-size: clamp(2.1rem, 5vw, 5.2rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.subtitle {
  max-width: 670px;
  margin-bottom: 0;
  color: oklch(86% 0.02 92);
  font-size: 1.04rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.controls-column {
  display: grid;
  gap: 14px;
}

.panel {
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.auto-panel,
.form-panel,
.result-panel {
  padding: 22px;
}

.auto-form {
  display: grid;
  gap: 10px;
}

.auto-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.auto-search-row button {
  white-space: nowrap;
}

.manual-separator {
  color: oklch(88% 0.02 90);
  font-size: 0.84rem;
  font-weight: 800;
  text-align: center;
}

.missing-list {
  margin: 0;
  padding-left: 18px;
  color: var(--danger);
  font-size: 0.78rem;
  font-weight: 700;
}

.panel-head {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 18px;
}

.panel-head h2 {
  margin-bottom: 4px;
  font-size: 1.1rem;
}

.panel-head p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0;
}

fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 18px;
}

legend {
  padding: 0;
  margin-bottom: 10px;
  font-weight: 800;
  font-size: 0.86rem;
  color: var(--accent-dark);
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.paired {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  font-size: 0.82rem;
  font-weight: 800;
}

label span {
  color: var(--muted);
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid oklch(72% 0.03 88);
  border-radius: 6px;
  background: oklch(99% 0.01 90);
  color: var(--ink);
  font: inherit;
  padding: 10px 12px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid oklch(74% 0.16 74 / 35%);
  border-color: var(--accent-dark);
}

input[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: var(--danger);
}

.error {
  min-height: 16px;
  color: var(--danger);
  font-size: 0.75rem;
  margin: 0;
}

.form-message {
  min-height: 22px;
  color: var(--accent-dark);
  font-size: 0.85rem;
  font-weight: 700;
}

.actions,
.download-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  padding: 10px 14px;
}

.primary {
  background: var(--accent);
  color: oklch(18% 0.02 70);
}

.secondary,
.download-grid button {
  background: transparent;
  border-color: var(--accent-dark);
  color: var(--accent-dark);
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

.empty-state {
  min-height: 420px;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed oklch(70% 0.035 88);
  border-radius: 8px;
  background: var(--surface-2);
}

.empty-state strong {
  color: var(--ink);
  font-size: 1.2rem;
}

.hidden {
  display: none !important;
}

.session-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  color: #334155;
  font-size: 0.9rem;
}

.session-bar button {
  width: auto;
  min-height: 36px;
  padding: 0 12px;
}

.output {
  display: grid;
  gap: 22px;
}

.output h3 {
  margin-bottom: 10px;
  font-size: 0.98rem;
}

.summary-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
  margin: 0;
}

.summary-list div {
  border-bottom: 1px solid var(--line);
  padding-bottom: 7px;
}

.summary-list dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.summary-list dd {
  margin: 2px 0 0;
  font-weight: 800;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.section-title span {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  color: var(--muted);
}

.barcode-frame {
  min-height: 160px;
  display: grid;
  place-items: center;
  overflow: auto;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--line);
  padding: 18px;
}

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

textarea {
  min-height: 150px;
  resize: vertical;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.55;
}

.hex-table-wrap {
  max-height: 470px;
  overflow: auto;
  border-radius: 8px;
  border: 1px solid oklch(35% 0.035 236);
  background: var(--code-bg);
}

.hex-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 980px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  color: var(--code-fg);
}

.hex-table th,
.hex-table td {
  padding: 7px 8px;
  border-bottom: 1px solid oklch(32% 0.025 236);
  text-align: left;
  white-space: nowrap;
}

.hex-table th {
  position: sticky;
  top: 0;
  background: oklch(15% 0.025 236);
  color: var(--accent);
  z-index: 1;
}

.hex-table td.byte {
  text-align: center;
}

.hex-table td.ascii {
  color: oklch(86% 0.05 145);
}

@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .form-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1480px);
    padding-top: 22px;
  }

  .auto-search-row,
  .paired,
  .summary-list {
    grid-template-columns: 1fr;
  }

  .auto-panel,
  .form-panel,
  .result-panel {
    padding: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
