/* ==========================================================================
   GDS SUPERIOR SPA STYLES 
   Modern, elegant, high-performance UI using CSS Variables & Grid
   ========================================================================== */

:root {
  /* Color Palette */
  --bg-base: #f1f5f9;
  --bg-dark: #0f172a;
  --panel-bg: rgba(255, 255, 255, 0.7);
  --panel-border: rgba(255, 255, 255, 0.6);

  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --primary-glow: rgba(56, 189, 248, 0.24);

  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;

  /* Layout & Shadow */
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 10px 25px -3px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.08);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;

  /* Animation */
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-base);
  background-image:
    radial-gradient(at 0% 0%, hsla(253, 16%, 7%, 0.02) 0px, transparent 50%),
    radial-gradient(at 50% 0%, hsla(225, 39%, 30%, 0.03) 0px, transparent 50%),
    radial-gradient(at 100% 0%, hsla(339, 49%, 30%, 0.02) 0px, transparent 50%);
  color: var(--text-main);
  font-family: 'Outfit', -apple-system, sans-serif;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Utilities
   ========================================================================== */
.hidden {
  display: none !important;
}

.fade-out {
  opacity: 0;
  transform: translateY(5px);
}

.fade-in {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.text-danger {
  color: var(--danger);
}

.text-primary {
  color: var(--primary);
}

.text-muted {
  color: var(--text-muted);
}

.text-xs {
  font-size: 0.8rem;
}

.mt-2 {
  margin-top: 0.5rem;
}

.mt-3 {
  margin-top: 0.75rem;
}

.mt-4 {
  margin-top: 1rem;
}

.mt-6 {
  margin-top: 1.5rem;
}

.mb-2 {
  margin-bottom: 0.5rem;
}

.border-top {
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.pt-3 {
  padding-top: 0.75rem;
}

.pt-4 {
  padding-top: 1rem;
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.flex-1 {
  flex: 1;
}

.h-full {
  height: 100%;
}

.bg-indigo {
  background: linear-gradient(135deg, #38bdf8, #60a5fa);
  color: white;
}

.bg-emerald {
  background: #10b981;
  color: white;
}

.bg-amber {
  background: #f59e0b;
  color: white;
}

/* Status Dots */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.dot-loading {
  background: var(--text-muted);
  animation: pulse 1.5s infinite;
}

.dot-online {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.dot-offline {
  background: var(--warning);
}

@keyframes pulse {
  0% {
    opacity: 0.5;
  }

  50% {
    opacity: 1;
  }

  100% {
    opacity: 0.5;
  }
}

/* Badges */
.badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-normal {
  background: #e2e8f0;
  color: #475569;
}

/* ==========================================================================
   Buttons & Inputs
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  transition: var(--transition);
  outline: none;
  line-height: 1;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 6px 16px rgba(14, 165, 233, 0.28);
}

.btn-secondary {
  background: white;
  border: 1px solid #cbd5e1;
  color: var(--text-main);
}

.btn-secondary:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn-danger {
  background: var(--danger);
  color: white;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
  background: #dc2626;
  box-shadow: 0 6px 16px rgba(239, 68, 68, 0.3);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--primary);
}

.btn-dashed {
  background: transparent;
  border: 1px dashed #cbd5e1;
  color: var(--text-muted);
  width: 100%;
  justify-content: center;
  padding: 12px;
}

.btn-dashed:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(56, 189, 248, 0.06);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-xs {
  padding: 4px 8px;
  font-size: 0.75rem;
  border-radius: 4px;
}

.btn-lg {
  padding: 14px 24px;
  font-size: 1rem;
  border-radius: 100px;
}

.btn-block {
  width: 100%;
  justify-content: center;
  padding: 12px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="time"] {
  width: 100%;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.875rem;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.8);
  color: var(--text-main);
  transition: var(--transition);
}

input:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Toggle Checkboxes */
.toggle-control {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 0.875rem;
  font-weight: 500;
}

.toggle-control input[type="checkbox"] {
  appearance: none;
  width: 44px;
  height: 24px;
  background: #cbd5e1;
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: 0.3s;
}

.toggle-control input[type="checkbox"]::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  top: 3px;
  left: 3px;
  transition: 0.3s;
}

.toggle-control input[type="checkbox"]:checked {
  background: var(--primary);
}

.toggle-control input[type="checkbox"]:checked::before {
  transform: translateX(20px);
}

/* ==========================================================================
   SPA Layout Shell
   ========================================================================== */
.spa-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.glass-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* Sidebar */
.sidebar {
  width: 260px;
  display: flex;
  flex-direction: column;
  z-index: 10;
  box-shadow: 1px 0 15px rgba(0, 0, 0, 0.02);
}

.sidebar-header {
  padding: 30px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.sidebar-header .logo {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--primary), #7dd3fc);
  color: white;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.9rem;
  letter-spacing: 1px;
  box-shadow: 0 8px 16px var(--primary-glow);
}

.sidebar-header h2 {
  font-size: 1.1rem;
  line-height: 1.2;
  font-weight: 700;
  color: var(--text-main);
}

.nav-menu {
  flex: 1;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 0.95rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}

.nav-item i {
  font-size: 1.2rem;
}

.nav-item:hover {
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-main);
}

.nav-item.active {
  background: white;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.sidebar-footer {
  padding: 24px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: relative;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 40px;
  background: rgba(241, 245, 249, 0.8);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid rgba(0, 0, 0, 0.02);
}

.status-indicator {
  display: flex;
  align-items: center;
  font-weight: 600;
  font-size: 0.9rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Views */
.view-section {
  padding: 30px 40px 100px;
  /* buffer for fab */
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.page-header p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Panels & Cards */
.panel-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(0, 0, 0, 0.02);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.panel-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Grids */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.stack-layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

/* Metrics */
.metric-card {
  padding: 24px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: var(--shadow-sm);
}

.metric-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
}

.metric-data {
  display: flex;
  flex-direction: column;
}

.metric-data .label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.metric-data strong {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.2;
  margin-top: 4px;
}

/* Forms */
.form-wrapper {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-wrapper.horizontal {
  flex-direction: row;
  flex-wrap: wrap;
}

.form-wrapper.horizontal .form-group {
  flex: 1;
  min-width: 150px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.form-group.half {
  width: calc(50% - 8px);
  display: inline-flex;
}

.form-group label,
.form-group span {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
}

.full-width {
  width: 100%;
  margin-top: 8px;
}

/* Tags & Lists */
.tag-box {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 42px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.02);
  border-radius: var(--radius-md);
  border: 1px dashed rgba(0, 0, 0, 0.1);
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: 'Fira Code', monospace;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.tag-pill.sm {
  padding: 2px 8px;
  font-size: 0.75rem;
}

.tag-remove {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
}

.tag-remove:hover {
  color: var(--danger);
}

.empty-state {
  color: var(--text-light);
  font-size: 0.875rem;
  margin: auto;
}

/* Routes */
.routes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 20px;
}

.route-card-item {
  padding: 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.empty-route-card {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.02);
  border-radius: var(--radius-md);
  border: 1px dashed rgba(0, 0, 0, 0.1);
}

/* Terminal */
.terminal-wrapper {
  background: #0f172a;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.terminal-header {
  background: #1e293b;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.5);
}

.traffic-lights {
  display: flex;
  gap: 8px;
}

.traffic-lights span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  opacity: 0.8;
}

.traffic-lights span:nth-child(1) {
  background: #ef4444;
}

.traffic-lights span:nth-child(2) {
  background: #f59e0b;
}

.traffic-lights span:nth-child(3) {
  background: #10b981;
}

.terminal-title {
  font-family: 'Fira Code', monospace;
  font-size: 0.85rem;
  color: #94a3b8;
  flex: 1;
  text-align: center;
}

.terminal-body {
  padding: 20px;
  height: 500px;
  overflow-y: auto;
  font-family: 'Fira Code', monospace;
  font-size: 0.85rem;
  color: #e2e8f0;
  line-height: 1.6;
}

.term-line {
  word-break: break-all;
  margin-bottom: 2px;
}

.term-line.sys {
  color: #10b981;
}

.term-line.err {
  color: #ef4444;
}

.term-line.warn {
  color: #f59e0b;
}

/* File List Archive */
.file-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.02);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.file-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 500;
  font-size: 0.9rem;
}

.file-info i {
  font-size: 1.2rem;
}

.file-meta {
  display: flex;
  align-items: center;
  gap: 16px;
}

.file-size {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: 'Fira Code', monospace;
}

.file-submeta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.status-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0;
}

.status-summary-label {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.history-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.history-list-panel,
.history-log-panel {
  min-height: 620px;
}

.history-run-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-run-item {
  width: 100%;
  border: 1px solid #dbeafe;
  background: linear-gradient(180deg, #f8fdff 0%, #f1f9ff 100%);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
}

.history-run-item:hover {
  border-color: var(--primary);
  box-shadow: 0 8px 20px rgba(56, 189, 248, 0.12);
}

.history-run-item.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14);
  background: white;
}

.history-run-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.history-run-id {
  font-family: 'Fira Code', monospace;
  font-size: 0.82rem;
  color: var(--text-main);
}

.history-run-meta,
.history-run-extra {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.history-run-desc {
  margin: 6px 0;
  color: var(--text-main);
  font-size: 0.88rem;
  line-height: 1.5;
}

.history-empty {
  min-height: 120px;
  display: grid;
  place-items: center;
  color: var(--text-light);
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius-md);
  background: #f8fafc;
}

.history-log-output {
  background: #0f172a;
  border-radius: var(--radius-md);
  height: 540px;
}

.terminal-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.terminal-hint {
  font-size: 0.82rem;
}

/* Floating Save Action */
.fab-wrapper {
  position: fixed;
  bottom: -80px;
  left: 50%;
  transform: translateX(-50%);
  transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 100;
}

.fab-wrapper.visible {
  bottom: 40px;
}

.shadow-glow {
  box-shadow: 0 10px 30px var(--primary-glow);
}

/* ==========================================================================
   Login Page Override
   ========================================================================== */
body.login-body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: radial-gradient(circle at 50% 50%, #f8fafc 0%, #e2e8f0 100%);
}

.login-container {
  display: flex;
  max-width: 900px;
  width: 100%;
  gap: 60px;
  padding: 40px;
  align-items: center;
}

.login-brand {
  flex: 1;
}

.login-brand .brand-logo {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--primary), #7dd3fc);
  color: white;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.2rem;
  margin-bottom: 24px;
  box-shadow: 0 16px 32px var(--primary-glow);
}

.login-brand h1 {
  font-size: 2.5rem;
  font-weight: 800;
  margin-bottom: 12px;
  letter-spacing: -1px;
}

.login-brand p {
  font-size: 1.1rem;
  color: var(--text-muted);
}

.login-box {
  flex: 1;
  max-width: 400px;
  padding: 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.login-box h2 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.login-box .subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  margin-top: 16px;
  padding: 10px;
  background: rgba(239, 68, 68, 0.1);
  border-radius: 8px;
}

@media (max-width: 1100px) {
  .history-layout {
    grid-template-columns: 1fr;
  }
}
