:root {
  --bg: #0d0f12;
  --surface: #161920;
  --border: #252830;
  --accent: #f59e0b;
  --accent2: #3b82f6;
  --danger: #ef4444;
  --success: #22c55e;
  --text: #e8eaf0;
  --muted: #6b7280;
  --radius: 8px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  display: flex;
  min-height: 100vh;
}

/* ── LOGIN ── */
#loginScreen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.login-card {
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
}
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 32px; }
.logo-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #000; font-size: 16px; flex-shrink: 0;
}
.app-name { font-weight: 700; font-size: 15px; }
.app-sub { font-size: 11px; color: var(--accent); font-weight: 500; letter-spacing: .05em; text-transform: uppercase; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 14px; font-family: inherit; outline: none;
  transition: border-color .2s;
}
.field input:focus { border-color: var(--accent); }
.btn-primary {
  width: 100%; padding: 11px;
  background: var(--accent); color: #000;
  border: none; border-radius: var(--radius);
  font-weight: 600; font-size: 14px; cursor: pointer;
  transition: opacity .2s;
}
.btn-primary:hover { opacity: .85; }
.login-error { color: var(--danger); font-size: 12px; margin-top: 10px; display: none; }

/* ── APP SHELL ── */
#app { display: none; width: 100%; }

/* ── SIDEBAR ── */
.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .logo-icon { width: 30px; height: 30px; font-size: 14px; border-radius: 6px; }
nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-section {
  font-size: 10px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
  padding: 12px 12px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 6px;
  cursor: pointer; color: var(--muted);
  font-size: 13px; font-weight: 500;
  transition: background .15s, color .15s;
  user-select: none;
}
.nav-item:hover { background: var(--border); color: var(--text); }
.nav-item.active { background: rgba(245,158,11,.1); color: var(--accent); }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.sidebar-footer { padding: 12px 8px; border-top: 1px solid var(--border); }
.admin-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: rgba(245,158,11,.08);
  border-radius: 6px;
}
.avatar {
  width: 28px; height: 28px;
  background: var(--accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #000; font-size: 12px; flex-shrink: 0;
}
.admin-badge .info { flex: 1; min-width: 0; }
.admin-badge .name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-badge .role-label { font-size: 10px; color: var(--accent); text-transform: capitalize; }
.logout-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 4px; }
.logout-btn:hover { color: var(--danger); }

/* ── MAIN ── */
main { margin-left: 220px; flex: 1; padding: 28px; min-width: 0; }
.page { display: none; }
.page.active { display: block; }
.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 20px; font-weight: 700; }
.page-header p { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ── STATS ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-card .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 500; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 6px; font-family: 'JetBrains Mono', monospace; }
.stat-card.accent-amber { border-color: rgba(245,158,11,.3); }
.stat-card.accent-blue  { border-color: rgba(59,130,246,.3); }
.stat-card.accent-green { border-color: rgba(34,197,94,.3); }

/* ── CHARTS ── */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 24px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; height: 280px; }
.chart-card h3 { font-size: 13px; font-weight: 600; margin-bottom: 16px; }
.chart-card canvas { max-height: 200px !important; }

/* ── TABLE ── */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 20px; }
.table-toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.table-toolbar h3 { font-size: 14px; font-weight: 600; flex: 1; }
.search-input {
  padding: 7px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 13px; width: 220px;
  outline: none; font-family: inherit;
}
.search-input:focus { border-color: var(--accent); }
select.filter-select {
  padding: 7px 10px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 13px;
  outline: none; cursor: pointer;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 10px 16px;
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody tr { transition: background .1s; }
tbody tr:hover { background: rgba(255,255,255,.03); }
tbody td { padding: 11px 16px; border-bottom: 1px solid rgba(37,40,48,.6); font-size: 13px; }
tbody tr:last-child td { border-bottom: none; }
.pagination {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 8px; padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
}
.pagination button {
  padding: 4px 10px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text); cursor: pointer; font-size: 12px;
}
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination button:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }

/* ── BADGES ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.badge-individual { background: rgba(59,130,246,.15);  color: #60a5fa; }
.badge-pro        { background: rgba(245,158,11,.15);  color: #fbbf24; }
.badge-team       { background: rgba(168,85,247,.15);  color: #c084fc; }
.badge-active     { background: rgba(34,197,94,.15);   color: #4ade80; }
.badge-suspended  { background: rgba(239,68,68,.15);   color: #f87171; }
.badge-trial      { background: rgba(245,158,11,.15);  color: #fbbf24; border: 1px solid rgba(245,158,11,.4); }
.badge-admin      { background: rgba(245,158,11,.15);  color: #fbbf24; }
.badge-contable   { background: rgba(59,130,246,.15);  color: #60a5fa; }
.badge-monthly    { background: rgba(34,197,94,.1);    color: #4ade80; }
.badge-annual     { background: rgba(168,85,247,.1);   color: #c084fc; }

/* ── SORT ── */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--accent); }
.sort-icon { font-size: 10px; opacity: .5; margin-left: 3px; }
th.sortable:hover .sort-icon { opacity: 1; }

