:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-sidebar: #0d1117;
  --bg-input: #21262d;
  --bg-hover: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --danger: #f85149;
  --success: #3fb950;
  --warning: #d29922;
  --radius: 6px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

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

/* Layout */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  bottom: 0;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 0 16px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-brand svg { width: 20px; height: 20px; }

.sidebar nav a {
  display: block;
  padding: 8px 16px;
  color: var(--text-muted);
  font-size: 13px;
  border-left: 3px solid transparent;
  transition: all 0.15s;
}

.sidebar nav a:hover { background: var(--bg-hover); color: var(--text); }
.sidebar nav a.active {
  color: var(--text);
  border-left-color: var(--accent);
  background: var(--bg-hover);
}

.sidebar-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.main {
  margin-left: 220px;
  flex: 1;
  padding: 24px 32px;
  min-width: 0;
}

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

.page-header h1 {
  font-size: 20px;
  font-weight: 600;
}

/* Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.card-value {
  font-size: 24px;
  font-weight: 600;
}

.card-value-link {
  display: block;
  color: var(--accent);
  cursor: pointer;
  transition: color 0.15s;
  text-decoration: none;
}

.card-value-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* Tables */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
}

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

th, td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg);
}

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

td code {
  font-family: 'SF Mono', SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 3px;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-green { background: rgba(63,185,80,0.15); color: var(--success); }
.badge-red { background: rgba(248,81,73,0.15); color: var(--danger); }
.badge-yellow { background: rgba(210,153,34,0.15); color: var(--warning); }
.badge-blue { background: rgba(88,166,255,0.15); color: var(--accent); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover { background: var(--bg-hover); border-color: var(--text-muted); }

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

.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(248,81,73,0.1); }

.btn-sm { padding: 3px 10px; font-size: 12px; }

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

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

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}

