:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --border: #e6edf5;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
}

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

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.15rem 0.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand img {
  display: block;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  border: 0;
  background: transparent;
  color: #475569;
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}

.nav-item svg {
  flex-shrink: 0;
}

.nav-item:hover {
  background: #f8fafc;
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-soft);
  color: #4338ca;
  font-weight: 600;
}

.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.15rem 1.25rem 0.35rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
}

.meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.meta-cluster {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 0.45rem 0.85rem;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.btn:hover {
  border-color: #c7d2fe;
  background: #f8fafc;
}

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

.btn-primary:hover {
  background: #4338ca;
  border-color: #4338ca;
  filter: none;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-small {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.monitor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1rem;
  padding: 0.85rem 1.25rem 1.5rem;
  align-items: start;
}

.monitor-primary {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.monitor-primary > *,
.insights > *,
.summary-cards,
.panel,
.table-scroll {
  min-width: 0;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.summary-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.05rem 1.1rem;
}

.summary-card .label {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0;
}

.summary-card .value {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0.2rem 0 0.15rem;
  line-height: 1.1;
}

.summary-card .sub {
  color: var(--muted);
  font-size: 0.78rem;
  margin: 0;
}

.summary-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.summary-icon.servers {
  background: #eef2ff;
  color: #4f46e5;
}

.summary-icon.alerts {
  background: #fee2e2;
  color: #dc2626;
}

.summary-icon.disk {
  background: #ecfeff;
  color: #0f766e;
}

.insights {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(220px, 0.85fr);
  gap: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.05rem 1.15rem 1.1rem;
}

.panel h2 {
  margin: 0 0 0.85rem;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

.empty {
  color: var(--muted);
  padding: 0.5rem 0 0.25rem;
}

.hidden {
  display: none !important;
}

.chart-canvas {
  position: relative;
  height: 280px;
}

.donut-layout {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.donut-wrap {
  position: relative;
  width: 180px;
  height: 180px;
  margin: 0.25rem auto 0;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.donut-center strong {
  font-size: 1.65rem;
  letter-spacing: -0.03em;
  line-height: 1;
}

.donut-center span {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 0.2rem;
}

.donut-legend {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.donut-legend li {
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  gap: 0.55rem;
  align-items: center;
  font-size: 0.85rem;
}

.donut-legend strong {
  font-variant-numeric: tabular-nums;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.swatch.ok {
  background: #22c55e;
}

.swatch.warn {
  background: #eab308;
}

.swatch.alert {
  background: #ef4444;
}

.history-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.filter-field .text-input {
  width: auto;
  min-width: 13rem;
}

.filter-field .filter-text {
  min-width: 9rem;
}

.filter-range {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  border: 0;
}

.filter-range legend {
  padding: 0 0.45rem 0.55rem 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.filter-field .range-input {
  width: 5.5rem;
  min-width: 5.5rem;
}

.filter-actions {
  display: flex;
  gap: 0.5rem;
}

.table-scroll {
  overflow-x: auto;
}

.servers-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.servers-table th,
.servers-table td {
  padding: 0.75rem 0.7rem;
  border-bottom: 1px solid #f1f5f9;
  text-align: left;
  white-space: nowrap;
}

.servers-table th {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.servers-table tbody tr:last-child td {
  border-bottom: 0;
}

.servers-table tbody tr {
  cursor: pointer;
}

.panel-history .servers-table tbody tr {
  cursor: default;
}

.servers-table tbody tr:hover,
.servers-table tbody tr.selected {
  background: #f8fafc;
}

.servers-table tbody tr.selected {
  background: #eef2ff;
}

.servers-table .metric-sub {
  color: var(--muted);
  font-size: 0.78rem;
}

.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge.alert {
  background: var(--danger-bg);
  color: var(--danger);
}

.metric-high {
  color: var(--danger);
  font-weight: 600;
}

.history-pager {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.activity-rail {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.activity-rail .panel h2 {
  margin-bottom: 0.35rem;
}

.activity-list {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.6rem 0.25rem;
  border-radius: 10px;
  cursor: pointer;
  color: inherit;
}

.activity-item:hover {
  background: #f8fafc;
}

.activity-dot {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-top: 0.05rem;
}

.activity-dot.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.activity-dot.alert {
  background: var(--danger-bg);
  color: var(--danger);
}

.activity-dot.warn {
  background: #fef9c3;
  color: #a16207;
}

.server-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex-shrink: 0;
}

.server-status.ok {
  color: #15803d;
}

.server-status.ok .status-dot {
  background: #22c55e;
}

.server-status.warn {
  color: #a16207;
}

.server-status.warn .status-dot {
  background: #eab308;
}

.server-status.alert {
  color: #dc2626;
}

.server-status.alert .status-dot {
  background: #ef4444;
}

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

.activity-copy strong {
  display: block;
  font-size: 0.88rem;
}

.activity-copy p {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.activity-time {
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

.view-script {
  padding: 0.85rem 1.25rem 1.5rem;
}

.script-panel {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 6.5rem);
}

.script-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

.script-header h2 {
  margin-bottom: 0.35rem;
}

.script-header a {
  color: var(--accent);
}

.script-actions {
  display: flex;
  gap: 0.5rem;
}

.field-label {
  display: block;
  margin: 0.9rem 0 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.text-input {
  width: 100%;
  background: #fff;
  border: 1px solid #dbe3ee;
  color: var(--text);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
}

.text-input:focus {
  outline: none;
  border-color: #818cf8;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.script-editor {
  flex: 1;
  width: 100%;
  min-height: 50vh;
  margin-top: 0.65rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  resize: vertical;
  tab-size: 2;
}

.script-editor:focus {
  outline: none;
  border-color: #818cf8;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.cron-block {
  margin-top: 0.85rem;
}

.copy-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.35rem 0 0.75rem;
}

.copy-target {
  flex: 1;
  min-width: 200px;
  font-size: 0.78rem;
  background: #f8fafc;
  color: var(--text);
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  word-break: break-all;
}

.banner {
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  font-size: 0.85rem;
}

.banner.ok {
  background: #f0fdf4;
  color: var(--ok);
}

.banner.error {
  background: #fef2f2;
  color: #b91c1c;
}

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at top left, rgba(199, 210, 254, 0.55), transparent 52%),
    radial-gradient(ellipse at bottom right, rgba(186, 230, 253, 0.45), transparent 48%),
    var(--bg);
}

.login-wrap {
  width: min(440px, calc(100% - 2rem));
  padding: 1.5rem 0;
}

.login-panel {
  padding: 1.75rem 1.7rem 1.5rem;
}

.login-logo {
  display: block;
}

.login-panel h1 {
  margin: 0.85rem 0 0.3rem;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
}

.login-panel .subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.login-panel form {
  margin-top: 0.35rem;
}

.login-submit {
  width: 100%;
  margin-top: 1.15rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 1rem;
}

@media (max-width: 1100px) {
  .monitor-layout,
  .insights,
  .summary-cards {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .side-nav {
    flex-direction: row;
  }

  .nav-item {
    width: auto;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }
}