/* ── PLAN LINK (usuarios — columna plan) ── */
.plan-cell-link {
  display: inline-flex; align-items: center; gap: 4px;
  cursor: pointer; text-decoration: none;
  border-bottom: 1px dashed rgba(107,114,128,.4);
  padding-bottom: 1px;
}
.plan-cell-link:hover .badge { opacity: .8; }
.plan-cell-link svg { width: 12px; height: 12px; color: var(--muted); flex-shrink: 0; }
.trial-expiry { font-size: 11px; color: #fbbf24; margin-top: 3px; }

/* ── ACTION BUTTONS ── */
.action-btn { padding: 4px 10px; border-radius: 4px; font-size: 11px; font-weight: 600; cursor: pointer; border: 1px solid; transition: opacity .2s; }
.action-btn:hover { opacity: .75; }
.btn-suspend  { background: rgba(239,68,68,.1);    border-color: rgba(239,68,68,.3);    color: #f87171; }
.btn-activate { background: rgba(34,197,94,.1);    border-color: rgba(34,197,94,.3);    color: #4ade80; }
.btn-plan     { background: rgba(59,130,246,.1);   border-color: rgba(59,130,246,.3);   color: #60a5fa; }
.btn-delete   { background: rgba(239,68,68,.05);   border-color: rgba(239,68,68,.2);    color: #f87171; }
.btn-edit     { background: rgba(245,158,11,.1);   border-color: rgba(245,158,11,.3);   color: #fbbf24; }
.btn-pwd      { background: rgba(168,85,247,.1);   border-color: rgba(168,85,247,.3);   color: #c084fc; }
.btn-new { padding: 7px 14px; background: var(--accent); color: #000; border: none; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-new:hover { opacity: .85; }

/* ── MODALS ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: center; justify-content: center; z-index: 200; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; width: 460px; max-width: 95vw; }
.modal h3 { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.modal .modal-sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-field { margin-bottom: 14px; }
.modal-field label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 5px; }
.modal-field input, .modal-field select {
  width: 100%; padding: 8px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text);
  font-size: 13px; font-family: inherit; outline: none;
}
.modal-field input:focus, .modal-field select:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.btn-cancel  { padding: 8px 18px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--muted); cursor: pointer; font-size: 13px; }
.btn-confirm { padding: 8px 18px; background: var(--accent); border: none; border-radius: 6px; color: #000; cursor: pointer; font-size: 13px; font-weight: 600; }
.btn-danger  { padding: 8px 18px; background: var(--danger); border: none; border-radius: 6px; color: #fff; cursor: pointer; font-size: 13px; font-weight: 600; }

/* ── MODAL DETALLE USUARIO ── */
.modal-user-detail { width: 480px; }
.modal-user-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-user-header h3 { font-size: 16px; font-weight: 700; }
.modal-close-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 20px; line-height: 1; padding: 2px; }
.modal-close-btn:hover { color: var(--text); }
.user-detail-meta { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.user-detail-avatar { width: 40px; height: 40px; background: var(--accent); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #000; font-size: 15px; flex-shrink: 0; }
.user-detail-name { font-weight: 600; font-size: 14px; }
.user-detail-email { font-size: 12px; color: var(--muted); margin-top: 1px; }
.trial-banner {
  background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.3);
  border-radius: 6px; padding: 10px 14px;
  font-size: 12px; color: #fbbf24;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}
.trial-banner svg { width: 14px; height: 14px; flex-shrink: 0; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.detail-box { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; }
.detail-box .db-label { font-size: 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 5px; }
.detail-box .db-value { font-size: 15px; font-weight: 700; font-family: 'JetBrains Mono', monospace; }
.detail-box .db-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.detail-rows { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.detail-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 12px; border-bottom: 1px solid rgba(37,40,48,.6); font-size: 12px; }
.detail-row:last-child { border-bottom: none; }
.detail-row .dr-label { color: var(--muted); }
.detail-row .dr-value { font-weight: 500; }
.detail-row .dr-value.warning { color: #fbbf24; }

/* ── TOAST ── */
#toast { position: fixed; bottom: 24px; right: 24px; padding: 12px 18px; border-radius: 8px; font-size: 13px; font-weight: 500; z-index: 300; transform: translateY(100px); transition: transform .3s; pointer-events: none; }
#toast.show { transform: translateY(0); }
#toast.success { background: var(--success); color: #000; }
#toast.error   { background: var(--danger);  color: #fff; }

/* ── STATES ── */
.empty-row td, .loading-row td { text-align: center; padding: 32px; color: var(--muted); }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── PLANES ── */
.plans-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.plan-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.plan-card.plan-individual { border-color: rgba(59,130,246,.4); }
.plan-card.plan-pro        { border-color: rgba(245,158,11,.4); }
.plan-card.plan-team       { border-color: rgba(168,85,247,.4); }
.plan-card h3 { font-size: 15px; font-weight: 700; text-transform: capitalize; margin-bottom: 4px; }
.plan-price { font-size: 28px; font-weight: 700; font-family: 'JetBrains Mono', monospace; margin-bottom: 12px; }
.plan-price span { font-size: 13px; font-weight: 400; color: var(--muted); }
.plan-feature { font-size: 12px; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.plan-feature strong { color: var(--text); }
.plan-trial-badge { font-size: 11px; color: #fbbf24; background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.2); border-radius: 4px; padding: 3px 8px; display: inline-block; margin-bottom: 10px; }
.plan-edit-btn { margin-top: 14px; width: 100%; padding: 7px; background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.3); border-radius: 6px; color: #fbbf24; font-size: 12px; font-weight: 600; cursor: pointer; }
.plan-edit-btn:hover { opacity: .75; }

/* ── API INFO ── */
.api-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.api-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.api-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.api-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.api-card h3 { font-size: 14px; font-weight: 700; }
.api-card .api-type { font-size: 11px; color: var(--muted); }
.api-status { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.api-status.active  { background: rgba(34,197,94,.15);  color: #4ade80; }
.api-status.limited { background: rgba(245,158,11,.15); color: #fbbf24; }
.api-desc { font-size: 12px; color: var(--muted); line-height: 1.6; margin-top: 8px; }
.api-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.api-tag { padding: 2px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; font-size: 11px; color: var(--muted); }
.api-counter { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.api-counter-box { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 8px 14px; text-align: center; min-width: 80px; }
.api-counter-box .cnt-value { font-size: 20px; font-weight: 700; font-family: 'JetBrains Mono', monospace; color: var(--accent); }
.api-counter-box .cnt-label { font-size: 10px; color: var(--muted); margin-top: 2px; text-transform: uppercase; letter-spacing: .04em; }
.api-last { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ── FLUJOS ── */
.flows-grid { display: flex; flex-direction: column; gap: 16px; }
.flow-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.flow-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.flow-title { display: flex; align-items: center; gap: 10px; }
.flow-num { width: 28px; height: 28px; background: rgba(245,158,11,.15); border: 1px solid rgba(245,158,11,.3); border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--accent); flex-shrink: 0; }
.flow-card h3 { font-size: 14px; font-weight: 700; }
.flow-dates { font-size: 11px; color: var(--muted); text-align: right; line-height: 1.6; }
.flow-steps { display: flex; flex-direction: column; gap: 0; }
.flow-step { display: flex; align-items: flex-start; gap: 10px; padding: 6px 0; border-bottom: 1px solid rgba(37,40,48,.5); font-size: 12px; color: var(--muted); }
.flow-step:last-child { border-bottom: none; }
.flow-step-icon { width: 20px; height: 20px; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 10px; flex-shrink: 0; margin-top: 1px; }
.fs-frontend { background: rgba(59,130,246,.15);  color: #60a5fa; }
.fs-backend  { background: rgba(34,197,94,.15);   color: #4ade80; }
.fs-db       { background: rgba(168,85,247,.15);  color: #c084fc; }
.fs-api      { background: rgba(245,158,11,.15);  color: #fbbf24; }
.fs-email    { background: rgba(239,68,68,.15);   color: #f87171; }
.flow-step-text strong { color: var(--text); }

/* ── PLATAFORMA ── */
.platform-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.platform-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.platform-card h3 { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.platform-card h3 svg { width: 14px; height: 14px; }
.pf-row { display: flex; justify-content: space-between; align-items: flex-start; padding: 7px 0; border-bottom: 1px solid rgba(37,40,48,.6); font-size: 13px; gap: 12px; }
.pf-row:last-child { border-bottom: none; }
.pf-label { color: var(--muted); flex-shrink: 0; font-size: 12px; }
.pf-value { font-weight: 500; text-align: right; word-break: break-all; }
.pf-value a { color: var(--accent); text-decoration: none; }
.pf-value a:hover { text-decoration: underline; }
.pf-badge { display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.pf-green  { background: rgba(34,197,94,.15);  color: #4ade80; }
.pf-blue   { background: rgba(59,130,246,.15); color: #60a5fa; }
.pf-amber  { background: rgba(245,158,11,.15); color: #fbbf24; }
.pf-purple { background: rgba(168,85,247,.15); color: #c084fc; }
