/* ── CSS Variables ──────────────────────────────────────── */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: rgba(0,0,0,0.12);
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --sidebar-w: 220px;
  --right-w: 220px;
  --header-h: 52px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html.de-dark {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: rgba(255,255,255,0.1);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

/* ── Layout ─────────────────────────────────────────────── */
.de-root { min-height: 100vh; display: flex; flex-direction: column; }

.de-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
}

.de-header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
}

.de-header-logo-icon {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 500;
}

.de-header-spacer { flex: 1; }

.de-header-btn {
  width: 32px; height: 32px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: color 0.15s, background 0.15s;
}
.de-header-btn:hover { background: var(--bg); color: var(--text); }

.de-main {
  display: flex;
  margin-top: var(--header-h);
  min-height: calc(100vh - var(--header-h));
}

/* ── Sidebar ─────────────────────────────────────────────── */
.de-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  background: var(--surface);
  border-right: 0.5px solid var(--border);
  padding: 12px 0;
}

.de-sidebar-section { padding: 8px 12px 4px; }
.de-sidebar-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.de-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  cursor: pointer;
  border-radius: 0;
  color: var(--text-muted);
  font-weight: 400;
  transition: background 0.1s, color 0.1s;
  position: relative;
  user-select: none;
}
.de-nav-item:hover { background: var(--bg); color: var(--text); }
.de-nav-item.active {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent);
  font-weight: 500;
}
.de-nav-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.de-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 500;
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* ── Center content ──────────────────────────────────────── */
.de-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  max-width: 800px;
}

.de-page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.de-page-back {
  width: 32px; height: 32px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
}
.de-page-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
}
.de-page-actions { display: flex; gap: 8px; }

/* ── Card ────────────────────────────────────────────────── */
.de-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}
.de-card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 0.5px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Field row ───────────────────────────────────────────── */
.de-field {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 0.5px solid var(--border);
  align-items: start;
}
.de-field:last-child { border-bottom: none; }

.de-field-label {
  font-size: 13px;
  color: var(--text-muted);
  padding-top: 7px;
  line-height: 1.4;
}
.de-field-label.req::after {
  content: " *";
  color: var(--danger);
}
.de-field-label.req-empty { color: var(--danger); }

.de-field-input { display: flex; flex-direction: column; gap: 4px; }

/* ── Form controls ───────────────────────────────────────── */
input[type="text"], textarea, select {
  width: 100%;
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 72px; }
select { cursor: pointer; }

.de-input-req-empty input[type="text"],
.de-input-req-empty textarea {
  border-color: var(--warning);
  background: color-mix(in srgb, var(--warning) 5%, var(--bg));
}

.de-source-tag {
  font-size: 11px;
  color: var(--text-muted);
}
.de-source-tag.high { color: var(--success); }
.de-source-tag.medium { color: var(--warning); }
.de-source-tag.low { color: var(--text-muted); }

/* ── Document items table ────────────────────────────────── */
.de-doc-table { width: 100%; border-collapse: collapse; }
.de-doc-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 6px 8px;
  border-bottom: 0.5px solid var(--border);
}
.de-doc-table td { padding: 6px 4px; vertical-align: top; }
.de-doc-table tr:not(:last-child) td { border-bottom: 0.5px solid var(--border); }
.de-doc-table input { font-size: 12px; padding: 4px 6px; }

.de-doc-add-btn {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 0.5px dashed var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  transition: color 0.15s, border-color 0.15s;
}
.de-doc-add-btn:hover { color: var(--accent); border-color: var(--accent); }

.de-doc-del-btn {
  width: 22px; height: 22px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
}
.de-doc-del-btn:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 0.5px solid transparent;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg); }
.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ── Right panel ──────────────────────────────────────────── */
.de-right {
  width: var(--right-w);
  flex-shrink: 0;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 16px 12px;
  border-left: 0.5px solid var(--border);
}

.de-right-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.de-action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  margin-bottom: 6px;
  transition: background 0.1s, color 0.1s;
  text-align: left;
}
.de-action-btn:hover { background: var(--bg); }
.de-action-btn.accent { color: var(--accent); border-color: var(--accent); }
.de-action-btn.accent:hover { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }

.de-right-divider {
  height: 0.5px;
  background: var(--border);
  margin: 12px 0;
}

.de-status-box {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}
.de-status-box.valid { border-color: var(--success); color: var(--success); }
.de-status-box.invalid { border-color: var(--danger); color: var(--danger); }

/* ── Upload screen ────────────────────────────────────────── */
.de-upload-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-h));
  padding: 40px 24px;
}

.de-upload-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 480px;
  text-align: center;
}

.de-upload-icon {
  width: 56px; height: 56px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
  color: var(--accent);
  font-size: 24px;
}

