@import url('https://fonts.googleapis.com/css2?family=Fira+Sans:wght@400;500;600;700&family=Fira+Code:wght@400;500;600&display=swap');

:root {
  --color-primary: #5865F2;
  --color-primary-hover: #4752c4;
  --color-accent: #22C55E;
  --color-accent-hover: #16a34a;
  --color-danger: #EF4444;
  --color-danger-hover: #dc2626;
  --color-warning: #F59E0B;

  --color-background: #0B0E14;
  --color-surface: #12151E;
  --color-surface-2: #171B27;
  --color-card: #1A1F2E;
  --color-border: #242A3A;
  --color-border-hover: #323A50;

  --color-foreground: #F1F3F9;
  --color-muted: #8891A8;
  --color-muted-2: #5B6478;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,.35);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.45);

  --ease: cubic-bezier(.4,0,.2,1);
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Fira Sans', -apple-system, sans-serif;
  background: var(--color-background);
  color: var(--color-foreground);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

a { color: inherit; }
svg { display: block; flex-shrink: 0; }

::selection { background: rgba(88,101,242,.35); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-border-hover); }

/* ─── Layout shell ─────────────────────────────────────────────────────── */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: var(--space-5) var(--space-3);
  display: flex; flex-direction: column;
  z-index: 40;
}
.sidebar-brand {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3); margin-bottom: var(--space-6);
}
.sidebar-brand .logo-badge {
  width: 32px; height: 32px; border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--color-primary), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff; flex-shrink: 0;
}
.sidebar-brand .name { font-size: 15px; font-weight: 700; color: #fff; }
.sidebar-brand .name span { color: var(--color-muted); font-weight: 500; }

.nav-section-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--color-muted-2); padding: var(--space-2) var(--space-3); margin-top: var(--space-4);
}
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 9px var(--space-3); border-radius: var(--radius-md);
  color: var(--color-muted); text-decoration: none; font-size: 14px; font-weight: 500;
  transition: background .15s var(--ease), color .15s var(--ease);
  cursor: pointer;
}
.nav-link:hover { background: var(--color-surface-2); color: var(--color-foreground); }
.nav-link.active { background: rgba(88,101,242,.12); color: #fff; }
.nav-link.active svg { color: var(--color-primary); }
.nav-link svg { width: 18px; height: 18px; color: var(--color-muted-2); }
.nav-link.active svg { color: var(--color-primary); }

.server-pill {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 7px var(--space-3); border-radius: var(--radius-md);
  font-size: 13px; color: var(--color-muted); text-decoration: none;
}
.server-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--color-accent); flex-shrink: 0; }
.server-pill:hover { background: var(--color-surface-2); color: var(--color-foreground); }
.server-pill.active { background: var(--color-surface-2); color: #fff; }

.sidebar-footer { margin-top: auto; padding-top: var(--space-4); border-top: 1px solid var(--color-border); }

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: var(--space-8) var(--space-10);
  max-width: 1200px;
}

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: var(--space-8); gap: var(--space-4); flex-wrap: wrap;
}
.page-header h1 { font-size: 24px; font-weight: 700; margin: 0 0 4px; letter-spacing: -.01em; }
.page-header .subtitle { color: var(--color-muted); font-size: 14px; margin: 0; }
.header-actions { display: flex; gap: var(--space-3); align-items: center; }

/* ─── Buttons ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-md);
  border: 1px solid transparent; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 600;
  text-decoration: none; white-space: nowrap;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease), opacity .15s;
  min-height: 40px;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-accent { background: var(--color-accent); color: #06240F; }
.btn-accent:hover { background: var(--color-accent-hover); }
.btn-danger { background: rgba(239,68,68,.12); color: #FCA5A5; border-color: rgba(239,68,68,.25); }
.btn-danger:hover { background: rgba(239,68,68,.2); }
.btn-ghost { background: var(--color-surface-2); color: var(--color-muted); border-color: var(--color-border); }
.btn-ghost:hover { background: var(--color-card); color: var(--color-foreground); border-color: var(--color-border-hover); }
.btn-sm { padding: 7px 13px; font-size: 13px; min-height: 32px; }
.btn-icon { padding: 8px; min-width: 36px; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ─── Cards ────────────────────────────────────────────────────────────── */

.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-8); }
.stat-card {
  background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-2);
}
.stat-card .icon-wrap {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: rgba(88,101,242,.12); color: var(--color-primary); margin-bottom: 2px;
}
.stat-card .icon-wrap.accent { background: rgba(34,197,94,.12); color: var(--color-accent); }
.stat-card .icon-wrap.warn { background: rgba(245,158,11,.12); color: var(--color-warning); }
.stat-card .val { font-size: 26px; font-weight: 700; color: #fff; letter-spacing: -.02em; }
.stat-card .lbl { font-size: 13px; color: var(--color-muted); }

.section-label {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--color-muted-2); margin-bottom: var(--space-4); display: flex; align-items: center; gap: 8px;
}

