/* ========== Custom Properties ========== */
:root {
  --bg-body: #0b1120;
  --bg-sidebar: #111827;
  --bg-card: #1a2332;
  --bg-input: #0f172a;
  --bg-hover: #1e293b;
  --border: #1e293b;
  --border-light: #2d3a4d;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.12);
  --green-border: rgba(34, 197, 94, 0.25);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.12);
  --amber-border: rgba(245, 158, 11, 0.25);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.12);
  --red-border: rgba(239, 68, 68, 0.25);
  --gray: #6b7280;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
  --transition: 150ms ease;
  --sidebar-width: 240px;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
}

/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; color-scheme: dark; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-body);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }

/* ========== Focus States ========== */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ========== Sidebar ========== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 40;
  border-right: 1px solid var(--border);
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.logo svg {
  color: var(--accent);
  flex-shrink: 0;
}

.logo-accent { color: var(--accent); }

.nav-links {
  list-style: none;
  padding: 8px 8px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-links li a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius);
  transition: all var(--transition);
  cursor: pointer;
}

.nav-links li a:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.nav-links li a.active {
  color: var(--accent);
  background: var(--accent-glow);
}

.nav-links li a svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-links li a.active svg,
.nav-links li a:hover svg { opacity: 1; }

.sidebar-version {
  padding: 0 20px 4px;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.sidebar-username {
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-link {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px;
  border-radius: var(--radius);
  transition: all var(--transition);
  cursor: pointer;
}

.logout-link:hover { color: var(--red); background: var(--red-bg); }
.logout-link svg { width: 18px; height: 18px; }

/* ========== Content ========== */
.content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 32px 40px;
  min-height: 100vh;
}

/* ========== Page Header ========== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

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

.page-header-meta {
  font-size: 13px;
  color: var(--text-muted);
}

/* ========== Cards ========== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  transition: border-color var(--transition);
}

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

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.card-header h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-header-plain {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

/* ========== Status Summary ========== */
.status-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.status-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
  transition: all var(--transition);
  cursor: default;
}

.status-card:hover {
  border-color: var(--border-light);
  transform: translateY(-1px);
}

.status-card-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.status-card .count {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.status-card .label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.status-card-icon svg { width: 20px; height: 20px; }

.status-card.total .count { color: var(--accent); }
.status-card.total .status-card-icon { background: var(--accent-glow); color: var(--accent); }
.status-card.total { border-color: rgba(59, 130, 246, 0.15); }

.status-card.ok .count { color: var(--green); }
.status-card.ok .status-card-icon { background: var(--green-bg); color: var(--green); }
.status-card.ok { border-color: var(--green-border); }

.status-card.missed .count { color: var(--amber); }
.status-card.missed .status-card-icon { background: var(--amber-bg); color: var(--amber); }
.status-card.missed { border-color: var(--amber-border); }

.status-card.failed .count { color: var(--red); }
.status-card.failed .status-card-icon { background: var(--red-bg); color: var(--red); }
.status-card.failed { border-color: var(--red-border); }

.status-card.inactive .count { color: var(--gray); }
.status-card.inactive .status-card-icon { background: rgba(107, 114, 128, 0.12); color: var(--gray); }

/* ========== Status Badges ========== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge-ok { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.badge-ok .badge-dot { background: var(--green); }

.badge-missed { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-border); }
.badge-missed .badge-dot { background: var(--amber); }

.badge-failed { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); }
.badge-failed .badge-dot { background: var(--red); }

.badge-inactive { background: rgba(107, 114, 128, 0.12); color: var(--gray); border: 1px solid rgba(107, 114, 128, 0.2); }
.badge-inactive .badge-dot { background: var(--gray); }

.badge-running { background: var(--accent-glow); color: var(--accent); border: 1px solid rgba(59, 130, 246, 0.25); }
.badge-running .badge-dot { background: var(--accent); animation: pulse-dot 1.5s ease-in-out infinite; }

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

/* ========== Tables ========== */
.table-wrap { overflow-x: auto; margin: -4px; padding: 4px; }

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

th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 14px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr { transition: background var(--transition); }
tbody tr:hover td { background: var(--bg-hover); }
tbody tr:last-child td { border-bottom: none; }

td a { font-weight: 500; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}

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

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.btn-primary:hover { background: var(--accent-hover); color: #fff; }

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

.btn-secondary { background: var(--bg-hover); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border-light); color: var(--text); border-color: var(--border-light); }

.btn-success { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.btn-success:hover { background: rgba(34, 197, 94, 0.2); color: var(--green); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: 6px; }
.btn-group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.btn-icon { padding: 6px; }

/* ========== Forms ========== */
.form-group { margin-bottom: 16px; }

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

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  line-height: 1.5;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder { color: var(--text-muted); }

.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ========== Inline Info Grid ========== */
.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.info-item label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.info-item-value {
  font-size: 14px;
  color: var(--text);
  word-break: break-all;
}

/* ========== Alerts ========== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: alert-in 200ms ease-out;
}

@keyframes alert-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.alert-success { background: var(--green-bg); border: 1px solid var(--green-border); color: var(--green); }
.alert-error { background: var(--red-bg); border: 1px solid var(--red-border); color: var(--red); }
.alert-info { background: var(--accent-glow); border: 1px solid rgba(59, 130, 246, 0.25); color: var(--accent-hover); }

/* ========== Modal ========== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

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

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 500px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg);
  animation: modal-in 200ms ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal h3 {
  margin-bottom: 20px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ========== Log Viewer ========== */
.log-viewer {
  background: #060a12;
  border-radius: var(--radius);
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  max-height: 420px;
  overflow-y: auto;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.log-viewer::-webkit-scrollbar { width: 6px; }
.log-viewer::-webkit-scrollbar-track { background: transparent; }
.log-viewer::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

.log-viewer .log-line { white-space: pre-wrap; word-break: break-all; padding: 1px 0; }
.log-viewer .log-line.error { color: var(--red); }
.log-viewer .log-line.success { color: var(--green); }
.log-viewer .log-line.warning { color: var(--amber); }

.log-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.log-controls label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }

.log-controls select {
  padding: 5px 10px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
}

/* ========== Toggle Switch ========== */
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { display: none; }

.toggle .slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border-light);
  border-radius: 22px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle .slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 2px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition);
}

.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(18px); }

/* ========== Login Page ========== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  background: var(--bg-body);
}

.login-box {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.login-brand svg { color: var(--accent); }

.login-brand-text {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

/* ========== Utility ========== */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.min-w-0 { min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mono {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-input);
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.copy-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.copy-btn:hover { border-color: var(--accent); color: var(--accent); }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state svg { margin-bottom: 12px; opacity: 0.4; }
.empty-state p { margin-top: 8px; font-size: 14px; }

.section-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ========== Toast ========== */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  min-width: 300px;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in 200ms ease-out;
}

.toast-success { background: var(--green-bg); border: 1px solid var(--green-border); color: var(--green); }
.toast-error { background: var(--red-bg); border: 1px solid var(--red-border); color: var(--red); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-8px); }
}

/* ========== Heartbeat Indicator ========== */
.heartbeat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}

.heartbeat-dot.online {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.heartbeat-dot.offline {
  background: var(--gray);
}

/* ========== Responsive ========== */
@media (max-width: 1024px) {
  .status-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .content { margin-left: 0; padding: 20px 16px; }
  .status-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { flex-direction: column; gap: 0; }
  .info-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .btn-group { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .status-grid { grid-template-columns: 1fr; }
}

/* ========== Reduced Motion ========== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
