@font-face {
  font-family: "FiraCode";
  src: url("/static/fonts/FiraCode-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}

:root {
  --bg: #0e0e12;
  --surface: #16161c;
  --surface-2: #1c1c24;
  --border: #25252f;
  --text: #e7e7ec;
  --muted: #8a8a99;
  --faint: #55555f;
  --accent: #6c5ce7;
  --accent-hover: #7d6ef0;
  --green: #3fb950;
  --red: #f85149;
  --amber: #d29922;
  --radius: 10px;
  --mono: "FiraCode", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: "Inter", -apple-system, system-ui, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Login ── */
.login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card {
  width: 320px; padding: 32px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 14px;
}
.login-title { font-size: 18px; font-weight: 600; text-align: center; margin-bottom: 6px; }
.login-error { color: var(--red); font-size: 13px; min-height: 16px; text-align: center; }

/* ── Layout ── */
.app { min-height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 24px;
  height: 56px; padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 600; letter-spacing: .2px; }
.brand-dim { color: var(--faint); }
.nav { display: flex; gap: 4px; }
.nav-item {
  padding: 7px 14px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active { color: var(--text); background: var(--surface-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.view { padding: 28px 24px 60px; max-width: 1180px; margin: 0 auto; }

/* ── Typography ── */
.page-title { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
.page-sub { color: var(--muted); margin: 0 0 24px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--faint); margin: 28px 0 12px; }

/* ── Buttons ── */
.btn {
  font-family: inherit; font-size: 13px; font-weight: 500;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #24242e; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--red); border-color: #3a2326; }
.btn-danger:hover { background: #2a1a1c; }

/* ── Inputs ── */
.input, select {
  font-family: inherit; font-size: 14px;
  padding: 9px 12px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
}
.input:focus, select:focus { outline: none; border-color: var(--accent); }

/* ── Cards / grid ── */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-name { font-weight: 600; font-size: 15px; }
.card-meta { color: var(--muted); font-size: 12px; font-family: var(--mono); margin-top: 4px; }
.card-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* ── Status dot / pill ── */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot-up { background: var(--green); box-shadow: 0 0 8px rgba(63,185,80,.5); }
.dot-down { background: var(--red); }
.dot-warn { background: var(--amber); }
.pill {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
}

/* ── Stat tiles ── */
.tiles { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); margin-bottom: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.tile-value { font-size: 26px; font-weight: 700; }
.tile-label { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ── Uptime timeline ── */
.uptime-row { display: grid; grid-template-columns: 150px 1fr 52px; align-items: center; gap: 14px; padding: 8px 0; }
.uptime-name { font-weight: 500; }
.uptime-bar { width: 100%; height: 22px; border-radius: 5px; overflow: hidden; background: var(--surface-2); display: block; }
.uptime-pct { text-align: right; color: var(--muted); font-family: var(--mono); font-size: 12px; }

/* ── Table ── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--faint); text-transform: uppercase; font-size: 11px; letter-spacing: .5px; position: sticky; top: 0; background: var(--surface-2); }
td { font-family: var(--mono); color: var(--text); max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
tbody tr:hover { background: var(--surface-2); }

.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

/* DB layout */
.db-layout { display: grid; grid-template-columns: 240px 1fr; gap: 18px; align-items: start; }
.db-tables { display: flex; flex-direction: column; gap: 2px; }
.db-table-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted);
}
.db-table-item:hover { background: var(--surface-2); color: var(--text); }
.db-table-item.active { background: var(--surface-2); color: var(--text); }
.db-table-count { font-family: var(--mono); font-size: 12px; color: var(--faint); }
.pager { display: flex; align-items: center; gap: 10px; margin-top: 14px; }

/* ── Log drawer ── */
.drawer {
  position: fixed; right: 0; top: 0; bottom: 0; width: min(840px, 92vw);
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 50;
  box-shadow: -20px 0 40px rgba(0,0,0,.4);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.drawer-title { font-family: var(--mono); font-weight: 600; }
.drawer-actions { display: flex; align-items: center; gap: 8px; }
.drawer-tail { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.drawer-body {
  flex: 1; margin: 0; padding: 16px 18px; overflow: auto;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
  color: #cfd3dc; white-space: pre-wrap; word-break: break-word;
}

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 11px 18px; border-radius: 10px; z-index: 100; font-size: 13px;
}
.toast.ok { border-color: #234a2a; }
.toast.err { border-color: #4a2326; color: #ffb4b0; }

.empty { color: var(--faint); text-align: center; padding: 48px 0; }

/* ── DB tab: wide layout & richer table ── */
.view.wide { max-width: 1600px; }
.db-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.db-head-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.db-size select { padding: 4px 8px; font-size: 12px; }
.db-rows { max-height: 72vh; overflow: auto; }
.db-rows th { vertical-align: bottom; }
.th-name { font-weight: 600; color: var(--muted); }
.th-type { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--faint); font-family: var(--mono); font-size: 10px; }
.th-pk { color: var(--accent); font-size: 9px; }
.cell-null { color: var(--faint); font-style: italic; }
.col-act { position: sticky; right: 0; background: var(--surface-2); white-space: nowrap; }
.col-act .btn { padding: 3px 9px; margin-left: 4px; }
.req { color: var(--amber); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-card {
  width: min(560px, 96vw); max-height: 88vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal-body { padding: 16px 18px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }
.f-row { display: flex; flex-direction: column; gap: 5px; }
.f-label { display: flex; align-items: baseline; gap: 8px; font-size: 12px; color: var(--muted); }
.f-type { color: var(--faint); font-family: var(--mono); font-size: 10px; margin-left: auto; }
.modal-body input, .modal-body textarea, .modal-body select {
  font-family: var(--mono); font-size: 13px; padding: 8px 10px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text); width: 100%; resize: vertical;
}
.modal-body input:focus, .modal-body textarea:focus, .modal-body select:focus { outline: none; border-color: var(--accent); }
.modal-body input[readonly], .modal-body select:disabled { opacity: .6; cursor: not-allowed; }
