/* shared/theme.css — CarpinterIA design system
   Usage: <link rel="stylesheet" href="shared/theme.css">
   Load BEFORE page-specific <style> blocks */

/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap');

/* ── CSS Variables ── */
:root {
  --bg: #f7f8fa;
  --surface: #fff;
  --border: #e2e5ea;
  --text: #1a1d23;
  --text-2: #5a5f6b;
  --text-3: #8b909c;
  --accent: #2e5faa;
  --accent-hover: #24508f;
  --accent-light: #eaf0fb;
  --danger: #c93c3c;
  --success: #2a8a4a;
  --warn: #c78b17;
  --radius: 8px;
}
html.dark {
  --bg: #1a1d23;
  --surface: #23272e;
  --border: #353a44;
  --text: #e8eaed;
  --text-2: #b0b5bf;
  --text-3: #6b7280;
  --accent: #5b8fd9;
  --accent-hover: #7ba7e5;
  --accent-light: #2a3444;
  --danger: #e05555;
  --success: #3bb06a;
  --warn: #d9a030;
}

/* ── Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Typography ── */
h1, h2, h3 { font-weight: 700; color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App Header ── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.app-header h1 { font-size: 18px; font-weight: 700; color: var(--accent); }
.app-header .spacer { flex: 1; }

/* ── Navigation Tabs ── */
.nav-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: 8px;
  padding: 3px;
  margin-left: 12px;
}
.nav-tab {
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s;
  font-family: inherit;
}
.nav-tab:hover { color: var(--text); background: var(--surface); }
.nav-tab.active { background: var(--accent); color: white; font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; color: var(--text); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { opacity: 0.9; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { opacity: 0.9; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border: none; background: transparent; color: var(--text-2); cursor: pointer; }
.btn-icon:hover { color: var(--accent); }

/* ── Forms ── */
label { font-size: 12px; font-weight: 500; color: var(--text-2); display: block; margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-3);
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
}
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: var(--accent-light); }

/* ── Status Badges ── */
.status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
.status-active, .status-success { background: #e3f5ea; color: var(--success); }
.status-inactive, .status-error { background: #fde2e2; color: var(--danger); }
.status-warning { background: #fef3cd; color: var(--warn); }
.status-info { background: var(--accent-light); color: var(--accent); }

/* ── Sticky KPI bar modifier ──
   Add `sticky-top` to any metric row to pin it at the top on scroll. */
.sticky-top {
  position: sticky;
  top: 0;
  z-index: 15;
  background: var(--bg);
  padding-top: 8px; padding-bottom: 8px; margin-top: -8px;
  box-shadow: 0 4px 12px -6px rgba(0,0,0,0.08);
}

/* ── Alert Cards (shared component) ──
   Usage: alertCard({severity, title, value, subtitle?, href?, icon?}) from utils.js
   Severities: critica (rojo), alta (naranja), media (amarillo), info (azul), ok (verde) */
.alert-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  min-height: 74px;
}
a.alert-card:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0,0,0,0.08); text-decoration: none; }
.alert-card .ac-icon { font-size: 26px; line-height: 1; flex-shrink: 0; }
.alert-card .ac-body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.alert-card .ac-title { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.3px; }
.alert-card .ac-value { font-size: 18px; font-weight: 700; color: var(--text); line-height: 1.2; }
.alert-card .ac-subtitle { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.alert-card .ac-cta { font-size: 11px; font-weight: 500; color: var(--accent); margin-left: auto; white-space: nowrap; }
.alert-card.sev-critica { border-left-color: var(--danger); background: linear-gradient(to right, color-mix(in srgb, var(--danger) 7%, var(--surface)), var(--surface) 60%); }
.alert-card.sev-critica .ac-value { color: var(--danger); }
.alert-card.sev-alta    { border-left-color: #ea7c1e; background: linear-gradient(to right, #fff3e8, var(--surface) 60%); }
.alert-card.sev-alta .ac-value { color: #b85d0e; }
.alert-card.sev-media   { border-left-color: var(--warn); background: linear-gradient(to right, #fef9e7, var(--surface) 60%); }
.alert-card.sev-media .ac-value { color: #8a6208; }
.alert-card.sev-info    { border-left-color: var(--accent); background: linear-gradient(to right, var(--accent-light), var(--surface) 60%); }
.alert-card.sev-info .ac-value { color: var(--accent); }
.alert-card.sev-ok      { border-left-color: var(--success); background: linear-gradient(to right, #e3f5ea, var(--surface) 60%); }
.alert-card.sev-ok .ac-value { color: var(--success); }
html.dark .alert-card.sev-alta  { background: linear-gradient(to right, rgba(234, 124, 30, 0.12), var(--surface) 60%); }
html.dark .alert-card.sev-media { background: linear-gradient(to right, rgba(199, 139, 23, 0.12), var(--surface) 60%); }
html.dark .alert-card.sev-ok    { background: linear-gradient(to right, rgba(42, 138, 74, 0.14), var(--surface) 60%); }

.alert-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.alert-row.empty { display: none; }

/* ── Toast Notifications ── */
.toast-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  color: white;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  animation: slideIn 0.25s ease;
  max-width: 360px;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--accent); }
.toast-warning { background: var(--warn); }

/* ── Loading Overlay ── */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  font-size: 14px;
  color: var(--text-2);
}
html.dark .loading-overlay { background: rgba(0,0,0,0.6); }
.loading-overlay.active { display: flex; }

.spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ── Animations ── */
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utility Classes ── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.gap-lg { gap: 24px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 16px; }
.text-muted { color: var(--text-3); }
.text-sm { font-size: 12px; }
.text-center { text-align: center; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: 'JetBrains Mono', 'Fira Code', monospace; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .app-header { padding: 10px 16px; }
  .app-header h1 { font-size: 15px; }
  .card { padding: 14px; }
  .nav-tab { padding: 5px 10px; font-size: 11.5px; }
}