.form-group input[type="checkbox"] {
  width: auto;
  padding: 0;
  background: none;
  border: revert;
  border-radius: 0;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-inline {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.form-inline .form-group { margin-bottom: 0; }

/* Modal / Dialog */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.dialog {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  min-width: 400px;
  max-width: 560px;
}

.dialog h2 {
  font-size: 16px;
  margin-bottom: 16px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* Wide dialog with side-panel */
.dialog.dialog-wide {
  max-width: 960px;
  min-width: 700px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.dialog-wide-body {
  display: flex;
  gap: 20px;
  flex: 1;
  min-height: 0;
}

.dialog-wide-form {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

.dialog-wide-help {
  width: 280px;
  flex-shrink: 0;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  padding-left: 20px;
  max-height: calc(90vh - 120px);
}

.help-panel-content { font-size: 12px; }

.help-panel-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

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

.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 380px;
}

.login-box h1 {
  font-size: 20px;
  margin-bottom: 4px;
}

.login-box p {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

/* Misc */
.mono {
  font-family: 'SF Mono', SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.mr-2 { margin-right: 8px; }

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

.hidden { display: none !important; }

/* Log viewer */
.log-viewer {
  background: #010409;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  font-family: 'SF Mono', SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.6;
}

.log-line {
  display: flex;
  gap: 12px;
  padding: 1px 0;
}

.log-line:hover { background: rgba(255,255,255,0.03); }

.log-ts {
  color: var(--text-muted);
  flex-shrink: 0;
  user-select: none;
}

.log-comp {
  color: #58a6ff;
  flex-shrink: 0;
  user-select: none;
  min-width: 100px;
}

.log-msg {
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
}

/* Copy block */
.copy-block {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: 'SF Mono', SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
  position: relative;
}

.copy-block .btn-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 8px;
  font-size: 11px;
}

/* Monitoring */
.mon-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.mon-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.mon-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.mon-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mon-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.mon-detail {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 8px;
}

.mon-chart-wrap {
  position: relative;
}

.mon-chart-wrap canvas {
  width: 100%;
  height: 160px;
  border-radius: 4px;
}

.mon-mounts {
  margin-top: 12px;
}

.mon-mount {
  margin-bottom: 8px;
}

.mon-mount-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.mon-mount-bar {
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.mon-mount-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.mon-legend {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.mon-legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* Sidebar divider */
.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 12px;
}

/* Observatorium dashboards */
.obs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.obs-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.obs-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.obs-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.obs-panel-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.obs-chart-wrap { position: relative; }

.obs-chart-wrap canvas {
  width: 100%;
  height: 180px;
  border-radius: 4px;
}

.obs-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.obs-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.obs-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.obs-time-range {
  display: flex;
  gap: 4px;
}

.obs-time-range button {
  padding: 3px 8px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.obs-time-range button:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.obs-time-range button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.obs-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(22,27,34,0.92);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text);
  white-space: nowrap;
  z-index: 10;
  display: none;
}

.obs-tooltip-time {
  color: var(--text-muted);
  margin-bottom: 2px;
}

.obs-tooltip-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.obs-tooltip-val {
  font-weight: 600;
  font-family: 'SF Mono', SFMono-Regular, Menlo, monospace;
}

/* Alert */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
}

.alert-warning {
  background: rgba(210,153,34,0.1);
  border: 1px solid rgba(210,153,34,0.3);
  color: #d29922;
}

/* Node detail */
.node-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.node-info-grid .card { padding: 12px; }
.node-info-grid .card-label { margin-bottom: 2px; }
.node-info-grid .card-value { font-size: 14px; font-weight: 500; word-break: break-all; }

.node-section { margin-bottom: 24px; }

.node-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.node-roles {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.node-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.meter { margin-bottom: 10px; }

.meter-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.meter-bar {
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

.node-detail-logs {
  background: #010409;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  max-height: 360px;
  overflow-y: auto;
  font-family: 'SF Mono', SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.6;
}

/* Env builder */
.env-builder { margin-bottom: 8px; }

.env-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  align-items: center;
}

.env-row input:first-child { width: 140px; flex-shrink: 0; }
.env-row input:nth-child(2) { flex: 1; }

/* Compose page layout */
.compose-page-body {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.compose-page-form {
  flex: 1;
  min-width: 0;
}

.compose-page-help {
  width: 300px;
  flex-shrink: 0;
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  border-left: 1px solid var(--border);
  padding-left: 24px;
}

.compose-page-actions {
  margin-bottom: 16px;
}

@media (max-width: 900px) {
  .compose-page-body { flex-direction: column; }
  .compose-page-help {
    width: 100%;
    position: static;
    max-height: none;
    border-left: none;
    border-top: 1px solid var(--border);
    padding-left: 0;
    padding-top: 16px;
  }
}

/* Compose editor */
.compose-editor {
  width: 100%;
  min-height: 260px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: 'SF Mono', SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
  tab-size: 2;
}

.compose-results { margin-top: 12px; }

/* Help sections (used in side-panel) */
.help-section { margin-bottom: 12px; }
.help-section:last-child { margin-bottom: 0; }
.help-section strong { display: block; margin-bottom: 6px; color: var(--text); font-size: 12px; }
.help-hint { color: var(--text-muted); margin-bottom: 6px; font-size: 11px; }
.help-vars { display: flex; flex-direction: column; gap: 2px; }
.help-var { display: flex; gap: 4px; align-items: baseline; }
.help-var code {
  font-family: 'SF Mono', SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
}

.help-example {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  font-family: 'SF Mono', SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
}

/* Advanced form section */
.form-advanced {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
}

.form-advanced summary {
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 0;
}

.form-advanced summary:hover { color: var(--accent); }
.form-advanced[open] summary { margin-bottom: 12px; }

/* YAML editor with syntax highlighting overlay */
.yaml-editor-wrap {
  position: relative;
  min-height: 300px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
}

.yaml-editor,
.yaml-highlight {
  font-family: 'SF Mono', SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  tab-size: 2;
  padding: 12px;
  margin: 0;
  border: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow: auto;
}

.yaml-editor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 300px;
  resize: vertical;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  z-index: 1;
  outline: none;
  border-radius: var(--radius);
}

.yaml-highlight {
  position: relative;
  z-index: 0;
  color: var(--text);
  pointer-events: none;
  min-height: 300px;
}

.yaml-key { color: var(--accent); }
.yaml-string { color: var(--success); }
.yaml-number { color: var(--warning); }
.yaml-bool { color: var(--warning); }
.yaml-comment { color: var(--text-muted); font-style: italic; }

/* Workload logs / inspect modals */
.wl-log-output,
.wl-inspect-output {
  background: #010409;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  max-height: calc(80vh - 120px);
  overflow: auto;
  font-family: 'SF Mono', SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
}

/* DNS two-column layout */
.dns-layout {
  display: flex;
  gap: 0;
  min-height: calc(100vh - 140px);
}

.dns-zone-list {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: var(--radius) 0 0 var(--radius);
  display: flex;
  flex-direction: column;
}

.dns-zone-list-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dns-zone-list-header span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.dns-zone-list-items {
  flex: 1;
  overflow-y: auto;
}

.dns-zone-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  font-size: 13px;
}

.dns-zone-item:last-child { border-bottom: none; }
.dns-zone-item:hover { background: var(--bg-hover); }

.dns-zone-item.active {
  background: var(--bg-hover);
  border-left: 3px solid var(--accent);
  padding-left: 13px;
}

.dns-zone-item-name {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dns-zone-item-count {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 8px;
}

.dns-zone-detail {
  flex: 1;
  min-width: 0;
  background: var(--bg-card);
  border-radius: 0 var(--radius) var(--radius) 0;
  border: 1px solid var(--border);
  border-left: none;
}

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

.dns-zone-detail-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.dns-zone-detail-body {
  padding: 20px;
}

.dns-zone-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 14px;
}

@media (max-width: 900px) {
  .dns-layout { flex-direction: column; min-height: auto; }
  .dns-zone-list {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 200px;
  }
  .dns-zone-detail {
    border-left: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
  }
}

@media (max-width: 900px) {
  .mon-grid {
    grid-template-columns: 1fr;
  }
  .node-info-grid {
    grid-template-columns: 1fr 1fr;
  }
}
