/* ═══════════════════════════════════════════════════════════════════════════
   PlagApp Design System — "Apple-grade"
   Tokens + primitivas. Color = affordance: el acento va en acciones/estados.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* Superficies y tinta */
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --surface-2: #FAFAFC;
  --ink: #1D1D1F;
  --ink-2: #6E6E73;
  --ink-3: #AEAEB2;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);

  /* Marca y semánticos (AA sobre blanco) */
  --accent: #0B7A5C;
  --accent-hover: #096A50;
  --accent-soft: #E7F4EF;
  --blue: #0071E3;   --blue-soft: #E8F2FE;
  --amber: #B25000;  --amber-soft: #FDF1E4;
  --red: #D70015;    --red-soft: #FDEBEC;
  --purple: #6E56CF; --purple-soft: #F0EDFB;

  /* Radios y sombras */
  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 22px;
  --shadow-s: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --shadow-m: 0 2px 6px rgba(0,0,0,.05), 0 10px 32px rgba(0,0,0,.09);
  --shadow-l: 0 8px 20px rgba(0,0,0,.08), 0 24px 64px rgba(0,0,0,.16);

  /* Tipografía */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Motion (curvas Apple) */
  --ease-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 150ms;
  --dur-base: 250ms;
  --dur-slow: 400ms;

  /* Vidrio */
  --glass: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.5);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.02em; }
h1 { font-size: 28px; }
h2 { font-size: 21px; }
h3 { font-size: 17px; }
h4 { font-size: 15px; }
p  { margin: 0; }

.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }

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

::selection { background: rgba(11, 122, 92, 0.18); }

:focus-visible {
  outline: 2.5px solid var(--blue);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Botones ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  min-height: 38px;
  border: none;
  border-radius: var(--radius-s);
  font: 600 14px/1 var(--font);
  letter-spacing: -0.01em;
  color: var(--ink);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out),
              background var(--dur-fast) ease,
              box-shadow var(--dur-fast) ease,
              opacity var(--dur-fast) ease;
  user-select: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn svg { width: 16px; height: 16px; flex: none; }

