/* CSS Reset and Variables */
:root {
  --bg-color: #ffffff;
  --text-color: #1e293b;
  --text-muted: #64748b;
  --card-bg: #f8fafc;
  --card-border: #e2e8f0;
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --warning-light: #fffbeb;
  --error-color: #ef4444;
  --error-light: #fef2f2;
  --border-radius: 8px;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

html[data-theme="dark"] {
  --bg-color: #0c111b;
  --text-color: #e8edf6;
  --text-muted: #94a3b8;
  --card-bg: #161e2e;
  --card-border: #26334d;
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #1e293b;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --warning-light: #2d2415;
  --error-color: #ef4444;
  --error-light: #2c1a1d;
}

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

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.5;
  font-size: 14px;
  padding: 16px;
}

button:focus-visible, textarea:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--primary-color) !important;
  outline-offset: 2px !important;
}

/* Guide highlight requirement */
.dth-guide-highlight {
  outline: 2px solid #2563eb !important;
  box-shadow: 0 0 8px rgba(37, 99, 235, 0.4) !important;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--card-border);
}

.app-brand strong {
  font-size: 18px;
  display: block;
}

.app-brand small {
  color: var(--text-muted);
  font-size: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.local-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--success-color);
  background: var(--primary-light);
  padding: 4px 10px;
  border-radius: 9999px;
  font-weight: 500;
}

.local-pill span {
  width: 8px;
  height: 8px;
  background-color: var(--success-color);
  border-radius: 50%;
}

.icon-button {
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--text-color);
  padding: 6px 10px;
  border-radius: var(--border-radius);
  cursor: pointer;
}

/* Workspace Panels */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  padding: 16px;
  min-width: 0;
}

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

.card-title {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--border-radius);
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--text-color);
  cursor: pointer;
  transition: all 0.15s ease;
}

