/* ── Kingdom Dashboard — main.css ──────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700;900&family=Cinzel+Decorative:wght@400;700&family=IM+Fell+English:ital@0;1&display=swap');

:root {
  /* Kingdom palette */
  --gold:        #FFD700;
  --gold-light:  #FFF0A0;
  --gold-dark:   #B8860B;
  --crimson:     #8B0000;
  --stone:       #2a2520;
  --stone-light: #3d3530;
  --stone-mid:   #332e29;
  --parchment:   #F5E6C8;
  --silver:      #C0C0C0;
  --bronze:      #CD7F32;

  /* Functional aliases kept for backwards compat */
  --bg:          #0d0a07;
  --bg2:         #110e0b;
  --surface:     #1e1b16;
  --surface2:    #2a2520;
  --surface3:    #332e29;
  --border:      #3d3630;
  --border2:     #4d4540;
  --accent:      #B8860B;
  --accent2:     #FFD700;
  --accent-glow: rgba(184,134,11,0.18);
  --success:     #5a9e6f;
  --danger:      #c0392b;
  --warn:        #d4a017;
  --text:        #F5E6C8;
  --text2:       #7a6a4a;
  --text3:       #a09070;
  --radius:      4px;
  --radius-lg:   4px;
  --font:        'Cinzel', serif;
  --mono:        'IM Fell English', serif;
  --shadow:      0 4px 24px rgba(0,0,0,.5);
  --shadow-lg:   0 8px 40px rgba(0,0,0,.7);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  display: flex;
  font-size: 14px;
  line-height: 1.5;
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(139,0,0,0.12) 0%, transparent 55%),
    repeating-linear-gradient(0deg, transparent, transparent 50px, rgba(0,0,0,0.04) 50px, rgba(0,0,0,0.04) 51px),
    repeating-linear-gradient(90deg, transparent, transparent 50px, rgba(0,0,0,0.04) 50px, rgba(0,0,0,0.04) 51px);
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold-dark); }

/* ── Sidebar ── */
#sidebar {
  width: 240px;
  background: linear-gradient(180deg, #1e1b16 0%, #16130f 100%);
  border-right: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  flex-shrink: 0;
  position: relative;
  box-shadow: 4px 0 20px rgba(0,0,0,0.4);
}
/* Glow accent line on right edge */
#sidebar::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 1px; height: 100%;
  background: linear-gradient(to bottom, transparent, rgba(184,134,11,0.2) 40%, transparent);
  pointer-events: none;
}

/* Logo */
.logo {
  padding: 20px 18px 18px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(184,134,11,0.06) 0%, transparent 100%);
}
.logo-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--gold-dark), #8B0000);
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 16px rgba(184,134,11,0.3);
  border: 1px solid var(--gold-dark);
}
.logo-icon svg { color: var(--gold-light); }
.logo-text {
  font-family: 'Cinzel Decorative', serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--parchment);
  letter-spacing: 0.05em;
}
.logo-text span { color: var(--gold); }

#sidebar nav { flex: 1; padding: 14px 10px; overflow-y: auto; }

.section-label {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  color: var(--gold-dark);
  padding: 14px 10px 6px;
  font-weight: 400;
  opacity: 0.8;
}
/* Gold divider before section labels */
.section-label::before {
  content: '';
  display: block;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin-bottom: 8px;
}

#sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text2);
  text-decoration: none;
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  transition: all .18s;
  margin-bottom: 2px;
  cursor: pointer;
  position: relative;
  text-transform: uppercase;
  border: 1px solid transparent;
}
#sidebar nav a:hover {
  background: rgba(184,134,11,0.08);
  color: var(--gold-dark);
  border-color: rgba(184,134,11,0.2);
}
#sidebar nav a.active {
  background: rgba(184,134,11,0.12);
  color: var(--gold);
  border: 1px solid rgba(184,134,11,0.3);
  box-shadow: inset 0 1px 0 rgba(255,215,0,0.06);
}
#sidebar nav a.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--gold);
  border-radius: 3px 0 0 3px;
  box-shadow: 0 0 8px rgba(255,215,0,0.5);
}
#sidebar nav a svg { flex-shrink: 0; }
#sidebar nav a[data-admin-only] { display: none; }
body.is-admin #sidebar nav a[data-admin-only] { display: flex; }