.btn-primary { background: var(--accent); color: #fff; box-shadow: none; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost { background: transparent; box-shadow: none; color: var(--ink-2); }
.btn-ghost:hover { background: rgba(0,0,0,0.05); color: var(--ink); }

.btn-danger { background: var(--red-soft); color: var(--red); box-shadow: none; }
.btn-danger:hover { background: #FBDDDF; }

.btn-sm { padding: 6px 11px; min-height: 30px; font-size: 13px; }
.btn-icon { padding: 8px; min-width: 38px; }
.btn-icon.btn-sm { min-width: 30px; }

/* ── Cards / bento ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-s);
  padding: 20px;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: -0.005em;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.bento {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}
.col-3  { grid-column: span 3; }
.col-4  { grid-column: span 4; }
.col-5  { grid-column: span 5; }
.col-6  { grid-column: span 6; }
.col-7  { grid-column: span 7; }
.col-8  { grid-column: span 8; }
.col-9  { grid-column: span 9; }
.col-12 { grid-column: span 12; }
@media (max-width: 1100px) {
  .col-3, .col-4, .col-5 { grid-column: span 6; }
  .col-6, .col-7, .col-8, .col-9 { grid-column: span 12; }
}
@media (max-width: 720px) {
  .col-3, .col-4, .col-5, .col-6 { grid-column: span 12; }
}

.card-interactive {
  cursor: pointer;
  transition: transform var(--dur-base) var(--ease-out), box-shadow var(--dur-base) ease;
}
.card-interactive:hover { transform: translateY(-2px) scale(1.01); box-shadow: var(--shadow-m); }
.card-interactive:active { transform: scale(0.985); }

/* ── Badges de estado ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-neutral { background: rgba(0,0,0,0.06); color: var(--ink-2); }
.badge-green   { background: var(--accent-soft); color: var(--accent); }
.badge-blue    { background: var(--blue-soft); color: var(--blue); }
.badge-amber   { background: var(--amber-soft); color: var(--amber); }
.badge-red     { background: var(--red-soft); color: var(--red); }
.badge-purple  { background: var(--purple-soft); color: var(--purple); }

/* ── Formularios ──────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--ink-3); }
.field .error-msg { font-size: 12.5px; color: var(--red); display: none; }
.field.has-error .error-msg { display: block; }
.field.has-error input, .field.has-error select, .field.has-error textarea {
  box-shadow: inset 0 0 0 1.5px var(--red);
}

input, select, textarea {
  font: 400 15px/1.4 var(--font);
  color: var(--ink);
  background: var(--surface);
  border: none;
  border-radius: var(--radius-s);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  padding: 10px 12px;
  min-height: 40px;
  width: 100%;
  transition: box-shadow var(--dur-fast) ease;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--accent);
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }

/* ── Segmented control (Apple) ────────────────────────────────────────── */
.segmented {
  display: inline-flex;
  background: rgba(0,0,0,0.055);
  border-radius: 10px;
  padding: 2.5px;
  gap: 2px;
}
.segmented button {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 8px;
  font: 600 13px/1 var(--font);
  color: var(--ink-2);
  cursor: pointer;
  transition: background var(--dur-fast) ease, color var(--dur-fast) ease,
              box-shadow var(--dur-fast) ease, transform var(--dur-fast) var(--ease-out);
}
.segmented button:active { transform: scale(0.96); }
.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* ── Tablas ───────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius-m); }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr { transition: background var(--dur-fast) ease; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tr.row-click { cursor: pointer; }

/* ── Modales (patrón canónico: overlay > modal) ───────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(28, 28, 30, 0.42);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-base) ease, visibility 0s linear var(--dur-base);
}
.modal-overlay.show {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--dur-base) ease;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-l);
  width: 100%;
  max-width: 560px;
  max-height: min(86vh, 900px);
  display: flex;
  flex-direction: column;
  transform: translateY(14px) scale(0.97);
  transition: transform var(--dur-slow) var(--ease-spring);
}
.modal-overlay.show .modal { transform: none; }
.modal-lg { max-width: 860px; }
.modal-xl { max-width: 1100px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 24px 12px;
}
.modal-header h3 { font-size: 19px; }
.modal-body { padding: 8px 24px 20px; overflow-y: auto; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px 20px;
  border-top: 1px solid var(--border);
}

/* ── Toasts ───────────────────────────────────────────────────────────── */
#toastStack {
  position: fixed;
  top: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 260px;
  max-width: 380px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  box-shadow: var(--shadow-m);
  padding: 12px 14px;
  pointer-events: auto;
  animation: toast-in var(--dur-slow) var(--ease-spring) both;
}
.toast.leaving { animation: toast-out var(--dur-base) ease both; }
.toast svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.toast-success svg { color: var(--accent); }
.toast-error svg { color: var(--red); }
.toast-info svg { color: var(--blue); }
.toast b { display: block; font-size: 13.5px; letter-spacing: -0.01em; }
.toast p { font-size: 12.5px; color: var(--ink-2); }

/* ── Empty states ─────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 44px 20px;
  text-align: center;
}
.empty-state__icon {
  width: 44px; height: 44px;
  color: var(--ink-3);
  margin-bottom: 4px;
}
.empty-state__icon svg { width: 100%; height: 100%; }
.empty-state__msg { font-weight: 600; color: var(--ink-2); }
.empty-state__hint { font-size: 13px; color: var(--ink-3); max-width: 340px; }

/* ── Skeletons ────────────────────────────────────────────────────────── */
.skeleton {
  position: relative;
  overflow: hidden;
  background: rgba(0,0,0,0.055);
  border-radius: 8px;
  min-height: 14px;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.65), transparent);
  animation: shimmer 1.4s infinite;
}

/* ── Misc ─────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 600 13px/1 var(--font);
  color: #fff;
  background: var(--accent);
  flex: none;
}

.kpi-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.kpi-delta { font-size: 12.5px; font-weight: 600; }
.kpi-delta.up { color: var(--accent); }
.kpi-delta.down { color: var(--red); }
.kpi-delta.warn { color: var(--amber); }

@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
}
