:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e2e4e9;
  --text: #16181d;
  --muted: #646b78;
  --accent: #d6411f;
  --accent-hover: #b8361a;
  --accent-soft: #fdece7;
  --ok: #18865a;
  --ok-soft: #e3f5ec;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --danger: #c53030;
  --danger-soft: #fdeaea;
  --info: #2b6cb0;
  --info-soft: #e6f0fa;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1f232c; --border: #2a2f3a;
    --text: #eceef2; --muted: #9aa2b1; --accent: #f0643f; --accent-hover: #ff7a56; --accent-soft: #3a1f17;
    --ok: #3ec98a; --ok-soft: #13301f; --warn: #e8b04a; --warn-soft: #33270f;
    --danger: #f56565; --danger-soft: #3a1717; --info: #63a4ec; --info-soft: #14263a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #171a21; --surface-2: #1f232c; --border: #2a2f3a;
  --text: #eceef2; --muted: #9aa2b1; --accent: #f0643f; --accent-hover: #ff7a56; --accent-soft: #3a1f17;
  --ok: #3ec98a; --ok-soft: #13301f; --warn: #e8b04a; --warn-soft: #33270f;
  --danger: #f56565; --danger-soft: #3a1717; --info: #63a4ec; --info-soft: #14263a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
img { max-width: 100%; display: block; }
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 9px; font: inherit; font-weight: 500; cursor: pointer;
  text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { filter: brightness(1.08); background: var(--ok); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-wa { background: #25d366; border-color: #25d366; color: #fff; }
.btn-wa:hover { background: #1ebe5b; }

/* Formularios */
label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 80px; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); font-weight: 400; margin: 0; }
.field { margin-bottom: 12px; }

/* Etiquetas */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }

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

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 12, 16, .55); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 12px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-lg { max-width: 960px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 12px; }
.modal-head h3 { margin: 0; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* Toast */
#toasts { position: fixed; bottom: 16px; right: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 100; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 420px; pointer-events: auto; font-size: 14px; }
.toast.error { background: var(--danger); color: #fff; }

.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 720px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
