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

:root {
  --red: #e3350d;
  --red-dark: #c42d0b;
  --bg: #f0f0f0;
  --surface: #fff;
  --border: #ddd;
  --text: #333;
  --muted: #666;
  --green: #2f9e44;
  --amber: #b45309;
  --blue: #2196f3;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { color: #111; letter-spacing: -0.02em; }
h1 { font-size: 1.9rem; margin: 0 0 0.5rem; }
h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 0.9rem; }
h1.tight { margin-bottom: 0.35rem; }

p { line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.mono { font-family: var(--mono); }

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: #f4f3ef;
  border: 1px solid #e6e4dc;
  border-radius: 4px;
  padding: 0.1em 0.35em;
  color: #1f2937;
}
code.block { display: block; padding: 0.4rem 0.6rem; margin: 0.2rem 0 0.6rem; word-break: break-all; }

pre {
  margin: 0;
  padding: 1rem;
  background: #1f2430;
  color: #e6e6e6;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.5;
}
pre code { background: none; border: none; padding: 0; color: inherit; }
pre.json { max-height: 320px; overflow: auto; }

/* Top bar */
.topbar {
  background: var(--red);
  color: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0.55rem 1rem;
  display: flex;
  align-items: center;
  gap: 1.2rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #fff;
  font-weight: 700;
  letter-spacing: -0.4px;
  position: relative;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; color: var(--red);
  border-radius: 6px; font-weight: 800;
}
.brand-name { font-size: 1.05rem; }
.brand-badge {
  font-size: 0.5rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: #fbbf24;
  position: absolute; top: -0.75em; right: -0.6em;
}
.nav { display: flex; gap: 0.3rem; flex: 1; }
.navlink {
  color: #fff; background: rgba(255,255,255,0.15);
  padding: 0.35rem 0.7rem; border-radius: 5px;
  font-size: 0.85rem;
}
.navlink:hover { background: rgba(255,255,255,0.3); text-decoration: none; }
.navlink.active { background: #fff; color: var(--red); font-weight: 600; }
.who { display: flex; align-items: center; gap: 0.55rem; font-size: 0.85rem; }
.who-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; background: rgba(255,255,255,0.3); }
.avatar-fallback { display: inline-flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; color: #fff; }
.linkbtn { background: none; border: none; color: rgba(255,255,255,0.75); cursor: pointer; font-size: 0.8rem; text-decoration: underline; padding: 0; }
.linkbtn:hover { color: #fff; }

/* Layout */
.wrap { max-width: 1120px; width: 100%; margin: 0 auto; padding: 1.5rem 1rem 3rem; flex: 1; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.2rem 1.4rem;
  margin-bottom: 1.2rem;
}
.card.narrow { max-width: 640px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.card-head h2 { margin-bottom: 0.5rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.2rem; }
.grid-2 .card, .grid-3 .card { margin-bottom: 0; }
@media (max-width: 820px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .topbar-inner { flex-wrap: wrap; gap: 0.6rem; }
  .nav { order: 3; width: 100%; }
  h1 { font-size: 1.5rem; }
}
.page-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.backlink { font-size: 0.82rem; }

/* Hero */
.hero { display: flex; gap: 2rem; align-items: center; border-left: 4px solid var(--red); }
.hero-copy { flex: 1; }
.hero h1 { font-size: 2.4rem; margin-bottom: 0.4rem; }
.lead { font-size: 1rem; color: var(--muted); max-width: 60ch; }
.hero-actions { display: flex; gap: 0.6rem; margin-top: 1.1rem; flex-wrap: wrap; }
.hero-panel {
  flex-shrink: 0; width: 320px;
  background: #fafafa; border: 1px solid var(--border);
  border-radius: 8px; padding: 1rem;
}
.hero-panel-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
@media (max-width: 820px) {
  .hero { flex-direction: column; align-items: stretch; }
  .hero-panel { width: auto; }
  .hero h1 { font-size: 1.9rem; }
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  background: var(--red); color: #fff; border: 1px solid var(--red);
  border-radius: 5px; padding: 0.5rem 0.95rem;
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--red-dark); border-color: var(--red-dark); text-decoration: none; color: #fff; }
.btn-sm { padding: 0.32rem 0.65rem; font-size: 0.78rem; }
.btn-ghost { background: #fff; color: var(--red); border-color: var(--border); }
.btn-ghost:hover { background: #fff5f2; border-color: var(--red); color: var(--red); }
.btn-secondary { background: #fff; color: #333; border-color: #bbb; }
.btn-secondary:hover { background: #f5f5f5; color: #111; }
.btn-danger { background: #fff; color: #b91c1c; border-color: #e7b4b4; }
.btn-danger:hover { background: #fef2f2; color: #b91c1c; border-color: #b91c1c; }
.btn-discord { background: #5865f2; border-color: #5865f2; }
.btn-discord:hover { background: #4752c4; border-color: #4752c4; }
.discord-dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; display: inline-block; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.8rem; }
.inline { display: inline; }

/* Badges */
.badge {
  display: inline-block; font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.15rem 0.45rem; border-radius: 4px;
  vertical-align: middle;
}
.badge-active { background: #e7f7ec; color: var(--green); }
.badge-pending { background: #fef3c7; color: var(--amber); }
.badge-paused { background: #f3f4f6; color: #4b5563; }
.badge-denied { background: #fdecec; color: #b91c1c; }
.badge-admin { background: #e8f1fd; color: #1d4ed8; margin-left: 0.3rem; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th, td { text-align: left; padding: 0.55rem 0.5rem; border-bottom: 1px solid #ececec; vertical-align: middle; }
th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
tr:last-child td { border-bottom: none; }
td.actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

/* Key-value + meters */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 1rem; margin: 0.7rem 0; font-size: 0.88rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.meter { margin-bottom: 0.9rem; }
.meter-head { display: flex; justify-content: space-between; font-size: 0.84rem; margin-bottom: 0.3rem; }
.meter-foot { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }
.bar { height: 9px; background: #ececec; border-radius: 6px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--red); border-radius: 6px; }

.key-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0.6rem 0 0.9rem; }
.key-value { flex: 1; min-width: 220px; padding: 0.5rem 0.6rem; background: #fafafa; border: 1px solid var(--border); border-radius: 5px; word-break: break-all; }

/* Forms */
label { display: block; font-size: 0.82rem; color: var(--muted); }
input[type=number], input[type=text], input[type=datetime-local], textarea, select {
  width: 100%; padding: 0.45rem 0.55rem; margin-top: 0.2rem;
  border: 1px solid #cfcfcf; border-radius: 5px;
  font-family: inherit; font-size: 0.9rem; background: #fff; color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(227,53,13,0.25); border-color: var(--red); }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.8rem; }
@media (max-width: 820px) { .form-grid { grid-template-columns: repeat(2, 1fr); } }
label.full { margin-top: 0.8rem; }
fieldset.models { border: 1px solid var(--border); border-radius: 6px; padding: 0.7rem 0.9rem; margin: 0.9rem 0 0; }
fieldset.models legend { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 0 0.3rem; }
label.check { display: flex; align-items: center; gap: 0.4rem; color: var(--text); margin: 0.2rem 0; font-size: 0.86rem; }
label.check input { width: auto; margin: 0; }

/* Flashes and banners */
.flashes { margin-bottom: 1rem; }
.flash { padding: 0.6rem 0.9rem; border-radius: 5px; margin-bottom: 0.4rem; font-size: 0.87rem; }
.flash-ok { background: #e7f7ec; color: #1b6e32; border: 1px solid #bfe6cb; }
.flash-error { background: #fdecec; color: #9b1c1c; border: 1px solid #f3c4c4; }
.banner { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.87rem; }
.banner-warn { background: #fff7e6; border: 1px solid #f5d9a8; color: #7c4a03; }

/* Misc */
.plain { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.steps { margin: 0; padding-left: 1.2rem; line-height: 1.6; }
.steps li { margin-bottom: 0.5rem; }
.dash-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.dash-head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.footer { border-top: 1px solid var(--border); background: #fafafa; }
.footer-inner {
  max-width: 1120px; margin: 0 auto; padding: 0.9rem 1rem;
  display: flex; gap: 1rem; flex-wrap: wrap; align-items: center;
  font-size: 0.78rem; color: var(--muted);
}
.footer-inner a { color: var(--muted); }
