/* ═══════════════════════════════════════════════════════════
   ORBRT — Design System
   FortiGate × Entra × Terminal Aesthetic
   Dark grey + green, muted & flat
   ═══════════════════════════════════════════════════════════ */

/* ── CSS Custom Properties ─────────────────────────────── */
:root {
  /* Surface palette — dark greys */
  --surface-0: #0d0d0d;
  --surface-1: #141414;
  --surface-2: #1a1a1a;
  --surface-3: #222222;
  --surface-4: #2a2a2a;
  --surface-5: #333333;

  /* Accent — muted greens */
  --accent-primary: #3ddc84;
  --accent-muted: #2ca866;
  --accent-dim: #1e7a4a;
  --accent-subtle: rgba(61, 220, 132, 0.08);
  --accent-border: rgba(61, 220, 132, 0.15);

  /* Status */
  --status-ok: #3ddc84;
  --status-warn: #e6a817;
  --status-error: #e05252;
  --status-info: #4a9ede;
  --status-neutral: #6b6b6b;

  /* Text */
  --text-primary: #e0e0e0;
  --text-secondary: #999999;
  --text-tertiary: #666666;
  --text-inverse: #0d0d0d;
  --text-accent: #3ddc84;

  /* Borders */
  --border-default: #2a2a2a;
  --border-subtle: #1f1f1f;
  --border-strong: #3a3a3a;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* Sizing */
  --sidebar-width: 240px;
  --sidebar-collapsed: 56px;
  --topbar-height: 48px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  /* Transitions */
  --transition-fast: 120ms ease;
  --transition-base: 200ms ease;
}

/* ── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--surface-0);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

a {
  color: var(--text-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover {
  color: var(--accent-primary);
}

/* ── App Shell ─────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.app-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--surface-1);
}

/* Custom scrollbar */
*::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--surface-4);
  border-radius: 2px;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--surface-5);
}

/* ── Sidebar ───────────────────────────────────────────── */
[x-cloak] { display: none !important; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface-0);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-base);
  overflow: hidden;
  z-index: 100;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.sidebar.collapsed .nav-children {
  display: none !important;
}

.sidebar.collapsed .nav-group-toggle {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.sidebar.collapsed .nav-group-toggle .nav-chevron,
.sidebar.collapsed .nav-group-toggle .nav-label {
  display: none;
}

.sidebar.collapsed .nav-section-label {
  display: none;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.sidebar.collapsed .nav-item .nav-label {
  display: none;
}

.sidebar.collapsed .nav-badge {
  display: none;
}

.sidebar.collapsed .sidebar-brand {
  justify-content: center;
  padding: 0;
}

.sidebar.collapsed .sidebar-system {
  display: none;
}

.sidebar.collapsed .sidebar-collapse-btn {
  width: 100%;
  justify-content: center;
}

.sidebar-brand {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-default);
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-brand .brand-icon {
  width: 26px;
  height: 26px;
  background: var(--surface-0);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-brand .brand-icon svg {
  width: 40px;
  height: 40px;
  color: var(--accent-primary);
}

.sidebar-brand .brand-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.sidebar-brand .brand-tag {
  font-size: 9px;
  font-family: var(--font-mono);
  color: var(--accent-muted);
  background: var(--accent-subtle);
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ── Sidebar Context Switchers ─────────────────────────── */
.sidebar-context {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ctx-switcher {
  position: relative;
}

.ctx-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  transition: all var(--transition-fast);
  text-align: left;
  color: var(--text-primary);
}

.ctx-trigger:hover {
  background: var(--surface-3);
  border-color: var(--border-default);
}

.ctx-icon {
  width: 14px;
  height: 14px;
  stroke: var(--text-tertiary);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.ctx-info {
  flex: 1;
  min-width: 0;
}

.ctx-label {
  display: block;
  font-size: 9px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1;
}

.ctx-value {
  display: block;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-primary);
  font-family: var(--font-mono);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ctx-chevron {
  width: 12px;
  height: 12px;
  stroke: var(--text-tertiary);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
  transition: transform var(--transition-fast);
}

.ctx-chevron.rotated {
  transform: rotate(180deg);
}

.ctx-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--surface-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 4px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.ctx-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-mono);
  text-align: left;
  transition: all var(--transition-fast);
}

.ctx-option:hover {
  background: var(--surface-4);
  color: var(--text-primary);
}

.ctx-option.active {
  color: var(--text-accent);
  background: var(--accent-subtle);
}

.ctx-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ctx-dot.ok { background: var(--status-ok); }
.ctx-dot.warn { background: var(--status-warn); }
.ctx-dot.info { background: var(--status-info); }
.ctx-dot.neutral { background: var(--status-neutral); }

.ctx-divider {
  height: 1px;
  background: var(--border-default);
  margin: 4px 0;
}

.ctx-action {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 11.5px;
  text-align: left;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.ctx-action:hover {
  background: var(--surface-4);
  color: var(--text-primary);
}

.ctx-action svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-section {
  margin-bottom: 4px;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-tertiary);
  padding: 12px 16px 4px;
  font-family: var(--font-mono);
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 7px 16px;
  color: var(--text-secondary);
  gap: 10px;
  transition: all var(--transition-fast);
  cursor: pointer;
  border-left: 2px solid transparent;
  font-size: 13px;
  position: relative;
}

.nav-item:hover {
  color: var(--text-primary);
  background: var(--surface-2);
}

.nav-item.active {
  color: var(--text-accent);
  background: var(--accent-subtle);
  border-left-color: var(--accent-primary);
}

.nav-item .nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.6;
}

.nav-item.active .nav-icon {
  opacity: 1;
}

.nav-item .nav-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-item .nav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item .nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-mono);
  background: var(--accent-dim);
  color: var(--accent-primary);
  padding: 1px 6px;
  border-radius: 8px;
  min-width: 18px;
  text-align: center;
}

