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

/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --surface-2:    #f8fafc;
  --surface-3:    #f1f5f9;
  --border:       #e2e8f0;
  --border-2:     #cbd5e1;
  --text:         #0f172a;
  --text-2:       #475569;
  --text-3:       #94a3b8;
  --accent:       #6366f1;
  --accent-hover: #4f46e5;
  --accent-sub:   rgba(99,102,241,.1);
  --green:        #10b981;
  --green-sub:    rgba(16,185,129,.1);
  --yellow:       #d97706;
  --yellow-sub:   rgba(217,119,6,.1);
  --red:          #ef4444;
  --red-sub:      rgba(239,68,68,.1);
  --blue:         #3b82f6;
  --radius:       8px;
  --radius-lg:    12px;
  --shadow:       0 4px 24px rgba(0,0,0,.08);
}

/* ── Dark theme ──────────────────────────────────────────────────────────── */
html[data-theme="dark"] {
  --bg:           #07090f;
  --surface:      #0d1117;
  --surface-2:    #131920;
  --surface-3:    #1a2233;
  --border:       #1e2836;
  --border-2:     #2a3547;
  --text:         #e2e8f0;
  --text-2:       #94a3b8;
  --text-3:       #64748b;
  --accent-hover: #7c7ff5;
  --accent-sub:   rgba(99,102,241,.15);
  --green-sub:    rgba(16,185,129,.15);
  --yellow:       #f59e0b;
  --yellow-sub:   rgba(245,158,11,.15);
  --red-sub:      rgba(239,68,68,.15);
  --shadow:       0 4px 24px rgba(0,0,0,.5);
}
html[data-theme="dark"] ::-webkit-scrollbar-track { background: var(--bg); }
html[data-theme="dark"] .login-page {
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(99,102,241,.07) 0%, transparent 70%), var(--bg);
}
html[data-theme="dark"] .login-card {
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
html[data-theme="dark"] .modal-overlay {
  background: rgba(0,0,0,.72);
}

/* Theme toggle button */
.theme-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border-2);
  background: none;
  font-size: .95rem;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all .18s;
}
.theme-btn:hover { background: var(--surface-3); }

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--surface-3); }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ─────────────────────────────────────────────────────────────────────────── */
/*  SHARED COMPONENTS                                                          */
/* ─────────────────────────────────────────────────────────────────────────── */

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 18px; border-radius: var(--radius); font-size: .84rem; font-weight: 600; border: none; transition: all .18s; }
.btn-primary   { background: var(--accent);   color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost     { background: none; border: 1px solid var(--border-2); color: var(--text-2); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger    { background: none; border: 1px solid var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red-sub); }
.btn-success   { background: var(--green); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: .78rem; }
.btn-icon { width: 32px; height: 32px; padding: 0; justify-content: center; border-radius: 6px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 20px; font-size: .72rem; font-weight: 600; }
.badge-green  { background: var(--green-sub);  color: var(--green); }
.badge-red    { background: var(--red-sub);    color: var(--red); }
.badge-yellow { background: var(--yellow-sub); color: var(--yellow); }
.badge-accent { background: var(--accent-sub); color: var(--accent); }
.badge-default{ background: var(--surface-3);  color: var(--text-2); }

/* Toggle ─────────────────────────────────────────────────────────────────── */
.toggle { position: relative; display: inline-block; width: 38px; height: 21px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0;
  background: var(--surface-3); border-radius: 999px;
  transition: background .2s;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle-track::after {
  content: '';
  position: absolute;
  left: 3px; top: 3px;
  width: 15px; height: 15px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}
.toggle input:checked + .toggle-track::after { transform: translateX(17px); }

/* Form elements */
.form-group  { display: flex; flex-direction: column; gap: 6px; }
.form-label  { font-size: .78rem; font-weight: 500; color: var(--text-2); }
.form-input  {
  background: var(--surface-3); border: 1px solid var(--border-2);
  border-radius: var(--radius); color: var(--text); padding: 9px 12px; font-size: .88rem;
  transition: border-color .18s;
}
.form-input:focus { outline: none; border-color: var(--accent); }
.form-input::placeholder { color: var(--text-3); }
select.form-input { appearance: none; }
.form-row    { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Card */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 16px; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 13px 16px; font-size: .84rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.35); z-index: 400;
  display: none; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius-lg); width: min(520px, 95vw);
  max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.modal-lg { width: min(680px, 95vw); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: .95rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-3); font-size: 1.3rem; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* Divider */
.divider { height: 1px; background: var(--border); margin: 0; }

/* Empty state */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-3); }
.empty-state .icon { font-size: 2.4rem; margin-bottom: 12px; }
.empty-state p { font-size: .88rem; }

