/* ===== Admin Panel ===== */

/* Admin CSS vars (extend root vars from style.css) */
:root {
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius-sm: 6px;
  --surface-2: #22252f;
  --border-hover: #3a3d4a;
  --text-secondary: #c4c4c7;
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.12);
  --red: #ef4444;
  --yellow: #f59e0b;
  --yellow-dim: rgba(245, 158, 11, 0.12);
  --blue: #3b82f6;
  --blue-dim: rgba(59, 130, 246, 0.12);
  --purple: #a855f7;
  --purple-dim: rgba(168, 85, 247, 0.12);
}

/* Login */
.admin-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.admin-login-box {
  width: 100%;
  max-width: 360px;
  padding: 2.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.admin-login-box input {
  display: block;
  width: 100%;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
  font-family: var(--font);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.admin-login-box input:focus {
  border-color: var(--text-dim);
}
.btn-admin-login {
  display: block;
  width: 100%;
  padding: 0.65rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font);
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-admin-login:hover { opacity: 0.9; }
.login-error {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--red);
  text-align: center;
}

/* Admin badge */
.admin-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  background: var(--purple-dim);
  color: var(--purple);
  border: 1px solid rgba(168, 85, 247, 0.3);
  border-radius: 100px;
  margin-left: 0.5rem;
  vertical-align: middle;
}

.auto-refresh-label {
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* Metrics Bar */
.metrics-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.metric {
  flex: 1;
  text-align: center;
  padding: 1rem 0.5rem;
  border-right: 1px solid var(--border);
}
.metric:last-child { border-right: none; }
.metric-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.metric-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Tabs */
.admin-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.tab {
  padding: 0.65rem 1.25rem;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--font);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--green);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.tab-actions {
  margin-bottom: 1rem;
  display: flex;
  gap: 0.5rem;
}

.subtable-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 2rem 0 0.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* Table */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.admin-table thead th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table tbody td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: middle;
}
.admin-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}
.date-cell {
  white-space: nowrap;
  font-size: 0.75rem;
  color: var(--text-dim) !important;
}
.plan-cell {
  font-weight: 500;
}
.mono {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.75rem;
}
.empty-cell {
  text-align: center;
  color: var(--text-dim) !important;
  padding: 2rem 0 !important;
}

/* Status Badges */
.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 500;
  border-radius: 100px;
  text-transform: lowercase;
}
.st-active, .st-RUNNING { background: var(--green-dim); color: var(--green); }
.st-provisioning { background: var(--yellow-dim); color: var(--yellow); }
.st-paused { background: var(--yellow-dim); color: var(--yellow); }
.st-stopped, .st-TERMINATED, .st-STOPPED { background: rgba(255, 68, 68, 0.12); color: var(--red); }
.st-error { background: rgba(255, 68, 68, 0.12); color: var(--red); }
.st-inactive { background: var(--surface-2); color: var(--text-dim); }
.st-available { background: var(--green-dim); color: var(--green); }
.st-assigned { background: var(--blue-dim); color: var(--blue); }
.st-disabled { background: var(--surface-2); color: var(--text-dim); }

/* Small Buttons */
.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.7rem;
  font-weight: 500;
  font-family: var(--font);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-sm.btn-red {
  color: var(--red);
  border-color: rgba(255, 68, 68, 0.3);
}
.btn-sm.btn-red:hover {
  background: rgba(255, 68, 68, 0.1);
}
.btn-sm.btn-green {
  color: var(--green);
  border-color: rgba(0, 208, 132, 0.3);
}
.btn-sm.btn-green:hover {
  background: var(--green-dim);
}

.btn-action {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--font);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}
.btn-action:hover { background: var(--surface-2); }
.btn-action.btn-green {
  color: var(--green);
  border-color: rgba(0, 208, 132, 0.3);
}
.btn-action.btn-green:hover {
  background: var(--green-dim);
}

/* Add Form */
.add-form {
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.add-form input {
  display: block;
  width: 100%;
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
  font-family: var(--font);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.add-form input:focus { border-color: var(--text-dim); }
.add-form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* Activity Feed (Admin) */
.activity-feed {
  max-height: 600px;
  overflow-y: auto;
}
.activity-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}
.activity-row:last-child { border-bottom: none; }
.activity-meta {
  min-width: 180px;
  flex-shrink: 0;
}
.activity-user {
  display: block;
  font-weight: 500;
  color: var(--text);
  font-size: 0.78rem;
}
.activity-agent {
  font-size: 0.7rem;
  color: var(--text-dim);
}
.activity-body {
  flex: 1;
  min-width: 0;
}
.activity-type {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  font-size: 0.65rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  margin-right: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.activity-body > span {
  color: var(--text-secondary);
}
.activity-feed .activity-time {
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ===== Dashboard Grid ===== */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
.dash-grid .full-width { grid-column: 1 / -1; }
.dash-grid .dash-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.dash-grid .dash-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.15rem;
  border-bottom: 1px solid var(--border);
}
.dash-grid .dash-card-header h3 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}
.header-count {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--surface-2);
  padding: 0.15rem 0.5rem;
  border-radius: 100px;
}
.dash-grid .dash-card-body {
  padding: 1.15rem;
}

/* Health Indicators */
.health-items {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.health-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.health-item span:nth-child(2) { flex: 1; }
.health-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-dim);
}
.health-dot.health-ok {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}
.health-dot.health-err {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
}
.health-status {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* Config Grid */
.config-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.config-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
}
.config-row:last-child { border-bottom: none; }
.config-key {
  color: var(--text-dim);
}
.config-val {
  color: var(--text);
  font-weight: 500;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.73rem;
  text-align: right;
  max-width: 60%;
  word-break: break-all;
}

