:root {
  --radius-pill: 999px;
  --radius-card: 32px;
  --radius-sm: 14px;
  --space-xs: 4px; --space-sm: 8px; --space-md: 16px; --space-lg: 24px; --space-xl: 48px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --t-el: background-color 0.3s ease, transform 0.2s ease, opacity 0.3s ease, border-color 0.3s ease;

  --bg-base: #0F1B31;
  --bg-surface-1: rgba(232, 236, 243, 0.03);
  --bg-surface-2: rgba(232, 236, 243, 0.06);
  --bg-surface-3: rgba(232, 236, 243, 0.12);
  --bg-accent: #C4B896;
  --bg-accent-hover: #D4C8A6;
  --text-primary: #E8ECF3;
  --text-secondary: rgba(232, 236, 243, 0.55);
  --text-accent: #0F1B31;
  --text-tech: rgba(232, 236, 243, 0.3);
  --error-color: #E89090;
  --ok-color: #8FB99A;
  --glow-color: 196, 184, 150;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

body {
  font-family: 'DM Sans', sans-serif;
  background-color: var(--bg-base);
  background-image: linear-gradient(135deg, var(--bg-base) 0%, #16233E 50%, #0A1428 100%);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#webgl-container { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0; pointer-events: none; }
body.authed #webgl-container { display: none; }

h1, h2 { font-family: 'Cormorant Garamond', serif; font-weight: 300; letter-spacing: 0.01em; }

/* tech labels (scattered, login only) */
.tech-label {
  position: fixed; font-family: 'JetBrains Mono', monospace; font-size: 10px;
  letter-spacing: 0.2em; color: var(--text-tech); text-transform: uppercase; z-index: 5;
}
.label-top-left { top: 48px; left: 48px; } .label-bottom-left { bottom: 48px; left: 48px; }
.label-vertical-right { top: 50%; right: 40px; transform: translateY(-50%) rotate(90deg); transform-origin: center right; display: flex; gap: 24px; }
.label-vertical-right::before { content: '['; opacity: .5; } .label-vertical-right::after { content: ']'; opacity: .5; }
body.authed .tech-label { display: none; }

/* ---------- LOGIN (mirrors the auth landing page) ---------- */
#login { position: relative; z-index: 10; min-height: 100vh; display: flex; align-items: center; justify-content: flex-end; padding: var(--space-xl); }
.auth-wrapper { display: flex; align-items: center; justify-content: center; width: 50%; }
.auth-panel {
  width: 100%; max-width: 440px; background-color: var(--bg-surface-1); border: 1px solid var(--bg-surface-2);
  border-radius: var(--radius-card); padding: var(--space-xl); display: flex; flex-direction: column; gap: 28px;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}
.header-group { display: flex; flex-direction: column; gap: var(--space-xs); }
.system-badge {
  font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--text-primary); background: var(--bg-surface-2);
  padding: 5px 12px; border-radius: var(--radius-pill); align-self: flex-start; margin-bottom: var(--space-md);
  letter-spacing: 0.15em; text-transform: uppercase;
}
#login h1 { font-size: 44px; line-height: 1.05; margin-bottom: 6px; }
.accent { color: var(--bg-accent); font-style: italic; }
.subtitle { color: var(--text-secondary); font-size: 13px; letter-spacing: 0.02em; }
.tech-divider { display: flex; align-items: center; gap: var(--space-md); color: var(--text-tech); font-family: 'JetBrains Mono', monospace; font-size: 9px; letter-spacing: 0.15em; text-transform: uppercase; }
.tech-divider::before, .tech-divider::after { content: ""; flex: 1; height: 1px; background-color: var(--bg-surface-2); }
.form-group { display: flex; flex-direction: column; gap: var(--space-md); }
.input-wrapper { display: flex; flex-direction: column; gap: 8px; }
.input-wrapper label { font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--text-secondary); padding-left: 18px; letter-spacing: 0.15em; text-transform: uppercase; }

input, select {
  width: 100%; padding: 0 22px; height: 52px; border: 1px solid transparent; outline: none;
  border-radius: var(--radius-pill); background-color: var(--bg-surface-2); color: var(--text-primary);
  font-family: 'DM Sans', sans-serif; font-size: 14px; transition: var(--t-el);
}
select { padding: 0 16px; }
input::placeholder { color: var(--text-tech); }
input:focus, select:focus { background-color: var(--bg-surface-3); border-color: var(--bg-accent); }
.error-msg { font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--error-color); letter-spacing: 0.1em; text-transform: uppercase; padding-left: 18px; min-height: 12px; opacity: 0; transition: opacity .2s ease; }
.error-msg:not(:empty) { opacity: 1; }

button { border: none; outline: none; border-radius: var(--radius-pill); cursor: pointer; font-family: 'DM Sans', sans-serif; font-weight: 500; transition: var(--t-el); display: inline-flex; align-items: center; justify-content: center; gap: 10px; }
.btn-primary {
  height: 56px; background-color: var(--bg-accent); color: var(--text-accent); font-size: 13px; letter-spacing: 0.15em;
  text-transform: uppercase; box-shadow: 0 0 40px rgba(var(--glow-color), 0.15);
}
.btn-primary:hover:not(:disabled) { background-color: var(--bg-accent-hover); transform: translateY(-1px); box-shadow: 0 0 60px rgba(var(--glow-color), 0.25); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary.compact { height: 44px; padding: 0 22px; }
.btn-primary .arrow { font-family: 'JetBrains Mono', monospace; }
.btn-primary:hover:not(:disabled) .arrow { transform: translateX(3px); }

button.ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--bg-surface-2); height: 40px; padding: 0 18px; font-size: 12px; letter-spacing: .04em; }
button.ghost:hover { color: var(--text-primary); border-color: var(--bg-accent); }
button.small { height: 30px; padding: 0 12px; font-size: 11px; font-family: 'JetBrains Mono', monospace; letter-spacing: .08em; }

