:root {
  --bg-main: #090d16;
  --bg-sidebar: #0f172a;
  --bg-panel: #131d33;
  --bg-card: #18243c;
  --bg-hover: #1e2e4d;
  --border-subtle: #243552;
  --border-strong: #334b73;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-primary: #3b82f6;
  --accent-hover: #2563eb;
  --accent-subtle: rgba(59, 130, 246, 0.12);

  --color-online: #10b981;
  --color-online-bg: rgba(16, 185, 129, 0.12);
  --color-running: #3b82f6;
  --color-running-bg: rgba(59, 130, 246, 0.12);
  --color-warning: #f59e0b;
  --color-warning-bg: rgba(245, 158, 11, 0.12);
  --color-danger: #ef4444;
  --color-danger-bg: rgba(239, 68, 68, 0.12);
  --color-paused: #8b5cf6;
  --color-paused-bg: rgba(139, 92, 246, 0.12);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  --sidebar-width: 260px;
  --header-height: 64px;
}

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

body {
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Layout */
.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  background: var(--accent-subtle);
  color: var(--accent-primary);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 4px;
}

.brand-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-primary);
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.nav-menu {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin-bottom: 2px;
  border-radius: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.nav-item.active {
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
  font-weight: 600;
  border-left: 3px solid var(--accent-primary);
}

.nav-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 1px 6px;
  border-radius: 10px;
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.nav-badge.alert {
  background-color: var(--color-danger);
  color: #fff;
  font-weight: 600;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border-subtle);
  background-color: rgba(0, 0, 0, 0.15);
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
}

.profile-meta .name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.profile-meta .role {
  font-size: 11px;
  color: var(--text-muted);
}

/* Main Content Area */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.top-bar {
  height: var(--header-height);
  padding: 0 28px;
  border-bottom: 1px solid var(--border-subtle);
  background-color: var(--bg-sidebar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 90;
}

.bar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 20px;
  background-color: var(--color-online-bg);
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-size: 12px;
  font-weight: 600;
  color: var(--color-online);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-online);
  box-shadow: 0 0 8px var(--color-online);
}

.bar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.btn-primary {
  background-color: var(--accent-primary);
  color: #fff;
}

.btn-primary:hover {
  background-color: var(--accent-hover);
}

.btn-secondary {
  background-color: var(--bg-panel);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background-color: var(--bg-card);
}

.btn-danger {
  background-color: var(--color-danger);
  color: #fff;
}

.btn-success {
  background-color: var(--color-online);
  color: #fff;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
}

/* Page Views */
.content-area {
  padding: 24px 28px 48px;
  flex: 1;
}

.page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.page-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* KPI Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.kpi-card {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.kpi-val {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 6px 0 2px;
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-secondary);
}

/* Section Box */
.section-panel {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

/* System Status Grid */
.system-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.component-status-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 12px 14px;
}

