/* warm codex aesthetic — cream, amber, deep brown */
:root {
  --bg:        #faf6ee;
  --surface:   #fffaf0;
  --surface-2: #f3ead6;
  --ink:       #3a2f1f;
  --ink-soft:  #6b5a40;
  --muted:     #8b7a5e;
  --line:      #e4d8bd;
  --line-soft: #efe5cf;
  --amber:     #b8722b;
  --amber-2:   #d8893a;
  --red:       #b04a2f;
  --green:     #5c7a3a;
  --code-bg:   #2d2418;
  --code-fg:   #f5deb3;
  --shadow:    0 1px 0 rgba(58,47,31,.04), 0 10px 30px -16px rgba(58,47,31,.18);
  --serif:     "Iowan Old Style","Palatino Linotype","Book Antiqua",Georgia,serif;
  --sans:      -apple-system,BlinkMacSystemFont,"Segoe UI",Inter,system-ui,sans-serif;
  --mono:      "JetBrains Mono",ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 20% 0%, rgba(184,114,43,.05), transparent 40%),
    radial-gradient(circle at 100% 100%, rgba(92,122,58,.04), transparent 50%);
}

/* ============================================================
   SHELL — sidebar + tool stage
   ============================================================ */
body.shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #2d2418 0%, #3a2f1f 100%);
  color: #f3e6c8;
  border-right: 1px solid #1a140c;
  position: sticky; top: 0;
  height: 100vh;
  display: flex; flex-direction: column;
  z-index: 5;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid rgba(245,222,179,.08);
}
.sidebar-brand .sigil { font-size: 26px; }
.sidebar-brand .brand-label {
  font-family: var(--serif); font-size: 19px; font-weight: 600;
  color: #fff7e6;
}
.sidebar-brand .brand-tag {
  font-family: var(--mono); font-size: 10px;
  color: #b89a6b; letter-spacing: .5px;
}
.sidebar-nav {
  flex: 1; padding: 12px 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.sb-item {
  appearance: none; border: none; background: none;
  width: 100%; text-align: left; cursor: pointer;
  color: #d4c3a0;
  padding: 9px 12px; border-radius: 6px;
  display: flex; align-items: center; gap: 12px;
  font: inherit; font-size: 13px;
  transition: background .12s, color .12s;
}
.sb-item:hover { background: rgba(245,222,179,.08); color: #fff7e6; }
.sb-item.active {
  background: rgba(184,114,43,.25);
  color: #fff7e6;
  box-shadow: inset 3px 0 0 var(--amber);
}
.sb-icon { font-size: 16px; width: 20px; text-align: center; }
.sb-label { flex: 1; }
.sb-ext { font-size: 11px; color: #8b7a5e; }
.sb-sep {
  height: 1px; margin: 8px 12px;
  background: rgba(245,222,179,.10);
}
.sidebar-foot {
  padding: 12px 18px; border-top: 1px solid rgba(245,222,179,.08);
}
.sidebar-foot .muted { color: #8b7a5e !important; font-family: var(--mono); font-size: 10px; }

.tool-stage { flex: 1; min-width: 0; }
.tool { display: none; flex-direction: column; min-height: 100vh; }
.tool.active { display: flex; }
.tool-body { padding: 22px; flex: 1; }

/* embed tools (externe Seiten per iframe) */
.embed-tool.active { display: flex; }
.embed-actions { display: flex; gap: 8px; align-items: center; }
.embed-actions .embed-open { text-decoration: none; }
.embed-frame-wrap { flex: 1; position: relative; background: var(--surface-2); }
.embed-frame { width: 100%; height: 100%; border: 0; display: block; }
.embed-frame.hidden { display: none; }
.embed-blocked {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center; padding: 24px;
  color: var(--ink-soft);
}
.embed-blocked.hidden { display: none; }
.embed-blocked p { max-width: 360px; margin: 0; }
.embed-blocked .embed-open { text-decoration: none; }

/* topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  letter-spacing: .2px;
}
.sigil { font-size: 22px; filter: sepia(.2) saturate(.9); }
.status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-soft); }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted); box-shadow: 0 0 0 3px rgba(139,122,94,.15);
  transition: background .2s, box-shadow .2s;
}
.dot.ok    { background: var(--green); box-shadow: 0 0 0 3px rgba(92,122,58,.18); }
.dot.fail  { background: var(--red);   box-shadow: 0 0 0 3px rgba(176,74,47,.18); }

/* tabs */
.tabs {
  display: flex; gap: 4px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.tab {
  appearance: none; background: none; border: none;
  font: inherit; color: var(--ink-soft);
  padding: 10px 16px; cursor: pointer;
  border-bottom: 2px solid transparent;
  font-family: var(--serif); font-size: 15px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--amber); border-bottom-color: var(--amber); }

/* panels */
.panel { display: none; }
.panel.active { display: block; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 16px; flex-wrap: wrap;
}
.panel-head h2 {
  font-family: var(--serif); font-weight: 600; font-size: 18px; margin: 0;
}
.controls { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.controls label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted);
}
.meta { color: var(--muted); font-family: var(--mono); font-size: 12px; }

input, select, textarea {
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 10px;
  font-size: 13px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(184,114,43,.15);
}
input[type=number] { width: 80px; }

/* buttons */
.btn {
  appearance: none; cursor: pointer;
  background: var(--amber); color: #fff7e6;
  border: 1px solid var(--amber);
  font: inherit; font-size: 13px;
  padding: 7px 14px; border-radius: 6px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: transform .05s, background .15s;
}
.btn:hover { background: var(--amber-2); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: transparent; color: var(--ink-soft);
  border-color: var(--line);
}
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn.danger:hover { background: #c75a3a; }
kbd {
  font-family: var(--mono); font-size: 10px;
  background: rgba(255,255,255,.18); padding: 1px 5px;
  border-radius: 3px; margin-left: 4px;
}

/* schema list */
.schema-list { display: grid; gap: 10px; }
.schema-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.schema-card > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
}
.schema-card > summary::-webkit-details-marker { display: none; }
.schema-card > summary::before {
  content: "▸"; color: var(--muted); transition: transform .15s;
  display: inline-block; width: 12px;
}
.schema-card[open] > summary::before { transform: rotate(90deg); }
.schema-card .cls-name {
  font-family: var(--serif); font-size: 16px; font-weight: 600;
}
.schema-card .cls-super {
  color: var(--muted); font-family: var(--mono); font-size: 11px;
}
.schema-card .cls-count {
  margin-left: auto; color: var(--ink-soft); font-family: var(--mono); font-size: 12px;
}
.schema-card .card-action {
  font-size: 11px; padding: 4px 10px; margin-left: 6px;
}
.schema-card > summary:hover .card-action.ghost { background: var(--surface); }
.schema-body { padding: 4px 16px 16px 42px; border-top: 1px solid var(--line-soft); }
.schema-body h4 {
  font-family: var(--serif); font-size: 13px; margin: 12px 0 6px;
  color: var(--ink-soft); font-weight: 600;
}
.prop-table { width: 100%; font-size: 12px; font-family: var(--mono); border-collapse: collapse; }
.prop-table th { text-align: left; color: var(--muted); font-weight: normal; padding: 4px 8px; }
.prop-table td { padding: 4px 8px; border-top: 1px dashed var(--line-soft); }
.pill {
  display: inline-block; font-size: 10px; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-soft); font-family: var(--mono);
  margin-right: 4px;
}
.pill.v { background: rgba(92,122,58,.15); color: var(--green); }
.pill.e { background: rgba(184,114,43,.15); color: var(--amber); }

/* records table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: auto;
  max-height: calc(100vh - 230px);
}
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead th {
  text-align: left; padding: 9px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft); font-weight: 600;
  font-family: var(--mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: .6px;
  position: sticky; top: 0;
}
tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--mono);
  max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
.rid-cell { color: var(--amber); }
.null-cell { color: var(--muted); font-style: italic; }
.bool-cell { color: var(--green); }
.num-cell  { color: var(--ink); }
.obj-cell  { color: var(--ink-soft); }

/* query */
#query-input {
  width: 100%; min-height: 130px;
  font-family: var(--mono); font-size: 13px;
  background: var(--code-bg); color: var(--code-fg);
  border-color: var(--code-bg);
  border-radius: 10px; padding: 12px 14px;
  margin-bottom: 14px; box-shadow: var(--shadow);
  resize: vertical;
}
#query-input:focus { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(184,114,43,.25); }
.json {
  background: var(--code-bg); color: var(--code-fg);
  border-radius: 10px; padding: 14px;
  font-family: var(--mono); font-size: 12px;
  overflow: auto; max-height: calc(100vh - 280px);
  margin: 0;
}
.hidden { display: none !important; }

/* drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(560px, 100%);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 60px -20px rgba(58,47,31,.25);
  transform: translateX(100%);
  transition: transform .2s ease;
  display: flex; flex-direction: column;
  z-index: 50;
}
.drawer.open { transform: translateX(0); }
.drawer header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.drawer header h3 {
  font-family: var(--mono); margin: 0; font-size: 14px; color: var(--amber);
}
.drawer header small { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .8px; }
.drawer-body { flex: 1; overflow: auto; padding: 16px 20px; }
.drawer footer {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.spacer { flex: 1; }
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(58,47,31,.25);
  opacity: 0; pointer-events: none; transition: opacity .2s;
  z-index: 40;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.field label .type-tag {
  font-size: 9px; padding: 1px 6px; border-radius: 3px;
  background: var(--surface-2); color: var(--ink-soft);
}
.field input, .field textarea { width: 100%; }
.field textarea { font-family: var(--mono); min-height: 60px; }
.field.readonly input { background: var(--surface-2); color: var(--muted); }
#drawer-raw { width: 100%; min-height: 200px; font-family: var(--mono); font-size: 12px; }

/* wizard */
.wizard {
  position: fixed; inset: 0; z-index: 60;
  display: none; align-items: center; justify-content: center;
  padding: 24px;
}
.wizard.open { display: flex; }
.wizard-backdrop {
  position: absolute; inset: 0; background: rgba(58,47,31,.35);
  backdrop-filter: blur(2px);
}
.wizard-shell {
  position: relative; z-index: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 30px 80px -30px rgba(58,47,31,.4);
  width: min(820px, 100%);
  max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.wizard-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  gap: 16px;
}
.wizard-head h3 { font-family: var(--serif); margin: 0; font-size: 17px; }
.wizard-head small { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .8px; }
.wizard-steps { display: flex; gap: 6px; }
.wizard-steps .step {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-2); color: var(--ink-soft);
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 11px;
  border: 1px solid var(--line);
}
.wizard-steps .step.active { background: var(--amber); color: #fff7e6; border-color: var(--amber); }
.wizard-steps .step.done   { background: var(--green); color: #fff; border-color: var(--green); }
.wizard-body { flex: 1; overflow: auto; padding: 18px 20px; }
.wizard-step { display: none; }
.wizard-step.active { display: block; }
.wizard-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 20px; border-top: 1px solid var(--line); background: var(--surface-2);
}
.table-wrap.thin { max-height: 320px; box-shadow: none; }
.table-wrap.thin table { font-size: 12px; }
.table-wrap.thin td { padding: 4px 6px; white-space: normal; max-width: none; }
.table-wrap.thin td input, .table-wrap.thin td select {
  width: 100%; padding: 4px 6px; font-size: 12px;
  background: transparent; border: 1px solid transparent;
}
.table-wrap.thin td input:focus, .table-wrap.thin td select:focus {
  background: var(--surface); border-color: var(--amber);
}
.table-wrap.thin td.check { text-align: center; width: 32px; }
.table-wrap.thin td.actions { width: 28px; text-align: center; }
.table-wrap.thin .row-del {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px;
}
.table-wrap.thin .row-del:hover { color: var(--red); }
.small { font-size: 12px; }
#wiz-progress { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; font-family: var(--mono); font-size: 12px; }
#wiz-progress .step-line { display: flex; gap: 8px; align-items: center; }
#wiz-progress .step-line.ok::before  { content: "✓"; color: var(--green); }
#wiz-progress .step-line.err::before { content: "✗"; color: var(--red); }
#wiz-progress .step-line.run::before { content: "…"; color: var(--amber); }
#wiz-progress .step-line.pending::before { content: "·"; color: var(--muted); }

/* toasts */
.toasts {
  position: fixed; bottom: 18px; right: 18px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 100;
}
.toast {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-left: 3px solid var(--amber);
  border-radius: 6px; padding: 10px 14px;
  box-shadow: var(--shadow); font-size: 13px;
  max-width: 380px;
  animation: slide-in .15s ease;
}
.toast.ok   { border-left-color: var(--green); }
.toast.fail { border-left-color: var(--red); }
@keyframes slide-in { from { transform: translateX(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ============================================================
   TUNNELS tab
   ============================================================ */
#tunnels-table td { white-space: nowrap; }
#tunnels-table tr.selected { background: rgba(184,114,43,.10); }
#tunnels-table tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--amber); }
.tunnel-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 11px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-soft);
}
.tunnel-status::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
}
.tunnel-status.running         { background: rgba(92,122,58,.15);  color: var(--green); }
.tunnel-status.running::before { background: var(--green); box-shadow: 0 0 0 2px rgba(92,122,58,.2); }
.tunnel-status.starting        { background: rgba(184,114,43,.15); color: var(--amber); }
.tunnel-status.starting::before{ background: var(--amber); animation: pulse 1.2s infinite; }
.tunnel-status.error           { background: rgba(176,74,47,.15);  color: var(--red); }
.tunnel-status.error::before   { background: var(--red); }
@keyframes pulse {
  0%, 100% { opacity: 1; } 50% { opacity: .3; }
}
.tunnel-actions { display: inline-flex; gap: 4px; }
.tunnel-actions .btn {
  padding: 3px 9px; font-size: 11px;
}
.source-pill {
  font-family: var(--mono); font-size: 10px;
  padding: 2px 7px; border-radius: 3px;
  background: var(--surface-2); color: var(--ink-soft);
}
.source-pill.managed { background: rgba(184,114,43,.15); color: var(--amber); }
.tunnels-log-wrap { margin-top: 16px; }
.tunnels-log-wrap summary {
  cursor: pointer; padding: 8px 0;
  font-family: var(--serif); font-weight: 600; color: var(--ink-soft);
}
#tunnel-log { max-height: 240px; }
.empty-row td {
  text-align: center; padding: 24px;
  color: var(--muted); font-style: italic;
}

@media (max-width: 700px) {
  .sidebar { width: 64px; }
  .sidebar .brand-label, .sidebar .brand-tag, .sb-label, .sidebar-foot { display: none; }
  .sb-item { justify-content: center; padding: 12px 0; }
}
@media (max-width: 600px) {
  .topbar { padding: 12px 14px; }
  .tool-body { padding: 14px; }
  .controls { width: 100%; }
}
