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

/* === DESIGN TOKENS === */
:root {
  /* Surfaces - 4-tier depth system */
  --bg: #0c0e14;
  --surface-1: #13161f;
  --surface-2: #1a1e2a;
  --surface-3: #222838;
  --surface-hover: #262d40;

  /* Borders */
  --border: #2a3042;
  --border-subtle: #1f2535;
  --border-focus: #6c5ce7;

  /* Text */
  --text-primary: #f0f1f5;
  --text-secondary: #7c8298;
  --text-tertiary: #525872;

  /* Semantic */
  --green: #34d399;
  --green-dim: rgba(52, 211, 153, 0.12);
  --red: #f87171;
  --red-dim: rgba(248, 113, 113, 0.10);
  --blue: #60a5fa;
  --blue-dim: rgba(96, 165, 250, 0.10);
  --orange: #fbbf24;
  --orange-dim: rgba(251, 191, 36, 0.10);
  --purple: #8b5cf6;
  --purple-dim: rgba(139, 92, 246, 0.12);

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  --radius: 10px;
  --radius-lg: 14px;
  --radius-sm: 6px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === HEADER === */
.header {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--sp-6);
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
  background: rgba(19, 22, 31, 0.85);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.header-brand .logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--purple), #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.header-brand h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.header-brand .domain {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 400;
  margin-left: var(--sp-1);
}

.header-right {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}

.header-right .monitor {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 var(--sp-3);
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--mono);
}

.monitor .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(52,211,153,0.4); }
  50% { opacity: 0.6; box-shadow: 0 0 0 4px rgba(52,211,153,0); }
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
  user-select: none;
}

.btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-focus);
  text-decoration: none;
  transform: translateY(-1px);
}

.btn:active { transform: translateY(0); }

/* Sizes */
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-lg { height: 36px; padding: 0 18px; font-size: 14px; }

/* Variants */
.btn-primary {
  background: linear-gradient(135deg, var(--purple), #6366f1);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(139,92,246,0.25);
}
.btn-primary:hover {
  box-shadow: 0 4px 16px rgba(139,92,246,0.35);
  border-color: transparent;
}

.btn-cta {
  background: linear-gradient(135deg, #059669, #10b981);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(16,185,129,0.25);
}
.btn-cta:hover {
  box-shadow: 0 4px 16px rgba(16,185,129,0.35);
  border-color: transparent;
}

.btn-danger {
  color: var(--red);
  border-color: rgba(248,113,113,0.25);
}
.btn-danger:hover { background: var(--red-dim); border-color: var(--red); }

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--surface-3); color: var(--text-primary); border-color: transparent; }

.btn-outline-green { color: var(--green); border-color: rgba(52,211,153,0.3); }
.btn-outline-green:hover { background: var(--green-dim); border-color: var(--green); }

.btn-outline-red { color: var(--red); border-color: rgba(248,113,113,0.25); }
.btn-outline-red:hover { background: var(--red-dim); border-color: var(--red); }

/* Button group */
.btn-group {
  display: flex;
  gap: 0;
}
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* === LAYOUT === */
.main {
  max-width: 1320px;
  margin: 0 auto;
  padding: var(--sp-6);
}

/* === STATS === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-3);
  margin-bottom: var(--sp-8);
}

.stat {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: var(--sp-5) var(--sp-5);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  transition: border-color 0.2s;
}

.stat:hover { border-color: var(--border); }

.stat .stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

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

.stat .stat-body { flex: 1; min-width: 0; }

.stat .stat-label {
  font-size: 12px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
  margin-bottom: 2px;
}

.stat .stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1.1;
}

.stat .stat-value.blue { color: var(--blue); }
.stat .stat-value.green { color: var(--green); }
.stat .stat-value.red { color: var(--red); }

/* === SECTION === */
.section {
  margin-bottom: var(--sp-8);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* === APP ROWS === */
.app-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.app-row {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all 0.2s ease;
}

.app-row:hover {
  border-color: var(--border);
  box-shadow: 0 4px 24px rgba(0,0,0,0.15);
}

/* Top section: identity + actions */
.app-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-5) var(--sp-3);
  gap: var(--sp-4);
}

.app-identity {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
}

.app-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
}

