/* ==========================================================================
   3 of Spades — Admin Command Center Styles
   Royal Velvet & Brass Palette matching 3ofspades.uk
   ========================================================================== */

:root {
  --bg-deep: #05140c;
  --bg-felt: #0d321c;
  --surface-card: #0c1f15;
  --surface-elevated: #122c1e;
  --surface-input: #081810;

  --gold: #e5c158;
  --gold-bright: #f3d780;
  --gold-dim: #b58c30;
  --brass-line: rgba(229, 193, 88, 0.22);
  --brass-line-strong: rgba(229, 193, 88, 0.48);

  --ivory: #faf6ee;
  --ivory-soft: #d7d0c2;
  --ivory-muted: #98a397;
  --crimson: #c63b42;
  --crimson-bg: rgba(198, 59, 66, 0.16);
  --emerald: #2ea566;
  --emerald-bg: rgba(46, 165, 102, 0.16);

  --font-display: 'Fraunces', Georgia, serif;
  --font-ui: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow-card: 0 14px 36px rgba(0, 0, 0, 0.42);
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 85% 45% at 50% -10%, rgba(27, 107, 58, 0.36), transparent 65%),
    linear-gradient(180deg, #071d11 0%, #05140c 60%, #040f09 100%);
  color: var(--ivory);
  font-family: var(--font-ui);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

code,
pre {
  font-family: var(--font-mono);
}

code {
  background: rgba(229, 193, 88, 0.12);
  color: var(--gold-bright);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.86em;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  margin: 0 0 4px;
  color: var(--ivory);
  font-weight: 700;
}

p {
  margin: 0;
}

.muted {
  color: var(--ivory-muted);
  font-size: 0.9rem;
}

/* ---------- Auth Gate ---------- */
.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 520px;
  background: var(--surface-card);
  border: 1px solid var(--brass-line-strong);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-card);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.brand-crest {
  width: 68px;
  height: 68px;
  border-radius: 18px;
  background: linear-gradient(145deg, #174e2d, #0a2415);
  border: 2px solid var(--gold);
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.auth-subtitle {
  color: var(--ivory-soft);
  font-size: 0.96rem;
}

.denied-box {
  width: 100%;
  text-align: left;
  background: var(--crimson-bg);
  border: 1px solid rgba(198, 59, 66, 0.45);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.denied-title {
  font-weight: 800;
  color: #ffb3b7;
}

.code-block {
  margin: 0;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--brass-line);
  color: var(--gold-bright);
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 10px 16px;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  text-decoration: none;
  transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease, opacity 140ms ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-lg {
  padding: 12px 24px;
  font-size: 1rem;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.84rem;
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-dim));
  color: #130e04;
  border-color: var(--gold-bright);
}

.btn-gold:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  color: var(--ivory);
  border-color: var(--brass-line);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(229, 193, 88, 0.12);
  border-color: var(--brass-line-strong);
}

.btn-crimson {
  background: var(--crimson-bg);
  color: #ffc5c8;
  border-color: rgba(198, 59, 66, 0.55);
}

.btn-crimson:hover:not(:disabled) {
  background: rgba(198, 59, 66, 0.28);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

/* ---------- Topbar & Tabs ---------- */
.dashboard-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(5, 20, 12, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--brass-line);
  padding: 12px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-mini {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(145deg, #174e2d, #0a2415);
  border: 1.5px solid var(--gold);
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.topbar-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
}

.topbar-sub {
  font-size: 0.78rem;
  color: var(--ivory-muted);
}

.live-badge,
.email-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid var(--brass-line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ivory-soft);
}

.live-badge {
  border-color: rgba(46, 165, 102, 0.45);
  background: var(--emerald-bg);
  color: #8df0b8;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
}

.tab-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 24px 0;
  border-bottom: 1px solid var(--brass-line);
  background: rgba(8, 26, 16, 0.65);
}

.tab-btn {
  border: none;
  border-bottom: 2.5px solid transparent;
  background: transparent;
  color: var(--ivory-muted);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.92rem;
  padding: 10px 14px 12px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: color 140ms ease, border-color 140ms ease;
}

.tab-btn:hover {
  color: var(--ivory);
}

.tab-btn.active {
  color: var(--gold-bright);
  border-bottom-color: var(--gold);
}

.tab-pill {
  font-size: 0.75rem;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(229, 193, 88, 0.16);
  color: var(--gold-bright);
}

.main-content {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
  flex: 1;
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 20px;
}

.tab-panel.active {
  display: flex;
}

