/* ── Design tokens ────────────────────────────────────────────── */
:root {
  --bg:           #f0fdfa;
  --bg-secondary: #ffffff;
  --bg-editor:    #ffffff;
  --bg-nav:       #ffffff;
  --border:       #ccfbf1;
  --text:         #0d1f1e;
  --text-muted:   #2d6a64;
  --primary:      #0d9488;
  --primary-hover:#0f766e;
  --primary-light:#f0fdfa;
  --accent:       #059669;
  --success:      #059669;
  --error:        #dc2626;
  --warning:      #d97706;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 1px 3px rgba(13,148,136,0.08);
  --shadow-md:    0 4px 16px rgba(13,148,136,0.12);
  --font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono:    "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
  --nav-h:        56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:           #0d1f1e;
    --bg-secondary: #0f2e2b;
    --bg-editor:    #0f2e2b;
    --bg-nav:       #0f2e2b;
    --border:       #134e4a;
    --text:         #ccfbf1;
    --text-muted:   #5eead4;
    --primary:      #2dd4bf;
    --primary-hover:#5eead4;
    --primary-light:#134e4a;
    --accent:       #34d399;
    --shadow:       0 1px 3px rgba(0,0,0,0.5);
    --shadow-md:    0 4px 16px rgba(0,0,0,0.6);
  }
}

[data-theme="dark"] {
  --bg:           #0d1f1e;
  --bg-secondary: #0f2e2b;
  --bg-editor:    #0f2e2b;
  --bg-nav:       #0f2e2b;
  --border:       #134e4a;
  --text:         #ccfbf1;
  --text-muted:   #5eead4;
  --primary:      #2dd4bf;
  --primary-hover:#5eead4;
  --primary-light:#134e4a;
  --accent:       #34d399;
  --shadow:       0 1px 3px rgba(0,0,0,0.5);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.6);
}

[data-theme="light"] {
  --bg:           #f0fdfa;
  --bg-secondary: #ffffff;
  --bg-editor:    #ffffff;
  --bg-nav:       #ffffff;
  --border:       #ccfbf1;
  --text:         #0d1f1e;
  --text-muted:   #2d6a64;
  --primary:      #0d9488;
  --primary-hover:#0f766e;
  --primary-light:#f0fdfa;
  --accent:       #059669;
  --shadow:       0 1px 3px rgba(13,148,136,0.08);
  --shadow-md:    0 4px 16px rgba(13,148,136,0.12);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Nav ──────────────────────────────────────────────────────── */
.nav {
  height: var(--nav-h);
  background: #ffffff;
  border-bottom: none;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 12px rgba(13,148,136,0.15);
}

[data-theme="dark"] .nav {
  background: var(--bg-nav);
  box-shadow: none;
}

.nav::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: linear-gradient(to right, #0d9488, #14b8a6, #059669);
}

[data-theme="dark"] .nav::after {
  background: linear-gradient(to right, #2dd4bf, #5eead4, #34d399);
}

.nav-inner {
  width: 100%;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 calc(160px + 32px) 0 calc(160px + 32px);
  display: flex;
  align-items: center;
  gap: 4px;
}

@media (max-width: 1200px) {
  .nav-inner {
    padding: 0 20px;
  }
}

.nav-logo {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--primary);
  text-decoration: none;
  margin-right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 2px;
  list-style: none;
}

.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 400;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.nav-links a:hover {
  color: var(--primary);
  background: var(--primary-light);
}

.nav-links a.active {
  color: var(--primary);
  font-weight: 600;
  background: var(--primary-light);
}

/* ── Nav actions ──────────────────────────────────────────────── */
.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.btn-support {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: none;
  text-decoration: none;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-support:hover { background: var(--primary-hover); color: #fff; }

.btn-theme {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: background 0.15s, color 0.15s;
}

.btn-theme:hover { background: var(--primary-light); color: var(--primary); }

/* ── Main layout ──────────────────────────────────────────────── */
.page-wrapper {
  flex: 1;
  display: grid;
  grid-template-columns: 160px 1fr 160px;
  gap: 16px;
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
  align-items: start;
}

.side-col {
  width: 160px;
  position: sticky;
  top: calc(var(--nav-h) + 24px);
}

.side-slot {
  width: 160px;
  min-height: 600px;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  font-size: 0.75rem;
  text-align: center;
}

.top-slot {
  width: 100%;
  height: 90px;
  background: var(--bg-secondary);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-bottom: 20px;
}

main {
  min-width: 0;
  padding: 0;
  grid-column: 2;
}

/* ── Page header ──────────────────────────────────────────────── */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.page-header p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ── Toolbar ──────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
}

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
  font-family: var(--font);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--primary-light);
  border-color: var(--text-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--primary-light);
  color: var(--text);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
}

.btn-icon {
  padding: 7px;
}