/* Toasts */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 999; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border-2);
  font-size: .84rem; box-shadow: var(--shadow);
  animation: slideIn .25s ease;
  min-width: 260px;
}
.toast.toast-success { border-color: var(--green); }
.toast.toast-error   { border-color: var(--red); }
.toast.toast-info    { border-color: var(--accent); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* Portal nav */
.portal-nav {
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 20px; position: sticky; top: 0; z-index: 100;
}
.portal-nav .brand { display: flex; align-items: center; gap: 10px; }
.portal-nav .brand-logo { font-size: 1.3rem; }
.portal-nav .brand-name { font-size: .92rem; font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.portal-nav .brand-sub  { font-size: .72rem; color: var(--text-3); }
.portal-nav .spacer { flex: 1; }
.portal-nav .nav-item { font-size: .82rem; color: var(--text-2); padding: 6px 12px; border-radius: 6px; transition: all .18s; }
.portal-nav .nav-item:hover { background: var(--surface-3); color: var(--text); }
.portal-nav .nav-item.active { color: var(--accent); background: var(--accent-sub); }
.portal-nav .user-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-3); border: 1px solid var(--border-2);
  border-radius: 20px; padding: 4px 12px 4px 5px; font-size: .78rem;
}
.portal-nav .user-avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700; color: #fff;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/*  LOGIN PAGE                                                                  */
/* ─────────────────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(99,102,241,.12) 0%, transparent 70%), var(--bg);
}
.login-card {
  width: min(420px, 95vw); padding: 44px 40px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: 0 8px 40px rgba(99,102,241,.08), 0 2px 8px rgba(0,0,0,.06);
}
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 30px; }
.login-logo-icon { font-size: 2rem; }
.login-logo-title { font-size: 1.15rem; font-weight: 700; }
.login-logo-sub { font-size: .75rem; color: var(--text-3); margin-top: 1px; }
.login-heading { font-size: 1.35rem; font-weight: 700; margin-bottom: 6px; }
.login-sub { font-size: .83rem; color: var(--text-2); margin-bottom: 28px; }
.login-card .form-group { margin-bottom: 16px; }
.login-btn { width: 100%; padding: 11px; font-size: .9rem; margin-top: 6px; justify-content: center; }
.login-error {
  background: var(--red-sub); border: 1px solid rgba(239,68,68,.3);
  color: var(--red); border-radius: var(--radius); padding: 10px 14px;
  font-size: .82rem; margin-bottom: 14px; display: none;
}
.login-error.visible { display: block; }
.login-footer { margin-top: 28px; font-size: .72rem; color: var(--text-3); text-align: center; }

/* ─────────────────────────────────────────────────────────────────────────── */
/*  DASHBOARD                                                                   */
/* ─────────────────────────────────────────────────────────────────────────── */
.dash-wrap { padding: 32px 36px; max-width: 1400px; margin: 0 auto; }
.dash-greeting h1 { font-size: 1.4rem; font-weight: 700; }
.dash-greeting p { color: var(--text-2); font-size: .87rem; margin-top: 4px; }