.app-icon.running { background: linear-gradient(135deg, #059669, #10b981); }
.app-icon.stopped { background: linear-gradient(135deg, #374151, #4b5563); }
.app-icon.static { background: linear-gradient(135deg, #2563eb, #3b82f6); }

.app-name-block { min-width: 0; }

.app-name-block h3 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.2px;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.app-name-block .desc {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}

/* Bottom section: metrics + uptime */
.app-bottom {
  display: flex;
  align-items: center;
  gap: var(--sp-6);
  padding: 0 var(--sp-5) var(--sp-4);
}

.app-metrics {
  display: flex;
  gap: var(--sp-6);
  align-items: center;
  flex: 1;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.metric .m-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  font-weight: 500;
}

.metric .m-value {
  font-size: 13px;
  font-weight: 500;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-secondary);
}

.metric .m-value a { color: var(--blue); }

/* Uptime bar */
.uptime-section {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-shrink: 0;
}

.uptime-bar {
  display: flex;
  gap: 1.5px;
  height: 22px;
  width: 140px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-3);
}

.uptime-bar .tick { flex: 1; min-width: 2px; border-radius: 1px; }
.uptime-bar .tick.up { background: var(--green); }
.uptime-bar .tick.down { background: var(--red); }
.uptime-bar .tick.unknown, .uptime-bar .tick.static { background: var(--surface-3); }

.uptime-pct {
  font-size: 13px;
  font-weight: 600;
  font-family: var(--mono);
  color: var(--green);
  min-width: 48px;
}

/* === STATUS BADGE === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge.up { background: var(--green-dim); color: var(--green); }
.badge.down { background: var(--red-dim); color: var(--red); }
.badge.stopped { background: rgba(107,114,128,0.15); color: #9ca3af; }
.badge.unknown { background: var(--orange-dim); color: var(--orange); }
.badge.static { background: var(--blue-dim); color: var(--blue); }

/* === PORT TABLE === */
.table-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.table-wrap th {
  text-align: left;
  padding: var(--sp-3) var(--sp-5);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-tertiary);
  font-weight: 600;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.table-wrap td {
  padding: var(--sp-3) var(--sp-5);
  font-size: 13px;
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--mono);
  color: var(--text-secondary);
}

.table-wrap tr:last-child td { border-bottom: none; }
.table-wrap tr:hover td { background: var(--surface-2); }
.table-wrap td.name { font-family: var(--font); font-weight: 500; color: var(--text-primary); }

/* === INCIDENTS === */
.incidents-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  overflow: hidden;
}

.incident {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  font-size: 13px;
  border-bottom: 1px solid var(--border-subtle);
  transition: background 0.1s;
}

.incident:last-child { border-bottom: none; }
.incident:hover { background: var(--surface-2); }

.incident .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.incident .dot.down { background: var(--red); box-shadow: 0 0 6px rgba(248,113,113,0.4); }
.incident .dot.resolved { background: var(--green); }

.incident .time {
  color: var(--text-tertiary);
  font-size: 12px;
  font-family: var(--mono);
  margin-left: auto;
}

.empty {
  color: var(--text-tertiary);
  font-size: 13px;
  padding: var(--sp-8) var(--sp-5);
  text-align: center;
}

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  width: 92%;
  max-width: 580px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,0.4);
}

.modal h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: var(--sp-5);
  letter-spacing: -0.3px;
}

.form-group { margin-bottom: var(--sp-4); }

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

.form-group input, .form-group select {
  width: 100%;
  height: 38px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px var(--purple-dim); }
.form-group input::placeholder { color: var(--text-tertiary); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}

.log-output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-4);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  max-height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
  color: var(--green);
}

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
  animation: toastIn 0.3s cubic-bezier(0.16,1,0.3,1);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.toast.success { background: var(--green); color: #000; }
.toast.error { background: var(--red); color: #fff; }

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

/* === RESPONSIVE === */
@media (max-width: 1024px) {
  .app-top { flex-direction: column; align-items: flex-start; }
  .app-bottom { flex-direction: column; align-items: flex-start; gap: var(--sp-3); }
  .app-actions { width: 100%; flex-wrap: wrap; }
}

@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .app-metrics { flex-wrap: wrap; gap: var(--sp-3); }
  .header { padding: 0 var(--sp-4); }
  .main { padding: var(--sp-4); }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .header-right { gap: var(--sp-1); }
}
