:root {
  --bg: #0b0b0c;
  --panel: #131316;
  --panel-2: #17171b;
  --border: rgba(255, 255, 255, 0.09);
  --text: #f4f3f1;
  --muted: rgba(255, 255, 255, 0.5);
  --accent: #e5352b;
  --accent-text: #fff;
  --ok: #22c55e;
  --warn: #f59e0b;
  --radius: 14px;
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

/* Elements that have a display rule of their own (the auth screen is
 * `display: grid`) would otherwise keep rendering while carrying the `hidden`
 * attribute, leaving the sign-in card visible underneath the app. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
.error { color: #ff6b6b; }

/* ------------------------------------------------------------- auth screen */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth .card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  display: grid;
  gap: 14px;
}
.auth h1 { margin: 0; font-size: 22px; }
.auth label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

input, select, textarea, button {
  font: inherit;
  color: inherit;
}
input, select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ------------------------------------------------------------------ layout */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { display: block; height: 24px; width: auto; }
.brand div { display: grid; }
.brand .muted { font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-actions select { width: auto; min-width: 180px; }
.dirty { color: var(--warn); font-size: 12px; }

.layout { display: grid; grid-template-columns: 190px 1fr; min-height: calc(100vh - 63px); }
.tabs {
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: grid;
  align-content: start;
  gap: 4px;
}
.tab {
  background: none;
  border: 0;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--muted);
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab[aria-selected="true"] { background: var(--panel-2); color: var(--text); font-weight: 600; }
.panel { padding: 22px; max-width: 1100px; }

h2 { margin: 0 0 4px; font-size: 19px; }
h3 { margin: 22px 0 8px; font-size: 15px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

/* -------------------------------------------------------------- components */
.btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 13px;
  cursor: pointer;
}
.btn:hover { border-color: rgba(255, 255, 255, 0.2); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-text); font-weight: 600; }
.btn.primary:disabled { opacity: 0.45; cursor: default; }
.btn.ghost { background: none; }
.btn.danger { color: #ff8080; border-color: rgba(255, 128, 128, 0.3); }
.btn.small { padding: 5px 9px; font-size: 13px; }

.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; color: var(--muted); }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.checkbox input { width: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
td code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

.list { display: grid; gap: 8px; }
.item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: grid;
  gap: 10px;
}
.item.dragging { opacity: 0.5; }
.item-head { display: flex; align-items: center; gap: 10px; }
.drag-handle { cursor: grab; color: var(--muted); user-select: none; }
.badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge.ok { color: var(--ok); border-color: rgba(34, 197, 94, 0.35); }
.badge.off { color: var(--muted); }
.spacer { flex: 1; }

.callout {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--panel);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}
.callout.warn { border-left-color: var(--warn); }

pre.snippet {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 12.5px;
  margin: 0;
}

.device-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.preview-stage {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0f0f12;
  min-height: 520px;
  position: relative;
  overflow: hidden;
}
.preview-stage.mobile { max-width: 400px; margin: 0 auto; }
.preview-stage iframe { width: 100%; height: 620px; border: 0; display: block; }

.empty { color: var(--muted); padding: 26px; text-align: center; border: 1px dashed var(--border); border-radius: 12px; }

.toast-stack { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 50; }
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--ok);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  max-width: 380px;
}
.toast.error { border-left-color: var(--accent); }

/* ------------------------------------------------ problems + activity log */
.problems {
  margin: 14px 22px 0;
  border: 1px solid rgba(255, 107, 107, 0.35);
  border-left: 3px solid var(--accent);
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 16px;
}
.problems header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.problems ol { margin: 0; padding-left: 20px; display: grid; gap: 12px; }
.problems li { font-size: 13px; }
.problems .where { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.problems .field-errors { margin: 6px 0 0; padding-left: 16px; display: grid; gap: 3px; }
.problems details { margin-top: 6px; }
.problems summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.problems pre, .activity pre {
  margin: 6px 0 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow: auto;
}

.activity {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 34vh;
  display: flex;
  flex-direction: column;
  background: #0d0d10;
  border-top: 1px solid var(--border);
  z-index: 30;
}
.activity header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}
.activity-body { overflow: auto; }
.activity-empty { padding: 18px 14px; }
.log-row {
  display: grid;
  grid-template-columns: 74px 54px 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 7px 14px;
  font-size: 12.5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.log-row.failed { background: rgba(229, 53, 43, 0.08); }
.log-row .time { color: var(--muted); white-space: nowrap; }
.log-row .status { font-weight: 600; }
.log-row .status.bad { color: #ff8080; }
.log-row .path { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.log-row .detail { grid-column: 3; }
.activity-open {
  position: fixed;
  left: 18px; bottom: 18px;
  z-index: 31;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
}
.field-error { color: #ff8080; font-size: 12px; margin: 2px 0 0; }
.item.invalid { border-color: rgba(255, 128, 128, 0.5); }
.badge.warn { background: rgba(229, 53, 43, 0.18); border-color: rgba(229, 53, 43, 0.45); color: #ffb3b3; }
.activity-open.alert { border-color: rgba(229, 53, 43, 0.55); color: #ffb3b3; }

/* --------------------------------------------------- keys, stats, settings */
/* Four headline numbers at most, so auto-fit is enough: at narrow widths they
 * pair up instead of shrinking to unreadable boxes. */
.grid.four { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.callout strong { display: block; margin-top: 2px; font-size: 1.55rem; font-weight: 640; letter-spacing: -0.02em; }

.key-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.tiny { font-size: 11px; }
.revealed-row > td { background: var(--panel-2); }
.revealed { display: flex; align-items: center; gap: 10px; }
/* The key can be ~51 characters: let it scroll rather than wrap, so it stays
 * selectable as one string and copyable by hand when the clipboard is refused. */
.revealed code { flex: 1 1 auto; min-width: 0; overflow-x: auto; white-space: nowrap; color: var(--text); }

.funnel { list-style: none; display: grid; gap: 14px; margin: 18px 0 0; padding: 0; }
.funnel > li { display: grid; gap: 6px; }
.funnel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 13px; }
.funnel-name code { color: var(--muted); font-size: 12px; }
.funnel-value { color: var(--muted); white-space: nowrap; }
.funnel-track { display: block; height: 8px; overflow: hidden; border-radius: 999px; background: rgba(255, 255, 255, 0.07); }
.funnel-fill { display: block; height: 100%; border-radius: 999px; background: var(--accent); }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .tabs { grid-auto-flow: column; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
}