/* Instance Cards (Dashboard) */
.instance-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
}
.instance-card {
  padding: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s;
}
.instance-card:hover { border-color: var(--border-hover); }
.ic-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}
.ic-plan {
  font-size: 0.7rem;
  color: var(--text-dim);
}
.ic-email {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.3rem;
}
.ic-meta {
  display: flex;
  gap: 0.75rem;
  font-size: 0.7rem;
  color: var(--text-dim);
  font-family: 'SF Mono', 'Fira Code', monospace;
  margin-bottom: 0.3rem;
}
.ic-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ic-time {
  font-size: 0.68rem;
  color: var(--text-dim);
}

/* Activity Full */
.activity-feed-full {
  max-height: 80vh;
}

/* Loading / Error */
.loading {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem;
}
.error-msg {
  color: var(--red);
  padding: 1rem;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}
.modal-content {
  width: 100%;
  max-width: 580px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
}
.btn-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0 0.25rem;
}
.btn-close:hover { color: var(--text); }
.modal-body {
  padding: 1.25rem;
}
.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
.modal-section h4 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}
.modal-row {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
}
.modal-row:last-child { border-bottom: none; }
.modal-key { color: var(--text-dim); }
.modal-val { color: var(--text); font-weight: 500; }
.modal-actions {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
}

/* ===== Skills ===== */
.category-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  font-size: 0.65rem;
  font-weight: 500;
  border-radius: 100px;
  text-transform: lowercase;
}
.cat-productivity { background: var(--blue-dim); color: var(--blue); }
.cat-intelligence { background: var(--purple-dim); color: var(--purple); }
.cat-autonomy { background: var(--yellow-dim); color: var(--yellow); }
.cat-general { background: var(--surface-2); color: var(--text-dim); }

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  transition: 0.2s;
}
.toggle-slider:before {
  content: "";
  position: absolute;
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--green-dim);
  border-color: rgba(0, 208, 132, 0.3);
}
.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(16px);
  background: var(--green);
}

.plan-skills-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 0.75rem;
}
.plan-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}
.plan-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.plan-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.plan-check:hover { background: var(--surface); }
.plan-check input {
  width: auto;
  margin-bottom: 0;
  accent-color: var(--green);
}
.plan-save-actions {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.add-form-select {
  display: block;
  width: 100%;
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
  font-family: var(--font);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
}
.add-form-select.compact {
  display: inline-block;
  width: auto;
  min-width: 200px;
  margin-bottom: 0;
  margin-right: 0.5rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

/* Modal skills */
.modal-skills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}
.skill-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  font-size: 0.7rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-secondary);
}
.skill-source {
  font-size: 0.6rem;
  padding: 0.05rem 0.3rem;
  background: var(--green-dim);
  color: var(--green);
  border-radius: 100px;
}
.modal-overrides {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}
.override-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.45rem;
  font-size: 0.68rem;
  border-radius: 100px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.ov-add { background: var(--green-dim); color: var(--green); border: 1px solid rgba(0, 208, 132, 0.2); }
.ov-remove { background: rgba(255, 68, 68, 0.08); color: var(--red); border: 1px solid rgba(255, 68, 68, 0.2); }
.btn-x {
  background: none;
  border: none;
  color: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  opacity: 0.7;
}
.btn-x:hover { opacity: 1; }
.modal-skill-add {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

/* ===== Version Bar ===== */
.version-bar {
  display: flex;
  gap: 1.5rem;
  padding: 0.6rem 1rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-secondary);
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.version-item { white-space: nowrap; }
.version-item strong { color: var(--text); }

/* ===== VM Detail Panel ===== */
.vm-detail-row td { padding: 0 !important; border-bottom: 2px solid var(--border); }
.vm-detail-panel { padding: 1rem; background: var(--bg); }
.vm-detail-loading { color: var(--text-dim); font-size: 0.8rem; padding: 1rem; }
.vm-detail-error { color: var(--red); font-size: 0.8rem; padding: 1rem; }

.vm-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.vm-tab {
  padding: 0.4rem 1rem;
  font-size: 0.75rem;
  font-weight: 500;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.vm-tab.active { color: var(--text); border-bottom-color: var(--primary); }
.vm-tab:hover { color: var(--text); }

.vm-tab-content { display: none; }
.vm-tab-content.active { display: block; }

/* Info Grid */
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem; }
.info-row { display: flex; gap: 0.5rem; font-size: 0.8rem; padding: 0.25rem 0; }
.info-label { color: var(--text-dim); min-width: 120px; }
.info-value { color: var(--text); }

/* Log Terminal */
.log-terminal {
  background: #0d0d0d;
  color: #c8c8c8;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.7rem;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.4;
}
.log-actions { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }

/* Action buttons */
.action-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.action-output { min-height: 60px; }

/* Responsive */
@media (max-width: 768px) {
  .dash-grid { grid-template-columns: 1fr; }
  .modal-grid { grid-template-columns: 1fr; }
  .modal-content { margin: 1rem; }
  .metrics-bar {
    flex-wrap: wrap;
  }
  .metric {
    flex-basis: 33.33%;
    border-bottom: 1px solid var(--border);
  }
  .admin-container { padding: 1rem; }
  .tabs { overflow-x: auto; }
  .admin-table {
    display: block;
    overflow-x: auto;
  }
  .activity-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
  .activity-meta { min-width: 0; }
}
