:root {
  --background: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --foreground: #0f172a;
  --muted-foreground: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --secondary: #7c3aed;
  --success: #10b981;
  --danger: #dc2626;
  --warning: #f59e0b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --card-shadow: 0 4px 20px -2px rgba(79, 70, 229, 0.1);
  --card-shadow-hover: 0 10px 25px -5px rgba(79, 70, 229, 0.15), 0 8px 10px -6px rgba(79, 70, 229, 0.1);
  --button-shadow: 0 4px 14px rgba(79, 70, 229, 0.28);
  --font-body: "Plus Jakarta Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
  color: var(--foreground);
  background: var(--background);
  font-family: var(--font-body);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--foreground);
  background:
    linear-gradient(180deg, rgba(79, 70, 229, 0.045), transparent 360px),
    var(--background);
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
  align-items: center;
  gap: clamp(2rem, 5vw, 4rem);
  padding: clamp(1.5rem, 5vw, 4rem);
}
.login-panel {
  max-width: 520px;
}
.login-panel h1,
.topbar h1,
.panel h2,
.login-manager h3 {
  margin: 0;
  color: var(--foreground);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.login-panel h1 {
  max-width: 12ch;
  font-size: clamp(2.8rem, 6vw, 5.5rem);
  line-height: 1.02;
}
.login-panel h1 span {
  color: transparent;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  background-clip: text;
}
.login-panel p {
  max-width: 34rem;
  color: var(--muted-foreground);
  font-size: 1.04rem;
  line-height: 1.68;
}
.login-panel .form-stack {
  margin-top: 1.5rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--card-shadow);
}
.login-visual {
  min-height: min(60vh, 590px);
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: 24px;
  background:
    linear-gradient(135deg, rgba(79, 70, 229, 0.92), rgba(124, 58, 237, 0.9)),
    #4f46e5;
  box-shadow: 0 24px 70px -30px rgba(79, 70, 229, 0.55);
}
.login-visual::before {
  content: "";
  position: absolute;
  inset: 2rem;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 20px;
  transform: perspective(900px) rotateX(5deg) rotateY(-8deg);
}
.orbital {
  position: absolute;
  inset: 17%;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 22px;
  transform: perspective(900px) rotateX(4deg) rotateY(-10deg);
}
.pulse-card {
  position: absolute;
  min-width: 136px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font: 700 0.84rem var(--font-body);
  backdrop-filter: blur(10px);
  box-shadow: 0 18px 34px -24px rgba(15, 23, 42, 0.58);
  animation: float 5s ease-in-out infinite;
}
.pulse-card.top { top: 10%; left: 14%; }
.pulse-card.middle { top: 44%; right: 7%; animation-delay: -1.5s; }
.pulse-card.bottom { bottom: 13%; left: 22%; animation-delay: -3s; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  background: #0f172a;
  color: #e2e8f0;
  border-right: 1px solid rgba(148, 163, 184, 0.18);
}
.brand {
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}
.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  font-weight: 800;
  box-shadow: 0 10px 30px -16px rgba(124, 58, 237, 0.85);
}
.brand strong {
  display: block;
  color: #fff;
  font-weight: 800;
  line-height: 1.1;
}
.brand span {
  display: block;
  margin-top: 0.12rem;
  color: #94a3b8;
  font-size: 0.84rem;
}
.sidebar nav {
  display: grid;
  gap: 0.28rem;
}
.sidebar a,
.ghost-btn {
  min-height: 44px;
  display: flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: #cbd5e1;
  padding: 0.72rem 0.85rem;
  text-align: left;
  text-decoration: none;
  font-weight: 700;
  transition: color 180ms ease, background 180ms ease, border-color 180ms ease;
}
.sidebar a:hover,
.sidebar a.active,
.ghost-btn:hover {
  color: #fff;
  border-color: rgba(129, 140, 248, 0.28);
  background: rgba(79, 70, 229, 0.18);
}
.ghost-btn {
  margin-top: auto;
}

