/**
 * SPID.js — Sovereign Passport · Vine Engine
 * public/css/layout.css
 *
 * Base reset, typography, and common UI components.
 * No hardcoded colors — all values reference tokens.css variables.
 */

/* ── RESET ────────────────────────────────────────────────────── */

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

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── GRAIN TEXTURE ────────────────────────────────────────────── */

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
  opacity: 0.4;
}

/* ── APP SHELL ────────────────────────────────────────────────── */

/* Sidebar is hidden by default — main takes full width.
   .sidebar-open on #app reveals the sidebar as a fixed overlay. */

#app {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: 1fr;
  grid-template-areas:
    "topbar"
    "main";
  min-height: 100vh;
}

/* ── TOPBAR ───────────────────────────────────────────────────── */

#topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  height: 56px;
  background: var(--bg-card);
  border-bottom: var(--border-faint);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-logo {
  font-family: var(--font-label);
  font-size: 16px;
  letter-spacing: 0.3em;
  color: var(--gold);
  text-decoration: none;
}

.topbar-vine-name {
  font-family: var(--font-display);
  font-style: normal;
  font-size: var(--text-xl);
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

/* ── SIDEBAR ──────────────────────────────────────────────────── */

/* Sidebar — fixed overlay, hidden by default.
   Slides in from the left when #app has .sidebar-open.
   A dim backdrop covers the content area behind it. */

#sidebar {
  position: fixed;
  top: 56px;
  left: 0;
  width: 240px;
  height: calc(100vh - 56px);
  background: var(--bg-card);
  border-right: var(--border-faint);
  padding: var(--space-5) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  overflow-y: auto;
  z-index: 90;
  transform: translateX(-100%);
  transition: transform var(--duration-slow) var(--ease),
              box-shadow var(--duration-slow) var(--ease);
  box-shadow: none;
}

#app.sidebar-open #sidebar {
  transform: translateX(0);
  box-shadow: var(--shadow-lg);
}

#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 56px 0 0 0;
  background: rgba(8, 15, 8, 0.7);
  z-index: 89;
  animation: fadeIn var(--duration-base) var(--ease) both;
}

#app.sidebar-open #sidebar-backdrop {
  display: block;
}

.nav-section-label {
  font-size: var(--text-xs);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-dim);
  padding: var(--space-4) var(--space-5) var(--space-2);
  opacity: 0.6;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  color: var(--ink-dim);
  text-decoration: none;
  font-size: var(--text-sm);
  transition: all var(--duration-base) var(--ease);
  border-left: 2px solid transparent;
  cursor: pointer;
  background: none;
  border-top: none;
  border-right: none;
  border-bottom: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  color: var(--ink);
  background: var(--bg-lift);
  border-left-color: var(--gold-dim);
}

.nav-item.active {
  color: var(--gold);
  background: var(--gold-faint);
  border-left-color: var(--gold);
}

.nav-item-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.nav-item-badge {
  margin-left: auto;
  background: var(--gold-faint);
  border: var(--border-gold);
  border-radius: var(--radius-full);
  padding: 1px 7px;
  font-size: 9px;
  color: var(--gold);
}

/* ── MAIN CONTENT ─────────────────────────────────────────────── */

#main {
  grid-area: main;
  padding: var(--space-7) var(--space-7);
  overflow-y: auto;
  height: calc(100vh - 56px);
}

.page-header {
  margin-bottom: var(--space-7);
}

.page-label {
  font-size: var(--text-xs);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.7;
  margin-bottom: var(--space-2);
}

.page-title {
  font-family: var(--font-display);
  font-size: clamp(28px, 4vw, 48px);
  font-weight: 300;
  color: var(--ink);
  line-height: 1.1;
}

.page-title em {
  font-style: italic;
  color: var(--gold);
}

.page-subtitle {
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--text-lg);
  color: var(--ink-dim);
  margin-top: var(--space-2);
}

/* ── CARDS ────────────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: var(--border-faint);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  position: relative;
  overflow: hidden;
  transition: border-color var(--duration-base);
}

.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent, var(--gold-dim), transparent);
  opacity: 0;
  transition: opacity var(--duration-base);
}

.card:hover::before { opacity: 1; }
.card:hover { border-color: var(--gold-dim); }

.card-title {
  font-size: var(--text-xs);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: var(--space-4);
}

/* ── GRID LAYOUTS ─────────────────────────────────────────────── */

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-5);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-5);
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
}

/* ── STAT BLOCKS ──────────────────────────────────────────────── */