/* Sidebar footer */
#sidebar > div:last-child {
  padding: 14px 18px !important;
  border-top: 1px solid var(--border) !important;
  font-family: 'IM Fell English', serif !important;
  font-style: italic !important;
  font-size: .72rem !important;
  color: var(--gold-dark) !important;
  text-align: center;
  background: linear-gradient(0deg, rgba(184,134,11,0.04) 0%, transparent 100%);
}

/* ── Main content area ── */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#topbar {
  background: linear-gradient(180deg, #1e1b16 0%, #16130f 100%);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4), 0 1px 0 rgba(184,134,11,0.08);
}
.page-title {
  font-family: 'Cinzel', serif;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--parchment);
}
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
}
.breadcrumb svg { color: var(--gold-dark); }
.breadcrumb span {
  color: var(--gold-dark);
  font-size: .85rem;
  font-family: 'IM Fell English', serif;
}
.user-info { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 30px; height: 30px;
  border-radius: 2px;
  border: 2px solid var(--gold-dark);
  box-shadow: 0 0 8px rgba(184,134,11,0.3);
}
.username {
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  color: var(--text3);
  font-weight: 700;
  letter-spacing: 0.08em;
}
.btn-logout {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.75rem;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  letter-spacing: 0.06em;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 6px;
  text-transform: uppercase;
}
.btn-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(139,0,0,0.1);
}

#content { flex: 1; padding: 24px; overflow-y: auto; }

/* ── Cards ── */
.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(184,134,11,0.04);
  position: relative;
}
/* Stone texture top accent */
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(184,134,11,0.25), transparent);
}
.card-title {
  font-family: 'Cinzel', serif;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--parchment);
}
.card-title svg { color: var(--gold-dark); }
.card-subtitle {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 0.85rem;
  color: var(--text2);
  margin-bottom: 16px;
  line-height: 1.6;
}

/* ── Buttons ── */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: 'Cinzel', serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary {
  background: linear-gradient(180deg, #2a2208 0%, #1a1505 100%);
  color: var(--gold);
  border-color: var(--gold-dark);
  box-shadow: 0 0 12px rgba(184,134,11,0.2), inset 0 1px 0 rgba(255,215,0,0.1);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #3a3010 0%, #2a2208 100%);
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(255,215,0,0.3), inset 0 1px 0 rgba(255,215,0,0.15);
  color: var(--gold-light);
}
.btn-success {
  background: rgba(90,158,111,0.15);
  color: var(--success);
  border-color: rgba(90,158,111,0.3);
  font-weight: 700;
}
.btn-success:hover { background: rgba(90,158,111,0.25); border-color: var(--success); }
.btn-danger {
  background: rgba(139,0,0,0.12);
  color: var(--danger);
  border: 1px solid rgba(139,0,0,0.25);
}
.btn-danger:hover { background: rgba(139,0,0,0.22); border-color: var(--danger); }
.btn-secondary {
  background: var(--surface2);
  color: var(--text3);
  border: 1px solid var(--border2);
}
.btn-secondary:hover { background: var(--surface3); color: var(--text); border-color: var(--gold-dark); }
.btn-sm { padding: 5px 11px; font-size: 0.7rem; border-radius: var(--radius); }
.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text2);
  padding: 5px;
  border-radius: var(--radius);
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { color: var(--danger); background: rgba(139,0,0,0.1); }