.button:hover:not(:disabled) {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.button-primary {
  background: var(--primary-color);
  color: #ffffff !important;
  border-color: var(--primary-color);
}

.button-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.button-secondary {
  background: var(--primary-light);
  color: var(--primary-color);
  border-color: var(--primary-color);
}

.button-danger {
  color: var(--error-color);
  border-color: var(--error-color);
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Inputs & Editors */
textarea.code-input {
  width: 100%;
  min-height: 180px;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 12px;
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  background: var(--bg-color);
  color: var(--text-color);
  resize: vertical;
  outline: none;
}

.xml-editor-shell {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  min-width: 0;
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  overflow: hidden;
  background: var(--bg-color);
}

.xml-editor-shell:focus-within {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.xml-editor-shell textarea.code-input {
  min-width: 0;
  min-height: 220px;
  margin: 0;
  border: 0;
  border-radius: 0;
  line-height: 20px;
  white-space: pre;
  overflow: auto;
}

.xml-line-numbers {
  min-height: 220px;
  max-height: 220px;
  margin: 0;
  padding: 12px 8px;
  overflow: hidden;
  border-right: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--text-muted);
  font: 12px/20px var(--font-mono);
  text-align: right;
  user-select: none;
  pointer-events: none;
}

.xml-line-number-spacer {
  position: relative;
  display: block;
  min-height: 20px;
}

.xml-line-number-window {
  position: absolute;
  inset: 0 0 auto;
  display: block;
  white-space: pre;
}

textarea.code-input:focus {
  border-color: var(--primary-color);
}

.drop-zone {
  border: 2px dashed var(--card-border);
  border-radius: var(--border-radius);
  padding: 12px;
  text-align: center;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}

.drop-zone.drag-over {
  border-color: var(--primary-color);
  background: var(--primary-light);
}

/* Alerts and banners */
.banner {
  padding: 10px 14px;
  border-radius: var(--border-radius);
  font-size: 13px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.banner-info {
  background: var(--primary-light);
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
}

.banner-warning {
  background: var(--warning-light);
  color: var(--warning-color);
  border: 1px solid var(--warning-color);
}

.banner-error {
  background: var(--error-light);
  color: var(--error-color);
  border: 1px solid var(--error-color);
}

.provenance-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  color: var(--primary-color);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

/* Grid & Layouts */
.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 12px;
  min-width: 0;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-group label {
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
}

.select-input, .text-field {
  padding: 8px 12px;
  border-radius: var(--border-radius);
  border: 1px solid var(--card-border);
  background: var(--bg-color);
  color: var(--text-color);
  font-size: 13px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

/* Path Picker & Candidates */
.candidate-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.candidate-pill {
  padding: 6px 12px;
  border-radius: 9999px;
  border: 1px solid var(--card-border);
  background: var(--bg-color);
  color: var(--text-color);
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.candidate-pill.active {
  border-color: var(--primary-color);
  background: var(--primary-light);
  color: var(--primary-color);
  font-weight: 600;
}

.xml-tree-picker {
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  background: var(--bg-color);
}

.xml-tree-picker .field-group {
  margin-bottom: 10px;
}

.xml-tree {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  background: var(--card-bg);
}

.tree-render-status {
  min-height: 18px;
  margin: 0 0 8px;
  color: var(--text-muted);
  font-size: 12px;
}

.xml-tree-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: stretch;
  border-bottom: 1px solid var(--card-border);
}

.xml-tree-row:last-child { border-bottom: 0; }

.tree-toggle {
  width: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.tree-toggle:hover { background: var(--primary-light); color: var(--primary-color); }
.tree-toggle-placeholder { width: 28px; }

.tree-show-more {
  width: calc(100% - 10px);
  margin: 5px;
  padding: 7px 10px;
  border: 1px dashed var(--card-border);
  border-radius: var(--border-radius);
  background: transparent;
  color: var(--primary-color);
  text-align: left;
  cursor: pointer;
}

.tree-empty {
  margin: 0;
  padding: 14px;
  color: var(--text-muted);
  font-size: 12px;
}

.xml-tree-node {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-bottom: 0;
  background: transparent;
  color: var(--text-color);
  text-align: left;
  cursor: pointer;
}

.xml-tree-node:hover { background: var(--primary-light); }
.xml-tree-node[aria-selected="true"] {
  background: var(--primary-light);
  color: var(--primary-color);
  font-weight: 600;
}

.xml-tree-node:focus-visible {
  position: relative;
  z-index: 1;
  outline: 2px solid var(--primary-color);
  outline-offset: -2px;
}

.tree-node-main { min-width: 0; }
.tree-node-name { display: block; font-family: var(--font-mono); }
.tree-node-path {
  display: block;
  overflow-wrap: anywhere;
  color: var(--text-muted);
  font: 11px/1.4 var(--font-mono);
}
.tree-node-badge {
  align-self: center;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 11px;
}

.confidence-badge {
  font-size: 10px;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
}

.confidence-high { background: #d1fae5; color: #065f46; }
.confidence-medium { background: #fef3c7; color: #92400e; }
.confidence-low { background: #fee2e2; color: #991b1b; }

html[data-theme="dark"] .confidence-high { background: #064e3b; color: #a7f3d0; }
html[data-theme="dark"] .confidence-medium { background: #78350f; color: #fde68a; }
html[data-theme="dark"] .confidence-low { background: #7f1d1d; color: #fecaca; }

/* Mapping Table */
.mapping-table-wrap {
  overflow-x: auto;
  margin-top: 12px;
}

table.mapping-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.mapping-table th, table.mapping-table td {
  padding: 8px 12px;
  border: 1px solid var(--card-border);
  text-align: left;
}

table.mapping-table th {
  background: var(--card-bg);
  font-weight: 600;
}

table.mapping-table tr.collision-row {
  background: var(--error-light);
}

.type-badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
}

.type-element { background: var(--primary-light); color: var(--primary-color); }
.type-attribute { background: var(--warning-light); color: var(--warning-color); }
.type-text { background: var(--card-border); color: var(--text-color); }

/* Table Preview */
.preview-container {
  overflow-x: auto;
  max-height: 400px;
  margin-top: 12px;
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
}

table.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  white-space: nowrap;
}

table.preview-table th {
  position: sticky;
  top: 0;
  background: var(--card-bg);
  padding: 8px 12px;
  border-bottom: 2px solid var(--card-border);
  text-align: left;
  z-index: 1;
}

table.preview-table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--card-border);
  border-right: 1px solid var(--card-border);
}

table.preview-table td.cell-formula {
  background: var(--warning-light);
  color: var(--warning-color);
  font-weight: 600;
}

/* Summary Grid */
.summary-bar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--primary-light);
  border-radius: var(--border-radius);
  font-size: 12px;
  font-weight: 500;
}

.summary-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.summary-item strong {
  color: var(--primary-color);
}

/* Diagnostics Panel */
.diagnostics-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.diagnostics-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
}

.diag-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: bold;
  flex-shrink: 0;
}

.diag-error { background: var(--error-color); color: #fff; }
.diag-warning { background: var(--warning-color); color: #fff; }
.diag-info { background: var(--primary-color); color: #fff; }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-content {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  padding: 20px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
  body {
    padding: 8px;
  }
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .options-grid {
    grid-template-columns: 1fr;
  }
  .xml-editor-shell {
    grid-template-columns: 44px minmax(0, 1fr);
  }
  .xml-tree-node {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }
  .tree-node-badge {
    padding-left: 0;
  }
}