/* ---------- Cards & KPIs ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}

.kpi-card {
  background: var(--surface-card);
  border: 1px solid var(--brass-line);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ivory-muted);
}

.kpi-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--gold-bright);
  line-height: 1.1;
}

.kpi-sub {
  font-size: 0.82rem;
  color: var(--ivory-soft);
}

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

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.toolbar-actions,
.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.toolbar-row {
  justify-content: space-between;
  margin-bottom: 14px;
}

.segmented {
  display: inline-flex;
  background: var(--surface-input);
  border: 1px solid var(--brass-line);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--ivory-muted);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.82rem;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
}

.seg-btn.active {
  background: rgba(229, 193, 88, 0.2);
  color: var(--gold-bright);
}

/* ---------- Charts & Breakdowns ---------- */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.82rem;
  color: var(--ivory-soft);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  display: inline-block;
}

.swatch-gold {
  background: var(--gold);
}

.swatch-emerald {
  background: var(--emerald);
}

.swatch-ivory {
  background: var(--ivory);
}

.trend-chart-wrap {
  width: 100%;
  overflow-x: auto;
}

.trend-svg {
  width: 100%;
  min-width: 560px;
  height: 240px;
  display: block;
}

.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.bar-list {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bar-row-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.86rem;
  color: var(--ivory-soft);
}

.bar-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--emerald), var(--gold));
}

/* ---------- Tables ---------- */
.summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.table-scroll {
  overflow-x: auto;
}

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

.data-table th,
.data-table td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid rgba(229, 193, 88, 0.12);
  vertical-align: middle;
}

.data-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ivory-muted);
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.badge-prod {
  background: var(--emerald-bg);
  color: #8df0b8;
  border: 1px solid rgba(46, 165, 102, 0.4);
}

.badge-dev {
  background: rgba(229, 193, 88, 0.16);
  color: var(--gold-bright);
  border: 1px solid var(--brass-line-strong);
}

.badge-fatal {
  background: var(--crimson-bg);
  color: #ffb3b7;
  border: 1px solid rgba(198, 59, 66, 0.45);
}

.badge-info {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ivory-soft);
  border: 1px solid var(--brass-line);
}

/* ---------- Errors Feed ---------- */
.errors-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.error-item {
  background: var(--surface-elevated);
  border: 1px solid var(--brass-line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.error-item summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.error-item summary::-webkit-details-marker {
  display: none;
}

.error-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 240px;
}

.error-msg {
  font-weight: 700;
  color: var(--ivory);
  word-break: break-word;
}

.error-body {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(229, 193, 88, 0.14);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- Forms & Audit ---------- */
.two-col-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1.1fr) minmax(300px, 0.9fr);
  gap: 18px;
}

@media (max-width: 900px) {
  .two-col-layout {
    grid-template-columns: 1fr;
  }
}

.form-card {
  max-width: 820px;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ivory-soft);
}

.field small {
  color: var(--ivory-muted);
  font-size: 0.78rem;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  background: var(--surface-input);
  border: 1px solid var(--brass-line);
  border-radius: var(--radius-sm);
  color: var(--ivory);
  font-family: var(--font-ui);
  font-size: 0.94rem;
  padding: 10px 12px;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--gold);
}

.toggle-field {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-elevated);
  border: 1px solid var(--brass-line);
  cursor: pointer;
}

.toggle-field input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--crimson);
}

.toggle-field small {
  display: block;
  color: var(--ivory-muted);
}

.warning-banner {
  background: var(--crimson-bg);
  border: 1px solid rgba(198, 59, 66, 0.55);
  color: #ffc5c8;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.preview-box {
  background: var(--emerald-bg);
  border: 1px solid rgba(46, 165, 102, 0.45);
  color: #b7f5d2;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.9rem;
}

.audit-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 520px;
  overflow-y: auto;
}

.audit-item {
  background: var(--surface-elevated);
  border: 1px solid var(--brass-line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.audit-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
}

.empty-state {
  text-align: center;
  padding: 28px 16px;
  color: var(--ivory-muted);
  border: 1px dashed var(--brass-line);
  border-radius: var(--radius-sm);
}

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}

.toast {
  background: var(--surface-elevated);
  border: 1px solid var(--brass-line-strong);
  color: var(--ivory);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  font-size: 0.9rem;
  font-weight: 600;
}

.toast-error {
  border-color: rgba(198, 59, 66, 0.7);
  background: #2b1014;
  color: #ffc5c8;
}

.toast-success {
  border-color: rgba(46, 165, 102, 0.65);
  background: #0d2b1c;
  color: #a6f4c7;
}