/* ─── Server / scenario list cards ────────────────────────────────────── */

.list-grid { display: flex; flex-direction: column; gap: var(--space-3); }

.item-card {
  background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  transition: border-color .15s var(--ease), background .15s var(--ease);
  flex-wrap: wrap;
}
.item-card:hover { border-color: var(--color-border-hover); }
.item-card.inactive { opacity: .55; }
.item-main { display: flex; align-items: center; gap: var(--space-4); min-width: 0; }
.item-icon {
  width: 44px; height: 44px; border-radius: var(--radius-md); flex-shrink: 0;
  background: var(--color-surface-2); display: flex; align-items: center; justify-content: center;
  color: var(--color-primary);
}
.item-info h3 { font-size: 15px; font-weight: 600; color: #fff; margin: 0 0 3px; }
.item-info p { font-size: 13px; color: var(--color-muted); margin: 0; }
.item-meta { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-size: 12px; color: var(--color-muted-2); flex-wrap: wrap; }
.item-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.badge-active { background: rgba(34,197,94,.14); color: #6ee7b7; }
.badge-inactive { background: var(--color-surface-2); color: var(--color-muted-2); }
.badge-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

.empty-state {
  text-align: center; padding: 72px 24px; color: var(--color-muted-2);
  background: var(--color-card); border: 1px dashed var(--color-border); border-radius: var(--radius-lg);
}
.empty-state svg { width: 52px; height: 52px; margin: 0 auto 16px; color: var(--color-border-hover); }
.empty-state .title { font-size: 15px; font-weight: 600; color: var(--color-foreground); margin-bottom: 6px; }
.empty-state .desc { font-size: 13px; margin-bottom: 20px; }

/* ─── Logs ─────────────────────────────────────────────────────────────── */

.log-row {
  display: grid; grid-template-columns: 150px 1fr auto; gap: var(--space-4);
  padding: 11px var(--space-2); border-bottom: 1px solid var(--color-border); font-size: 13px; align-items: center;
}
.log-row:last-child { border-bottom: none; }
.log-time { color: var(--color-muted-2); font-family: 'Fira Code', monospace; font-size: 12px; }
.log-user { color: #A5B4FC; font-weight: 500; }
.log-cmd { color: var(--color-accent); font-family: 'Fira Code', monospace; font-size: 12px; justify-self: end; }

.console-box {
  background: #05070B; border: 1px solid var(--color-border); border-radius: var(--radius-md);
  padding: var(--space-4); font-family: 'Fira Code', monospace; font-size: 12.5px; color: #9CA8C4;
  max-height: 420px; overflow-y: auto; white-space: pre-wrap; line-height: 1.6;
}

/* ─── Forms ────────────────────────────────────────────────────────────── */

.field { margin-bottom: var(--space-4); }
.field:last-child { margin-bottom: 0; }
.field label {
  display: block; font-size: 13px; font-weight: 500; color: var(--color-muted); margin-bottom: 6px;
}
.field .hint { font-size: 12px; color: var(--color-muted-2); margin-top: 6px; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; padding: 10px 14px; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  color: var(--color-foreground); font-size: 14px; font-family: inherit;
  outline: none; transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input:focus, textarea:focus, select:focus {
  border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(88,101,242,.15);
}
input[readonly] { color: var(--color-muted); cursor: not-allowed; }
textarea { resize: vertical; min-height: 90px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238891A8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

.checkbox-row { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; color: var(--color-muted); }
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--color-primary); cursor: pointer; }

/* ─── Toast ────────────────────────────────────────────────────────────── */

.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--color-card); border: 1px solid var(--color-border); box-shadow: var(--shadow-lg);
  padding: 12px 20px; border-radius: var(--radius-md); font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 10px; opacity: 0; pointer-events: none;
  transition: opacity .25s var(--ease), transform .25s var(--ease); z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: rgba(34,197,94,.35); }
.toast.success svg { color: var(--color-accent); }
.toast.error { border-color: rgba(239,68,68,.35); }
.toast.error svg { color: var(--color-danger); }

/* ─── Modal ────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(4,6,10,.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  opacity: 0; pointer-events: none; transition: opacity .2s var(--ease);
}
.modal-overlay.show { opacity: 1; pointer-events: auto; }
.modal-box {
  background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-xl);
  padding: var(--space-6); width: min(420px, 90vw); box-shadow: var(--shadow-lg);
  transform: scale(.96) translateY(8px); transition: transform .2s var(--ease);
}
.modal-overlay.show .modal-box { transform: scale(1) translateY(0); }
.modal-box h2 { font-size: 17px; margin: 0 0 var(--space-4); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: var(--space-5); }

/* ─── Focus visibility (a11y) ──────────────────────────────────────────── */
a:focus-visible, button:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--color-primary); outline-offset: 2px;
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s var(--ease); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding: var(--space-5); }
  .row-2 { grid-template-columns: 1fr; }
}