/* ---------- APP SHELL ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px; padding: 16px 30px;
  background: rgba(15, 27, 49, 0.72); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--bg-surface-2);
}
.brand { font-family: 'Cormorant Garamond', serif; font-size: 26px; font-weight: 400; }
.brand .accent { font-size: 13px; font-family: 'JetBrains Mono', monospace; letter-spacing: .1em; }
.tabs { display: flex; gap: 6px; flex: 1; }
.tabs button { background: transparent; color: var(--text-secondary); border: 1px solid transparent; border-radius: var(--radius-pill); height: 38px; padding: 0 20px; font-size: 13px; }
.tabs button.active { color: var(--bg-accent); border-color: var(--bg-surface-2); background: var(--bg-surface-1); }
.tabs button:hover { color: var(--text-primary); }

.tab { display: none; flex-direction: column; gap: 22px; max-width: 1080px; margin: 0 auto; padding: 30px; }
.tab.active { display: flex; }
.panel { background: var(--bg-surface-1); border: 1px solid var(--bg-surface-2); border-radius: var(--radius-card); padding: 26px 28px; backdrop-filter: blur(12px); }
.panel h2 { font-size: 26px; margin-bottom: 18px; }
.panel h2 .sub, .hint { color: var(--text-tech); font-size: 12px; font-style: italic; font-family: 'DM Sans', sans-serif; }
.panel.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.panel.inline input { width: auto; flex: 1; min-width: 180px; height: 44px; }
.panel.inline label { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 13px; }
.panel.inline input[type=checkbox] { width: auto; height: auto; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--bg-surface-2); font-size: 13px; }
th { color: var(--text-tech); font-family: 'JetBrains Mono', monospace; font-weight: 400; font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
td { font-family: 'JetBrains Mono', monospace; color: var(--text-primary); }
.pill { padding: 3px 11px; border-radius: var(--radius-pill); font-size: 11px; border: 1px solid var(--bg-surface-2); font-family: 'JetBrains Mono', monospace; }
.pill.admin { color: var(--bg-accent); border-color: var(--bg-accent); }
.pill.on, .pill.allow { color: var(--ok-color); border-color: var(--ok-color); }
.pill.off, .pill.deny { color: var(--error-color); border-color: var(--error-color); }
.pill.shadow { color: var(--text-tech); }
td.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* access */
.access-head { display: flex; gap: 24px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.access-head label { color: var(--text-secondary); display: flex; gap: 8px; align-items: center; font-size: 13px; }
.access-head select { width: auto; min-width: 150px; height: 40px; }
.defswitch #default-state { color: var(--text-primary); font-weight: 500; }
.custom-grant { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.custom-grant input { flex: 1; height: 44px; }
.group-h { margin: 18px 0 4px; color: var(--bg-accent); font-family: 'JetBrains Mono', monospace; font-size: 11px; text-transform: uppercase; letter-spacing: .14em; border-bottom: 1px solid var(--bg-surface-2); padding-bottom: 5px; }
.group-h:first-child { margin-top: 6px; }
.tree { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; }
.row { display: flex; align-items: center; gap: 14px; padding: 8px 10px; border-radius: var(--radius-sm); }
.row:hover { background: var(--bg-surface-1); }
.row .rpath { flex: 1; min-width: 0; font-family: 'JetBrains Mono', monospace; }
.row .rpath b { color: var(--text-primary); font-weight: 500; }
.row .rpath small { color: var(--text-tech); display: block; font-size: 11px; font-family: 'DM Sans', sans-serif; margin-top: 2px; }
.seg { display: flex; border: 1px solid var(--bg-surface-2); border-radius: var(--radius-pill); overflow: hidden; }
.seg button { background: transparent; color: var(--text-secondary); border-radius: 0; height: 30px; padding: 0 14px; font-size: 11px; font-family: 'JetBrains Mono', monospace; letter-spacing: .06em; }
.seg button.sel-inherit { background: var(--bg-surface-3); color: var(--text-primary); }
.seg button.sel-allow { background: rgba(143, 185, 154, .18); color: var(--ok-color); }
.seg button.sel-deny { background: rgba(232, 144, 144, .18); color: var(--error-color); }

.toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); background: rgba(15,27,49,.92); border: 1px solid var(--bg-accent); color: var(--text-primary); padding: 11px 20px; border-radius: var(--radius-pill); font-size: 13px; z-index: 40; backdrop-filter: blur(10px); box-shadow: 0 0 40px rgba(var(--glow-color), .15); }

@media (max-width: 1024px) {
  #login { justify-content: center; padding: var(--space-md); }
  .auth-wrapper { width: 100%; }
  .label-vertical-right { display: none; }
}
@media (max-width: 600px) {
  .auth-panel { padding: var(--space-lg); } #login h1 { font-size: 36px; }
  .label-top-left, .label-bottom-left { display: none; }
  .topbar { flex-wrap: wrap; gap: 12px; padding: 14px 18px; } .tab { padding: 18px; }
}