.nav-item .nav-badge.warn {
  background: rgba(230, 168, 23, 0.15);
  color: var(--status-warn);
}

.nav-item .nav-badge.error {
  background: rgba(224, 82, 82, 0.15);
  color: var(--status-error);
}

/* Sidebar children */
.nav-children {
  display: none;
}
.nav-group.open .nav-children {
  display: block;
}
.nav-children .nav-item {
  padding-left: 44px;
  font-size: 12.5px;
}

.nav-group-toggle {
  display: flex;
  align-items: center;
  padding: 7px 16px;
  color: var(--text-secondary);
  gap: 10px;
  cursor: pointer;
  border-left: 2px solid transparent;
  font-size: 13px;
  transition: all var(--transition-fast);
  user-select: none;
}

.nav-group-toggle:hover {
  color: var(--text-primary);
  background: var(--surface-2);
}

.nav-group-toggle .nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.6;
}

.nav-group-toggle .nav-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-group-toggle .nav-label {
  flex: 1;
  white-space: nowrap;
}

.nav-group-toggle .nav-chevron {
  width: 14px;
  height: 14px;
  transition: transform var(--transition-fast);
  opacity: 0.4;
}

.nav-group-toggle .nav-chevron svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

.nav-group.open .nav-group-toggle .nav-chevron {
  transform: rotate(90deg);
}

.nav-group.open .nav-group-toggle {
  color: var(--text-primary);
}

/* Sidebar footer */
.sidebar-footer {
  border-top: 1px solid var(--border-default);
  padding: 8px;
  flex-shrink: 0;
}

.sidebar-system {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
}

.system-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-ok);
  flex-shrink: 0;
  animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.system-info {
  flex: 1;
  min-width: 0;
}

.system-info .system-label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.system-info .system-version {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
}