/* ── Toggle ── */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.feature-toggle-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .18s, background .18s;
}
.feature-toggle-item:hover { border-color: rgba(184,134,11,0.4); background: var(--surface3); }
.toggle { position: relative; width: 42px; height: 23px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: 23px;
  cursor: pointer;
  transition: .25s;
}
.slider:before {
  content: '';
  position: absolute;
  height: 17px; width: 17px;
  left: 2px; bottom: 2px;
  background: var(--text2);
  border-radius: 50%;
  transition: .25s;
}
input:checked + .slider { background: rgba(184,134,11,0.2); border-color: var(--gold-dark); }
input:checked + .slider:before { transform: translateX(19px); background: var(--gold); }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-label {
  font-family: 'Cinzel', serif;
  font-size: 0.7rem;
  color: var(--text3);
  margin-bottom: 7px;
  display: block;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.form-input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 13px;
  color: var(--text);
  font-size: 0.875rem;
  font-family: 'IM Fell English', serif;
  font-style: italic;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-input:focus { border-color: var(--gold-dark); box-shadow: 0 0 0 3px rgba(184,134,11,0.1); }
.form-input::placeholder { color: var(--text2); font-style: italic; }
textarea.form-input { resize: vertical; min-height: 80px; }
select.form-input { cursor: pointer; font-style: normal; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
th {
  background: linear-gradient(180deg, var(--surface2) 0%, var(--surface) 100%);
  color: var(--gold-dark);
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 11px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 10px 16px;
  border-top: 1px solid rgba(61,54,48,0.4);
  vertical-align: middle;
  font-family: 'IM Fell English', serif;
}
tr:hover td { background: rgba(184,134,11,0.04); }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 2px;
  font-family: 'Cinzel', serif;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.badge-green  { background: rgba(90,158,111,0.12); color: var(--success); border: 1px solid rgba(90,158,111,0.25); }
.badge-red    { background: rgba(139,0,0,0.12);    color: var(--danger);  border: 1px solid rgba(139,0,0,0.25); }
.badge-yellow { background: rgba(184,134,11,0.12); color: var(--warn);    border: 1px solid rgba(184,134,11,0.25); }
.badge-blue   { background: rgba(184,134,11,0.08); color: var(--gold-dark); border: 1px solid rgba(184,134,11,0.2); }

/* ── Module Grid ── */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.module-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: border-color .2s, box-shadow .2s;
}
.module-card:hover { border-color: rgba(184,134,11,0.45); box-shadow: 0 4px 20px rgba(0,0,0,.4), 0 0 12px rgba(184,134,11,0.06); }
.module-card .mc-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.module-card .mc-name { font-family: 'Cinzel', serif; font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; }
.module-card .mc-details { font-family: 'IM Fell English', serif; font-style: italic; font-size: 0.82rem; color: var(--text2); line-height: 1.5; }
.module-card .mc-actions { display: flex; gap: 7px; margin-top: 14px; }

/* ── Log Stream ── */
#log-stream {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  height: 380px;
  overflow-y: auto;
  font-family: 'IM Fell English', serif;
  font-size: 0.82rem;
  line-height: 1.7;
}
#log-stream::-webkit-scrollbar { width: 6px; }
#log-stream::-webkit-scrollbar-track { background: transparent; }
#log-stream::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
.log-entry { display: flex; gap: 14px; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.03); }
.log-ts { color: var(--text2); flex-shrink: 0; font-style: italic; }
.log-user { color: var(--gold); }
.log-role { color: var(--warn); }
.log-reason { color: var(--text3); }

/* ── Trigger List ── */
.trigger-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 8px;
  transition: border-color .15s;
}
.trigger-item:hover { border-color: rgba(184,134,11,0.4); }
.trigger-item .ti-words {
  font-size: 0.74rem;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 2px;
  padding: 2px 7px;
  color: var(--gold-dark);
  font-family: 'Cinzel', serif;
  display: inline-block;
  margin: 2px;
}
.trigger-item .ti-response { font-family: 'IM Fell English', serif; font-style: italic; font-size: 0.82rem; color: var(--text2); margin-top: 6px; }
.trigger-item .ti-actions { margin-left: auto; display: flex; gap: 6px; flex-shrink: 0; }

