/* MIUI — Stripe-style design system (no Tailwind/runtime).
 * Palette inspired by stripe.com / dashboard.stripe.com.
 */
:root {
  --bg: #f6f9fc;
  --surface: #ffffff;
  --surface-soft: #f7fafc;
  --line: #e3e8ee;
  --line-strong: #d4dbe3;

  --text: #0a2540;
  --text-s: #425466;
  --text-t: #697386;
  --text-faint: #8898aa;

  --accent: #635bff;
  --accent-hover: #5851ec;
  --accent-strong: #4f3ff0;
  --accent-soft: #ecebff;

  --success: #0f9d58;
  --success-soft: #d6f7ed;
  --warning: #c5793b;
  --warning-soft: #fdf3e7;
  --danger: #cd3d64;
  --danger-soft: #fde2eb;

  --radius-lg: 12px;
  --radius: 8px;
  --radius-sm: 6px;

  --shadow-1: 0 1px 2px rgba(10, 37, 64, 0.06);
  --shadow-2: 0 4px 16px rgba(10, 37, 64, 0.08);
  --shadow-focus: 0 0 0 3px rgba(99, 91, 255, 0.18);

  --font: Inter, "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: -0.003em;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* —— Top bar —— */
header.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0 18px;
  min-height: 56px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

header.topbar .brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}

header.topbar .brand::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 91, 255, 0.18);
}

header.topbar nav {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 0;
  margin-left: 24px;
}

header.topbar nav a {
  display: inline-flex;
  align-items: center;
  height: 56px;
  padding: 0 14px;
  color: var(--text-s);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

header.topbar nav a:hover {
  color: var(--text);
}

header.topbar nav a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.user-info {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text-t);
  font-size: 13px;
}

.user-info span {
  color: var(--text-s);
  font-weight: 500;
}

.user-info a {
  color: var(--text-t);
  font-weight: 500;
  font-size: 13px;
  text-decoration: none;
}

.user-info a:hover {
  color: var(--text);
}

/* Public projectinfo header (slim variant) */
header:not(.topbar) {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

header:not(.topbar) h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

header:not(.topbar) a {
  color: var(--text-s);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}

header:not(.topbar) a:hover {
  color: var(--text);
}

/* —— Main containers —— */
.app-main {
  max-width: 1080px;
  margin: 32px auto 0;
  padding: 0 24px 48px;
}

.app-main--wide {
  max-width: 1280px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.page-header--end {
  align-items: flex-end;
}

.page-header h1 {
  margin: 0 0 2px;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.012em;
}

.page-header .muted,
.page-header .subtle {
  color: var(--text-t);
  font-size: 13px;
}

.subtle {
  color: var(--text-t);
  font-size: 13px;
}

/* —— Sections / cards —— */
section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-1);
}

h2 {
  margin: 0 0 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-t);
}

p {
  margin: 0 0 8px;
}

p:last-child {
  margin-bottom: 0;
}

a {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}

a:hover {
  color: var(--accent-strong);
  text-decoration: none;
}

code {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-s);
}

/* —— Forms —— */
label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-s);
}

input,
textarea,
select {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea {
  height: auto;
  min-height: 84px;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23697386' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

input:hover,
textarea:hover,
select:hover {
  border-color: var(--text-faint);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  height: auto;
  margin: 0;
  accent-color: var(--accent);
}

::placeholder {
  color: var(--text-faint);
}

/* —— Buttons —— */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow-1);
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

button:hover,
.btn:hover {
  background: var(--accent-hover);
  color: #fff;
}

button:active,
.btn:active {
  background: var(--accent-strong);
}

button:focus-visible,
.btn:focus-visible {
  box-shadow: var(--shadow-focus);
}

button.secondary,
.btn-secondary {
  background: var(--surface);
  color: var(--text-s);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-1);
}

button.secondary:hover,
.btn-secondary:hover {
  background: var(--surface-soft);
  color: var(--text);
  border-color: var(--text-faint);
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #b53558;
}

.btn-warning {
  background: var(--warning);
  color: #fff;
}

.btn-warning:hover {
  background: #b46a30;
  color: #fff;
}

/* —— Tables —— */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 12px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-t);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

td {
  padding: 12px 14px;
  color: var(--text-s);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: var(--surface-soft);
  color: var(--text);
}

/* —— Layout helpers —— */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.log-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.muted {
  color: var(--text-t);
}

.ok {
  color: var(--success);
  font-weight: 600;
}

.bad {
  color: var(--danger);
  font-weight: 600;
}

.mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
  word-break: break-all;
  color: var(--text-s);
}

.token {
  font-family: var(--font-mono);
  font-size: 12.5px;
  word-break: break-all;
  max-width: 360px;
  color: var(--text-s);
}

.empty {
  text-align: center;
  padding: 28px;
  color: var(--text-t);
}

