/* ─── CSS Variables & Reset ─────────────────────────────────────── */
:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: rgba(30, 41, 59, 0.7);
  --bg-hover: rgba(51, 65, 85, 0.3);
  --border: #334155;
  --border-light: rgba(51, 65, 85, 0.5);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.3);
  --green-bg: rgba(34, 197, 94, 0.1);
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.3);
  --red-bg: rgba(239, 68, 68, 0.1);
  --orange: #f97316;
  --orange-glow: rgba(249, 115, 22, 0.3);
  --orange-bg: rgba(249, 115, 22, 0.1);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.1);
  --purple: #a855f7;
  --purple-bg: rgba(168, 85, 247, 0.15);
  --teal: #14b8a6;
  --teal-bg: rgba(20, 184, 166, 0.15);
  --indigo: #6366f1;
  --gradient-accent: linear-gradient(135deg, #3b82f6, #6366f1);
  --gradient-header: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: all 0.15s ease;
}

/* ─── Light Theme ──────────────────────────────────────────────── */
[data-theme="light"] {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-hover: rgba(241, 245, 249, 0.8);
  --border: #e2e8f0;
  --border-light: rgba(226, 232, 240, 0.5);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --gradient-header: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 50%, #f8fafc 100%);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.12);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.4s ease, color 0.4s ease;
}

/* ─── Animated Background Mesh ─────────────────────────────────── */
.bg-mesh {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.bg-mesh .orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.15;
  animation: orbFloat 20s ease-in-out infinite;
}

[data-theme="light"] .bg-mesh .orb { opacity: 0.08; }

.bg-mesh .orb:nth-child(1) {
  width: 500px; height: 500px;
  background: var(--blue);
  top: -100px; left: -100px;
  animation-delay: 0s;
}

.bg-mesh .orb:nth-child(2) {
  width: 400px; height: 400px;
  background: var(--purple);
  top: 50%; right: -100px;
  animation-delay: -7s;
  animation-duration: 25s;
}

.bg-mesh .orb:nth-child(3) {
  width: 350px; height: 350px;
  background: var(--indigo);
  bottom: -50px; left: 30%;
  animation-delay: -14s;
  animation-duration: 22s;
}

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(50px, -30px) scale(1.1); }
  50% { transform: translate(-20px, 40px) scale(0.95); }
  75% { transform: translate(30px, 20px) scale(1.05); }
}

/* ─── Header ───────────────────────────────────────────────────── */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 38px;
  height: 38px;
  background: var(--gradient-accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: white;
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.3);
  position: relative;
  overflow: hidden;
}

.logo::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255,255,255,0.2));
}

.header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header h1 span {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 14px;
  margin-left: 8px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.last-updated {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-right: 8px;
}

.last-updated .pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse-green 2s infinite;
}

/* ─── Buttons ──────────────────────────────────────────────────── */
.btn {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  white-space: nowrap;
}

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

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-icon.active {
  color: var(--blue);
  background: var(--blue-bg);
  border-color: rgba(59, 130, 246, 0.3);
}

/* Theme toggle */
.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.theme-toggle:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* ─── Layout ───────────────────────────────────────────────────── */
.layout {
  display: flex;
  max-width: 1440px;
  margin: 0 auto;
  min-height: calc(100vh - 62px);
}

.main {
  flex: 1;
  padding: 24px 28px;
  min-width: 0;
}

/* ─── Activity Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: 320px;
  border-left: 1px solid var(--border);
  background: var(--bg-secondary);
  padding: 20px;
  overflow-y: auto;
  position: sticky;
  top: 62px;
  height: calc(100vh - 62px);
  transition: var(--transition);
}

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

.sidebar-header h3 {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--gradient-accent);
  color: white;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  align-items: center;
  justify-content: center;
}

/* Activity feed items */
.activity-item {
  display: flex;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
  animation: fadeSlideIn 0.3s ease forwards;
  opacity: 0;
}

.activity-item:hover {
  background: var(--bg-hover);
}

.activity-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}

.activity-dot.Running { background: var(--green); box-shadow: 0 0 8px var(--green-glow); }
.activity-dot.Stopped { background: var(--red); box-shadow: 0 0 8px var(--red-glow); }
.activity-dot.Terminated { background: var(--orange); box-shadow: 0 0 8px var(--orange-glow); }
.activity-dot.Created { background: var(--blue); }

.activity-content {
  flex: 1;
  min-width: 0;
}

