/* ========== Z-AMPP Design System ========== */
:root {
  /* base palette - dark, gray-leaning, frame.io inspired */
  --bg-0: #0B0D11;
  --bg-1: #14171E;
  --bg-2: #1B1F27;
  --bg-3: #232833;
  --bg-4: #2D3340;
  --hover: rgba(255,255,255,0.04);
  --hover-strong: rgba(255,255,255,0.07);
  --border: rgba(255,255,255,0.06);
  --border-strong: rgba(255,255,255,0.10);
  --border-stronger: rgba(255,255,255,0.14);

  /* text */
  --text-1: #F2F3F6;
  --text-2: #A8AEBC;
  --text-3: #8B92A0;  /* WCAG AA (#133) - was #6B7280, 4.06:1 vs --bg-0; now ~7.5:1 */
  --text-4: #6B7280;

  /* accent — Flame Blue (Wild Dragon brand, Pantone 286 C) */
  --accent: #1025A1;
  --accent-hover: #1830B8;
  --accent-soft: rgba(16, 37, 161, 0.14);
  --accent-soft-2: rgba(16, 37, 161, 0.22);
  --accent-text: #C7CFEA;

  /* status */
  --success: #2DD4A8;
  --success-soft: rgba(45, 212, 168, 0.14);
  --warning: #F5A623;
  --warning-soft: rgba(245, 166, 35, 0.14);
  --danger: #FF5B5B;
  --danger-soft: rgba(255, 91, 91, 0.14);
  --live: #FF3B30;
  --live-soft: rgba(255, 59, 48, 0.18);
  --purple: #B57CFA;
  --purple-soft: rgba(181, 124, 250, 0.14);

  /* radius */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  /* shadow */
  --shadow-pop: 0 12px 32px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.25);
  --shadow-card: 0 1px 0 rgba(255,255,255,0.04) inset, 0 1px 2px rgba(0,0,0,0.3);

  /* sizing (density tweakable) */
  --sidebar-w: 232px;
  --row-h: 44px;
  --topbar-h: 48px;
  --gap: 16px;

  /* fonts */
  --font-sans: "Geist", "Söhne", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "Geist Mono", "JetBrains Mono", ui-monospace, monospace;
}

/* density tweak */
[data-density="compact"] {
  --row-h: 36px;
  --topbar-h: 48px;
  --gap: 12px;
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; }
body {
  margin: 0;
  background: var(--bg-0);
  color: var(--text-1);
  font-family: var(--font-sans);
  font-feature-settings: "ss01", "cv11";
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.07); border-radius: 99px; border: 2px solid var(--bg-0); }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.14); }

/* ========== Layout ========== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  background: var(--bg-0);
}
.app[data-sidebar="collapsed"] { --sidebar-w: 56px; }

/* ========== Sidebar ========== */
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #FF6B35 0%, #C8362D 50%, #5B2D8A 100%);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  color: white;
  letter-spacing: -0.02em;
  flex-shrink: 0;
  box-shadow: 0 0 12px rgba(255, 107, 53, 0.25);
}
.brand-name {
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 14px;
  white-space: nowrap;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-3);
  margin-left: auto;
  font-family: var(--font-mono);
  white-space: nowrap;
}
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
}
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-4);
  padding: 14px 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  height: 32px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 80ms, color 80ms;
  position: relative;
}
.nav-item:hover {
  background: var(--hover);
  color: var(--text-1);
}
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.nav-item.active .nav-icon { color: var(--accent); }
.nav-item.has-children > .nav-caret {
  margin-left: auto;
  opacity: 0.5;
  transition: transform 120ms;
}
.nav-item.has-children.open > .nav-caret { transform: rotate(90deg); }
.nav-icon {
  width: 16px; height: 16px;
  color: var(--text-3);
  flex-shrink: 0;
}
.nav-item:hover .nav-icon { color: var(--text-2); }
.nav-children {
  margin: 2px 0 4px 22px;
  border-left: 1px solid var(--border-strong);
  padding-left: 6px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.nav-children .nav-item {
  height: 28px;
  font-size: 12.5px;
  font-weight: 450;
}
.nav-badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-3);
  background: var(--bg-3);
  padding: 1px 6px;
  border-radius: 99px;
  line-height: 1.5;
}
.nav-badge.dev {
  color: var(--warning);
  background: var(--warning-soft);
}
.nav-badge.live {
  color: var(--live);
  background: var(--live-soft);
  display: flex;
  align-items: center;
  gap: 4px;
}
.nav-badge.live::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--live);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  display: grid; place-items: center;
  font-weight: 700; font-size: 11px;
  color: #fff;
  flex-shrink: 0;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.user-name { font-size: 12.5px; font-weight: 500; }