/* ── Select ───────────────────────────────────────────────────── */
select {
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 28px 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  cursor: pointer;
  font-family: var(--font);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ── Editor panels ────────────────────────────────────────────── */
.editor-layout {
  display: grid;
  gap: 16px;
}

.editor-layout.two-col {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
  height: calc(100vh - 220px);
  min-height: 400px;
}

.editor-layout.two-col .editor-panel {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-editor);
  min-height: 0;
}

.editor-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 40px;
  min-height: 40px;
  border-bottom: 1px solid var(--border);
  background: var(--primary);
  gap: 8px;
}

.editor-panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff !important;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.editor-panel-actions .btn-ghost {
  color: rgba(255,255,255,0.75);
}

.editor-panel-actions .btn-ghost:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.editor-panel-actions {
  display: flex;
  gap: 4px;
}

/* ── Line number gutter ───────────────────────────────────────── */
.editor-with-lines {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.line-gutter {
  padding: 16px 10px 16px 12px;
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.7;
  text-align: right;
  user-select: none;
  min-width: 48px;
  border-right: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
}

.line-gutter div { height: calc(0.9rem * 1.7); }

textarea {
  flex: 1 1 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 16px;
  border: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.7;
  background: var(--bg-editor);
  color: var(--text);
  outline: none;
  white-space: pre;
  overflow-x: auto;
  overflow-y: auto;
}

textarea::placeholder { color: var(--text-muted); opacity: 0.6; }

.output-area {
  flex: 1;
  min-height: 0;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.7;
  overflow: auto;
  white-space: pre;
}

/* ── Status bar ───────────────────────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--primary-light);
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  min-height: 36px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}

.status-badge.valid   { color: var(--success); }
.status-badge.invalid { color: var(--error); }
.status-badge.idle    { color: var(--text-muted); }

/* ── Notification toast ───────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 999;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ── Error message ────────────────────────────────────────────── */
.error-msg {
  color: var(--error);
  background: rgba(220,38,38,0.10);
  background: color-mix(in srgb, var(--error) 10%, transparent);
  border: 1px solid rgba(220,38,38,0.25);
  border: 1px solid color-mix(in srgb, var(--error) 25%, transparent);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: var(--font-mono);
  margin-top: 8px;
  display: none;
}

.error-msg.visible { display: block; }

/* ── XPath result area ────────────────────────────────────────── */
.xpath-result {
  flex: 1;
  min-height: 0;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.7;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Footer ───────────────────────────────────────────────────── */
footer {
  margin-top: auto;
  background: #071a19;
  color: #8892c8;
  font-size: 0.875rem;
}

.footer-grid {
  max-width: 1560px;
  margin: 0 auto;
  padding: 40px 20px 32px;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 40px;
}

.footer-brand .footer-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: #9ee8e0;
  margin-bottom: 10px;
}

.footer-brand p {
  color: #4d8a84;
  font-size: 0.85rem;
  line-height: 1.7;
  max-width: 300px;
}

.footer-col h3 {
  font-size: 0.8rem;
  font-weight: 600;
  color: #9ee8e0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.footer-col ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.footer-col a {
  color: #4d8a84;
  text-decoration: none;
  transition: color 0.15s;
}

.footer-col a:hover { color: #9ee8e0; }

.footer-bottom {
  border-top: 1px solid #134e4a;
  max-width: 1560px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: #4d8a84;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 768px) {
  .footer-grid {
    grid-template-columns: 1fr 1fr;
  }
  .footer-brand {
    grid-column: 1 / -1;
  }
}

/* ── Diff output ──────────────────────────────────────────────── */
.diff-output {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.8;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 16px;
}

.diff-line {
  display: block;
  padding: 2px 8px;
  border-radius: 3px;
  white-space: pre-wrap;
  word-break: break-all;
}

.diff-added   { background: rgba(5,150,105,0.10); color: var(--success); }
.diff-removed { background: rgba(220,38,38,0.10);  color: var(--error); }
.diff-changed { background: rgba(217,119,6,0.10);  color: var(--warning); }
.diff-key     { font-weight: 700; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .page-wrapper {
    grid-template-columns: 1fr;
  }
  .side-col { display: none; }
  .top-slot { display: flex; }
}

@media (max-width: 768px) {
  .editor-layout.two-col {
    grid-template-columns: 1fr;
  }

  .page-header h1 { font-size: 1.3rem; }

  .nav-links a {
    padding: 6px 8px;
    font-size: 0.85rem;
  }

  .editor-layout.two-col { height: 80vh; min-height: 400px; }
}

@media (max-width: 1200px) {
  .nav-inner { padding: 0 24px; }
}

@media (max-width: 480px) {
  .page-wrapper { padding: 16px; }
  .toolbar { gap: 6px; }
  .nav-inner { padding: 0 16px; }
}
