@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg:     #07090f;
  --bg2:    #0d1422;
  --bg3:    #131d2e;
  --bg4:    #19243c;
  --border: #1e2d45;
  --text:   #dde3ef;
  --muted:  #5e6e88;
  --c1:     #4f8ef7;
  --c2:     #22d3ee;
  --c3:     #34d399;
  --c4:     #fbbf24;
  --c5:     #f87171;
  --c6:     #a78bfa;
  --c7:     #fb923c;
  --red:    #ef4444;
  --green:  #10b981;
  --radius: 12px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--c1); text-decoration: none; }
a:hover { opacity: .8; }
input, select, textarea {
  font-family: inherit;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: .88rem;
  outline: none;
  width: 100%;
  transition: border-color .2s;
}
input:focus, select:focus { border-color: var(--c1); }
input::placeholder { color: var(--muted); }
label { font-size: .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .6px; display: block; margin-bottom: 5px; }

/* ── BOTONES ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 20px; border-radius: 8px; font-weight: 600;
  font-size: .82rem; cursor: pointer; border: none; font-family: inherit;
  transition: opacity .2s, transform .1s; white-space: nowrap;
}
.btn:hover { opacity: .85; }
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--c1); color: #fff; }
.btn-success   { background: var(--green); color: #fff; }
.btn-danger    { background: var(--red); color: #fff; }
.btn-secondary { background: var(--bg4); border: 1px solid var(--border); color: var(--muted); }
.btn-sm        { padding: 5px 12px; font-size: .75rem; border-radius: 6px; }
.btn-full      { width: 100%; }
.btn-icon      { padding: 7px; border-radius: 7px; }

/* ── LOGIN ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 20% 15%, rgba(180,40,40,.10) 0%, transparent 55%),
              radial-gradient(ellipse at 80% 85%, rgba(26,60,120,.14) 0%, transparent 55%),
              var(--bg);
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 44px 44px 48px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 80px rgba(0,0,0,.5);
}
.login-logo-panel {
  background: #fff;
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}
.login-logo-img {
  max-width: 100%;
  height: 46px;
  object-fit: contain;
}
.login-sub {
  text-align: center;
  font-size: .65rem;
  color: var(--muted);
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 36px;
}
.login-form .field { margin-bottom: 20px; }
.login-page .btn-primary {
  background: linear-gradient(90deg, #a72b2b, #1c3f78);
}
.login-page .btn-primary:hover { filter: brightness(1.08); }
.login-page input:focus { border-color: #a72b2b; }
.login-alert {
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.3);
  color: #f87171;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .82rem;
  margin-bottom: 18px;
}
.login-footer {
  text-align: center;
  margin-top: 24px;
  font-size: .7rem;
  color: var(--muted);
}

/* ── HEADER PORTAL ── */
.portal-header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 200;
}
.ph-logo {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.4rem;
  letter-spacing: 4px;
  background: linear-gradient(90deg, var(--c1), var(--c2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.ph-right { display: flex; align-items: center; gap: 16px; }
.ph-user {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 24px; padding: 5px 14px 5px 8px;
}
.ph-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--c1), var(--c2));
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.ph-uname { font-size: .8rem; font-weight: 600; }
.ph-role  { font-size: .65rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* ── PORTAL MAIN ── */
.portal-main { padding: 36px 28px; max-width: 1400px; margin: 0 auto; }
.portal-section { margin-bottom: 48px; }
.section-title {
  font-size: .6rem;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  color: var(--muted);
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 20px;
}
.section-title::before {
  content: ''; width: 3px; height: 13px;
  background: var(--c1); border-radius: 2px;
}
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* ── APP CARD ── */
.app-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 22px 18px;
  cursor: pointer;
  transition: border-color .2s, transform .15s, box-shadow .2s;
  display: flex; flex-direction: column; gap: 14px;
  text-decoration: none; color: inherit;
  position: relative; overflow: hidden;
}
.app-card:hover {
  border-color: var(--accent-color, var(--c1));
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0,0,0,.3);
}
.app-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--accent-color, var(--c1));
  opacity: 0; transition: opacity .2s;
}
.app-card:hover::before { opacity: 1; }
.app-card-top {
  display: flex; align-items: flex-start; justify-content: space-between;
}
.app-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
  background: color-mix(in srgb, var(--accent-color, var(--c1)) 15%, transparent);
}
.app-badge {
  font-size: .58rem; font-weight: 700; letter-spacing: 1px;
  padding: 3px 8px; border-radius: 4px; text-transform: uppercase;
  background: color-mix(in srgb, var(--accent-color, var(--c1)) 15%, transparent);
  color: var(--accent-color, var(--c1));
  border: 1px solid color-mix(in srgb, var(--accent-color, var(--c1)) 30%, transparent);
}
.app-name {
  font-size: 1rem; font-weight: 700; margin-bottom: 4px;
}
.app-desc { font-size: .75rem; color: var(--muted); line-height: 1.5; }
.app-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 10px; border-top: 1px solid var(--border);
}
.app-open {
  font-size: .75rem; font-weight: 600;
  color: var(--accent-color, var(--c1));
  display: flex; align-items: center; gap: 5px;
}
.app-open svg { width: 13px; height: 13px; }