.de-upload-title { font-size: 18px; font-weight: 500; margin-bottom: 8px; }
.de-upload-sub { color: var(--text-muted); margin-bottom: 24px; font-size: 13px; }

.de-drop-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 28px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 16px;
}
.de-drop-zone:hover, .de-drop-zone.drag-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
}
.de-drop-zone input { display: none; }
.de-drop-zone-text { color: var(--text-muted); font-size: 13px; }
.de-drop-zone-text span { color: var(--accent); font-weight: 500; }

.de-import-sep {
  font-size: 11px;
  color: var(--text-muted);
  margin: 16px 0 12px;
  text-align: center;
}

.de-import-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.de-import-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
}

/* ── Readiness panel ─────────────────────────────────────── */
.de-readiness-group { margin-bottom: 6px; }
.de-readiness-label {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.de-readiness-label.de-readiness-blocker { color: var(--danger); }
.de-readiness-label.de-readiness-warn { color: var(--warning); }
.de-readiness-label.de-readiness-ok { color: var(--success); }
.de-readiness-list {
  list-style: none;
  padding: 0;
  margin: 0 0 4px;
}
.de-readiness-list li {
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 0 2px 10px;
  border-left: 2px solid var(--border);
  cursor: default;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.de-readiness-list.absent li { border-left-color: var(--danger); color: var(--text); }
.de-readiness-list.needs-confirm li { border-left-color: var(--warning); }

/* ── Address autocomplete ────────────────────────────────── */
.de-suggest-list {
  display: none;
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  z-index: 150;
  max-height: 220px;
  overflow-y: auto;
}
.de-suggest-list.open { display: block; }
.de-suggest-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  border-bottom: 0.5px solid var(--border);
  line-height: 1.4;
}
.de-suggest-item:last-child { border-bottom: none; }
.de-suggest-item:hover { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); color: var(--accent); }

/* ── Modal ───────────────────────────────────────────────── */
.de-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.de-overlay.open { display: flex; }
.de-modal {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.de-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.de-modal-title { font-size: 15px; font-weight: 500; }
.de-modal-close {
  width: 28px; height: 28px;
  border: 0.5px solid var(--border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
}
.de-modal-body { overflow-y: auto; flex: 1; }
.de-xml-pre {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 11px;
  font-family: "Consolas", "Monaco", monospace;
  overflow-x: auto;
  white-space: pre;
  color: var(--text);
  line-height: 1.6;
}

/* ── Toast / spinner ─────────────────────────────────────── */
.de-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  z-index: 300;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.de-toast.show { opacity: 1; }
.de-toast.success { background: var(--success); color: #fff; }
.de-toast.error { background: var(--danger); color: #fff; }

.de-spinner {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 400;
  align-items: center;
  justify-content: center;
}
.de-spinner.show { display: flex; }
.de-spinner-inner {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.de-spinner-ring {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.de-spinner-text { font-size: 13px; color: var(--text-muted); }

/* ── Empty/error states ──────────────────────────────────── */
.de-empty {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.de-error-list {
  list-style: none;
  padding: 0;
}
.de-error-list li {
  padding: 6px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 12px;
  color: var(--danger);
  display: flex;
  gap: 6px;
}
.de-error-list li::before { content: "•"; }
.de-error-list li[data-section] { cursor: pointer; flex-direction: column; gap: 2px; }
.de-error-list li[data-section]:hover { background: color-mix(in srgb, var(--danger) 6%, transparent); border-radius: 4px; }
.de-error-hint { font-size: 11px; color: var(--text-muted); font-style: italic; padding-left: 10px; }

@keyframes navFlash {
  0%   { background: color-mix(in srgb, var(--danger) 20%, transparent); }
  60%  { background: color-mix(in srgb, var(--danger) 20%, transparent); }
  100% { background: transparent; }
}
.de-nav-xsd-error { animation: navFlash 3s ease forwards; }

/* ── Log panel ───────────────────────────────────────────── */
.de-log {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  font-size: 11px;
  font-family: monospace;
  color: var(--text-muted);
  line-height: 1.8;
  max-height: 120px;
  overflow-y: auto;
}

/* ── Progress bar ────────────────────────────────────────── */
.de-progress {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}
.de-progress-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}

/* ── Schema version selector ──────────────────────────────── */
.de-schema-select {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.de-schema-select select { width: auto; padding: 4px 8px; font-size: 12px; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 640px) {
  .de-sidebar, .de-right { display: none; }
  .de-content { padding: 16px; max-width: 100%; }
  .de-field { grid-template-columns: 1fr; }
  .de-field-label { padding-top: 0; }
  .de-right.mobile-open {
    display: block;
    position: fixed;
    top: var(--header-h);
    right: 0;
    bottom: 0;
    z-index: 150;
    background: var(--surface);
  }
}