/* ── Tags Input ── */
.tags-input {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 11px;
  cursor: text;
  transition: border-color .15s, box-shadow .15s;
}
.tags-input:focus-within { border-color: var(--gold-dark); box-shadow: 0 0 0 3px rgba(184,134,11,0.1); }
.tags-input input {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.875rem;
  font-family: 'IM Fell English', serif;
  font-style: italic;
  outline: none;
  flex: 1;
  min-width: 80px;
}
.tag {
  background: rgba(184,134,11,0.15);
  color: var(--gold-dark);
  border: 1px solid rgba(184,134,11,0.3);
  border-radius: 2px;
  padding: 2px 9px;
  font-family: 'Cinzel', serif;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.tag button { background: none; border: none; color: var(--gold-dark); cursor: pointer; padding: 0; font-size: .9rem; line-height: 1; opacity: .7; }
.tag button:hover { opacity: 1; color: var(--danger); }

/* ── Login Screen ── */
#login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(139,0,0,0.2) 0%, transparent 55%),
    repeating-linear-gradient(0deg, transparent, transparent 50px, rgba(0,0,0,0.04) 50px, rgba(0,0,0,0.04) 51px);
}
.login-box {
  background: linear-gradient(180deg, #1e1b16 0%, #16130f 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 52px;
  text-align: center;
  max-width: 420px;
  box-shadow: 0 0 60px rgba(184,134,11,0.12), var(--shadow-lg), inset 0 1px 0 rgba(184,134,11,0.08);
  position: relative;
}
/* Gold top edge */
.login-box::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-dark), transparent);
}
/* Crown ornament above box */
.login-box::after {
  content: '♛';
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 28px;
  color: var(--gold);
  text-shadow: 0 0 16px rgba(255,215,0,0.6);
  filter: drop-shadow(0 2px 8px rgba(184,134,11,0.4));
}
.login-logo {
  width: 60px; height: 60px;
  background: linear-gradient(135deg, var(--gold-dark), #8B0000);
  border-radius: 3px;
  border: 1px solid var(--gold-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 0 24px rgba(184,134,11,0.3);
}
.login-logo svg { color: var(--gold-light); }
.login-box h1 {
  font-family: 'Cinzel Decorative', serif;
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  background: linear-gradient(180deg, var(--gold-light) 0%, var(--gold) 50%, var(--gold-dark) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 2px 8px rgba(255,215,0,0.3));
}
.login-box p {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  color: var(--text2);
  font-size: 0.9rem;
  margin-bottom: 30px;
  line-height: 1.7;
}
.btn-discord {
  background: linear-gradient(180deg, #7289da 0%, #5865f2 100%);
  color: #fff;
  padding: 13px 30px;
  font-size: 0.8rem;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.15);
  cursor: pointer;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: all .15s;
  box-shadow: 0 0 20px rgba(88,101,242,.25);
}
.btn-discord:hover {
  background: linear-gradient(180deg, #8299ea 0%, #6875f2 100%);
  box-shadow: 0 0 28px rgba(88,101,242,.4);
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 9px 20px;
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: none;
  background: none;
  color: var(--text2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 7px;
}
.tab.active { color: var(--gold); border-color: var(--gold-dark); }
.tab:hover:not(.active) { color: var(--gold-dark); }

/* ── Misc utilities ── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 18px; }
.mt-3 { margin-top: 14px; }
.text-sm { font-size: 0.8rem; }
.text-muted { color: var(--text2); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.hidden { display: none !important; }
code {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 2px;
  padding: 2px 7px;
  font-size: 0.8rem;
  font-family: 'IM Fell English', serif;
  font-style: italic;
  color: var(--gold-dark);
}

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  position: relative;
  overflow: hidden;
  transition: border-color .2s, box-shadow .2s;
}
.stat-card:hover {
  border-color: rgba(184,134,11,0.4);
  box-shadow: 0 0 16px rgba(184,134,11,0.08);
}
/* Corner torch glow */
.stat-card::before {
  content: '';
  position: absolute;
  top: -20px; right: -20px;
  width: 70px; height: 70px;
  background: radial-gradient(circle, rgba(184,134,11,0.12) 0%, transparent 70%);
  pointer-events: none;
}
.stat-card .stat-icon {
  width: 32px; height: 32px;
  background: rgba(184,134,11,0.1);
  border: 1px solid rgba(184,134,11,0.2);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.stat-card .stat-icon svg { color: var(--gold-dark); }
.stat-card .sv {
  font-family: 'Cinzel Decorative', serif;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--parchment);
}
.stat-card .sl {
  font-family: 'IM Fell English', serif;
  font-style: italic;
  font-size: 0.78rem;
  color: var(--text2);
  margin-top: 3px;
}

/* ── Spinner ── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--gold-dark);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}
.toast {
  background: linear-gradient(180deg, var(--surface2) 0%, var(--surface) 100%);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 13px 18px;
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  animation: slideIn .2s ease;
  min-width: 230px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
}
.toast.success { border-color: rgba(90,158,111,0.4); }
.toast.success svg { color: var(--success); }
.toast.error { border-color: rgba(139,0,0,0.4); }
.toast.error svg { color: var(--danger); }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Leveling ── */
.lv-reward-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: var(--radius);
  margin-bottom: 6px;
  border: 1px solid var(--border);
}
.lv-reward-level {
  background: rgba(184,134,11,0.12);
  color: var(--gold-dark);
  border: 1px solid rgba(184,134,11,0.25);
  border-radius: 2px;
  padding: 3px 10px;
  font-family: 'Cinzel', serif;
  font-size: .75rem;
  font-weight: 700;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.lv-reward-role { flex: 1; font-family: 'IM Fell English', serif; font-style: italic; font-size: .85rem; color: var(--text3); }

/* ── Logging ── */
.log-event-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.log-event-card.log-cat-hidden { display: none; }
.log-event-header { display: flex; align-items: center; justify-content: space-between; }
.log-event-name { font-family: 'Cinzel', serif; font-size: .75rem; font-weight: 700; display: flex; align-items: center; gap: 7px; text-transform: uppercase; letter-spacing: 0.08em; }
.log-event-name i { color: var(--gold-dark); }
.log-event-card .form-input { font-size: .78rem; padding: 6px 10px; }
.log-cat-tab.active { background: rgba(184,134,11,0.12); color: var(--gold); border-color: rgba(184,134,11,0.35); }

/* ── Command permissions ── */
.cp-cat-label {
  font-family: 'Cinzel', serif;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--gold-dark);
  font-weight: 700;
  padding: 18px 0 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cp-cat-label svg { color: var(--gold-dark); }
.cp-row { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 8px; transition: border-color .15s; }
.cp-row:hover { border-color: rgba(184,134,11,0.4); }
.cp-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.cp-cmd { font-family: 'Cinzel', serif; font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: 0.08em; min-width: 120px; display: flex; align-items: center; gap: 7px; }
.cp-cmd svg { color: var(--gold-dark); }
.cp-usage { font-family: 'IM Fell English', serif; font-style: italic; font-size: .78rem; color: var(--gold-dark); background: var(--bg); border: 1px solid var(--border2); border-radius: 2px; padding: 3px 8px; }
.cp-desc { font-family: 'IM Fell English', serif; font-style: italic; font-size: .82rem; color: var(--text2); }
.cp-roles { display: flex; flex-wrap: wrap; gap: 5px; min-height: 24px; margin-bottom: 10px; }
.cp-role-tag { display: inline-flex; align-items: center; gap: 5px; background: rgba(184,134,11,0.12); border: 1px solid rgba(184,134,11,0.25); color: var(--gold-dark); border-radius: 2px; padding: 3px 9px; font-family: 'Cinzel', serif; font-size: .7rem; font-weight: 700; text-transform: uppercase; }
.cp-role-tag button { background: none; border: none; color: inherit; cursor: pointer; opacity: .6; font-size: .9rem; padding: 0; line-height: 1; }
.cp-role-tag button:hover { opacity: 1; color: var(--danger); }
.cp-add { display: flex; gap: 8px; }
.bypass-item { display: inline-flex; align-items: center; gap: 6px; background: var(--surface2); border: 1px solid var(--border2); border-radius: 2px; padding: 4px 10px; font-family: 'IM Fell English', serif; font-style: italic; font-size: 0.82rem; margin: 3px; }
.bypass-item button { background: none; border: none; color: var(--text2); cursor: pointer; font-size: .9rem; padding: 0 2px; }
.bypass-item button:hover { color: var(--danger); }
.mp-role-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }

/* ── Hierarchy ── */
.hierarchy { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.hier-card { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 11px 18px; font-size: .8rem; text-align: center; min-width: 90px; }
.hier-card .hc-name { font-family: 'Cinzel', serif; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; font-size: .75rem; }
.hier-card .hc-level { font-family: 'IM Fell English', serif; font-style: italic; font-size: .75rem; color: var(--text2); margin-top: 3px; }
.hier-arrow { color: var(--gold-dark); display: flex; align-items: center; }

/* ── Module Edit Panel ── */
#module-edit-panel { position: relative; border-color: var(--gold-dark); box-shadow: 0 0 0 1px rgba(184,134,11,0.15), var(--shadow); }
#module-edit-panel::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; background: linear-gradient(90deg, var(--gold-dark), #8B0000, var(--gold-dark)); border-radius: var(--radius) var(--radius) 0 0; }

/* ── Page frame ── */
.page-frame { display: none; flex: 1; flex-direction: column; min-width: 0; }
.page-frame.active { display: flex; }
#page-iframe { border: none; flex: 1; width: 100%; background: transparent; }

/* ── Rank card ── */
#uc-canvas { max-width: 100%; display: block; }

/* ── Error pages ── */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  gap: 18px;
}
.error-code {
  font-family: 'Cinzel Decorative', serif;
  font-size: 5rem;
  font-weight: 900;
  letter-spacing: .02em;
  background: linear-gradient(135deg, var(--gold), var(--crimson));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1;
}
.error-title { font-family: 'Cinzel', serif; font-size: 1.2rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; }
.error-desc { font-family: 'IM Fell English', serif; font-style: italic; color: var(--text2); font-size: .95rem; max-width: 380px; line-height: 1.6; }

/* ── Staff/member mode ── */
body.member-mode #sidebar { display: none !important; }
body.member-mode #main { margin-left: 0 !important; }
body.member-mode #topbar .breadcrumb { display: none !important; }
body.member-mode #topbar { justify-content: flex-end !important; padding: 0 20px !important; }
body.staff-mode nav a:not([data-page="reports"]) { display: none !important; }
body.staff-mode nav .section-label { display: none !important; }

/* ── Page shell ── */
#page-container { flex: 1; overflow-y: auto; position: relative; }
.page-view { display: none; width: 100%; min-height: 100%; }
.page-view.active { display: block; }
.page-loading { display: flex; align-items: center; justify-content: center; min-height: 300px; }
.page-error {
  padding: 40px;
  text-align: center;
  color: var(--danger);
  font-family: 'IM Fell English', serif;
  font-style: italic;
}

/* ── Kingdom battlements decorative header bar ── */
/* Added to all content area tops via pseudo */
#content::before {
  content: '';
  display: block;
  height: 3px;
  background: linear-gradient(90deg, transparent, rgba(184,134,11,0.15), transparent);
  margin-bottom: 0;
  margin-left: -24px;
  margin-right: -24px;
  width: calc(100% + 48px);
}

@media (max-width: 768px) {
  #sidebar { display: none; }
  .form-row { grid-template-columns: 1fr; }
  .module-grid { grid-template-columns: 1fr; }
}
