:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #fffffc;
  --surface-alt: #eef1ed;
  --border: #dae0d8;
  --border-strong: #b9c3bc;
  --text: #1b201e;
  --muted: #636e69;
  --accent: #167b64;
  --accent-strong: #0d5d4b;
  --accent-soft: #dbf1ea;
  --danger: #c24145;
  --success: #1e8e5c;
  --warning: #b77b16;
  --shadow: 0 16px 38px rgb(22 34 29 / 10%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121416;
  --surface: #1d2022;
  --surface-alt: #272c2d;
  --border: #3e4646;
  --border-strong: #5e6968;
  --text: #ecf0ed;
  --muted: #9da7a2;
  --accent: #42b893;
  --accent-strong: #65d2a8;
  --accent-soft: #254038;
  --danger: #ef6b67;
  --success: #64d291;
  --warning: #dfad57;
  --shadow: 0 18px 42px rgb(0 0 0 / 25%);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 12px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 760;
  text-decoration: none;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border: 2px solid var(--accent);
  border-radius: 7px;
  background:
    linear-gradient(135deg, transparent 49%, var(--accent) 50% 58%, transparent 59%),
    linear-gradient(45deg, var(--accent-soft), var(--surface));
}

.topbar-actions,
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.status-pill,
.value-badge,
.row-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-alt);
  font-size: 0.82rem;
  white-space: nowrap;
}

.status-pill.ready,
.row-status.done {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success), var(--border) 60%);
  background: color-mix(in srgb, var(--success) 12%, var(--surface));
}

.row-status.error {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger), var(--border) 60%);
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 18px;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px clamp(12px, 3vw, 32px) 32px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.intake-panel,
.settings-panel {
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

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

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  font-size: clamp(1.15rem, 2vw, 1.45rem);
  line-height: 1.2;
  letter-spacing: 0;
}

.panel-header p,
.file-meta,
.empty-row,
.empty-preview {
  color: var(--muted);
  font-size: 0.9rem;
}

.primary-button,
.secondary-button,
.icon-button,
.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 13px;
  font-weight: 690;
  text-decoration: none;
}

.primary-button {
  color: #fff;
  background: var(--accent);
}

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

.secondary-button,
.download-button {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface-alt);
}

.secondary-button:hover:not(:disabled),
.download-button:hover:not(:disabled) {
  border-color: var(--accent);
}

.icon-button {
  width: 40px;
  padding: 0;
  color: var(--text);
  border-color: var(--border);
  background: var(--surface-alt);
}

.icon-button svg,
.drop-icon svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.drop-zone {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 18px;
  padding: 20px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: var(--surface-alt);
  outline: none;
}

.drop-zone strong,
.drop-zone span {
  display: block;
}

.drop-zone span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.drop-zone.dragging,
.drop-zone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: var(--accent);
  background: var(--surface);
}

.table-shell {
  min-height: 0;
  overflow: auto;
  border-top: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: var(--surface);
  font-size: 0.78rem;
  font-weight: 760;
  text-transform: uppercase;
}

.empty-row td {
  padding: 42px 14px;
  text-align: center;
}

.file-name {
  max-width: min(38vw, 520px);
  overflow: hidden;
  border: 0;
  padding: 0;
  color: var(--text);
  background: transparent;
  font-weight: 720;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-name:hover {
  color: var(--accent);
}

.file-name.selected {
  color: var(--accent);
}

.row-actions {
  text-align: right;
}

.settings-form {
  display: grid;
  gap: 18px;
  padding: 18px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend,
.field > span:first-child {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 760;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.segmented-control label {
  min-width: 0;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  display: grid;
  place-items: center;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0 8px;
  background: var(--surface-alt);
  color: var(--text);
  font-weight: 690;
}

.segmented-control input:checked + span {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.segmented-control input:disabled + span {
  opacity: 0.45;
  text-decoration: line-through;
}

.field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.field input[type="range"],
.field input[type="color"],
.field input[type="number"],
.field select {
  grid-column: 1 / -1;
  width: 100%;
}

.field input[type="color"],
.field input[type="number"],
.field select {
  height: 42px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-alt);
  color: var(--text);
}

.field input[type="number"],
.field select {
  padding: 0 10px;
  font-weight: 650;
}

.hidden-field {
  display: none;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  color: var(--text);
  font-weight: 650;
}

.action-stack {
  display: grid;
  gap: 10px;
}

.wide {
  width: 100%;
}

.preview {
  display: grid;
  place-items: center;
  min-height: 240px;
  margin: 0 18px 18px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background:
    linear-gradient(45deg, var(--surface-alt) 25%, transparent 25% 75%, var(--surface-alt) 75%),
    linear-gradient(45deg, var(--surface-alt) 25%, var(--surface) 25% 75%, var(--surface-alt) 75%);
  background-position: 0 0, 10px 10px;
  background-size: 20px 20px;
}

.preview img {
  display: block;
  max-width: 100%;
  max-height: 380px;
  object-fit: contain;
}

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

  .settings-panel {
    order: -1;
  }
}

@media (max-width: 680px) {
  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .header-actions {
    justify-content: space-between;
  }

  .drop-zone {
    align-items: flex-start;
  }

  th:nth-child(2),
  td:nth-child(2),
  th:nth-child(4),
  td:nth-child(4) {
    display: none;
  }

  .file-name {
    max-width: 46vw;
  }
}
