/* ===== DB Editor – Design ===== */

:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f3f3f5;
  --line: #e4e4e7;
  --text: #18181b;
  --muted: #71717a;
  --accent: #10b981;
  --accent-hover: #059669;
  --accent-soft: #d1fae5;
  --accent-fg: #ffffff;
  --accent-text: #047857;
  --danger: #e11d48;
  --danger-soft: #ffe4e6;
  --warn-soft: #fef3c7;
  --warn-fg: #b45309;
  --overlay: rgba(9, 9, 11, .4);
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 10px 30px -12px rgba(0,0,0,.18);
}
html.dark {
  color-scheme: dark;
  --bg: #09090b;
  --surface: #111113;
  --surface-2: #18181b;
  --line: #27272a;
  --text: #e4e4e7;
  --muted: #8b8b95;
  --accent: #10b981;
  --accent-hover: #34d399;
  --accent-soft: rgba(16, 185, 129, .14);
  --accent-fg: #03150e;
  --accent-text: #6ee7b7;
  --danger: #fb7185;
  --danger-soft: rgba(251, 113, 133, .12);
  --warn-soft: rgba(245, 158, 11, .14);
  --warn-fg: #fbbf24;
  --overlay: rgba(0, 0, 0, .6);
  --shadow: 0 0 0 1px rgba(255,255,255,.03), 0 20px 40px -16px rgba(0,0,0,.7);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[x-cloak] { display: none !important; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

.text-muted  { color: var(--muted); }
.text-danger { color: var(--danger); }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }

/* ----- Flächen ----- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.topbar { background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; }

/* ----- Eingaben ----- */
.input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--muted); }
.field-label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }

/* ----- Buttons ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 13px; font-weight: 500; white-space: nowrap; cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn-danger:hover { filter: brightness(1.08); }
.icon-btn {
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: 34px; height: 34px; border-radius: 10px;
  color: var(--muted); background: transparent; border: 0; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.sm { width: 26px; height: 26px; border-radius: 8px; }
.logo {
  display: grid; place-items: center; flex-shrink: 0;
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #34d399, #047857);
  color: #fff; font-weight: 700; font-size: 12px; letter-spacing: .02em;
}

/* ----- Navigation ----- */
.nav-item {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px; border-radius: 8px; border: 0; background: transparent;
  color: var(--text); font-size: 13px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: background .12s;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.group-head {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 6px 10px; margin-top: 6px; border-radius: 8px; border: 0; background: transparent;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); cursor: pointer;
}
.group-head:hover { color: var(--text); background: var(--surface-2); }
.chev { width: 12px; height: 12px; transition: transform .15s; flex-shrink: 0; }
.chev.open { transform: rotate(90deg); }

/* ----- Badges ----- */
.badge {
  display: inline-flex; align-items: center; padding: 1px 6px; border-radius: 6px;
  font-size: 10.5px; font-family: "JetBrains Mono", ui-monospace, monospace;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge-pk { background: var(--warn-soft); color: var(--warn-fg); font-weight: 600; font-family: Inter, sans-serif; }

/* ----- Schalter ----- */
.switch {
  position: relative; width: 36px; height: 20px; flex-shrink: 0;
  border-radius: 999px; border: 0; background: var(--line); cursor: pointer;
  transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s;
}
.switch.is-on { background: var(--accent); }
.switch.is-on::after { transform: translateX(16px); }
.switch:disabled { opacity: .4; cursor: not-allowed; }

/* ----- Tabelle (Desktop) ----- */
.grid-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.grid-table th {
  position: sticky; top: 0; z-index: 2;
  text-align: left; font-weight: 600; white-space: nowrap;
  padding: 9px 12px; background: var(--surface-2);
  border-bottom: 1px solid var(--line); border-right: 1px solid var(--line);
}
.grid-table td {
  padding: 0; vertical-align: top;
  border-bottom: 1px solid var(--line); border-right: 1px solid var(--line);
}
.grid-table tbody tr:hover td { background: var(--surface-2); }
.cell {
  padding: 8px 12px; min-height: 36px; max-width: 360px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default;
}
.cell-null { color: var(--muted); font-style: italic; }
.cell-edit {
  display: block; width: 100%; min-width: 180px; height: 36px; padding: 0 12px;
  border: 0; outline: none; background: var(--accent-soft); color: var(--text);
  box-shadow: inset 0 0 0 2px var(--accent); font-size: 13px;
}

/* ----- Mobile Karten ----- */
.row-card {
  display: block; width: 100%; text-align: left;
  padding: 12px 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  transition: transform .08s, background .15s;
}
.row-card:active { transform: scale(.985); background: var(--surface-2); }

.fab {
  position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom));
  z-index: 30; width: 54px; height: 54px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-fg);
  font-size: 28px; line-height: 1; box-shadow: 0 10px 24px -8px rgba(16,185,129,.7);
  cursor: pointer;
}

