:root {
  --bg: #0b1020;
  --bg-2: #0f172a;
  --panel: rgba(22, 30, 54, 0.72);
  --panel-solid: #161e36;
  --panel-2: #1e2742;
  --text: #e6ecff;
  --muted: #8a96b8;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.28);
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --accent-3: #06b6d4;
  --ok: #10b981;
  --warn: #f59e0b;
  --err: #ef4444;
  --tag: #7dd3fc;
  --attr: #fbbf24;
  --val: #86efac;
  --txt: #e6ecff;
  --shadow: 0 10px 40px -10px rgba(0,0,0,.6);
  --glow: 0 0 0 1px rgba(99,102,241,.35), 0 8px 32px -8px rgba(99,102,241,.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Inter', -apple-system, Segoe UI, Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  position: relative;
}
body::before {
  content: '';
  position: fixed; inset: 0;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(99,102,241,.18), transparent 60%),
    radial-gradient(1000px 500px at 110% 10%, rgba(6,182,212,.14), transparent 60%),
    radial-gradient(900px 600px at 50% 120%, rgba(139,92,246,.16), transparent 60%),
    linear-gradient(180deg, #070b1a 0%, #0b1020 100%);
  z-index: -2;
  pointer-events: none;
}

/* Floating background orbs */
.bg-orbs { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.orb {
  position: absolute; border-radius: 50%; filter: blur(80px); opacity: .35;
  animation: float 18s ease-in-out infinite;
}
.orb-1 { width: 420px; height: 420px; background: #6366f1; top: -120px; left: -80px; }
.orb-2 { width: 380px; height: 380px; background: #06b6d4; bottom: -120px; right: -60px; animation-delay: -6s; }
.orb-3 { width: 320px; height: 320px; background: #8b5cf6; top: 40%; left: 55%; animation-delay: -12s; }
@keyframes float {
  0%, 100% { transform: translate(0,0) scale(1); }
  33% { transform: translate(40px,-30px) scale(1.05); }
  66% { transform: translate(-30px,20px) scale(.97); }
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 22px;
  background: linear-gradient(180deg, rgba(15,23,42,.85), rgba(15,23,42,.55));
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo {
  width: 42px; height: 42px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 8px 24px -8px rgba(99,102,241,.6), inset 0 1px 0 rgba(255,255,255,.25);
  animation: logoIn .6s cubic-bezier(.2,.9,.3,1.4);
}
@keyframes logoIn {
  0% { transform: scale(.4) rotate(-20deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.brand-text { min-width: 0; }
.topbar h1 {
  font-size: 17px; margin: 0; font-weight: 700; letter-spacing: -.01em;
  background: linear-gradient(90deg, #fff, #c7d2fe);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.muted { color: var(--muted); font-weight: 500; }
.tagline { margin: 1px 0 0; font-size: 11.5px; color: var(--muted); }

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

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(30, 39, 66, 0.7);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 9px 14px; border-radius: 10px;
  cursor: pointer; font-size: 13px; font-weight: 500; font-family: inherit;
  transition: all .18s ease;
  position: relative; overflow: hidden;
  backdrop-filter: blur(8px);
}
.btn .ico { font-size: 13px; line-height: 1; }
.btn::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,.08) 50%, transparent 70%);
  transform: translateX(-100%); transition: transform .5s ease;
}
.btn:hover { transform: translateY(-1px); border-color: rgba(148,163,184,.45); background: rgba(40,52,87,.85); }
.btn:hover::before { transform: translateX(100%); }
.btn:active { transform: translateY(0); }
.btn.ghost { background: transparent; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #fff;
  box-shadow: 0 6px 20px -6px rgba(99,102,241,.6);
}
.btn.primary:hover { box-shadow: 0 10px 30px -6px rgba(99,102,241,.8); }

/* Layout w/ resizable splitter */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: var(--split, 1fr) 6px var(--split-r, 1fr);
  min-height: 0;
  padding: 16px;
  gap: 0;
}
.pane {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  box-shadow: var(--shadow);
  animation: paneIn .5s ease both;
}
#paneRight { animation-delay: .08s; }
@keyframes paneIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 16px;
  background: linear-gradient(180deg, rgba(30,39,66,.6), rgba(30,39,66,.2));
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  gap: 12px;
}
.pane-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pane-title strong { font-weight: 600; letter-spacing: .01em; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-in { background: var(--accent-3); box-shadow: 0 0 12px var(--accent-3); animation: pulse 2.4s ease-in-out infinite; }
.dot-out { background: var(--accent-2); box-shadow: 0 0 12px var(--accent-2); animation: pulse 2.4s ease-in-out infinite .8s; }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .55; transform: scale(.85); }
}
.hint { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

.badge {
  background: rgba(30, 39, 66, 0.8);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  transition: all .25s ease;
  letter-spacing: .02em;
}
.badge.ok {
  color: #a7f3d0;
  border-color: rgba(16,185,129,.5);
  background: rgba(6,78,59,.5);
  box-shadow: 0 0 0 3px rgba(16,185,129,.08);
}
.badge.err {
  color: #fecaca;
  border-color: rgba(239,68,68,.5);
  background: rgba(127,29,29,.4);
}

/* Editor / output */
.editor-wrap { flex: 1; position: relative; min-height: 0; display: flex; }
textarea, pre {
  flex: 1; margin: 0; padding: 16px 18px; border: 0; outline: none;
  background: transparent; color: var(--text);
  font-family: 'JetBrains Mono', Consolas, Menlo, monospace;
  font-size: 13px; line-height: 1.65; resize: none; overflow: auto;
  white-space: pre; tab-size: 2;
  scrollbar-width: thin;
  scrollbar-color: rgba(148,163,184,.3) transparent;
}
textarea::placeholder { color: var(--muted); opacity: .55; }
textarea:focus { background: rgba(99,102,241,.03); }
textarea::-webkit-scrollbar, pre::-webkit-scrollbar, .tab-panel::-webkit-scrollbar { width: 10px; height: 10px; }
textarea::-webkit-scrollbar-thumb, pre::-webkit-scrollbar-thumb, .tab-panel::-webkit-scrollbar-thumb {
  background: rgba(148,163,184,.22); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box;
}
textarea::-webkit-scrollbar-thumb:hover, pre::-webkit-scrollbar-thumb:hover { background: rgba(148,163,184,.4); background-clip: padding-box; }

.drop-hint {
  position: absolute; inset: 8px; border-radius: 10px;
  display: none; place-items: center;
  background: rgba(99,102,241,.12);
  border: 2px dashed rgba(99,102,241,.6);
  color: #c7d2fe; font-weight: 600; font-size: 14px;
  pointer-events: none;
}
.editor-wrap.dragover .drop-hint { display: grid; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Tabs */
.tabs { display: flex; gap: 2px; position: relative; background: rgba(11,16,32,.6); padding: 3px; border-radius: 10px; border: 1px solid var(--border); }
.tab {
  padding: 5px 12px; font-size: 12px; font-weight: 500; font-family: inherit;
  background: transparent; color: var(--muted); border: 0;
  border-radius: 7px; cursor: pointer; transition: color .2s ease;
  position: relative; z-index: 1;
}
.tab:hover { color: var(--text); }
.tab.active { color: #fff; }
.tab.active::before {
  content: ''; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 7px;
  box-shadow: 0 4px 14px -4px rgba(99,102,241,.6);
  animation: tabPop .25s ease;
}
@keyframes tabPop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.tab-panel { display: none; flex: 1; min-height: 0; overflow: auto; }
.tab-panel.active { display: block; animation: fadeIn .25s ease; }

#danfe { padding: 24px; background: linear-gradient(180deg, #eef2f7 0%, #e2e8f0 100%); color: #0f172a; }
#danfe .empty {
  color: #64748b; text-align: center; padding: 60px 20px;
  font-family: 'Inter', sans-serif; font-size: 14px;
}
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: .55; animation: floatY 3s ease-in-out infinite; }
@keyframes floatY { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.empty p { margin: 0; }

/* Resizer */
.resizer {
  cursor: col-resize;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: background .2s ease;
  user-select: none;
}
.resizer::before {
  content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px;
  background: transparent; transform: translateX(-50%); transition: background .2s ease;
}
.resizer:hover::before, .resizer.dragging::before { background: linear-gradient(180deg, transparent, var(--accent), transparent); }
.resizer-grip {
  width: 4px; height: 44px; border-radius: 4px;
  background: var(--border-strong); transition: all .2s ease;
}
.resizer:hover .resizer-grip, .resizer.dragging .resizer-grip {
  background: var(--accent); height: 60px; box-shadow: 0 0 16px rgba(99,102,241,.6);
}
body.resizing { cursor: col-resize; user-select: none; }
body.resizing iframe, body.resizing textarea { pointer-events: none; }

/* Footer */
.footbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 22px; font-size: 11px; color: var(--muted);
  border-top: 1px solid var(--border);
  background: rgba(11,16,32,.6);
  backdrop-filter: blur(10px);
}
kbd {
  display: inline-block; padding: 1px 6px; font-size: 10px;
  background: rgba(30,39,66,.8); border: 1px solid var(--border-strong);
  border-radius: 4px; font-family: 'JetBrains Mono', monospace;
  box-shadow: 0 1px 0 rgba(255,255,255,.05) inset, 0 1px 2px rgba(0,0,0,.4);
}

/* Toast */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: linear-gradient(135deg, rgba(16,185,129,.95), rgba(6,182,212,.95));
  color: #fff; font-size: 13px; font-weight: 500;
  padding: 11px 20px; border-radius: 999px;
  box-shadow: 0 12px 40px -8px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.1) inset;
  opacity: 0; pointer-events: none; transition: all .35s cubic-bezier(.2,.9,.3,1.2);
  z-index: 1000; backdrop-filter: blur(10px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: linear-gradient(135deg, rgba(239,68,68,.95), rgba(245,158,11,.95)); }

/* Syntax highlight */
.tag { color: var(--tag); }
.attr { color: var(--attr); }
.val { color: var(--val); }
.txt { color: var(--txt); }
.com { color: #64748b; font-style: italic; }

/* DANFE (mantém aparência de impressão) */
.danfe-doc {
  background: #fff; color: #000; padding: 16px; max-width: 820px; margin: 0 auto;
  font-family: Arial, sans-serif; font-size: 10pt; box-shadow: 0 20px 60px -10px rgba(0,0,0,.4);
  border-radius: 6px;
}
.danfe-doc h2 { font-size: 14pt; margin: 0 0 8px; text-align: center; }
.danfe-doc h3 { font-size: 10pt; margin: 12px 0 4px; background: #000; color: #fff; padding: 3px 6px; }
.danfe-doc table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.danfe-doc th, .danfe-doc td { border: 1px solid #000; padding: 3px 5px; font-size: 8pt; vertical-align: top; }
.danfe-doc th { background: #e5e7eb; text-align: left; font-weight: bold; }
.danfe-doc .lbl { font-size: 6.5pt; color: #333; display: block; text-transform: uppercase; }
.danfe-doc .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.danfe-doc .grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.danfe-doc .grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; }
.danfe-doc .cell { border: 1px solid #000; padding: 3px 5px; margin: -0.5px; font-size: 8pt; min-height: 22px; }
.danfe-doc .chave { font-family: monospace; letter-spacing: 1px; font-size: 9pt; }
.danfe-doc .right { text-align: right; }
.danfe-doc .center { text-align: center; }

/* Print */
.print-only { display: none; }
@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; color: #000; overflow: visible; }
  body::before, .bg-orbs { display: none !important; }
  .no-print { display: none !important; }
  .print-only { display: block !important; }
  #printArea .danfe-doc { box-shadow: none; max-width: 100%; }
}

/* Responsive */
@media (max-width: 880px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
    padding: 10px;
  }
  .resizer { display: none; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 12px; padding: 14px 16px; }
  .actions { width: 100%; }
  .btn { flex: 1; justify-content: center; }
  .tagline { display: none; }
}
/* Light theme */
body[data-theme="light"] {
  --bg: #f6f8fc;
  --bg-2: #eef2f7;
  --panel: rgba(255,255,255,0.78);
  --panel-solid: #ffffff;
  --panel-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15,23,42,0.10);
  --border-strong: rgba(15,23,42,0.18);
  --tag: #2563eb;
  --attr: #b45309;
  --val: #047857;
  --txt: #0f172a;
}
body[data-theme="light"]::before {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(99,102,241,.18), transparent 60%),
    radial-gradient(1000px 500px at 110% 10%, rgba(6,182,212,.14), transparent 60%),
    radial-gradient(900px 600px at 50% 120%, rgba(139,92,246,.12), transparent 60%),
    linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
}
body[data-theme="light"] .orb { opacity: .22; }
body[data-theme="light"] .topbar h1 {
  background: linear-gradient(90deg, #0f172a, #4338ca);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
body[data-theme="light"] .footbar { background: rgba(255,255,255,.7); }
body[data-theme="light"] kbd { background: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.06) inset, 0 1px 2px rgba(0,0,0,.08); }
body[data-theme="light"] .tabs { background: rgba(15,23,42,.05); }
body[data-theme="light"] textarea:focus { background: rgba(99,102,241,.04); }

/* Icon-only button */
.btn.icon-only { padding: 9px 11px; }
.btn.icon-only .ico { font-size: 15px; }

/* Summary panel */
#summary { padding: 22px 24px; }
.summary-wrap { display: flex; flex-direction: column; gap: 16px; max-width: 900px; margin: 0 auto; }

.card {
  background: linear-gradient(180deg, rgba(30,39,66,.55), rgba(30,39,66,.25));
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 16px 18px;
  backdrop-filter: blur(10px);
  animation: cardIn .4s ease both;
}
body[data-theme="light"] .card {
  background: linear-gradient(180deg, #ffffff, #f8fafc);
}
@keyframes cardIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.card-head {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 12px;
  text-transform: uppercase; letter-spacing: .05em;
}
.card-icon { font-size: 16px; }
.card-head span:nth-child(2) { flex: 1; }

.chip {
  font-size: 10.5px; padding: 3px 9px; border-radius: 999px; font-weight: 600;
  text-transform: none; letter-spacing: 0;
}
.chip-ok { background: rgba(16,185,129,.15); color: #6ee7b7; border: 1px solid rgba(16,185,129,.4); }
.chip-err { background: rgba(239,68,68,.15); color: #fca5a5; border: 1px solid rgba(239,68,68,.4); }
body[data-theme="light"] .chip-ok { color: #047857; }
body[data-theme="light"] .chip-err { color: #b91c1c; }

.chave-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px; font-weight: 500;
  background: rgba(11,16,32,.5); padding: 12px 14px; border-radius: 10px;
  letter-spacing: 1.5px; color: var(--text);
  border: 1px solid var(--border);
  word-break: break-all;
}
body[data-theme="light"] .chave-value { background: #f1f5f9; }

.chave-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px;
}
.chave-grid > div {
  background: rgba(11,16,32,.4); padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border);
}
body[data-theme="light"] .chave-grid > div { background: #f8fafc; }
.chave-grid .span-2 { grid-column: span 2; }
.chave-grid .lbl {
  display: block; font-size: 9.5px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 3px;
}
.chave-grid b { font-size: 13px; font-weight: 600; }

.cards-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.metric {
  padding: 16px; border-radius: 14px;
  background: rgba(30,39,66,.55); border: 1px solid var(--border-strong);
  position: relative; overflow: hidden;
  animation: cardIn .5s ease both;
  transition: transform .2s ease;
}
.metric:hover { transform: translateY(-2px); }
.metric::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--c, var(--accent));
}
.metric-blue { --c: linear-gradient(90deg,#3b82f6,#6366f1); }
.metric-green { --c: linear-gradient(90deg,#10b981,#06b6d4); }
.metric-orange { --c: linear-gradient(90deg,#f59e0b,#ef4444); }
.metric-purple { --c: linear-gradient(90deg,#8b5cf6,#ec4899); }
body[data-theme="light"] .metric { background: #fff; }
.metric-lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.metric-val { font-size: 22px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.metric-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }

.tax-bars { display: flex; flex-direction: column; gap: 10px; }
.tax-row { display: grid; grid-template-columns: 70px 1fr 110px; gap: 12px; align-items: center; font-size: 12px; }
.tax-lbl { font-weight: 600; color: var(--muted); }
.tax-track { height: 8px; background: rgba(148,163,184,.18); border-radius: 99px; overflow: hidden; }
.tax-fill { height: 100%; border-radius: 99px; transition: width .6s cubic-bezier(.2,.9,.3,1); animation: barGrow .8s ease; }
@keyframes barGrow { from { width: 0 !important; } }
.tax-val { text-align: right; font-family: 'JetBrains Mono', monospace; font-size: 11.5px; }

.parties { display: flex; align-items: center; gap: 14px; }
.party { flex: 1; min-width: 0; }
.party-role { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.party-name { font-size: 14px; font-weight: 600; margin-top: 3px; word-break: break-word; }
.party-doc { font-size: 12px; color: var(--muted); margin-top: 4px; font-family: 'JetBrains Mono', monospace; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.party-arrow { font-size: 22px; color: var(--accent); opacity: .6; }

.qr-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
#qrCanvas { background: #fff; padding: 10px; border-radius: 10px; line-height: 0; }
#qrCanvas svg { display: block; }
.qr-link { color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 500; }
.qr-link:hover { text-decoration: underline; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(6px); animation: fadeIn .2s ease; }
.modal-card {
  position: relative; background: var(--panel-solid);
  border: 1px solid var(--border-strong); border-radius: 16px;
  padding: 28px 32px; max-width: 480px; width: 90%;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.7);
  animation: modalIn .3s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(20px) scale(.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-card h2 { margin: 0 0 18px; font-size: 18px; }
.modal-close {
  position: absolute; top: 12px; right: 14px; background: transparent; border: 0;
  color: var(--muted); font-size: 26px; cursor: pointer; line-height: 1; padding: 4px 10px;
  border-radius: 8px;
}
.modal-close:hover { background: rgba(148,163,184,.15); color: var(--text); }
.kbd-grid { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; font-size: 13px; align-items: center; }
.kbd-grid > div:nth-child(odd) { white-space: nowrap; }
.modal-foot { margin: 18px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.6; border-top: 1px solid var(--border); padding-top: 14px; }

/* Head tools */
.head-tools { display: flex; align-items: center; gap: 10px; }
.head-btn {
  background: rgba(11,16,32,.4); border: 1px solid var(--border);
  color: var(--muted); width: 28px; height: 28px; border-radius: 7px;
  cursor: pointer; font-size: 13px; display: inline-grid; place-items: center;
  transition: all .15s ease;
}
.head-btn:hover { background: rgba(99,102,241,.2); color: var(--text); border-color: var(--accent); }
.head-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Word wrap states */
textarea.wrap, pre.wrap { white-space: pre-wrap !important; word-break: break-word; }

/* Search bar */
.search-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; background: rgba(11,16,32,.7);
  border-bottom: 1px solid var(--border);
  animation: slideDown .2s ease;
}
@keyframes slideDown { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.search-bar input {
  flex: 1; background: rgba(30,39,66,.6); border: 1px solid var(--border-strong);
  color: var(--text); padding: 6px 10px; border-radius: 6px; font-size: 12px;
  font-family: inherit; outline: none;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar button {
  background: rgba(30,39,66,.6); color: var(--muted); border: 1px solid var(--border-strong);
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer; font-size: 11px;
  display: grid; place-items: center;
}
.search-bar button:hover { color: var(--text); background: rgba(99,102,241,.2); }
.search-count { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; padding: 0 4px; }
mark.search-hit { background: rgba(251,191,36,.45); color: inherit; border-radius: 2px; padding: 0 1px; }
mark.search-hit.current { background: #fbbf24; color: #000; }

/* Items table */
.card-items .card-head input.items-search {
  background: rgba(11,16,32,.5); border: 1px solid var(--border);
  color: var(--text); padding: 4px 10px; border-radius: 6px; font-size: 11px;
  font-family: inherit; outline: none; margin-left: auto; max-width: 160px;
}
.chip-btn {
  background: rgba(99,102,241,.2); color: #c7d2fe;
  border: 1px solid rgba(99,102,241,.4); padding: 4px 10px;
  border-radius: 6px; font-size: 11px; cursor: pointer; font-family: inherit;
}
.chip-btn:hover { background: rgba(99,102,241,.35); }
.items-scroll { overflow-x: auto; max-height: 340px; overflow-y: auto; border-radius: 8px; }
.items-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.items-table th, .items-table td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); }
.items-table th { background: rgba(11,16,32,.6); color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; position: sticky; top: 0; backdrop-filter: blur(8px); }
.items-table tbody tr:hover { background: rgba(99,102,241,.08); }
.items-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.items-table .mono { font-family: 'JetBrains Mono', monospace; font-size: 10.5px; }
.items-table .strong { font-weight: 600; color: var(--text); }

/* Tree view */
#tree { padding: 18px 22px; font-family: 'JetBrains Mono', monospace; font-size: 12.5px; line-height: 1.7; }
.t-node, .t-leaf, .t-close { padding-left: calc(var(--d, 0) * 14px); }
.t-node summary { cursor: pointer; list-style: none; outline: none; padding: 1px 0; border-radius: 4px; }
.t-node summary::-webkit-details-marker { display: none; }
.t-node summary::before { content: '▶'; display: inline-block; width: 12px; font-size: 9px; color: var(--muted); transition: transform .15s; margin-right: 2px; }
.t-node[open] > summary::before { transform: rotate(90deg); }
.t-node summary:hover { background: rgba(99,102,241,.1); }
.t-leaf { padding: 1px 0 1px 14px; }
.t-tag { color: var(--tag); }
.t-attr { color: var(--attr); }
.t-val { color: var(--val); }
.t-text { color: var(--text); padding: 0 4px; }
.t-count { font-size: 10px; color: var(--muted); background: rgba(148,163,184,.15); padding: 0 6px; border-radius: 99px; margin-left: 6px; font-family: 'Inter', sans-serif; }

/* Diff modal */
.modal-wide { max-width: 90vw; width: 1100px; }
.diff-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.diff-inputs textarea {
  height: 140px; padding: 10px 12px; font-size: 11.5px;
  background: rgba(11,16,32,.6); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 8px;
  font-family: 'JetBrains Mono', monospace; resize: vertical; outline: none;
}
.diff-inputs textarea:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.diff-result { max-height: 50vh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; background: rgba(11,16,32,.5); }
.diff-stats { display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); align-items: center; font-size: 12px; }
.diff-body { font-family: 'JetBrains Mono', monospace; font-size: 11.5px; line-height: 1.6; padding: 8px 0; }
.diff-body > div { display: flex; padding: 1px 14px; white-space: pre; }
.d-eq { color: var(--muted); }
.d-add { background: rgba(16,185,129,.12); color: #6ee7b7; }
.d-rem { background: rgba(239,68,68,.12); color: #fca5a5; }
.d-sym { width: 20px; flex-shrink: 0; opacity: .7; }
.d-line { flex: 1; }

/* History */
.history-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow: auto; }
.history-item {
  background: rgba(11,16,32,.5); border: 1px solid var(--border);
  padding: 12px 14px; border-radius: 10px; cursor: pointer;
  transition: all .15s ease; display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.history-item:hover { border-color: var(--accent); background: rgba(99,102,241,.1); transform: translateX(2px); }
.history-meta { flex: 1; min-width: 0; }
.history-title { font-weight: 600; font-size: 13px; }
.history-sub { font-size: 11px; color: var(--muted); margin-top: 2px; font-family: 'JetBrains Mono', monospace; }
.history-time { font-size: 10.5px; color: var(--muted); }
.history-empty { text-align: center; color: var(--muted); padding: 30px; font-size: 13px; }

/* JSON output */
.json-output {
  max-height: 60vh; overflow: auto; padding: 16px;
  background: rgba(11,16,32,.6); border: 1px solid var(--border);
  border-radius: 10px; font-family: 'JetBrains Mono', monospace;
  font-size: 12px; line-height: 1.6; color: var(--text);
  margin: 0 0 14px;
}

@media (max-width: 720px) {
  .diff-inputs { grid-template-columns: 1fr; }
  .modal-wide { width: 95%; }
  .chave-grid { grid-template-columns: repeat(2, 1fr); }
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
  .parties { flex-direction: column; align-items: flex-start; }
  .party-arrow { transform: rotate(90deg); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