/* ── Top Bar ───────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--surface-0);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  padding: 0 20px;
  flex-shrink: 0;
  gap: 16px;
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  flex: 1;
  min-width: 0;
}

.topbar-breadcrumb .bc-separator {
  color: var(--text-tertiary);
  font-size: 11px;
}

.topbar-breadcrumb .bc-item {
  color: var(--text-secondary);
  white-space: nowrap;
}

.topbar-breadcrumb .bc-item:last-child {
  color: var(--text-primary);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.topbar-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  background: none;
  border: none;
  position: relative;
}

.topbar-btn:hover {
  color: var(--text-primary);
  background: var(--surface-3);
}

.topbar-btn .notification-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-error);
}

.topbar-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border-default);
  margin: 0 4px;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.topbar-user:hover {
  background: var(--surface-3);
}

.user-avatar {
  width: 26px;
  height: 23px;
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.user-name {
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ── Mobile Hamburger (hidden on desktop) ──────────────── */
.topbar-hamburger {
  display: none;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  background: none;
  border: none;
  flex-shrink: 0;
}
.topbar-hamburger:hover {
  color: var(--text-primary);
  background: var(--surface-3);
}
.topbar-hamburger svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Sidebar backdrop (mobile only) ────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 999;
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE — Tablet (≤ 1024px)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .topbar-hamburger {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform var(--transition-base);
    z-index: 1000;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    width: var(--sidebar-width);
  }

  /* When mobile menu is open, always show full sidebar regardless of collapsed state */
  .sidebar.collapsed.mobile-open { width: var(--sidebar-width); }
  .sidebar.collapsed.mobile-open .nav-children { display: block !important; }
  .sidebar.collapsed.mobile-open .nav-group-toggle { justify-content: initial; padding-left: 12px; padding-right: 12px; }
  .sidebar.collapsed.mobile-open .nav-group-toggle .nav-chevron,
  .sidebar.collapsed.mobile-open .nav-group-toggle .nav-label { display: initial; }
  .sidebar.collapsed.mobile-open .nav-section-label { display: block; }
  .sidebar.collapsed.mobile-open .nav-item { justify-content: initial; padding-left: 12px; padding-right: 12px; }
  .sidebar.collapsed.mobile-open .nav-item .nav-label { display: initial; }
  .sidebar.collapsed.mobile-open .nav-badge { display: flex; }
  .sidebar.collapsed.mobile-open .sidebar-brand { justify-content: initial; padding: 0 16px; }
  .sidebar.collapsed.mobile-open .sidebar-system { display: flex; }
  .sidebar.collapsed.mobile-open .sidebar-collapse-btn { width: auto; justify-content: initial; }

  .sidebar-backdrop {
    display: block;
  }

  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-divider { display: none; }
  .user-name { display: none; }

  .app-content { padding: 16px; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE — Mobile (≤ 768px)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar-breadcrumb { font-size: 12px; }
  .topbar-breadcrumb .bc-separator,
  .topbar-breadcrumb .bc-item:first-child { display: none; }

  .app-content { padding: 12px; }

  /* Stat cards stack */
  .stat-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .stat-card { padding: 14px; }

  /* Tables scroll horizontally */
  .card { overflow: hidden; }
  .table-wrapper,
  .data-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .data-table { min-width: 600px; }

  /* Setting rows stack on mobile */
  .setting-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .setting-row .form-select,
  .setting-row select {
    max-width: 100%;
    width: 100%;
  }

  /* Modals full-width on mobile */
  .modal {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 85vh;
    margin: 5vh auto;
  }
  .modal-wide {
    width: 95vw !important;
    max-width: 95vw !important;
  }

  /* Form rows stack */
  .form-row {
    flex-direction: column;
    gap: 12px;
  }

  /* Page headers stack */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .page-header-actions {
    width: 100%;
    flex-wrap: wrap;

  }

  /* Search modal */
  .search-modal {
    width: 95vw !important;
    max-width: 95vw !important;
    margin-top: 10vh;
  }

  /* User modal */
  .user-modal {
    width: 95vw !important;
    max-width: 95vw !important;
  }
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE — Small phone (≤ 480px)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  html { font-size: 13px; }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .toolbar { flex-wrap: wrap; gap: 8px; }
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .tab { white-space: nowrap; flex-shrink: 0; }

  .radio-detail-grid {
    grid-template-columns: 1fr;
  }
}
