:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8faff;
  --ink: #152033;
  --muted: #647087;
  --line: #d9e0ec;
  --accent: #10b981;
  --accent-strong: #059669;
  --accent-soft: #ecfdf5;
  --success: #16805e;
  --success-soft: #eaf8f2;
  --warning: #a65a00;
  --warning-soft: #fff6e6;
  --danger: #b4233f;
  --shadow: 0 12px 34px rgba(28, 43, 74, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="dark"] body { background-color: #0c111b !important; color: #e8edf6 !important; }

html[data-theme="dark"],
html[data-theme="dark"] body,
html[data-site-theme="dark"],
html[data-site-theme="dark"] body,
html[data-theme="dark"] .app,
html[data-site-theme="dark"] .app,
html[data-theme="dark"] .workspace,
html[data-site-theme="dark"] .workspace {
  background-color: #0c111b !important;
  color: #e8edf6 !important;
}

html[data-site-theme="dark"], html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c111b;
  --surface: #151d2a;
  --surface-2: #101722;
  --ink: #edf1f8;
  --muted: #a5afc0;
  --line: #303b4f;
  --accent: #34d399;
  --accent-strong: #6ee7b7;
  --accent-soft: #064e3b;
  --success: #72dbb4;
  --success-soft: #17372d;
  --warning: #f2c16f;
  --warning-soft: #3a2e19;
  --danger: #ff8d9a;
  --shadow: 0 14px 38px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--bg); font-size: 14px; }
button, textarea, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
button:focus-visible, textarea:focus-visible, select:focus-visible, input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

/* Guide highlight */
.dth-guide-highlight {
  outline: 3px solid #10b981 !important;
  outline-offset: 3px !important;
  border-radius: 8px !important;
}

.app-header {
  display: flex;
  min-height: 74px;
  padding: 15px clamp(16px, 3vw, 36px);
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
}
.app-brand, .header-actions { display: flex; align-items: center; }
.app-brand { gap: 12px; }
.app-brand div { display: grid; gap: 2px; }
.app-brand strong { font-size: 16px; }
.app-brand small { color: var(--muted); }
.header-actions { gap: 12px; }
.local-pill { display: inline-flex; align-items: center; gap: 7px; color: var(--success); font-weight: 700; font-size: 12px; }
.local-pill span { width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 14%, transparent); }
.icon-button { display: grid; width: 38px; height: 38px; padding: 0; place-items: center; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--surface); }
#theme-button::before { width: 16px; height: 16px; border: 2px solid currentColor; border-radius: 50%; content: ""; box-shadow: inset -5px -3px 0 -2px var(--surface), 5px -3px 0 -4px currentColor; }