/* ----- Menü (Popover) ----- */
.menu {
  position: absolute; right: 0; top: 100%; margin-top: 6px; z-index: 40;
  min-width: 210px; padding: 4px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.menu button {
  display: block; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 8px; border: 0; background: transparent;
  color: var(--text); font-size: 13px; cursor: pointer;
}
.menu button:hover { background: var(--surface-2); }

/* ----- Modals ----- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: var(--overlay); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.modal {
  position: relative; display: flex; flex-direction: column;
  width: 100%; max-height: 92dvh;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 22px 22px 0 0; box-shadow: var(--shadow);
  padding-bottom: env(safe-area-inset-bottom);
}
.modal::before {
  content: ""; display: block; width: 40px; height: 4px; margin: 8px auto 0;
  border-radius: 4px; background: var(--line);
}
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 14px 20px 12px; }
.modal-body {
  display: flex; flex-direction: column; gap: 14px;
  min-height: 0; overflow-y: auto; padding: 4px 20px 18px;
}
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--line);
}

@media (min-width: 768px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { width: min(560px, calc(100vw - 48px)); max-height: 86vh; border-radius: 18px; }
  .modal::before { display: none; }
  .modal.wide { width: min(940px, calc(100vw - 48px)); }
  .modal.narrow { width: min(420px, calc(100vw - 48px)); }
  .modal-head { padding: 20px 22px 12px; }
  .modal-body { padding: 4px 22px 20px; }
  .modal-body.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 22px; }
}

/* ----- Sidebar & Layout (Mobile = Schublade) ----- */
@media (max-width: 767px) {
  .sidebar {
    position: fixed; inset-block: 0; left: 0; z-index: 40;
    width: min(300px, 86vw);
    transform: translateX(0); transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.closed { transform: translateX(-105%); }
}
@media (min-width: 768px) {
  .sidebar { position: static; width: 264px; flex-shrink: 0; transform: none !important; }
}

/* ----- Toasts ----- */
.toast {
  pointer-events: auto; max-width: 420px; padding: 10px 14px; border-radius: 12px;
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow);
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.toast-ok { border-color: transparent; background: var(--accent); color: var(--accent-fg); }
.toast-err { border-color: transparent; background: var(--danger); color: #fff; }

.sub-panel { border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: var(--surface-2); }

/* ----- Logo-Bild ----- */
.brand-img {
  display: block; flex-shrink: 0;
  height: 36px; width: auto; max-width: 180px;
  object-fit: contain;
}
.brand-img.lg { height: 64px; max-width: 240px; }

/* ===== Erweiterungen: Suche, Filter, Auswahl, Tabellenmodus ===== */
.btn-on { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.sel { max-width: 200px; height: 34px; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface);
}
@media (min-width: 768px) { .toolbar { padding: 10px 20px; } }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 4px 3px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-text); font-size: 12px; font-weight: 500;
}
.chip-btn { background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; }
.chip-x {
  display: grid; place-items: center; width: 18px; height: 18px; border-radius: 999px;
  border: 0; background: transparent; color: inherit; font-size: 11px; opacity: .7; cursor: pointer;
}
.chip-x:hover { opacity: 1; background: rgba(127,127,127,.2); }

.selbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--accent-soft); border-bottom: 1px solid var(--line); font-size: 13px;
}
@media (min-width: 768px) { .selbar { padding: 8px 20px; } }

.th-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer;
}
.th-btn:hover { color: var(--accent-text); }

.lead-th, .lead-td { width: 120px; min-width: 120px; padding-left: 8px !important; padding-right: 8px !important; }
.lead-td > div { min-height: 36px; }

