:root {
  --bg: #0e1014;
  --surface: #171a21;
  --surface2: #1f2430;
  --border: rgba(255, 255, 255, 0.07);
  --text: #eceff4;
  --muted: #8b93a3;
  --accent: #e8953a;
  --accent-soft: #f5b041;
  --highlight: #5b9fd4;
  --green: #5ecf8f;
  --yellow: #e8c547;
  --red: #ef6b6b;
  --gradient: linear-gradient(145deg, #e8953a 0%, #5b9fd4 100%);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.4);
  --radius: 10px;
  --radius-lg: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(232, 149, 58, 0.07), transparent),
    radial-gradient(ellipse 50% 35% at 0% 100%, rgba(91, 159, 212, 0.06), transparent);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
}

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

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-screen[hidden],
#app[hidden] {
  display: none !important;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.login-card h1 {
  font-size: 1.75rem;
  margin-bottom: 0.75rem;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-error {
  margin-top: 1rem;
  color: var(--red);
  font-size: 0.9rem;
}

/* Nav */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: rgba(14, 16, 20, 0.9);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.logo::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
  margin-right: 0.5rem;
  vertical-align: middle;
  transform: translateY(-1px);
}

.nav-links { display: flex; gap: 0.5rem; }

.tab {
  padding: 0.5rem 0.25rem;
  margin: 0 0.65rem;
  border-radius: 0;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
}

.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent-soft);
  border-bottom-color: var(--accent);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-pill img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.btn {
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: #1a1208;
  box-shadow: 0 2px 12px rgba(232, 149, 58, 0.3);
}

.btn-primary:hover {
  background: var(--accent-soft);
  box-shadow: 0 4px 16px rgba(232, 149, 58, 0.4);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover { color: var(--text); }

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 2rem; }

.section { display: none; }
.section.active { display: block; }

.hero-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.hero-title span {
  color: var(--accent-soft);
}

.subtitle { color: var(--muted); margin-bottom: 2rem; max-width: 600px; }

/* Stat cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--gradient);
}

.stat-card .label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.stat-card .value {
  font-size: 2rem;
  font-weight: 700;
}

.stat-card .delta {
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.delta.up { color: var(--green); }
.delta.down { color: var(--red); }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card h3 .badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.55rem;
  border-radius: 4px;
  background: rgba(232, 149, 58, 0.15);
  color: var(--accent-soft);
}

/* Chart */
.chart-wrap { height: 220px; position: relative; }

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

th { color: var(--muted); font-weight: 500; font-size: 0.8rem; text-transform: uppercase; }

tr:hover td { background: var(--surface2); }

.tag {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.tag-risk { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.tag-ok { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.tag-warn { background: rgba(234, 179, 8, 0.15); color: var(--yellow); }

/* Guild grid */
.guild-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.guild-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  cursor: pointer;
  transition: border-color 0.2s;
}

.guild-card:hover { border-color: var(--accent); }
.guild-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.guild-card h4 { margin-bottom: 0.25rem; }
.guild-card p { color: var(--muted); font-size: 0.85rem; }

/* Protection editor */
.protection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.prot-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.prot-card h4 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.toggle {
  width: 44px;
  height: 24px;
  background: #333;
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle.on { background: var(--accent); }

.toggle::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}

.toggle.on::after { transform: translateX(20px); }

.field { margin-bottom: 0.75rem; }
.field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }

.field input, .field select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }

@media (max-width: 768px) {
  .two-col { grid-template-columns: 1fr; }
  .nav { flex-wrap: wrap; gap: 1rem; }
}

.loading { color: var(--muted); padding: 2rem; text-align: center; }

.hidden { display: none !important; }

.card-desc {
  color: var(--muted);
  font-size: 0.9rem;
  margin: -0.5rem 0 1rem;
}

.muted-text { color: var(--muted); font-size: 0.85rem; }

.mono, .mono-sm {
  font-family: ui-monospace, 'Cascadia Code', monospace;
  font-size: 0.8rem;
  color: var(--highlight);
}

.mono-sm { font-size: 0.75rem; }

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.info-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
}

.info-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.info-value {
  font-size: 0.95rem;
  word-break: break-all;
}

.breakdown-list { display: flex; flex-direction: column; gap: 0.5rem; }

.breakdown-row {
  display: grid;
  grid-template-columns: 1fr minmax(80px, 140px) 36px;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.85rem;
}

.breakdown-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.breakdown-bar {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}

.breakdown-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--highlight));
  border-radius: 4px;
  min-width: 2px;
}

.breakdown-count {
  text-align: right;
  font-weight: 600;
  color: var(--text);
}

#tbl-hq-servers td, #tbl-guilds td, #tbl-hq-events td, #tbl-dev-actions td {
  font-size: 0.85rem;
  vertical-align: top;
}