.activity-app {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-change {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.activity-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.activity-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Status donut in sidebar */
.status-donut-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  text-align: center;
}

.status-donut-wrapper canvas {
  max-height: 160px;
}

.donut-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

.donut-legend span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.donut-legend .legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* ─── KPI Cards ────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
  align-items: start;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gradient-accent);
  opacity: 0;
  transition: opacity 0.3s;
}

.kpi-card:hover::before { opacity: 1; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.kpi-card.glow-green { border-color: rgba(34, 197, 94, 0.25); }
.kpi-card.glow-green::before { background: var(--green); opacity: 0.6; }
.kpi-card.glow-red { border-color: rgba(239, 68, 68, 0.25); }
.kpi-card.glow-red::before { background: var(--red); opacity: 0.6; }

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kpi-icon.blue { background: var(--blue-bg); color: var(--blue); }
.kpi-icon.green { background: var(--green-bg); color: var(--green); }
.kpi-icon.red { background: var(--red-bg); color: var(--red); }
.kpi-icon.purple { background: var(--purple-bg); color: var(--purple); }

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

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.kpi-value.green { color: var(--green); }
.kpi-value.red { color: var(--red); }
.kpi-value.orange { color: var(--orange); }

.kpi-chart-container {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}

.kpi-mini-chart {
  width: 40px;
  height: 40px;
}

/* Environment breakdown row */
.env-breakdown {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.env-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  backdrop-filter: blur(16px);
  transition: var(--transition);
}

.env-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }

.env-card-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.env-card-dot.prod { background: var(--blue); }
.env-card-dot.qa { background: var(--purple); }
.env-card-dot.staging { background: var(--purple); }
.env-card-dot.demo { background: var(--teal); }
.env-card-dot.default { background: var(--text-muted); }

.env-card-info {
  flex: 1;
}

.env-card-name {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

.env-card-count {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ─── Toolbar ──────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 340px;
}

.search-box input {
  width: 100%;
  padding: 9px 14px 9px 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  transition: var(--transition);
}

.search-box input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.search-box input::placeholder { color: var(--text-muted); }

.search-box svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 16px;
  height: 16px;
}

.search-shortcut {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  color: var(--text-muted);
  pointer-events: none;
}

.filter-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  transition: var(--transition-fast);
  font-family: inherit;
}

.chip:hover { background: var(--bg-card); color: var(--text-primary); }
.chip.active { border-color: var(--blue); color: var(--blue); background: var(--blue-bg); }
.chip.active-green { border-color: var(--green); color: var(--green); background: var(--green-bg); }
.chip.active-red { border-color: var(--red); color: var(--red); background: var(--red-bg); }
.chip.active-orange { border-color: var(--orange); color: var(--orange); background: var(--orange-bg); }

/* ─── Bulk Actions Bar ─────────────────────────────────────────── */
.bulk-bar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--blue-bg);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  animation: fadeSlideIn 0.2s ease;
}

.bulk-bar.active { display: flex; }

.bulk-bar .bulk-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
}

.bulk-bar .bulk-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

/* ─── Table ────────────────────────────────────────────────────── */
.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.3);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: var(--transition-fast);
  white-space: nowrap;
}

[data-theme="light"] thead th {
  background: rgba(241, 245, 249, 0.5);
}

thead th:hover { color: var(--text-primary); }

thead th .sort-arrow {
  display: inline-block;
  margin-left: 3px;
  opacity: 0.3;
  font-size: 10px;
}

thead th.sorted .sort-arrow { opacity: 1; color: var(--blue); }

tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: var(--transition-fast);
}

tbody tr:hover { background: var(--bg-hover); }

tbody tr.selected {
  background: var(--blue-bg);
  border-color: rgba(59, 130, 246, 0.2);
}

tbody td {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  vertical-align: middle;
}

tbody td:first-child { color: var(--text-primary); }

/* Star / Pin */
.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px;
  transition: var(--transition-fast);
  font-size: 16px;
  line-height: 1;
}