.user-role { font-size: 11px; color: var(--text-3); }
.user-meta .user-name, .user-meta .user-role { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ========== Top bar ========== */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
  background: var(--bg-0);
}
.crumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-2);
}
.crumb .sep { color: var(--text-4); }
.crumb .current { color: var(--text-1); font-weight: 500; }
.topbar .spacer { flex: 1; }
.status-pip {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px;
  color: var(--text-3);
  font-family: var(--font-mono);
}
.status-pip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.status-pip.warn .dot { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }

.icon-btn {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  color: var(--text-2);
  transition: background 80ms, color 80ms;
}
.icon-btn:hover { background: var(--hover); color: var(--text-1); }
.icon-btn svg { width: 16px; height: 16px; }

.search {
  position: relative;
  height: 32px;
  width: 280px;
  display: flex; align-items: center;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0 12px 0 32px;
  color: var(--text-2);
  font-size: 12.5px;
  transition: border 80ms, background 80ms;
}
.search:focus-within {
  border-color: var(--accent);
  background: var(--bg-2);
}
.search input { flex: 1; outline: 0; border: 0; background: transparent; min-width: 0; }
.search .search-icon {
  position: absolute;
  left: 10px;
  width: 14px; height: 14px;
  color: var(--text-3);
}
.kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-3);
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  line-height: 1.2;
}

/* ========== Buttons ========== */
.btn {
  height: 32px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background 80ms, border 80ms, color 80ms;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--hover); color: var(--text-1); }
.btn.subtle { background: var(--bg-2); color: var(--text-1); border-color: var(--border); }
.btn.subtle:hover { background: var(--bg-3); border-color: var(--border-strong); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.danger:hover { background: rgba(255,91,91,0.22); }
.btn svg { width: 14px; height: 14px; }
.btn.lg { height: 36px; padding: 0 16px; font-size: 13px; }
.btn.sm { height: 26px; padding: 0 10px; font-size: 12px; }
.btn.icon-only { padding: 0; width: 32px; justify-content: center; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ========== Badges ========== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}
.badge.live { background: var(--live-soft); color: var(--live); }
.badge.live::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--live); animation: pulse 1.6s ease-in-out infinite; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); }
.badge.neutral { background: var(--bg-3); color: var(--text-2); }
.badge.purple { background: var(--purple-soft); color: var(--purple); }
.badge.outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text-2); }

/* ========== Cards / Panels ========== */
.panel {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.panel-header {
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}
.panel-header h3 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.panel-body { padding: 16px; }

/* ========== Page chrome ========== */
.page {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
.page-header {
  padding: 24px 28px 8px;
  display: flex;
  align-items: flex-end;
  gap: 16px;
}
.page-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.page-header .subtitle {
  color: var(--text-3);
  font-size: 13px;
}
.page-header .spacer { flex: 1; }
.page-body { padding: 16px 28px 40px; }

/* ========== Generic utility ========== */
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; }
.muted { color: var(--text-3); }
.subtle-text { color: var(--text-2); font-size: 12.5px; }
.mono { font-family: var(--font-mono); }
.divider { height: 1px; background: var(--border); margin: 12px 0; }

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 200ms ease both; }

[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-4);
  color: var(--text-1);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  z-index: 100;
  pointer-events: none;
  border: 1px solid var(--border-strong);
}