.stat-block {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.stat-value {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 300;
  color: var(--ink);
  line-height: 1;
}

.stat-label {
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

/* ── BUTTONS ──────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px var(--space-6);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all var(--duration-base) var(--ease);
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--gold);
  color: var(--bg);
}

.btn-primary:hover:not(:disabled) {
  background: var(--gold-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-gold);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-dim);
  border: var(--border-faint);
}

.btn-ghost:hover:not(:disabled) {
  border-color: var(--gold-dim);
  color: var(--ink);
}

.btn-danger {
  background: transparent;
  color: var(--red-status);
  border: 1px solid rgba(192, 57, 43, 0.3);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(192, 57, 43, 0.08);
}

/* ── BADGES ───────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
}

.badge-approved {
  background: rgba(39, 174, 96, 0.1);
  color: var(--green-status);
  border: 1px solid rgba(39, 174, 96, 0.3);
}

.badge-invited {
  background: var(--gold-faint);
  color: var(--gold);
  border: var(--border-gold);
}

.badge-candidate {
  background: rgba(41, 128, 185, 0.1);
  color: var(--blue-status);
  border: 1px solid rgba(41, 128, 185, 0.3);
}

.badge-suspended {
  background: rgba(243, 156, 18, 0.1);
  color: var(--amber-status);
  border: 1px solid rgba(243, 156, 18, 0.3);
}

.badge-revoked {
  background: rgba(192, 57, 43, 0.1);
  color: var(--red-status);
  border: 1px solid rgba(192, 57, 43, 0.3);
}

.badge-admin {
  background: linear-gradient(135deg,
    rgba(201, 168, 76, 0.15), rgba(201, 168, 76, 0.05));
  color: var(--gold);
  border: var(--border-gold);
}

/* ── FORM FIELDS ──────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.field label {
  font-size: var(--text-xs);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.field input,
.field select,
.field textarea {
  background: var(--bg-lift);
  border: var(--border-faint);
  border-radius: var(--radius-md);
  padding: 10px var(--space-4);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  outline: none;
  transition: border-color var(--duration-base),
              box-shadow var(--duration-base);
  width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--gold-dim);
  box-shadow: 0 0 0 3px var(--gold-faint);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--ink-dim);
  opacity: 0.5;
}

.field textarea {
  resize: vertical;
  min-height: 80px;
}

/* ── DIVIDERS ─────────────────────────────────────────────────── */

.divider {
  height: 1px;
  background: linear-gradient(to right,
    transparent, var(--gold-dim), transparent);
  margin: var(--space-6) 0;
}

.divider-label {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--text-xs);
  color: var(--ink-dim);
  margin: var(--space-5) 0;
}

.divider-label::before,
.divider-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--ink-faint);
}

/* ── NOTICES ──────────────────────────────────────────────────── */

.notice {
  display: flex;
  gap: var(--space-3);
  background: var(--gold-faint);
  border: var(--border-gold);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--ink-dim);
  line-height: 1.6;
}

.notice-icon { flex-shrink: 0; }

.notice-error {
  background: rgba(192, 57, 43, 0.05);
  border-color: rgba(192, 57, 43, 0.3);
  color: var(--red-status);
}

/* ── TABLE ────────────────────────────────────────────────────── */

.table-container {
  overflow-x: auto;
  border: var(--border-faint);
  border-radius: var(--radius-md);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

thead tr {
  background: var(--bg-lift);
  border-bottom: var(--border-faint);
}

th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-weight: 400;
}

td {
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-faint);
  color: var(--ink-dim);
}

tr:last-child td { border-bottom: none; }

tr:hover td {
  background: var(--bg-lift);
  color: var(--ink);
}

/* ── STATUS DOT ───────────────────────────────────────────────── */

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot-green   { background: var(--green-status); }
.status-dot-gold    { background: var(--gold); }
.status-dot-amber   { background: var(--amber-status); }
.status-dot-red     { background: var(--red-status); }
.status-dot-dim     { background: var(--ink-dim); }

/* ── PULSE ANIMATION ──────────────────────────────────────────── */

.pulse {
  animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── TOAST ────────────────────────────────────────────────────── */

#toast {
  position: fixed;
  bottom: var(--space-7);
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-elevated);
  border: var(--border-gold);
  border-radius: var(--radius-md);
  padding: 10px var(--space-5);
  font-size: var(--text-sm);
  color: var(--ink);
  z-index: 10000;
  transition: transform var(--duration-slow) var(--ease);
  white-space: nowrap;
  pointer-events: none;
}

#toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ── SCROLLBAR ────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--ink-faint);
  border-radius: 2px;
}

/* ── REVEAL ANIMATION ─────────────────────────────────────────── */

.fade-in {
  animation: fadeIn var(--duration-slow) var(--ease) both;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-in-1 { animation-delay: 0.05s; }
.fade-in-2 { animation-delay: 0.10s; }
.fade-in-3 { animation-delay: 0.15s; }
.fade-in-4 { animation-delay: 0.20s; }
.fade-in-5 { animation-delay: 0.25s; }

/* ── HAMBURGER ────────────────────────────────────────────────── */

#hamburger {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 32px;
  height: 32px;
  padding: 4px;
  background: none;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}

#hamburger span {
  display: block;
  width: 18px;
  height: 1px;
  background: var(--ink-dim);
  border-radius: 1px;
  transition: transform var(--duration-base) var(--ease),
              opacity  var(--duration-base) var(--ease),
              background var(--duration-base);
  transform-origin: center;
}

#hamburger:hover span { background: var(--gold); }

#app.sidebar-open #hamburger span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
#app.sidebar-open #hamburger span:nth-child(2) { opacity: 0; transform: scaleX(0); }
#app.sidebar-open #hamburger span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ── BACK TO TOP ──────────────────────────────────────────────── */

.page-header { position: relative; }

.back-to-top {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 500;
  transition: all var(--duration-base) var(--ease);
  box-shadow: 0 0 16px var(--gold-glow), var(--shadow-md);
  animation: bttPulse 3s ease-in-out infinite;
}

@keyframes bttPulse {
  0%, 100% { box-shadow: 0 0 16px var(--gold-glow), var(--shadow-md); }
  50%       { box-shadow: 0 0 28px var(--gold-pulse), var(--shadow-md); }
}

.back-to-top:hover {
  background: var(--bg-elevated);
  border-color: var(--gold);
  transform: scale(1.1);
  box-shadow: 0 0 32px var(--gold-pulse), var(--shadow-md);
}

/* ── RESPONSIVE ───────────────────────────────────────────────── */

@media (max-width: 900px) {
  #main { padding: var(--space-5); }
  .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .grid-2           { grid-template-columns: 1fr; }
}