.star-btn:hover { color: #fbbf24; }
.star-btn.pinned { color: #fbbf24; }

/* Checkbox */
.row-check {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
  cursor: pointer;
}

/* App name cell */
.app-name-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-name-link {
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px dashed transparent;
  transition: var(--transition-fast);
}

.app-name-link:hover { border-bottom-color: var(--text-muted); }

/* ─── Status Badge ─────────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  transition: all 0.5s ease;
}

.status-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  transition: all 0.5s ease;
}

.status-Running { background: var(--green-bg); color: var(--green); border: 1px solid rgba(34, 197, 94, 0.2); }
.status-Running .dot { background: var(--green); box-shadow: 0 0 8px var(--green-glow); animation: pulse-green 2s infinite; }
.status-Stopped { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239, 68, 68, 0.2); }
.status-Stopped .dot { background: var(--red); box-shadow: 0 0 8px var(--red-glow); }
.status-Terminated { background: var(--orange-bg); color: var(--orange); border: 1px solid rgba(249, 115, 22, 0.2); }
.status-Terminated .dot { background: var(--orange); box-shadow: 0 0 8px var(--orange-glow); }
.status-Created { background: var(--blue-bg); color: var(--blue); border: 1px solid rgba(59, 130, 246, 0.2); }
.status-Created .dot { background: var(--blue); }

@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ─── Environment Tag ──────────────────────────────────────────── */
.env-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.env-prod { background: var(--blue-bg); color: var(--blue); }
.env-staging { background: var(--purple-bg); color: var(--purple); }
.env-qa { background: var(--purple-bg); color: var(--purple); }
.env-dev { background: var(--teal-bg); color: var(--teal); }
.env-demo { background: var(--teal-bg); color: var(--teal); }
.env-default { background: rgba(148, 163, 184, 0.15); color: var(--text-secondary); }

/* ─── Uptime Bar ───────────────────────────────────────────────── */
.uptime-bar { display: flex; align-items: center; gap: 8px; }

.uptime-bar-track {
  flex: 1; height: 5px;
  background: rgba(51, 65, 85, 0.4);
  border-radius: 3px; overflow: hidden;
  min-width: 50px;
}

[data-theme="light"] .uptime-bar-track { background: rgba(148, 163, 184, 0.3); }

.uptime-bar-fill {
  height: 100%; border-radius: 3px;
  background: linear-gradient(90deg, var(--green), #4ade80);
  transition: width 0.8s ease;
}

.uptime-bar-fill.low { background: linear-gradient(90deg, var(--red), #f87171); }
.uptime-bar-fill.medium { background: linear-gradient(90deg, var(--orange), #fb923c); }

.uptime-value { font-size: 12px; font-weight: 600; color: var(--text-secondary); min-width: 44px; text-align: right; }

/* ─── Row Actions ──────────────────────────────────────────────── */
.row-actions { display: flex; gap: 2px; }

/* ─── Group Header ─────────────────────────────────────────────── */
.group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.4);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: var(--transition-fast);
}

[data-theme="light"] .group-header { background: rgba(241, 245, 249, 0.6); }

.group-header:hover { background: var(--bg-hover); }

.group-header .group-chevron {
  transition: transform 0.2s;
  color: var(--text-muted);
}

.group-header.collapsed .group-chevron { transform: rotate(-90deg); }

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

.group-header .group-count {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
}

/* ─── Modal ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden;
  transition: all 0.3s ease;
}

.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95) translateY(20px);
  transition: transform 0.3s ease;
}

.modal-overlay.active .modal { transform: scale(1) translateY(0); }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 17px; font-weight: 600; }

.modal-body { padding: 20px 24px; }

.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
}

/* ─── Form ─────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block; font-size: 12px;
  font-weight: 500; color: var(--text-secondary);
  margin-bottom: 5px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: 9px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px; font-family: inherit;
  transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.form-group textarea { min-height: 70px; resize: vertical; }

.form-group select {
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M4.646 5.646a.5.5 0 0 1 .708 0L8 8.293l2.646-2.647a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.status-preview { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; }

.password-wrapper { position: relative; }
.password-wrapper input { padding-right: 44px; }

.password-toggle {
  position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%);
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  padding: 4px; display: flex;
}

.password-toggle:hover { color: var(--text-primary); }

/* ─── History View ─────────────────────────────────────────────── */
.history-panel { display: none; }
.history-panel.active { display: block; }

.history-back {
  display: inline-flex; align-items: center; gap: 6px;
  margin-bottom: 16px; font-size: 13px;
  color: var(--text-secondary); cursor: pointer;
  background: none; border: none; font-family: inherit;
  transition: var(--transition-fast);
}

.history-back:hover { color: var(--text-primary); }

.history-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}

.history-header h2 { font-size: 20px; font-weight: 600; }

.period-tabs {
  display: flex; gap: 3px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 3px;
}

.period-tab {
  padding: 5px 14px; border: none; background: transparent;
  color: var(--text-muted); font-size: 12px; font-weight: 500;
  cursor: pointer; border-radius: 6px;
  transition: var(--transition-fast); font-family: inherit;
}

.period-tab.active { background: var(--gradient-accent); color: white; }
.period-tab:hover:not(.active) { color: var(--text-primary); }

.uptime-display {
  text-align: center; padding: 28px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 20px;
}

.uptime-big { font-size: 48px; font-weight: 700; letter-spacing: -0.03em; }
.uptime-big.high { color: var(--green); }
.uptime-big.medium { color: var(--orange); }
.uptime-big.low { color: var(--red); }

.uptime-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.chart-container {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 20px;
}

.chart-container canvas { max-height: 260px; }

/* ─── Timeline ─────────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 32px; }

.timeline::before {
  content: ''; position: absolute;
  left: 11px; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}

.timeline-item {
  position: relative; padding-bottom: 20px;
  animation: fadeSlideIn 0.3s ease forwards; opacity: 0;
}

.timeline-item:nth-child(1) { animation-delay: 0.05s; }
.timeline-item:nth-child(2) { animation-delay: 0.1s; }
.timeline-item:nth-child(3) { animation-delay: 0.15s; }
.timeline-item:nth-child(4) { animation-delay: 0.2s; }
.timeline-item:nth-child(5) { animation-delay: 0.25s; }

.timeline-dot {
  position: absolute; left: -32px; top: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--border); background: var(--bg-primary);
}

.timeline-dot.Running { border-color: var(--green); background: var(--green-bg); }
.timeline-dot.Stopped { border-color: var(--red); background: var(--red-bg); }
.timeline-dot.Terminated { border-color: var(--orange); background: var(--orange-bg); }
.timeline-dot.Created { border-color: var(--blue); background: var(--blue-bg); }

.timeline-content {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px;
}

.timeline-time { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }

.timeline-change { display: flex; align-items: center; gap: 8px; font-size: 13px; }

.timeline-arrow { color: var(--text-muted); }

/* ─── Skeleton ─────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, rgba(51, 65, 85, 0.5) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-row { height: 48px; margin-bottom: 2px; }

/* ─── Empty State ──────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state svg { width: 56px; height: 56px; margin-bottom: 12px; opacity: 0.4; }
.empty-state h3 { font-size: 16px; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p { font-size: 13px; max-width: 320px; margin: 0 auto; }

/* ─── Toast ────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 20px; left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex; flex-direction: column-reverse; gap: 8px;
  align-items: center;
}

.toast {
  padding: 10px 18px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 13px; color: var(--text-primary);
  display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.3s ease;
  max-width: 420px;
  white-space: nowrap;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--blue); }

.toast .undo-btn {
  background: none; border: none;
  color: var(--blue); cursor: pointer;
  font-weight: 600; font-size: 13px;
  font-family: inherit;
  margin-left: 8px;
}

.toast .undo-btn:hover { text-decoration: underline; }

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

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

/* ─── Keyboard Shortcuts Modal ─────────────────────────────────── */
.shortcuts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.shortcut-item {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.shortcut-item span:first-child {
  font-size: 13px; color: var(--text-secondary);
}

.shortcut-key {
  display: inline-flex; padding: 2px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px; font-weight: 600;
  color: var(--text-primary);
  font-family: 'SF Mono', 'Cascadia Code', monospace;
}

/* ─── Animations ───────────────────────────────────────────────── */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeSlideIn 0.3s ease forwards; }

/* ─── Responsive ───────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .sidebar { display: none; }
  .sidebar.mobile-open { display: block; position: fixed; right: 0; top: 62px; z-index: 150; height: calc(100vh - 62px); box-shadow: var(--shadow-lg); }
  .sidebar-toggle { display: flex; }
}

@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .header { padding: 12px 16px; }
  .main { padding: 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-card { padding: 16px; }
  .kpi-value { font-size: 24px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-left { flex-direction: column; }
  .search-box { max-width: 100%; }
  .table-container { overflow-x: auto; }
  table { min-width: 700px; }
  .modal { width: 95%; }
  .env-breakdown { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .header h1 span { display: none; }
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 22px; }
  .filter-chips { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .env-breakdown { grid-template-columns: 1fr; }
}