.workspace {
  width: min(1400px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 3vw, 34px);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Toolbar */
.toolbar {
  display: flex;
  padding: 12px 16px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.mode-switch {
  display: inline-flex;
  padding: 4px;
  gap: 3px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.mode-switch button {
  min-width: 105px;
  padding: 8px 16px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  font-size: 13px;
  transition: all 0.15s ease;
}
.mode-switch button.active {
  color: white;
  background: var(--accent-strong);
}

.utility-group { display: flex; gap: 8px; }

.button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: var(--surface);
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.button:hover:not(:disabled), .icon-button:hover { border-color: var(--accent); }
.button.primary { color: white; border-color: var(--accent-strong); background: var(--accent-strong); }
.button.primary:hover:not(:disabled) { background: var(--accent); }
.button.secondary { background: var(--surface-2); }
.button.quiet { color: var(--muted); background: transparent; }
.button.quiet:hover:not(:disabled) { color: var(--ink); background: var(--surface-2); }
.button.small { min-height: 32px; padding: 4px 10px; font-size: 12px; }
.button.tiny { min-height: 26px; padding: 2px 8px; font-size: 11px; border-radius: 6px; }

.compact-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}
.compact-check input { accent-color: var(--accent); cursor: pointer; }

/* Card Sections */
.card-section {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card-heading {
  display: flex;
  min-height: 56px;
  padding: 12px 18px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.card-title { display: flex; align-items: center; gap: 10px; }
.card-title h2, .card-title label { margin: 0; color: var(--ink); font-weight: 750; font-size: 15px; }
.step-num {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border-radius: 7px;
  color: var(--accent);
  background: var(--accent-soft);
  font: 700 11px/1 ui-monospace, monospace;
}

.file-input-wrapper { display: flex; align-items: center; gap: 10px; }
.file-name-text { font-size: 12px; color: var(--muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Input Drop Zone */
.drop-zone { position: relative; width: 100%; }
.drop-zone textarea {
  display: block;
  width: 100%;
  padding: 16px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: var(--surface-2);
  font: 13px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace;
  resize: vertical;
}
.drop-zone textarea:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.drop-zone.drag-over { outline: 2px dashed var(--accent); outline-offset: -4px; }

.input-error-bar {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  border-top: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
}

/* Structure Grid */
.structure-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px;
  background: var(--surface-2);
}
.options-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.box-title { font-weight: 700; font-size: 13px; color: var(--ink); }
.radio-group { display: flex; flex-direction: column; gap: 8px; }
.radio-label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.radio-label input { accent-color: var(--accent); cursor: pointer; }
.radio-label code { background: var(--surface-2); padding: 2px 5px; border-radius: 4px; font-size: 12px; border: 1px solid var(--line); }

.columns-manager-box { min-height: 140px; }
.columns-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cols-actions { display: flex; gap: 6px; }
.columns-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
  padding: 4px 2px;
}
.column-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12px;
}
.column-item-left { display: flex; align-items: center; gap: 8px; }
.column-item-left input { accent-color: var(--accent); }
.column-item-right { display: flex; gap: 4px; }

/* Options Inline Grid */
.options-inline-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px;
  padding: 16px;
  background: var(--surface-2);
}
.option-field { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.option-field select {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 600;
}

/* Metric Strip */
.metric-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.metric-strip article { padding: 12px 16px; border-right: 1px solid var(--line); }
.metric-strip article:last-child { border-right: 0; }
.metric-strip span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.metric-strip strong { font-size: 18px; color: var(--ink); }

/* Table Container & Preview */
.table-container { width: 100%; overflow-x: auto; max-height: 380px; overflow-y: auto; background: var(--surface-2); }
.preview-table { width: 100%; border-collapse: collapse; table-layout: auto; font-size: 13px; }
.preview-table th, .preview-table td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; white-space: nowrap; max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.preview-table th { background: var(--surface); position: sticky; top: 0; z-index: 2; font-weight: 700; color: var(--ink); box-shadow: 0 1px 0 var(--line); }
.preview-table td { background: var(--surface); }
.preview-table tr:nth-child(even) td { background: var(--surface-2); }
.preview-table .cell-formula { color: var(--warning); font-weight: 700; }

.empty-table-placeholder, .empty-hint {
  padding: 30px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* Output Area */
.output-wrapper { position: relative; }
.output-wrapper textarea {
  display: block;
  width: 100%;
  min-height: 200px;
  padding: 16px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: var(--surface-2);
  font: 13px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace;
  resize: vertical;
}

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; }
.badge.info { color: var(--accent-strong); background: var(--accent-soft); }

/* Toast / Status */
.status-message {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.status-message.error { color: var(--danger); background: var(--surface); border-color: var(--danger); }
.status-message.success { color: var(--success); background: var(--surface); border-color: var(--success); }

@media (max-width: 900px) {
  .structure-grid { grid-template-columns: 1fr; }
  .metric-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric-strip article:nth-child(3) { border-right: 0; }
}

@media (max-width: 640px) {
  .app-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .card-heading { flex-direction: column; align-items: flex-start; gap: 10px; }
  .options-inline-grid { flex-direction: column; align-items: flex-start; gap: 12px; }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .export-actions { width: 100%; }
  .export-actions button { flex: 1; }
}