.rownum {
  display: none; min-width: 28px; text-align: right; padding-right: 4px;
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.grid-table td.is-active { box-shadow: inset 0 0 0 2px var(--accent); }
.grid-table tr.is-sel td { background: var(--accent-soft); }

.fk-btn {
  flex-shrink: 0; width: 20px; height: 20px; border-radius: 6px; border: 0;
  background: var(--surface-2); color: var(--accent-text); font-size: 12px; line-height: 1; cursor: pointer;
}
.fk-btn:hover { background: var(--accent-soft); }
.link-btn { font-size: 12px; color: var(--accent-text); background: none; border: 0; padding: 0; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* Tabellenmodus: Excel-artiges Gitter */
.sheet-mode .rownum { display: inline-block; }
.sheet-mode .grid-table th,
.sheet-mode .grid-table td { border-color: var(--line); }
.sheet-mode .grid-table th { background: var(--surface-2); }
.sheet-mode .grid-table td .cell { padding: 4px 8px; min-height: 28px; font-size: 12.5px; }
.sheet-mode .grid-table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 40%, transparent); }
.sheet-mode .grid-table tbody tr:hover td { background: var(--accent-soft); }
.sheet-mode .grid-table tbody tr.is-sel td { background: var(--accent-soft); }
/* ---------- Storage-Browser ---------- */
.st-modal { max-width: 1180px; }
.st-body { min-width: 0; }
.st-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.st-detail { background: var(--surface-2, transparent); }
.st-list { max-height: 56vh; }
.st-row {
  display: grid;
  grid-template-columns: 20px 40px minmax(0, 1fr) 84px 150px 64px;
  align-items: center; gap: 8px; padding: 6px 10px;
  border-bottom: 1px solid var(--line); font-size: 13px;
}
.st-row:last-child { border-bottom: 0; }
.st-head { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.st-row:not(.st-head):hover { background: var(--accent-soft); }
.st-active { background: var(--accent-soft); }
.st-thumb { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; overflow: hidden; background: var(--surface-2, rgba(127,127,127,.12)); }
.st-thumb img { width: 100%; height: 100%; object-fit: cover; }
.st-preview { width: 100%; max-height: 220px; object-fit: contain; border-radius: 10px; background: rgba(127,127,127,.1); }
@media (max-width: 767px) {
  .st-row { grid-template-columns: 20px 36px minmax(0, 1fr) 64px 56px; }
  .st-row > .text-right.hidden { display: none; }
}
@media (min-width: 1024px) {
  .st-grid { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
}

/* Vollbild für den Storage-Browser */
.modal.st-modal.st-full {
  position: fixed; inset: 0; width: 100vw; max-width: none;
  height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0;
}
.modal.st-modal.st-full .st-body { flex: 1 1 auto; min-height: 0; overflow: auto; }
.modal.st-modal.st-full .st-list { max-height: none; flex: 1 1 auto; }
.modal.st-modal.st-full .st-grid { flex: 1 1 auto; min-height: 0; }
.modal.st-modal.st-full .st-grid > .st-list { min-height: 0; }

/* ---------- SQL-Editor (Multi-Aufgaben & Vollbild) ---------- */
.sql-modal { max-width: 1180px; }
.modal.sql-modal.st-full {
  position: fixed; inset: 0; width: 100vw; max-width: none;
  height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0;
}
.modal.sql-modal.st-full .sql-body { flex: 1 1 auto; min-height: 0; }
.sql-tabs {
  display: flex; align-items: center; gap: 6px;
  overflow-x: auto; padding-bottom: 2px;
}
.sql-tab {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 8px 0 10px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  font-size: 12.5px; font-weight: 500; white-space: nowrap; flex-shrink: 0;
  transition: background .12s, border-color .12s, color .12s;
}
.sql-tab:hover { color: var(--text); }
.sql-tab.is-active {
  background: var(--surface); color: var(--text);
  border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft);
}
.sql-tab-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer;
}
.sql-dot {
  width: 7px; height: 7px; border-radius: 999px; flex-shrink: 0; background: var(--muted); opacity: .45;
}
.sql-dot.is-running { background: var(--warn-fg); opacity: 1; animation: sqlPulse 1s ease-in-out infinite; }
.sql-dot.is-ok { background: var(--accent); opacity: 1; }
.sql-dot.is-partial { background: var(--warn-fg); opacity: 1; }
.sql-dot.is-error { background: var(--danger); opacity: 1; }
@keyframes sqlPulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.sql-editor-area {
  min-height: 150px;
  line-height: 1.5;
  tab-size: 2;
}
.modal.sql-modal.st-full .sql-editor-area { min-height: 220px; }

.sql-stmt-list {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 190px; overflow-y: auto;
  padding: 6px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2);
}
.sql-stmt-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 6px 8px; border-radius: 8px; border: 1px solid transparent;
  background: var(--surface); color: var(--text); font-size: 12px; cursor: pointer;
  transition: border-color .12s, background .12s;
}
.sql-stmt-item:hover { border-color: var(--line); background: var(--surface-2); }
.sql-stmt-item.is-active { border-color: var(--accent); background: var(--accent-soft); }
.sql-stmt-item.is-err { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.sql-badge-ok { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.sql-badge-err { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