.dash-tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
  margin-top: 32px;
}
.tool-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px 20px;
  display: flex; flex-direction: column; gap: 14px;
  transition: border-color .2s, transform .2s, box-shadow .2s;
  position: relative;
}
.tool-card:hover { border-color: var(--border-2); transform: translateY(-2px); box-shadow: 0 6px 24px rgba(0,0,0,.07); }
.tool-card.has-access { border-color: var(--border); }
.tool-card.has-access:hover { border-color: var(--accent); }
.tool-card.no-access { opacity: .45; pointer-events: none; }
.tool-icon { font-size: 2.2rem; line-height: 1; }
.tool-name { font-size: .96rem; font-weight: 700; }
.tool-desc { font-size: .8rem; color: var(--text-2); line-height: 1.5; flex: 1; }
.tool-open-btn { align-self: flex-start; }

/* ─────────────────────────────────────────────────────────────────────────── */
/*  BACKOFFICE                                                                  */
/* ─────────────────────────────────────────────────────────────────────────── */
.bo-layout { height: calc(100vh - 56px); display: flex; overflow: hidden; }

/* Sidebar */
.bo-sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto;
  padding: 16px 0;
}
.bo-nav-section { padding: 0 12px; margin-bottom: 4px; }
.bo-nav-label { font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); padding: 6px 8px 4px; }
.bo-nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 12px; border-radius: 6px;
  font-size: .84rem; color: var(--text-2);
  transition: all .15s; cursor: pointer; border: none;
  background: none; width: 100%; text-align: left;
}
.bo-nav-item:hover { background: var(--surface-3); color: var(--text); }
.bo-nav-item.active { background: var(--accent-sub); color: var(--accent); font-weight: 600; }
.bo-nav-item .nav-icon { font-size: 1rem; width: 18px; text-align: center; }

/* Content */
.bo-content { flex: 1; overflow-y: auto; padding: 28px 32px; }

/* Section header */
.section-hdr { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.section-hdr h2 { font-size: 1.1rem; font-weight: 700; }
.section-hdr .hdr-sub { font-size: .8rem; color: var(--text-2); margin-top: 2px; }

/* Stats row */
.stats-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 28px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.05); }
.stat-card .s-num { font-size: 2rem; font-weight: 700; line-height: 1; color: var(--accent); }
.stat-card .s-lbl { font-size: .76rem; color: var(--text-2); margin-top: 5px; }

/* Section panel hide/show */
.bo-section { display: none; }
.bo-section.active { display: block; }

/* Access matrix */
.access-matrix { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.access-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; }
.access-row .tool-lbl { font-size: .84rem; display: flex; align-items: center; gap: 8px; }
.access-row .src-badge { font-size: .68rem; color: var(--text-3); margin-left: 6px; }

/* ─────────────────────────────────────────────────────────────────────────── */
/*  TOOL FRAME                                                                  */
/* ─────────────────────────────────────────────────────────────────────────── */
.frame-wrap { display: flex; flex-direction: column; height: 100vh; }
.frame-nav { height: 48px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 14px; flex-shrink: 0; }
.frame-nav .back-btn { font-size: .8rem; color: var(--text-2); display: flex; align-items: center; gap: 5px; padding: 5px 10px; border-radius: 5px; transition: all .15s; }
.frame-nav .back-btn:hover { background: var(--surface-3); color: var(--text); }
.frame-nav .tool-title { font-size: .88rem; font-weight: 600; }
.frame-nav .frame-sep { width: 1px; height: 20px; background: var(--border-2); }
.frame-nav .user-pill {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface-2,var(--surface-3)); border: 1px solid var(--border-2,var(--border));
  border-radius: 99px; padding: 3px 12px 3px 4px; font-size: .78rem;
}
.frame-nav .user-initial {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: .68rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.frame-nav .user-name { color: var(--text); font-weight: 500; }
.frame-content { flex: 1; overflow: hidden; }
.frame-content iframe { width: 100%; height: 100%; border: none; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.flex  { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12{ gap: 12px; }
.text-2{ color: var(--text-2); }
.text-3{ color: var(--text-3); }
.fw-600{ font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 768px) {
  .bo-sidebar { width: 200px; }
  .bo-content { padding: 18px 16px; }
  .dash-wrap  { padding: 20px 16px; }
  .form-row   { grid-template-columns: 1fr; }
}