/* —— Badge / pill —— */
.badge,
.pill {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge.off,
.pill.off {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.warn,
.pill.warn {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge.neutral,
.pill.neutral {
  background: var(--surface-soft);
  color: var(--text-s);
  border: 1px solid var(--line);
}

/* —— Banners (flash messages) —— */
section.message {
  background: var(--accent-soft);
  border-color: rgba(99, 91, 255, 0.32);
  color: var(--accent-strong);
  padding: 14px 18px;
  font-size: 13.5px;
}

section.message.success {
  background: var(--success-soft);
  border-color: rgba(15, 157, 88, 0.28);
  color: var(--success);
}

section.message.warn {
  background: var(--warning-soft);
  border-color: rgba(197, 121, 59, 0.32);
  color: var(--warning);
}

section.message.danger {
  background: var(--danger-soft);
  border-color: rgba(205, 61, 100, 0.32);
  color: var(--danger);
}

/* —— Login —— */
.login {
  max-width: 400px;
  margin: 0 auto;
}

.login--hero {
  margin: clamp(48px, 12vh, 96px) auto 24px;
  padding: 36px 32px;
  box-shadow: var(--shadow-2);
}

.login h2 {
  font-size: 20px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: -0.01em;
  color: var(--text);
  text-align: center;
  margin-bottom: 24px;
}

.login form > p {
  margin: 0 0 12px;
}

.login form button[type="submit"] {
  width: 100%;
  height: 40px;
  margin-top: 4px;
}

/* —— Stat cards —— */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-1);
}

.stat-card .label {
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-t);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-card .value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.012em;
  color: var(--text);
}

.stat-card .value.green {
  color: var(--success);
}

.stat-card .value.blue {
  color: var(--accent);
}

.stat-card .value.orange {
  color: var(--warning);
}

/* —— Auto-refresh switch —— */
.auto-refresh-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-s);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.auto-refresh-toggle input[type="checkbox"] {
  accent-color: var(--accent);
}

/* —— Code / details / preformatted —— */
pre {
  white-space: pre-wrap;
  margin: 12px 0 0;
  padding: 14px 16px;
  background: #0a2540;
  color: #e6ebf1;
  border: 1px solid #0a2540;
  border-radius: var(--radius);
  max-height: 420px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
}

details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 500;
  list-style: none;
}

details summary::-webkit-details-marker {
  display: none;
}

details summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  transform: translateY(-1px);
  transition: transform 0.15s;
}

details[open] summary::before {
  transform: rotate(90deg) translateX(-1px);
}

/* —— Pagination —— */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.pagination a,
.pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-s);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}

.pagination a:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.pagination .current {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* —— Footer —— */
.footer {
  text-align: center;
  padding: 32px 20px 16px;
  font-size: 12px;
  color: var(--text-t);
}

.footer strong {
  color: var(--text-s);
  font-weight: 600;
}

/* Backward compat: glow-text is now plain accent text */
.glow-text {
  color: var(--accent);
  font-weight: 600;
  background: none;
  -webkit-text-fill-color: currentColor;
  filter: none;
  animation: none;
}

.glow-text::after {
  content: none;
}

/* —— Error pages (404/502) —— */
.page-error {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.page-error .error-panel {
  width: min(100%, 480px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-2);
}

.page-error .error-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  color: var(--text-s);
  font-size: 14px;
  font-weight: 600;
}

.page-error .error-mark {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 91, 255, 0.18);
}

.page-error .error-mark--warning {
  background: var(--warning);
  box-shadow: 0 0 0 3px rgba(197, 121, 59, 0.22);
}

.page-error .error-code {
  display: inline-block;
  margin-bottom: 14px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.page-error .error-code--warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.page-error .error-title {
  margin: 0 0 10px;
  font-size: 26px;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -0.012em;
  color: var(--text);
}

.page-error .error-desc {
  margin: 0;
  color: var(--text-t);
  font-size: 14px;
  line-height: 1.6;
}

.page-error .error-actions {
  margin-top: 22px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.page-error .btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.page-error .btn-primary:hover {
  background: var(--accent-hover);
}

.page-error .error-meta {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--text-faint);
  font-size: 12px;
}

/* —— Responsive —— */
@media (max-width: 960px) {
  header.topbar {
    padding: 0 16px;
  }

  header.topbar nav {
    margin-left: 0;
    width: 100%;
    overflow-x: auto;
    border-top: 1px solid var(--line);
  }

  header.topbar nav a {
    height: 48px;
    padding: 0 12px;
  }

  .topbar-actions {
    margin-left: auto;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .log-grid {
    grid-template-columns: 1fr 1fr;
  }

  .app-main,
  .app-main--wide {
    padding: 0 16px 32px;
  }

  table {
    font-size: 13px;
  }

  th,
  td {
    padding: 10px 12px;
  }
}

@media (max-width: 640px) {
  .app-main,
  .app-main--wide {
    margin-top: 20px;
  }

  .log-grid {
    grid-template-columns: 1fr;
  }

  .page-header h1 {
    font-size: 22px;
  }

  .stat-card .value {
    font-size: 24px;
  }
}
