/* OpenClawing Dashboard — Dark Theme */
:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --bg-hover: #475569;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --sidebar-w: 240px;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

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

/* Layout */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.main {
  padding: 1.5rem 2rem;
  overflow-x: hidden;
}

.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 600; }

/* Sidebar */
.sidebar {
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

.brand-icon { font-size: 1.5rem; }
.brand-icon-lg { font-size: 3rem; }
.brand-text { font-size: 1.1rem; font-weight: 700; }

.nav-section { margin-bottom: 0.5rem; }
.nav-label {
  padding: 0.5rem 1.25rem 0.25rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--bg-input);
  color: var(--text);
  text-decoration: none;
}

.nav-icon { width: 1.25rem; text-align: center; font-size: 0.85rem; }

.nav-bottom {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

.nav-logout { color: var(--danger); }
.nav-logout:hover { background: rgba(239, 68, 68, 0.1); }

.main { margin-left: var(--sidebar-w); }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card-header h2, .card-header h3 { font-size: 1rem; font-weight: 600; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}

.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }
.stat-success { color: var(--success); }
.stat-warning { color: var(--warning); }

/* Gauges */
.gauges-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 0.75rem; }
.gauge { }
.gauge-header { display: flex; justify-content: space-between; margin-bottom: 0.35rem; }
.gauge-label { font-weight: 500; font-size: 0.85rem; }
.gauge-value { font-size: 0.8rem; color: var(--text-muted); font-family: var(--font-mono); }
.gauge-bar { height: 8px; background: var(--bg-input); border-radius: 4px; overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease; }
.stat-row { font-size: 0.85rem; padding-top: 0.5rem; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:hover { background: rgba(59, 130, 246, 0.05); }
.table-footer td { font-weight: 600; border-top: 2px solid var(--border); }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-active { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-paused { background: rgba(234, 179, 8, 0.15); color: var(--warning); }
.badge-decommissioned { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

.badge-tier-beta-free { background: rgba(148, 163, 184, 0.15); color: var(--text-muted); }
.badge-tier-starter { background: rgba(59, 130, 246, 0.15); color: var(--accent); }
.badge-tier-growth { background: rgba(168, 85, 247, 0.15); color: #a855f7; }
.badge-tier-premium { background: rgba(234, 179, 8, 0.15); color: var(--warning); }

/* Health dots */
.health-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.health-green { background: var(--success); box-shadow: 0 0 4px var(--success); }
.health-yellow { background: var(--warning); box-shadow: 0 0 4px var(--warning); }
.health-red { background: var(--danger); box-shadow: 0 0 4px var(--danger); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-decoration: none;
  color: var(--text);
}

.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.78rem; }
.btn-full { width: 100%; justify-content: center; }

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; }

.btn-secondary { background: var(--bg-input); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-hover); text-decoration: none; }

.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: #0f172a; }
.btn-danger { background: var(--danger); color: white; }

/* Inputs */
.input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  color: var(--text);
  font-size: 0.85rem;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

.input:focus { border-color: var(--accent); }
.input-sm { padding: 0.3rem 0.5rem; font-size: 0.78rem; width: auto; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.35rem; font-size: 0.85rem; }
.form-hint { display: block; font-size: 0.75rem; color: var(--text-dim); margin-top: 0.25rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-check { margin-bottom: 0.75rem; }
.form-check label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-size: 0.85rem; }
.form-check input[type="checkbox"] { accent-color: var(--accent); }

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.tab {
  padding: 0.6rem 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Client detail */
.client-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.client-meta { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.5rem; }
.client-actions { display: flex; gap: 0.5rem; }
.client-link { color: var(--text); }
.client-link:hover { color: var(--accent); }

/* Detail grid */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.detail-list { }
.detail-list dt { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em; margin-top: 0.5rem; }
.detail-list dd { font-size: 0.9rem; margin-left: 0; }

/* Log viewer */
.log-viewer {
  background: #0c0c0c;
  color: #d4d4d4;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  max-height: 500px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.4;
}

.config-viewer {
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  max-height: 400px;
  overflow-y: auto;
  white-space: pre;
}

/* Agent editor */
.agent-file-list { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.editor-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.editor-header h4 { font-weight: 600; }
.editor-textarea {
  width: 100%;
  background: #0c0c0c;
  color: #d4d4d4;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  resize: vertical;
  line-height: 1.5;
  min-height: 300px;
  outline: none;
}
.editor-textarea:focus { border-color: var(--accent); }

/* Validation */
.validate-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.validate-action { padding: 1rem; background: var(--bg-input); border-radius: var(--radius); }
.validate-action h4 { margin-bottom: 0.35rem; }
.validate-action .btn { margin-top: 0.75rem; }
.validate-output { margin-top: 1rem; }
.validate-result { border-radius: var(--radius); overflow: hidden; }
.validate-pass { border: 1px solid var(--success); }
.validate-fail { border: 1px solid var(--danger); }
.validate-header {
  padding: 0.5rem 1rem;
  font-weight: 600;
  font-size: 0.85rem;
}
.validate-pass .validate-header { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.validate-fail .validate-header { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* Wizard */
.wizard-form { }
.wizard-step {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.wizard-step legend {
  font-weight: 600;
  padding: 0 0.5rem;
  color: var(--accent);
}
.wizard-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1rem; }

/* Bulk operations */
.bulk-grid { display: flex; flex-direction: column; gap: 0.75rem; }
.bulk-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--bg-input);
  border-radius: var(--radius);
}
.bulk-item h3 { font-size: 0.9rem; margin-bottom: 0.25rem; }

/* Port grid */
.port-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 0.35rem;
  margin-top: 1rem;
}
.port-cell {
  padding: 0.35rem;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  border-radius: 3px;
}
.port-used { background: rgba(59, 130, 246, 0.2); color: var(--accent); border: 1px solid var(--accent); }
.port-free { background: var(--bg-input); color: var(--text-dim); border: 1px solid var(--border); }

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.85rem; }
.alert-error { background: rgba(239, 68, 68, 0.15); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.3); }

/* Toast */
#toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 1000; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  animation: toast-in 0.3s ease, toast-out 0.3s ease 3s forwards;
  max-width: 400px;
}
.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-warning { background: var(--warning); color: #0f172a; }

@keyframes toast-in { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; } }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  min-width: 400px;
  max-width: 90vw;
}
.modal-header { font-weight: 600; font-size: 1.1rem; margin-bottom: 0.75rem; }
.modal-body { color: var(--text-muted); margin-bottom: 1.25rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

/* Login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-brand h1 { font-size: 1.5rem; margin-top: 0.5rem; }
.login-form .form-group { margin-bottom: 1.25rem; }

/* Utility */
.monospace { font-family: var(--font-mono); font-size: 0.8rem; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.78rem; }
.text-center { text-align: center; }
.link { color: var(--accent); }
.link:hover { text-decoration: underline; }
.filters { display: flex; align-items: center; }
.tab-content { margin-top: 0; }

/* Responsive */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; width: 100%; height: auto; flex-direction: row; overflow-x: auto; }
  .main { margin-left: 0; padding: 1rem; }
  .detail-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .gauges-grid { grid-template-columns: 1fr; }
}
