/* Cureveda ETL admin panel. No framework: one stylesheet, system fonts. */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --border: #e2e5ea;
  --text: #1c2128;
  --muted: #6b7280;
  --accent: #2f6feb;
  --accent-soft: #e8f0fe;
  --ok: #1a7f46;
  --ok-soft: #e6f4ec;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --bad: #c03434;
  --bad-soft: #fdeaea;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --panel-2: #21262e;
    --border: #2f3641;
    --text: #e6e9ef;
    --muted: #9aa4b2;
    --accent: #6ea0ff;
    --accent-soft: #1d2a43;
    --ok: #4bbd7c;
    --ok-soft: #14301f;
    --warn: #e0b341;
    --warn-soft: #33290d;
    --bad: #f07a7a;
    --bad-soft: #3a1c1c;
  }
}

* { box-sizing: border-box; }

/* Any author rule that sets display beats the UA's [hidden], and .login-wrap
   sets display: grid. Without this the login screen stays over the app. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------------------------------------------------------------- shell */
header.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.brand { font-weight: 650; letter-spacing: -0.01em; }
.brand span { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 12px; }
nav.tabs { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
nav.tabs button {
  background: none;
  border: 0;
  padding: 7px 12px;
  border-radius: 6px;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
nav.tabs button:hover { background: var(--panel-2); color: var(--text); }
nav.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

main { padding: 20px; max-width: 1500px; margin: 0 auto; }
section.view { display: none; }
section.view.active { display: block; }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.card > h2 {
  margin: 0;
  padding: 12px 16px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.card > h2 .spacer { flex: 1; }
.card-body { padding: 16px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); }

.tile {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.tile .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.tile .value { font-size: 22px; font-weight: 600; margin-top: 4px; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td {
  text-align: left;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 460px;
  overflow: hidden;
  text-overflow: ellipsis;
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  background: var(--panel-2);
  position: sticky;
  top: 0;
  cursor: default;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono, .mono { font-family: var(--mono); font-size: 12px; }
td.null { color: var(--muted); font-style: italic; }
.clickable { cursor: pointer; }

/* --------------------------------------------------------------- badges */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: lowercase;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.idle { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.badge.run { background: var(--accent-soft); color: var(--accent); }

/* --------------------------------------------------------------- forms */
input, select, textarea, button { font: inherit; color: var(--text); }
input[type="text"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
label.field > span .hint { text-transform: none; font-weight: 400; opacity: 0.75; font-style: italic; }
.form-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.checkline { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.checkline input { width: auto; }

button.btn {
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 550;
}
button.btn:hover { filter: brightness(1.07); }
button.btn:disabled { opacity: 0.5; cursor: not-allowed; }
button.btn.ghost { background: var(--panel-2); color: var(--text); border-color: var(--border); }
button.btn.danger { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
button.btn.small { padding: 3px 9px; font-size: 12px; font-weight: 500; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* --------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 360px;
}
.login-card h1 { margin: 0 0 4px; font-size: 19px; }
.login-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }

/* ------------------------------------------------------------ data view */
.split { display: grid; grid-template-columns: 290px 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }
.tablelist { max-height: 70vh; overflow-y: auto; }
.tablelist button {
  display: flex;
  gap: 8px;
  align-items: baseline;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
}
.tablelist button:hover { background: var(--panel-2); }
.tablelist button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tablelist button > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tablelist .rowcount { margin-left: auto; color: var(--muted); font-size: 11.5px; font-weight: 400; white-space: nowrap; }
.tablelist .schema { white-space: nowrap; }
.tablelist .schema { color: var(--muted); }

textarea.sql {
  font-family: var(--mono);
  font-size: 13px;
  min-height: 165px;
  resize: vertical;
  line-height: 1.55;
}

/* The view query is the whole editor, so it gets most of the screen. */
textarea.sql.view-sql { min-height: 55vh; }
pre.view-header {
  margin: 0 0 6px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
  white-space: pre-wrap;
}

/* --------------------------------------------------------------- misc */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err {
  background: var(--bad-soft);
  color: var(--bad);
  border-radius: 6px;
  padding: 9px 12px;
  margin-bottom: 12px;
  white-space: pre-wrap;
  font-size: 13px;
}
.warn-note { background: var(--warn-soft); color: var(--warn); border-radius: 6px; padding: 9px 12px; margin-bottom: 12px; font-size: 13px; }
.ok-note { background: var(--ok-soft); color: var(--ok); border-radius: 6px; padding: 9px 12px; margin-bottom: 12px; font-size: 13px; }
.empty { padding: 26px; text-align: center; color: var(--muted); }

dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  max-width: min(900px, 94vw);
  width: 100%;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h3 { margin: 0; padding: 14px 18px; border-bottom: 1px solid var(--border); font-size: 15px; }
dialog .dialog-body { padding: 18px; max-height: 70vh; overflow: auto; }
dialog .dialog-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
pre.detail { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 12px; overflow: auto; font-size: 12px; white-space: pre-wrap; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 11px 15px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16);
  z-index: 50;
  max-width: 380px;
  font-size: 13px;
}
.toast.bad { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
