/* ─── Design Tokens ─── */
:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --surface-hover: #f3f4f6;
  --text: #111827;
  --text2: #6b7280;
  --text3: #9ca3af;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-light: #ede9fe;
  --accent-subtle: #f5f3ff;
  --green: #22c55e;
  --green-light: #dcfce7;
  --red: #ef4444;
  --red-light: #fee2e2;
  --orange: #f59e0b;
  --orange-light: #fef3c7;
  --blue: #3b82f6;
  --blue-light: #dbeafe;
  --teal: #14b8a6;
  --teal-light: #ccfbf1;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.08), 0 8px 10px -6px rgba(0,0,0,.04);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --sidebar-width: 256px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #1a1c25;
    --surface-hover: #252830;
    --text: #f3f4f6;
    --text2: #9ca3af;
    --text3: #6b7280;
    --accent-light: #2e1e5e;
    --accent-subtle: #1e1535;
    --green-light: #052e16;
    --red-light: #450a0a;
    --orange-light: #451a03;
    --blue-light: #172554;
    --teal-light: #042f2e;
    --border: #2d2f3a;
    --border-light: #23252e;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.2);
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.3), 0 2px 4px -2px rgba(0,0,0,.2);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.3), 0 4px 6px -4px rgba(0,0,0,.2);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.3), 0 8px 10px -6px rgba(0,0,0,.2);
  }
}

/* Manual theme overrides (take precedence over @media queries) */
html.dark {
  --bg: #0f1117;
  --surface: #1a1c25;
  --surface-hover: #252830;
  --text: #f3f4f6;
  --text2: #9ca3af;
  --text3: #6b7280;
  --accent-light: #2e1e5e;
  --accent-subtle: #1e1535;
  --green-light: #052e16;
  --red-light: #450a0a;
  --orange-light: #451a03;
  --blue-light: #172554;
  --teal-light: #042f2e;
  --border: #2d2f3a;
  --border-light: #23252e;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.2);
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.3), 0 2px 4px -2px rgba(0,0,0,.2);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.3), 0 4px 6px -4px rgba(0,0,0,.2);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.3), 0 8px 10px -6px rgba(0,0,0,.2);
}
html.light {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --surface-hover: #f3f4f6;
  --text: #111827;
  --text2: #6b7280;
  --text3: #9ca3af;
  --accent-light: #ede9fe;
  --accent-subtle: #f5f3ff;
  --green-light: #dcfce7;
  --red-light: #fee2e2;
  --orange-light: #fef3c7;
  --blue-light: #dbeafe;
  --teal-light: #ccfbf1;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,.08), 0 8px 10px -6px rgba(0,0,0,.04);
}

/* ─── Reset & Base ─── */
.hidden { display: none !important; }
.mt-24 { margin-top: 28px; }
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Auth Screen ─── */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 50%, #2563eb 100%);
}
.auth-bg-pattern {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 80%, rgba(255,255,255,.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255,255,255,.06) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.03) 0%, transparent 70%);
  animation: authPulse 8s ease-in-out infinite alternate;
}
@keyframes authPulse {
  from { opacity: .6; }
  to { opacity: 1; }
}
.auth-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255,255,255,.1);
  position: relative;
  z-index: 1;
  animation: authSlideIn .5s cubic-bezier(.16,1,.3,1);
}
@keyframes authSlideIn {
  from { opacity: 0; transform: translateY(20px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.auth-logo-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 6px;
}
.auth-logo-icon { width: 40px; height: 40px; flex-shrink: 0; }
.auth-logo-icon svg { width: 100%; height: 100%; border-radius: 10px; }
.auth-logo-text { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.auth-subtitle { text-align: center; color: var(--text2); font-size: 14px; margin-bottom: 32px; }
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text2);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all .2s;
  font-family: var(--font);
}
.auth-tab-active {
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow-sm);
}
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.input-group { position: relative; }
.input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text3);
  pointer-events: none;
}
.auth-form input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  transition: border-color .2s, box-shadow .2s;
}
.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.btn-auth {
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all .2s;
  box-shadow: 0 1px 3px rgba(124,58,237,.3);
}
.btn-auth:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(124,58,237,.35); }
.btn-auth:active { transform: translateY(0); }
.btn-auth:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.auth-error { color: var(--red); font-size: 13px; text-align: center; margin-top: 8px; min-height: 20px; }

