/* ===== CSS Variables — Apple-inspired ===== */
:root {
  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-hover: #f0f0f2;
  --bg-input: #f5f5f7;
  --bg-terminal: #1d1d1f;
  --text: #1d1d1f;
  --text-secondary: #86868b;
  --text-terminal: #33ff33;
  --border: #d2d2d7;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --yellow: #ffcc00;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 240px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #000000;
  --bg-card: #1c1c1e;
  --bg-sidebar: #1c1c1e;
  --bg-hover: #2c2c2e;
  --bg-input: #2c2c2e;
  --bg-terminal: #000000;
  --text: #f5f5f7;
  --text-secondary: #98989d;
  --border: #38383a;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}

/* ===== Login Page ===== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px 40px;
  width: 380px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo { margin-bottom: 32px; color: var(--text); }
.login-logo svg { margin-bottom: 12px; opacity: 0.8; }
.login-logo h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.login-logo p { color: var(--text-secondary); font-size: 15px; margin-top: 4px; }

.form-group { margin-bottom: 16px; }
.form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition);
}
.form-group input:focus { border-color: var(--accent); }

.error-text { color: var(--red); font-size: 13px; margin-top: 12px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }
.btn-icon { padding: 6px; border: none; background: transparent; }
.btn-icon:hover { background: var(--bg-hover); border-radius: 6px; }

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

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.3px;
}

.sidebar-nav { flex: 1; padding: 0 8px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition);
  margin-bottom: 2px;
  position: relative;
}
.nav-item:hover { background: var(--bg-hover); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item.active svg { stroke: #fff; }

.badge {
  position: absolute;
  right: 10px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
}
.theme-toggle:hover { background: var(--bg-hover); }
[data-theme="dark"] .icon-sun { display: inline; }
[data-theme="dark"] .icon-moon { display: none; }
.icon-sun { display: none; }
.icon-moon { display: inline; }

.btn-logout {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
}
.btn-logout:hover { color: var(--red); }

/* ===== Main ===== */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 24px 32px;
  min-height: 100vh;
}

.page { animation: fadeIn 0.2s ease; }
.hidden { display: none !important; }

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

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h2 { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; letter-spacing: -0.5px; }
.stat-card .stat-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ===== Nodes Grid ===== */
.nodes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.node-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition);
  cursor: pointer;
}
.node-card:hover { box-shadow: var(--shadow-lg); }

.node-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.node-card-header h3 { font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 8px; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.offline { background: var(--red); box-shadow: 0 0 6px var(--red); }
.status-dot.warning { background: var(--orange); }

.node-tags { display: flex; gap: 6px; }
.tag {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.tag-entry { background: rgba(0,113,227,0.1); color: var(--accent); }
.tag-wg { background: rgba(52,199,89,0.1); color: var(--green); }
.tag-subagg { background: rgba(255,149,0,0.1); color: var(--orange); }

.node-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}
.metric { text-align: center; }
.metric-label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; }
.metric-value { font-size: 18px; font-weight: 600; }

.node-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}

/* ===== Progress bars ===== */
.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
}
.progress-green { background: var(--green); }
.progress-orange { background: var(--orange); }
.progress-red { background: var(--red); }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-hover); }

/* ===== Alerts List ===== */
.alerts-list { display: flex; flex-direction: column; gap: 8px; }
.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.alert-item.critical { border-left: 3px solid var(--red); }
.alert-item.warning { border-left: 3px solid var(--orange); }
.alert-item.info { border-left: 3px solid var(--accent); }
.alert-message { flex: 1; }
.alert-time { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }

/* ===== Terminal ===== */
.terminal {
  background: var(--bg-terminal);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  color: var(--text-terminal);
  min-height: 400px;
  max-height: 60vh;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.terminal-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-terminal);
  border-radius: 0 0 var(--radius) var(--radius);
  border-top: 1px solid #333;
  padding: 8px 16px;
}
.terminal-prompt { color: var(--green); font-family: monospace; font-weight: 700; margin-right: 8px; }
.terminal-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-family: monospace;
  font-size: 13px;
}

/* ===== Settings ===== */
.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.settings-card h3 { font-size: 17px; font-weight: 600; margin-bottom: 16px; }

.form-row { margin-bottom: 14px; display: flex; align-items: center; gap: 12px; }
.form-row label { font-size: 14px; min-width: 200px; color: var(--text-secondary); }
.form-row.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row.checkboxes { gap: 20px; }
.form-row.checkboxes label { min-width: unset; display: flex; align-items: center; gap: 6px; color: var(--text); cursor: pointer; }

.input-sm, .select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  outline: none;
  min-width: 120px;
}
.input-sm:focus, .select:focus { border-color: var(--accent); }

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

.modal {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 28px;
  width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-size: 20px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-secondary); }
.modal-close:hover { color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.modal input[type="text"],
.modal input[type="number"],
.modal input[type="password"],
.modal select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.modal input:focus, .modal select:focus { border-color: var(--accent); }
.modal label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; font-weight: 500; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { width: 64px; }
  .sidebar-header span, .nav-item span, .sidebar-footer .btn-logout { display: none; }
  .sidebar-header { justify-content: center; padding: 16px 8px; }
  .nav-item { justify-content: center; padding: 12px; }
  .main { margin-left: 64px; padding: 16px; }
  .nodes-grid { grid-template-columns: 1fr; }
  .modal { width: 95%; padding: 20px; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ===== Charts Grid ===== */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 16px;
}
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.chart-card canvas { height: 200px !important; }
.chart-card h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ===== Files ===== */
.files-breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 13px;
  overflow-x: auto;
  white-space: nowrap;
}
.files-breadcrumb .crumb {
  color: var(--accent);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}
.files-breadcrumb .crumb:hover { background: var(--bg-hover); }
.files-breadcrumb .sep { color: var(--text-secondary); }

.file-editor-textarea {
  width: 100%;
  height: 400px;
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 13px;
  background: var(--bg-terminal);
  color: var(--text-terminal);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  resize: vertical;
  outline: none;
  tab-size: 4;
}

.file-icon { margin-right: 6px; opacity: 0.6; }
.file-link { color: var(--accent); cursor: pointer; }
.file-link:hover { text-decoration: underline; }

/* ===== Actions ===== */
.actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.action-group {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.action-group h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.action-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.action-btn { font-size: 13px; }
.action-btn.running { opacity: 0.6; pointer-events: none; }

/* ===== Backup ===== */
.backup-info { margin-bottom: 16px; }
.backup-info p { color: var(--text-secondary); font-size: 14px; }

/* ===== Utility ===== */
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-orange { color: var(--orange); }
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: 12px; }
.mt-8 { margin-top: 8px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.items-center { align-items: center; }