.comp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.comp-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.comp-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Status Badges */
.badge-status {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-status.online { background-color: var(--color-online-bg); color: var(--color-online); border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-status.running { background-color: var(--color-running-bg); color: var(--color-running); border: 1px solid rgba(59, 130, 246, 0.3); }
.badge-status.warning, .badge-status.degraded { background-color: var(--color-warning-bg); color: var(--color-warning); border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-status.danger, .badge-status.failed { background-color: var(--color-danger-bg); color: var(--color-danger); border: 1px solid rgba(239, 68, 68, 0.3); }
.badge-status.paused { background-color: var(--color-paused-bg); color: var(--color-paused); border: 1px solid rgba(139, 92, 246, 0.3); }

/* Pipeline Flow */
.pipeline-container {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
}

.pipeline-stage {
  flex: 1;
  min-width: 140px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pipeline-stage:hover {
  border-color: var(--accent-primary);
  background-color: var(--bg-hover);
}

.stage-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stage-count {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 4px;
}

/* Tables */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background-color: var(--bg-panel);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th {
  background-color: var(--bg-sidebar);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
  color: var(--text-secondary);
}

.data-table tr:hover td {
  background-color: var(--bg-hover);
}

.table-clickable tr {
  cursor: pointer;
}

.text-strong {
  color: var(--text-primary);
  font-weight: 600;
}

.font-mono {
  font-family: var(--font-mono);
}

/* Filters bar */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.search-input, .select-input {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}

.search-input:focus, .select-input:focus {
  border-color: var(--accent-primary);
}

/* Modal / Drawer */
dialog {
  border: none;
  background: transparent;
  padding: 0;
  max-width: 100vw;
  max-height: 100vh;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-dialog {
  background-color: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  width: 720px;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.3);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--bg-sidebar);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background-color: var(--bg-sidebar);
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

.close-btn:hover {
  color: var(--text-primary);
}

/* Command bar terminal */
.terminal-output {
  background-color: #04060a;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #38bdf8;
  max-height: 240px;
  overflow-y: auto;
  white-space: pre-wrap;
  margin-top: 12px;
}

/* =========================================================================
   RESPONSIVE MOBILE DESIGN & ACCESSIBILITY
   ========================================================================= */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: -290px;
    width: 280px;
    height: 100vh;
    height: 100dvh;
    z-index: 1000;
    transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
  }

  .sidebar.open {
    left: 0;
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.85), 0 0 10px rgba(0, 0, 0, 0.5);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.25s ease;
  }

  .sidebar-backdrop.active {
    display: block;
    opacity: 1;
  }

  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    margin-right: 10px;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
  }

  .mobile-menu-btn:hover,
  .mobile-menu-btn:active {
    background: var(--bg-hover);
    color: var(--accent-primary);
  }

  .sidebar-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    margin-left: auto;
    border-radius: 4px;
    transition: all 0.15s ease;
  }

  .sidebar-close-btn:hover,
  .sidebar-close-btn:active {
    color: var(--text-primary);
    background: var(--bg-hover);
  }

  .top-bar {
    padding: 0 12px;
    height: 56px;
  }

  .top-bar .status-indicator {
    padding: 3px 8px;
    font-size: 11px;
  }

  .top-bar .status-text {
    display: none;
  }

  .top-bar .bar-actions {
    gap: 6px;
  }

  .top-bar .bar-actions .btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  .content-area {
    padding: 14px 12px 80px; /* 80px bottom clearance for mobile nav */
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .page-header > div:last-child,
  .page-header > button {
    width: 100%;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px;
  }

  .filters-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .filters-bar input,
  .filters-bar select {
    width: 100% !important;
  }

  .table-container {
    margin-left: -12px;
    margin-right: -12px;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .modal-dialog-large {
    width: 95vw !important;
    max-width: 95vw !important;
    margin: 12px auto;
  }

  .modal-tabs {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    padding: 0 10px;
  }

  /* Mobile Bottom Navigation Bar */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    height: calc(60px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border-subtle);
    z-index: 950;
    align-items: center;
    justify-content: space-around;
    padding-left: 4px;
    padding-right: 4px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
  }

  .mobile-bottom-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    padding: 6px 4px;
    border-radius: 6px;
    flex: 1;
    min-width: 0;
    transition: color 0.15s ease, background-color 0.15s ease;
  }

  .mobile-bottom-item svg {
    flex-shrink: 0;
  }

  .mobile-bottom-item.active {
    color: var(--accent-primary);
    font-weight: 600;
  }

  .mobile-bottom-item:active {
    background-color: var(--accent-subtle);
  }
}

@media (max-width: 600px) {
  #btn-open-command span:first-child {
    display: none;
  }
  .bar-actions #btn-refresh span {
    font-size: 11px;
  }
  .bar-actions #btn-run-scan span {
    font-size: 11px;
  }
}

@media (min-width: 901px) {
  .mobile-menu-btn,
  .sidebar-close-btn,
  .sidebar-backdrop,
  .mobile-bottom-nav {
    display: none !important;
  }
}

/* Modal Tabs Navigation */
.modal-tabs {
  display: flex;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 20px;
  gap: 8px;
}

.modal-tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}

.modal-tab:hover {
  color: var(--text-primary);
}

.modal-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
  font-weight: 600;
}

.modal-dialog-large {
  width: 920px;
  max-width: 95vw;
}

/* Document Previews (CV & Cover Letter) */
.doc-container {
  background-color: #050811;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 24px;
  font-size: 13px;
  line-height: 1.6;
  color: #e2e8f0;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  max-height: 520px;
  overflow-y: auto;
}

.doc-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.variant-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 16px;
  transition: border-color 0.15s ease;
}

.variant-card:hover {
  border-color: var(--accent-primary);
}

.variant-card.selected {
  border-color: var(--accent-primary);
  background-color: rgba(59, 130, 246, 0.05);
}

.variant-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.variant-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.variant-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Guardrails Manager UI */
.guardrail-editor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.guardrail-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.guardrail-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.guardrail-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}

.guardrail-num-input {
  background-color: var(--bg-main);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 6px;
  width: 140px;
}

.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  background-color: var(--bg-hover);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip-remove {
  cursor: pointer;
  color: var(--text-muted);
  font-weight: bold;
}

.chip-remove:hover {
  color: var(--color-danger);
}

.chip-add-input {
  background-color: var(--bg-main);
  border: 1px dashed var(--border-strong);
  color: var(--text-primary);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 16px;
  outline: none;
  width: 180px;
}

.toast-alert {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background-color: var(--color-online);
  color: #fff;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  z-index: 9999;
  animation: slideUp 0.25s ease-out;
}

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