/* ==========================================================================
   Hermes Control — dark adaptive theme (mobile-first)
   ========================================================================== */

:root {
  /* Palette */
  --bg: #0d1117;
  --surface: #151c2b;
  --surface-raised: #1b2537;
  --text: #f3f6fb;
  --text-muted: #8d9ab0;
  --border: rgba(148, 163, 184, 0.18);

  --accent: #8b7cff;
  --accent-hover: #a39bff;
  --accent-strong: #6f63e8;

  --running: #38bdf8;
  --completed: #34d399;
  --waiting: #fbbf24;
  --danger: #fb7185;

  /* Shape & rhythm */
  --radius: 14px;
  --radius-sm: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.35);

  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Reset & base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p {
  margin: 0;
}

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Accessible focus ring (never removed without replacement) */
:focus-visible {
  outline: 2px solid var(--accent-hover);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Screen-reader-only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.brand-mark {
  color: var(--accent);
  font-size: 1.25rem;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: 999px;
  border: 1px solid rgba(52, 211, 153, 0.4);
  background: rgba(52, 211, 153, 0.1);
  color: var(--completed);
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 32px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.status-online .status-dot {
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------- Buttons ---------- */
.button {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: var(--space-2) var(--space-4);
  min-height: 44px; /* touch target */
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.button-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #ffffff;
}

.button-primary:hover {
  background: linear-gradient(180deg, var(--accent-hover), var(--accent));
}

.button-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.button-secondary:hover {
  background: var(--surface-raised);
  border-color: var(--accent);
}

/* ---------- Layout ---------- */
.dashboard {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  flex: 1;
}

/* ---------- Metrics ---------- */
.metrics {
  display: grid;
  grid-template-columns: 1fr; /* mobile: single column */
  gap: var(--space-3);
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow);
}

.metric-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.metric-value {
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.metric-value-mono {
  font-family: var(--font-mono);
  font-size: 1.05rem;
}

.status-dot-running { color: var(--running); }
.status-dot-completed { color: var(--completed); }

/* ---------- Agents section ---------- */
.agents-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.agents-header {
  display: flex;
  flex-direction: column; /* mobile: stacked */
  gap: var(--space-3);
}

.agents-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.filter-btn {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: var(--space-1) var(--space-4);
  min-height: 44px; /* touch target */
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

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

.filter-btn[aria-pressed="true"] {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.filter-btn-danger {
  color: var(--danger);
}

.filter-btn-danger:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(251, 113, 133, 0.1);
}

/* ---------- Add task form ---------- */
.task-form-panel {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.task-form-panel form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr; /* mobile: stacked */
  gap: var(--space-3);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.form-field label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-field input,
.form-field select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  min-height: 44px;
}

.form-field input:hover,
.form-field select:hover {
  border-color: var(--accent);
}

.form-field input:focus,
.form-field select:focus {
  outline: 2px solid var(--accent-hover);
  outline-offset: 1px;
}

.form-field input[aria-invalid="true"] {
  border-color: var(--danger);
}

.field-error {
  font-size: 0.8rem;
  color: var(--danger);
  margin: 0;
}

.form-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ---------- Agent list ---------- */
.agent-list {
  display: grid;
  grid-template-columns: 1fr; /* mobile: single column */
  gap: var(--space-3);
}

.agent-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  box-shadow: var(--shadow);
}

.agent-card-top {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.agent-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(139, 124, 255, 0.16);
  color: var(--accent-hover);
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.agent-info {
  flex: 1;
  min-width: 0; /* allow word wrap on narrow screens */
}

.agent-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.agent-task {
  color: var(--text-muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.task-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid;
  white-space: nowrap;
}

.task-badge .status-dot {
  width: 6px;
  height: 6px;
}

.badge-running {
  color: var(--running);
  border-color: rgba(56, 189, 248, 0.4);
  background: rgba(56, 189, 248, 0.1);
}

.badge-completed {
  color: var(--completed);
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(52, 211, 153, 0.1);
}

.badge-waiting {
  color: var(--waiting);
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.1);
}

/* Progress */
.progress-block {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.15);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--running));
  transition: width 0.6s ease;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-5) var(--space-4);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.empty-title {
  color: var(--text-muted);
}

/* ---------- Footer ---------- */
.footer {
  border-top: 1px solid var(--border);
  padding: var(--space-4);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* ==========================================================================
   Adaptive breakpoints (mobile-first, min-width)
   ========================================================================== */
@media (min-width: 560px) {
  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .agents-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .form-row {
    grid-template-columns: 2fr 1fr;
  }
}

@media (min-width: 900px) {
  .metrics {
    grid-template-columns: repeat(4, 1fr);
  }
}

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