/* ── ADMIN PANEL ── */
.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 32px 24px; }
.admin-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 32px;
}
.admin-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.6rem; letter-spacing: 3px; color: var(--text);
}

/* ── TABS ── */
.tab-nav {
  display: flex; gap: 4px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 10px; padding: 4px; margin-bottom: 28px;
  width: fit-content;
}
.tab-btn {
  padding: 7px 20px; border-radius: 7px; font-size: .8rem;
  font-weight: 600; cursor: pointer; border: none;
  background: transparent; color: var(--muted); font-family: inherit;
  transition: all .2s;
}
.tab-btn.active { background: var(--c1); color: #fff; }

/* ── TABLE ── */
.table-wrap {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
thead th {
  background: var(--bg3); padding: 11px 14px;
  text-align: left; font-size: .65rem; text-transform: uppercase;
  letter-spacing: .8px; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid rgba(30,45,69,.5); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(79,142,247,.04); }
tbody td { padding: 11px 14px; vertical-align: middle; }

/* ── ROLE BADGE ── */
.role-badge {
  display: inline-block; padding: 2px 9px; border-radius: 5px;
  font-size: .67rem; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
}
.role-admin            { background: rgba(79,142,247,.15);  color: #4f8ef7; }
.role-gerencia         { background: rgba(52,211,153,.15);  color: #34d399; }
.role-ventas           { background: rgba(34,211,238,.15);  color: #22d3ee; }
.role-compras          { background: rgba(251,191,36,.15);  color: #fbbf24; }
.role-gerente_sucursal { background: rgba(167,139,250,.15); color: #a78bfa; }

/* ── STATUS BADGE ── */
.status-on  { color: #34d399; font-weight: 600; font-size: .75rem; }
.status-off { color: var(--muted); font-weight: 600; font-size: .75rem; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px;
  width: 100%; max-width: 520px;
  max-height: 88vh; overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
  transform: translateY(8px); transition: transform .2s;
}

/* ── TOGGLE 3 POSICIONES (excepciones de apps) ── */
.tri-toggle {
  display: inline-flex; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 20px; padding: 2px; gap: 2px;
}
.tri-toggle button {
  border: none; background: transparent; color: var(--muted);
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .3px;
  padding: 5px 10px; border-radius: 18px; cursor: pointer; transition: all .15s;
  font-family: inherit;
}
.tri-toggle button.active { color: #fff; }
.tri-toggle button[data-v="default"].active { background: var(--bg4); color: var(--text); }
.tri-toggle button[data-v="1"].active { background: var(--green); }
.tri-toggle button[data-v="0"].active { background: var(--red); }
.tri-toggle button:not(.active):hover { color: var(--text); }
.modal-overlay.open .modal { transform: translateY(0); }
.modal-title {
  font-weight: 700; font-size: 1.05rem; margin-bottom: 24px;
  padding-bottom: 14px; border-bottom: 1px solid var(--border);
}
.modal-field { margin-bottom: 16px; }
.modal-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border);
}

/* ── PERMISOS GRID ── */
.perm-grid {
  display: grid; grid-template-columns: 160px 1fr;
  gap: 1px; background: var(--border);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.perm-header {
  background: var(--bg3); padding: 9px 14px;
  font-size: .65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--muted);
}
.perm-apps-header {
  background: var(--bg3); padding: 9px 14px;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.perm-role-name {
  background: var(--bg2); padding: 10px 14px;
  display: flex; align-items: center;
}
.perm-checkboxes {
  background: var(--bg2); padding: 8px 14px;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.perm-check {
  display: flex; align-items: center; gap: 5px;
  font-size: .75rem; cursor: pointer;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 10px;
  transition: all .15s;
}
.perm-check input { width: auto; }
.perm-check.checked { border-color: var(--c1); background: rgba(79,142,247,.1); color: var(--c1); }

/* ── TOAST ── */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 18px;
  font-size: .82rem; font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  transform: translateY(80px); opacity: 0;
  transition: all .3s; z-index: 9000;
  display: flex; align-items: center; gap: 8px;
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.ok   { border-color: var(--green); color: var(--green); }
#toast.err  { border-color: var(--red);   color: var(--red); }

/* ── RESPONSIVE ── */
@media (max-width: 640px) {
  .login-card { padding: 32px 24px; }
  .portal-main { padding: 24px 16px; }
  .apps-grid { grid-template-columns: 1fr; }
}