/* ─── App Layout ─── */
.app-layout {
  min-height: 100vh;
}

/* ─── Sidebar ─── */
.sidebar {
  background: #111318;
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  z-index: 150;
  border-right: 1px solid rgba(255,255,255,.06);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 24px;
}
.sidebar-logo-icon { width: 32px; height: 32px; flex-shrink: 0; border-radius: 8px; }
.sidebar-logo-text { font-size: 18px; font-weight: 700; color: white; letter-spacing: -.01em; }

.sidebar-nav { flex: 1; padding: 0 12px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: #9ca3af;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all .15s;
  width: 100%;
  text-align: left;
  font-family: var(--font);
}
.sidebar-item svg { width: 20px; height: 20px; flex-shrink: 0; opacity: .7; }
.sidebar-item:hover { background: rgba(255,255,255,.06); color: #e5e7eb; }
.sidebar-item:hover svg { opacity: 1; }
.sidebar-item-active {
  background: rgba(124,58,237,.15);
  color: #c4b5fd;
}
.sidebar-item-active svg { opacity: 1; color: #a78bfa; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-user { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: white;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-user-info { display: flex; flex-direction: column; min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #e5e7eb; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-connection { font-size: 11px; color: #6b7280; }
.sidebar-logout {
  padding: 8px;
  border: none;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  border-radius: 6px;
  transition: all .15s;
  display: flex;
}
.sidebar-logout svg { width: 18px; height: 18px; }
.sidebar-logout:hover { background: rgba(239,68,68,.1); color: #ef4444; }

/* ─── Mobile Header ─── */
.mobile-header {
  display: none;
  position: sticky;
  top: 0;
  z-index: 100;
  background: #111318;
  color: white;
  padding: 12px 16px;
  align-items: center;
  gap: 12px;
}
.mobile-menu-btn {
  padding: 8px;
  border: none;
  background: transparent;
  color: white;
  cursor: pointer;
  border-radius: 6px;
}
.mobile-menu-btn svg { width: 22px; height: 22px; }
.mobile-title { font-size: 16px; font-weight: 700; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 140;
  backdrop-filter: blur(2px);
}

@media (max-width: 768px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { transform: translateX(-100%); transition: transform .3s cubic-bezier(.4,0,.2,1); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .mobile-header { display: flex; }
  .content-area { padding-top: 0; }
}

/* ─── Content Area ─── */
.content-area {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  overflow-y: auto;
}
@media (max-width: 768px) {
  .content-area { margin-left: 0; }
}

main { max-width: 1200px; margin: 0 auto; padding: 32px; }
@media (max-width: 768px) { main { padding: 20px 16px; } }

.page-header { margin-bottom: 28px; }
.page-title { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-bottom: 4px; }
.page-desc { color: var(--text2); font-size: 15px; }

/* ─── Stat Cards ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: all .2s;
  box-shadow: var(--shadow-sm);
}
.stat-card:hover { box-shadow: var(--shadow); }
.stat-card-accent { border-color: var(--accent); background: var(--accent-subtle); }
.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon-blue { background: var(--blue-light); color: var(--blue); }
.stat-icon-purple { background: var(--accent-light); color: var(--accent); }
.stat-icon-teal { background: var(--teal-light); color: var(--teal); }
.stat-icon-orange { background: var(--orange-light); color: var(--orange); }
.stat-icon-red { background: var(--red-light); color: var(--red); }
.stat-icon-green { background: var(--green-light); color: var(--green); }
.stat-info { min-width: 0; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 2px; text-transform: uppercase; letter-spacing: .5px; font-weight: 500; }

/* ─── Layout Grid ─── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }
@media (max-width: 768px) { .two-col { grid-template-columns: 1fr; } }

/* ─── Panels ─── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}
.panel h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.h2-sub { font-weight: 400; color: var(--text3); font-size: 13px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.panel-header h2 { margin-bottom: 0; }
.panel-title-row { display: flex; align-items: center; gap: 10px; }
.panel-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
}

.list-container { max-height: 400px; overflow-y: auto; }
.empty { color: var(--text3); text-align: center; padding: 32px; font-size: 14px; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 60px 24px; color: var(--text3); }
.empty-icon { width: 48px; height: 48px; opacity: .5; }

/* ─── Buttons ─── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: white;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all .2s;
  box-shadow: 0 1px 3px rgba(124,58,237,.25);
  white-space: nowrap;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(124,58,237,.3); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-small {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all .15s;
}
.btn-small:hover { transform: translateY(-1px); }
.btn-accent { background: var(--accent); color: white; box-shadow: 0 1px 2px rgba(124,58,237,.2); }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-approve, .btn-deny {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-weight: 600;
  transition: all .15s;
  font-family: var(--font);
}
.btn-approve { background: var(--green); color: white; box-shadow: 0 1px 2px rgba(34,197,94,.2); }
.btn-deny { background: var(--red); color: white; box-shadow: 0 1px 2px rgba(239,68,68,.2); }
.btn-approve:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(34,197,94,.3); }
.btn-deny:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(239,68,68,.3); }

.btn-danger-outline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1.5px solid var(--red);
  border-radius: 6px;
  background: transparent;
  color: var(--red);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all .15s;
}
.btn-danger-outline:hover { background: var(--red); color: white; }

/* ─── Request Items ─── */
.request-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background .15s;
  border-radius: var(--radius-sm);
  margin: 0 -4px;
  padding-left: 16px;
  padding-right: 16px;
}
.request-item:hover { background: var(--surface-hover); }
.request-item:last-child { border-bottom: none; }
.tool-badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.tool-Bash { background: var(--orange-light); color: #b45309; }
.tool-Write { background: var(--red-light); color: #b91c1c; }
.tool-Edit { background: var(--orange-light); color: #92400e; }
.tool-Read { background: var(--blue-light); color: #1d4ed8; }
.tool-default { background: var(--accent-light); color: #6d28d9; }
.request-summary { flex: 1; font-family: var(--mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text2); }
.request-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ─── Bar Chart ─── */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; padding: 4px 0; border-radius: 6px; transition: background .15s; }
.bar-row:hover { background: var(--surface-hover); }
.bar-label { width: 80px; font-size: 13px; font-weight: 600; color: var(--text2); }
.bar-track { flex: 1; height: 24px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; transition: width .5s cubic-bezier(.4,0,.2,1); }
.bar-count { min-width: 70px; font-size: 13px; font-weight: 600; text-align: right; color: var(--text); }
.bar-pct { font-weight: 400; font-size: 11px; color: var(--text2); }

#approvalTrendChart { width: 100%; height: 180px; }

/* ─── Activity Items ─── */
.activity-item {
  padding: 12px 8px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
  display: flex;
  gap: 10px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background .15s;
  flex-wrap: wrap;
  align-items: center;
}
.activity-item:hover { background: var(--surface-hover); }
.activity-item:last-child { border-bottom: none; }
.activity-time { color: var(--text3); font-size: 11px; white-space: nowrap; font-family: var(--mono); }
.activity-event {
  font-weight: 600;
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--accent-subtle);
  color: var(--accent);
}
.activity-details {
  width: 100%;
  font-size: 12px;
  color: var(--text2);
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
  display: none;
  border: 1px solid var(--border-light);
}
.activity-item.expanded .activity-details { display: block; }
.activity-expand { color: var(--accent); font-size: 11px; margin-left: auto; font-weight: 500; }

/* ─── Device Items ─── */
.device-item {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.device-item:hover { background: var(--surface-hover); }
.device-item:last-child { border-bottom: none; }
.device-name { font-weight: 600; font-size: 14px; }
.device-meta { font-size: 12px; color: var(--text3); margin-top: 2px; }
.device-actions { display: flex; gap: 6px; }
.btn-unpair {
  padding: 5px 12px;
  border: 1.5px solid var(--red);
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 600;
  background: transparent;
  color: var(--red);
  opacity: 0;
  transition: all .15s;
  font-family: var(--font);
}
.device-item:hover .btn-unpair { opacity: 1; }
.btn-unpair:hover { background: var(--red); color: white; }

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: modalFadeIn .2s;
}
@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: modalSlideIn .3s cubic-bezier(.16,1,.3,1);
  border: 1px solid var(--border);
}
@keyframes modalSlideIn { from { opacity: 0; transform: scale(.96) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-card h3 { font-size: 18px; font-weight: 700; margin-bottom: 20px; letter-spacing: -.01em; }
.modal-card pre {
  background: var(--bg);
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  overflow-x: auto;
  margin: 8px 0;
  font-family: var(--mono);
  border: 1px solid var(--border-light);
  line-height: 1.6;
}
.modal-card .modal-actions { display: flex; gap: 8px; margin-top: 20px; justify-content: flex-end; }
.modal-card .btn-close {
  padding: 8px 18px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  transition: all .15s;
}
.modal-card .btn-close:hover { background: var(--surface-hover); }

.modal-form { display: flex; flex-direction: column; gap: 14px; }
.modal-form label { font-size: 13px; font-weight: 600; color: var(--text2); }
.modal-form input, .modal-form select {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  transition: border-color .2s, box-shadow .2s;
}
.modal-form input:focus, .modal-form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.modal-form .form-row { display: flex; gap: 14px; }
.modal-form .form-row > * { flex: 1; }

/* ─── AI Chat ─── */
.chat-tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 24px; }
.chat-tool-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  transition: all .2s;
  box-shadow: var(--shadow-sm);
  font-family: var(--font);
}
.chat-tool-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.chat-tool-card:active { transform: translateY(0); }
.chat-tool-card.active { border-color: var(--accent); background: var(--accent-subtle); box-shadow: 0 0 0 3px var(--accent-light); }
.chat-tool-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  color: white;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.chat-tool-info { min-width: 0; }
.chat-tool-name { font-weight: 600; font-size: 14px; color: var(--text); }
.chat-tool-desc { font-size: 12px; color: var(--text3); margin-top: 1px; }

.chat-agent-status {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 20px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.chat-agent-online { background: var(--green-light); color: #15803d; border: 1px solid rgba(34,197,94,.2); }
.chat-agent-offline { background: var(--orange-light); color: #92400e; border: 1px solid rgba(245,158,11,.2); }

.chat-sessions-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.chat-sessions-header h2 { font-size: 16px; font-weight: 600; color: var(--text); }

.chat-sessions-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.chat-session-item {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background .15s;
}
.chat-session-item:last-child { border-bottom: none; }
.chat-session-item:hover { background: var(--surface-hover); }
.chat-session-name { font-weight: 600; font-size: 14px; }
.chat-session-meta { font-size: 12px; color: var(--text3); margin-top: 2px; }
.chat-session-status {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.chat-session-status.streaming { background: var(--green-light); color: #15803d; }
.chat-session-status.idle { background: var(--accent-light); color: var(--accent); }

/* Chat View */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.chat-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  transition: all .15s;
}
.chat-back-btn:hover { background: var(--surface-hover); border-color: var(--accent); }
.chat-view-title { flex: 1; font-weight: 700; font-size: 16px; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  min-height: 400px;
  max-height: calc(100vh - 280px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-msg {
  padding: 14px 18px;
  border-radius: var(--radius);
  max-width: 85%;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: msgFadeIn .3s;
}
@keyframes msgFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.chat-msg.user {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(124,58,237,.2);
}
.chat-msg.assistant {
  background: var(--surface);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}
.chat-msg.assistant pre {
  background: var(--bg);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13px;
  border: 1px solid var(--border-light);
}
.chat-msg.assistant code { font-family: var(--mono); font-size: 13px; }
.chat-msg.error {
  background: var(--red-light);
  color: #b91c1c;
  align-self: center;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid rgba(239,68,68,.2);
}
.chat-msg.streaming { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); }

.chat-input-bar {
  display: flex;
  gap: 10px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  resize: none;
  max-height: 120px;
  font-family: var(--font);
  transition: border-color .2s, box-shadow .2s;
  line-height: 1.5;
}
.chat-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.chat-voice-btn {
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-voice-btn:hover { color: var(--purple); border-color: var(--purple); }
.chat-voice-btn.listening {
  color: #ef4444;
  border-color: #ef4444;
  background: rgba(239,68,68,.08);
  animation: voice-pulse 1.5s ease-in-out infinite;
}
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.3); }
  50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}
.chat-send-btn {
  padding: 12px 14px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: white;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(124,58,237,.25);
}
.chat-send-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(124,58,237,.3); }
.chat-send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ─── Canvas Charts ─── */
canvas { width: 100%; border-radius: var(--radius-sm); }

/* ─── Sidebar Badge ─── */
.sidebar-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--red);
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
}
.sidebar-badge.has-count { display: inline-flex; }

/* ─── Requests Tab ─── */
.requests-full-list { max-height: 600px; }
.requests-actions { display: flex; gap: 8px; }

/* ─── Settings Tab ─── */
.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-light);
}
.settings-row:last-child { border-bottom: none; }
.settings-row-info { flex: 1; }
.settings-row-label { font-size: 14px; font-weight: 600; color: var(--text); }
.settings-row-desc { font-size: 13px; color: var(--text3); margin-top: 2px; }
.theme-selector {
  display: flex;
  gap: 6px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.theme-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: all .15s;
  font-family: var(--font);
}
.theme-option:hover { color: var(--text); background: var(--surface-hover); }
.theme-option.active { background: var(--accent); color: white; box-shadow: var(--shadow-sm); }
.settings-form { display: flex; flex-direction: column; gap: 16px; max-width: 400px; }
.settings-form-group { display: flex; flex-direction: column; gap: 6px; }
.settings-form-group label { font-size: 13px; font-weight: 600; color: var(--text2); }
.settings-form-group input {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  transition: border-color .2s, box-shadow .2s;
}
.settings-form-group input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.settings-form-actions { display: flex; align-items: center; gap: 12px; }
.settings-form-status { font-size: 13px; font-weight: 500; }
.settings-form-status.success { color: var(--green); }
.settings-form-status.error { color: var(--red); }
.settings-hint { font-size: 13px; color: var(--text3); margin-bottom: 16px; }
.api-key-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background .15s;
}
.api-key-item:hover { background: var(--surface-hover); }
.api-key-item:last-child { border-bottom: none; }
.api-key-name { font-weight: 600; font-size: 14px; color: var(--text); }
.api-key-meta { font-size: 12px; color: var(--text3); margin-top: 2px; }
.api-key-prefix { font-family: var(--mono); font-size: 13px; color: var(--text2); background: var(--bg); padding: 2px 8px; border-radius: 4px; border: 1px solid var(--border-light); }
.api-key-info { flex: 1; min-width: 0; }
.api-key-actions { flex-shrink: 0; }
.api-key-reveal { background: var(--green-light); border: 1px solid rgba(34,197,94,.3); border-radius: var(--radius-sm); padding: 16px; margin-top: 16px; }
.api-key-reveal-label { font-size: 13px; font-weight: 600; color: #15803d; margin-bottom: 8px; }
.api-key-reveal-value { font-family: var(--mono); font-size: 14px; background: var(--surface); padding: 10px 14px; border-radius: 6px; word-break: break-all; user-select: all; border: 1px solid var(--border); color: var(--text); }
.api-key-reveal-warning { font-size: 12px; color: #92400e; margin-top: 8px; }

/* ─── Rules Management ─── */
.rules-action-bar { display: flex; gap: 10px; margin-bottom: 20px; }
.rule-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background .15s;
  border-radius: var(--radius-sm);
}
.rule-item:hover { background: var(--surface-hover); }
.rule-item:last-child { border-bottom: none; }
.rule-info { flex: 1; min-width: 0; }
.rule-info-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.rule-pattern { font-family: var(--mono); font-size: 13px; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rule-pattern-type { font-size: 11px; color: var(--text3); padding: 1px 6px; background: var(--bg); border-radius: 4px; }
.rule-action-badge {
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
  flex-shrink: 0;
}
.rule-action-allow { background: var(--green-light); color: #15803d; }
.rule-action-deny { background: var(--red-light); color: #b91c1c; }
.rule-priority { font-size: 11px; color: var(--text3); }
.rule-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.rule-toggle {
  position: relative;
  width: 36px;
  height: 20px;
  border: none;
  border-radius: 10px;
  background: var(--border);
  cursor: pointer;
  transition: background .2s;
  padding: 0;
}
.rule-toggle.active { background: var(--green); }
.rule-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  transition: transform .2s;
  box-shadow: var(--shadow-sm);
}
.rule-toggle.active::after { transform: translateX(16px); }
.rule-edit-btn, .rule-delete-btn {
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 600;
  font-family: var(--font);
  transition: all .15s;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text2);
}
.rule-edit-btn:hover { border-color: var(--accent); color: var(--accent); }
.rule-delete-btn:hover { border-color: var(--red); color: var(--red); }
.template-item {
  padding: 12px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all .15s;
}
.template-item:hover { background: var(--surface-hover); border-color: var(--accent); }
.template-item-name { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.template-item-desc { font-size: 12px; color: var(--text3); }

/* ─── Audit Controls ─── */
.audit-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.audit-filter-select {
  padding: 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  cursor: pointer;
}
.audit-filter-select:focus { outline: none; border-color: var(--accent); }
.btn-export {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all .15s;
}
.btn-export:hover { border-color: var(--accent); color: var(--accent); }
.event-badge {
  font-weight: 600;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.event-badge-created { background: var(--blue-light); color: #1d4ed8; }
.event-badge-responded { background: var(--green-light); color: #15803d; }
.event-badge-expired { background: var(--orange-light); color: #92400e; }
.event-badge-paired { background: var(--accent-light); color: #6d28d9; }
.event-badge-revoked { background: var(--red-light); color: #b91c1c; }
.event-badge-default { background: var(--accent-subtle); color: var(--accent); }

/* ─── Permission Search ─── */
.perm-search-panel { margin-bottom: 24px; }
.perm-search-row { display: flex; gap: 10px; margin-bottom: 10px; }
.perm-search-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  transition: border-color .2s, box-shadow .2s;
}
.perm-search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.perm-filter-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.filter-chip {
  padding: 5px 12px;
  border: 1.5px solid var(--border);
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text2);
  font-family: var(--font);
  transition: all .15s;
}
.filter-chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-chip.active { background: var(--accent); color: white; border-color: var(--accent); }
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  flex-shrink: 0;
}
.status-dot-approved { background: var(--green); }
.status-dot-denied { background: var(--red); }
.status-dot-pending { background: var(--blue); }
.status-dot-expired { background: var(--orange); }
.perm-result-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  transition: background .15s;
}
.perm-result-item:hover { background: var(--surface-hover); }
.perm-result-item:last-child { border-bottom: none; }
.perm-result-time { color: var(--text3); font-size: 11px; font-family: var(--mono); white-space: nowrap; }
.perm-result-summary { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text2); font-family: var(--mono); }

/* ─── Chat Abort Button ─── */
.chat-abort-btn {
  padding: 12px 14px;
  border: 2px solid var(--red);
  border-radius: var(--radius);
  background: transparent;
  color: var(--red);
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-abort-btn:hover { background: var(--red); color: white; }

/* ─── Typing Dots Animation ─── */
.typing-dots span {
  animation: typingBounce 1.4s infinite ease-in-out;
  display: inline-block;
  font-size: 24px;
  line-height: 1;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* ─── Chat Thinking & Tool Activity ─── */
.chat-thinking {
  background: var(--accent-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text2);
}
.chat-thinking summary {
  padding: 8px 12px;
  cursor: pointer;
  font-style: italic;
  font-weight: 500;
  color: var(--text3);
  user-select: none;
  list-style: none;
}
.chat-thinking summary::before {
  content: '\25B6 ';
  font-size: 10px;
  margin-right: 4px;
  display: inline-block;
  transition: transform .15s;
}
.chat-thinking[open] summary::before {
  transform: rotate(90deg);
}
.chat-thinking-body {
  padding: 6px 12px 10px;
  font-style: italic;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 200px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text3);
  border-top: 1px solid var(--border-light);
}

.chat-tool-activity {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  border-radius: 6px;
  font-size: 12px;
  border: 1px solid var(--border-light);
  background: var(--bg);
}
.chat-tool-activity-name {
  font-weight: 600;
  font-family: var(--mono);
  color: var(--text);
}
.chat-tool-activity-status {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
}
.chat-tool-running .chat-tool-activity-status {
  background: var(--orange-light);
  color: #92400e;
}
.chat-tool-done .chat-tool-activity-status {
  background: var(--green-light);
  color: #15803d;
}
.chat-tool-activity-input {
  color: var(--text3);
  font-family: var(--mono);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

/* ─── Animation utils ─── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
