:root {
  --bg: #f6f8f6;
  --panel: #ffffff;
  --panel-raised: #f0f3f1;
  --border: #e7ebe8;
  --text: #16241c;
  --muted: #6b7a71;
  --accent: #3b82f6;
  --accent-hover: #2f6fd8;
  --accent-soft: #16233d;
  --accent-system: #3b82f6;
  --accent-system-hover: #2f6fd8;
  --accent-system-soft: #16233d;
  --danger: #d9534f;
  --sidebar-bg: #ffffff;
  --sidebar-text: #6b7a71;
  --sidebar-text-active: #16241c;
  --radius: 16px;
  --shadow-card: 0 1px 2px rgba(22,36,28,0.04), 0 8px 24px -14px rgba(22,36,28,0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0b0f;
    --panel: #15171e;
    --panel-raised: #1b1e27;
    --border: #262933;
    --text: #f2f3f6;
    --muted: #8b8d98;
    --sidebar-bg: #0a0b0f;
    --sidebar-text: #8b8d98;
    --sidebar-text-active: #ffffff;
    --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 12px 32px -16px rgba(0,0,0,0.6);
  }
}

* { box-sizing: border-box; }

.login-overlay {
  position: fixed; inset: 0; background: var(--bg); display: flex;
  align-items: center; justify-content: center; z-index: 20; padding: 16px;
}
.login-overlay.hidden { display: none; }
.login-box { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; width: 100%; max-width: 360px; }
.login-brand { justify-content: center; margin-bottom: 12px; }
.login-box form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-box input {
  font-family: inherit; font-size: 14px; padding: 9px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.login-error { color: var(--danger); font-size: 13px; margin: 0; }
.user-email-label { font-size: 11px; color: var(--muted); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---- sidebar ---- */

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 24px;
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.brand-name {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: var(--sidebar-text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
}

.nav-item:hover { background: var(--accent-system-soft); }

.nav-item.active {
  background: var(--accent);
  color: var(--sidebar-text-active);
}

.nav-icon { font-size: 14px; width: 16px; text-align: center; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---- content ---- */

.content {
  flex: 1;
  padding: 24px 32px 48px;
  min-width: 0;
}

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

.content-header h1 {
  font-size: 22px;
  margin: 0;
}

.page.hidden { display: none; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel-raised);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}

.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 10px; }

/* Antes era blanco sobre fondo oscuro. Con el tema claro quedaba blanco
   sobre panel blanco: el botón desaparecía. Ahora usa el color de marca,
   igual que los otros tres sistemas. */
.btn.primary {
  background: var(--accent-system);
  border-color: var(--accent-system);
  color: #ffffff;
  font-weight: 600;
}

.btn.primary:hover { background: var(--accent-system-hover); }

.sidebar .btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--sidebar-text);
}

.sidebar .btn.ghost:hover { background: var(--panel-raised); }

.file-btn { display: inline-flex; align-items: center; justify-content: center; }

/* ---- dashboard stat cards ---- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
}

.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
}

.panel.full-width { width: 100%; }

.panel h2 {
  font-size: 14px;
  margin: 0 0 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel-hint {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 16px;
}

/* ---- context form ---- */

.context-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.context-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.context-form input {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.context-form button { grid-column: 1 / -1; justify-self: start; }

/* ---- agent cards ---- */

.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.agent-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.agent-card:hover {
  border-color: var(--accent-system);
  transform: translateY(-2px);
}

.agent-card h3 { margin: 0 0 6px; font-size: 16px; }

.agent-card p {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.agent-status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-system-soft);
  color: var(--accent-system);
}

/* ---- modal ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal.wide { max-width: 640px; }

.modal h2 { margin-top: 0; margin-bottom: 4px; font-size: 18px; }

.prompt-output {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.modal-actions-right { display: flex; gap: 8px; flex-wrap: wrap; }

.pdf-section { margin-top: 12px; }

.pdf-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.copy-status { font-size: 13px; color: var(--accent-system); }

.hidden { display: none !important; }

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 12px 16px; }
  .sidebar-nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .content { padding: 16px; }
  .context-form { grid-template-columns: 1fr; }
}