.workspace {
  width: 100%;
  max-width: 1380px;
  padding: clamp(1rem, 2.4vw, 2.4rem);
}
.topbar {
  min-height: 118px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 1.15rem;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
}
.topbar h1 {
  font-size: clamp(2.25rem, 3.8vw, 4rem);
  line-height: 1.04;
}
.top-actions,
.button-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.section-label {
  display: inline-flex;
  align-items: center;
  gap: 0.52rem;
  margin-bottom: 0.7rem;
  color: var(--primary);
  font: 700 0.72rem var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.section-label span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.12);
}

.grid { display: grid; gap: 0.9rem; }
.metrics-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 1rem;
}
.metric-card,
.panel,
.chart-card,
.info-list div,
.cookie-item {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
}
.metric-card {
  height: 116px;
  min-width: 0;
  overflow: hidden;
  padding: 1rem;
}
.metric-card span,
.chart-card span,
.info-list span {
  color: var(--muted-foreground);
  font: 700 0.72rem var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.metric-card strong {
  display: -webkit-box;
  min-height: 2.5rem;
  margin-top: 0.55rem;
  overflow: hidden;
  color: var(--foreground);
  font-size: clamp(1.45rem, 2vw, 1.9rem);
  font-weight: 800;
  line-height: 1.1;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.metric-card.compact {
  height: 112px;
}
.metric-card.compact strong {
  font-size: 1.04rem;
  font-weight: 800;
  line-height: 1.28;
}
.panel {
  position: relative;
  overflow: hidden;
  margin-top: 1rem;
  padding: clamp(1rem, 1.8vw, 1.5rem);
}
.panel-head {
  min-height: 68px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.panel h2 {
  font-size: clamp(1.5rem, 2.3vw, 2.25rem);
  line-height: 1.08;
}
.inverted {
  color: #fff;
  border-color: rgba(99, 102, 241, 0.24);
  background: linear-gradient(135deg, #312e81, #4f46e5);
  box-shadow: 0 16px 40px -20px rgba(79, 70, 229, 0.5);
}
.inverted h2,
.inverted .login-manager h3,
.inverted .section-label { color: #fff; }
.inverted .section-label span { background: #a78bfa; box-shadow: 0 0 0 4px rgba(167, 139, 250, 0.18); }
.inverted label { color: rgba(255, 255, 255, 0.82); }
.inverted textarea,
.inverted input,
.inverted select {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}
.form-stack {
  display: grid;
  gap: 0.9rem;
}
label {
  display: grid;
  gap: 0.4rem;
  color: #334155;
  font-size: 0.9rem;
  font-weight: 700;
}
input,
textarea,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--foreground);
  padding: 0.68rem 0.85rem;
  outline: none;
  line-height: 1.35;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
textarea {
  min-height: 118px;
  max-height: 260px;
  resize: vertical;
  line-height: 1.45;
}
input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}
.toggle-row {
  height: 56px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.72rem;
  overflow: hidden;
  padding: 0.82rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
.toggle-row input {
  width: 18px;
  min-height: auto;
  accent-color: var(--primary);
}

.primary-btn,
.outline-btn,
.danger-btn {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 1.1rem;
  text-decoration: none;
  font-weight: 800;
  color: var(--foreground);
  white-space: nowrap;
  touch-action: manipulation;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, border-color 180ms ease;
}
.primary-btn {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  box-shadow: var(--button-shadow);
}
.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.32);
}
.outline-btn {
  color: #334155;
  border-color: var(--border-strong);
  background: #fff;
}
.outline-btn:hover {
  transform: translateY(-1px);
  border-color: #a5b4fc;
  background: #f8fafc;
}
.outline-btn.light {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.42);
  background: rgba(255, 255, 255, 0.08);
}
.danger-btn {
  color: #fff;
  background: var(--danger);
}
.danger-btn:hover {
  transform: translateY(-1px);
  background: #b91c1c;
}
.primary-btn:active,
.outline-btn:active,
.danger-btn:active {
  transform: translateY(0);
}

.segmented {
  height: 50px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 0.28rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
}
.segmented button {
  min-width: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted-foreground);
  font-weight: 800;
}
.segmented button.active {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  box-shadow: 0 7px 14px -10px rgba(79, 70, 229, 0.8);
}

.cookie-list {
  min-height: 200px;
  max-height: 280px;
  display: grid;
  gap: 0.65rem;
  overflow: auto;
}
.cookie-item {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  overflow: hidden;
  padding: 0.82rem 0.9rem;
}
.cookie-item strong,
.info-list strong {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.62rem;
  background: var(--surface-soft);
  color: var(--muted-foreground);
  font: 700 0.72rem var(--font-mono);
  white-space: nowrap;
}
.badge.ok {
  border-color: rgba(16, 185, 129, 0.24);
  background: rgba(16, 185, 129, 0.1);
  color: #047857;
}
.badge.warn {
  border-color: rgba(220, 38, 38, 0.2);
  background: rgba(220, 38, 38, 0.08);
  color: #b91c1c;
}
.hint {
  color: var(--muted-foreground);
  line-height: 1.45;
}
.login-manager {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.panel-head.tight {
  min-height: 64px;
  align-items: center;
  margin-bottom: 0.85rem;
}
.login-manager h3 {
  font-size: 1.22rem;
  line-height: 1.18;
}
.login-status {
  min-height: 38px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  overflow: hidden;
  margin: 0.85rem 0;
}

.system-grid {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 0.9rem;
}
.server-metrics-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 0.9rem;
}
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}
.chart-card {
  height: 314px;
  min-width: 0;
  overflow: hidden;
  padding: 1rem;
}
.chart-card canvas {
  display: block;
  width: 100%;
  height: 240px;
  margin-top: 0.65rem;
  border-radius: 12px;
  background: #fff;
}
.info-list {
  display: grid;
  align-content: start;
  gap: 0.65rem;
}
.info-list div {
  height: 78px;
  overflow: hidden;
  padding: 0.82rem 0.95rem;
}
.info-list strong {
  margin-top: 0.22rem;
  font-size: 1rem;
}
.log-box {
  height: 520px;
  min-height: 520px;
  max-height: 520px;
  overflow: auto;
  margin: 0;
  padding: 1rem;
  border: 1px solid #1e293b;
  border-radius: 14px;
  background: #0f172a;
  color: #dbeafe;
  font: 0.78rem/1.55 var(--font-mono);
}
.log-box.small {
  height: 220px;
  min-height: 220px;
  max-height: 220px;
}
.error-text {
  min-height: 44px;
  margin: 0;
  padding: 0.75rem 0.9rem;
  border: 1px solid rgba(220, 38, 38, 0.22);
  border-radius: 12px;
  background: rgba(220, 38, 38, 0.08);
  color: #b91c1c;
  font-weight: 800;
}
.error-text:empty { display: none; }
.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
  max-width: min(420px, calc(100vw - 2rem));
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 14px;
  background: #0f172a;
  color: #fff;
  padding: 0.85rem 1rem;
  box-shadow: 0 16px 40px -18px rgba(15, 23, 42, 0.55);
}

@keyframes float {
  0%, 100% { transform: translateY(-5px); }
  50% { transform: translateY(5px); }
}

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 224px minmax(0, 1fr); }
  .metrics-grid,
  .server-metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts-grid,
  .system-grid { grid-template-columns: 1fr; }
  .chart-card { height: 300px; }
}

@media (max-width: 860px) {
  .login-shell {
    grid-template-columns: 1fr;
    align-content: center;
  }
  .login-visual { display: none; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
  }
  .sidebar nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ghost-btn { margin-top: 0.8rem; }
  .workspace { padding: 1rem; }
  .topbar,
  .panel-head {
    min-height: auto;
    flex-direction: column;
    align-items: stretch;
  }
  .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .metrics-grid,
  .server-metrics-grid,
  .sidebar nav { grid-template-columns: 1fr; }
  .top-actions,
  .button-row { width: 100%; }
  .primary-btn,
  .outline-btn,
  .danger-btn { flex: 1 1 auto; }
  .metric-card,
  .metric-card.compact { height: 112px; }
  .log-box {
    height: 420px;
    min-height: 420px;
    max-height: 420px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
