/* ==========================================================================
   AFCO Admin Panel - common design system
   Bootstrap 5.3 + custom tokens. Light / dark via [data-bs-theme].
   ========================================================================== */
:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --brand: #6366f1;
  --brand-2: #8b5cf6;
  --brand-soft: rgba(99, 102, 241, .12);
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 16px;
  --sidebar-w: 272px;
  --sidebar-w-mini: 84px;
  --topbar-h: 68px;
  --ease: cubic-bezier(.22, .61, .36, 1);

  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6eaf2;
  --text: #0f172a;
  --muted: #64748b;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 10px 30px -12px rgba(15, 23, 42, .15);
  --sidebar-bg: linear-gradient(180deg, #0f172a 0%, #111c3a 100%);
  --sidebar-text: #94a3b8;
  --sidebar-hover: rgba(255, 255, 255, .06);
}
[data-bs-theme="dark"] {
  --brand-soft: rgba(129, 140, 248, .16);
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-2: #0f1729;
  --border: #1f2a44;
  --text: #e5e9f4;
  --muted: #8b97b3;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 14px 34px -14px rgba(0, 0, 0, .6);
  --sidebar-bg: linear-gradient(180deg, #0a0f1e 0%, #0d1530 100%);
}

* { -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: .925rem;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -.003em;
}
a { text-decoration: none; }
::selection { background: var(--brand); color: #fff; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---------- layout ---------- */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 1040;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; transition: width .28s var(--ease), transform .28s var(--ease);
  border-right: 1px solid rgba(255, 255, 255, .04);
}
.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; transition: margin .28s var(--ease); }
.content { flex: 1; padding: 1.75rem 1.75rem 1rem; max-width: 1480px; width: 100%; margin: 0 auto; }

.sidebar-brand { display: flex; align-items: center; gap: .8rem; padding: 1.25rem 1.4rem; height: var(--topbar-h); }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 1.05rem;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 8px 20px -6px rgba(99, 102, 241, .7);
}
.brand-name { color: #fff; font-weight: 700; font-size: 1.05rem; line-height: 1.1; white-space: nowrap; }
.brand-name small { display: block; color: var(--sidebar-text); font-weight: 500; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; margin-top: 3px; }

.sidebar-scroll { flex: 1; overflow-y: auto; padding: .5rem .9rem 1rem; }
.nav-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .12em; font-weight: 600; color: #5d6b8a; padding: 1.1rem .8rem .45rem; white-space: nowrap; }
.nav-link-item {
  display: flex; align-items: center; gap: .8rem; padding: .7rem .85rem; margin-bottom: 3px; border-radius: 12px;
  color: var(--sidebar-text); font-weight: 500; position: relative; transition: background .2s, color .2s; white-space: nowrap;
}
.nav-link-item i { font-size: 1.15rem; width: 22px; text-align: center; flex: none; }
.nav-link-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link-item.active { background: linear-gradient(90deg, rgba(99, 102, 241, .28), rgba(139, 92, 246, .08)); color: #fff; }
.nav-link-item.active::before {
  content: ''; position: absolute; left: -.9rem; top: 22%; bottom: 22%; width: 4px; border-radius: 0 4px 4px 0;
  background: linear-gradient(var(--brand), var(--brand-2)); box-shadow: 0 0 14px var(--brand);
}
.sidebar-user { margin: .75rem; padding: .8rem; border-radius: 14px; background: rgba(255, 255, 255, .05); display: flex; align-items: center; gap: .75rem; }
.sidebar-user .meta { min-width: 0; }
.sidebar-user .name { color: #fff; font-weight: 600; font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .role { font-size: .72rem; color: var(--sidebar-text); text-transform: capitalize; }

/* collapsed (desktop) */
body.sidebar-mini .sidebar { width: var(--sidebar-w-mini); }
body.sidebar-mini .main { margin-left: var(--sidebar-w-mini); }
body.sidebar-mini .brand-name, body.sidebar-mini .nav-label, body.sidebar-mini .nav-link-item span,
body.sidebar-mini .sidebar-user .meta { display: none; }
body.sidebar-mini .nav-link-item { justify-content: center; padding: .8rem; }
body.sidebar-mini .sidebar-brand { justify-content: center; padding: 1.25rem .5rem; }
body.sidebar-mini .sidebar-user { justify-content: center; }

.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(2, 6, 23, .55); backdrop-filter: blur(3px); z-index: 1035; }
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; }
  .main { margin-left: 0 !important; }
  body.sidebar-open .sidebar { transform: none; box-shadow: 0 0 60px rgba(0, 0, 0, .5); }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .content { padding: 1.1rem; }
  body.sidebar-mini .brand-name, body.sidebar-mini .nav-label, body.sidebar-mini .nav-link-item span, body.sidebar-mini .sidebar-user .meta { display: revert; }
}

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 1020; height: var(--topbar-h); padding: 0 1.75rem;
  display: flex; align-items: center; gap: 1rem;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
@media (max-width: 991.98px) { .topbar { padding: 0 1rem; } }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  display: inline-grid; place-items: center; transition: .2s var(--ease); box-shadow: var(--shadow-sm); cursor: pointer;
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand); transform: translateY(-1px); }
.topbar-title { font-weight: 700; font-size: 1.05rem; margin: 0; }
.avatar {
  width: 38px; height: 38px; border-radius: 12px; flex: none; display: grid; place-items: center; font-weight: 700; font-size: .8rem; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--accent));
}
.avatar.sm { width: 34px; height: 34px; border-radius: 10px; font-size: .72rem; }
.user-menu { display: flex; align-items: center; gap: .7rem; padding: .3rem .6rem .3rem .3rem; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; color: var(--text); }
.user-menu .who { line-height: 1.15; text-align: left; }
.user-menu .who b { display: block; font-size: .82rem; }
.user-menu .who small { color: var(--muted); font-size: .72rem; }
.dropdown-menu { border-radius: 14px; border: 1px solid var(--border); box-shadow: var(--shadow); padding: .5rem; background: var(--surface); }
.dropdown-item { border-radius: 9px; padding: .55rem .8rem; font-weight: 500; color: var(--text); }
.dropdown-item:hover { background: var(--brand-soft); color: var(--text); }

/* ---------- page header ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; animation: fadeUp .5s var(--ease) both; }
.page-header h1 { font-size: 1.55rem; font-weight: 800; letter-spacing: -.02em; margin: 0; }
.page-header p { color: var(--muted); margin: .25rem 0 0; }
.crumbs { font-size: .78rem; color: var(--muted); margin-bottom: .45rem; display: flex; gap: .45rem; align-items: center; }
.crumbs a { color: var(--muted); } .crumbs a:hover { color: var(--brand); }

/* ---------- cards ---------- */
.card-x { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); animation: fadeUp .5s var(--ease) both; }
.card-x-head { padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.card-x-head h3 { font-size: 1rem; font-weight: 700; margin: 0; }
.card-x-body { padding: 1.4rem; }

.stat-card { padding: 1.3rem 1.4rem; display: flex; align-items: center; gap: 1rem; position: relative; overflow: hidden; transition: .25s var(--ease); }
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.stat-card::after { content: ''; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%; background: var(--tone-soft); opacity: .7; }
.stat-icon { width: 52px; height: 52px; border-radius: 15px; display: grid; place-items: center; font-size: 1.4rem; color: #fff; flex: none; background: var(--tone); box-shadow: 0 10px 22px -10px rgba(15, 23, 42, .6); z-index: 1; }
.stat-body { position: relative; z-index: 1; }
.stat-label { color: var(--muted); font-size: .8rem; font-weight: 500; }
.stat-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.tone-indigo { --tone: linear-gradient(135deg, #6366f1, #8b5cf6); --tone-soft: rgba(99, 102, 241, .14); }
.tone-cyan   { --tone: linear-gradient(135deg, #06b6d4, #3b82f6); --tone-soft: rgba(6, 182, 212, .14); }
.tone-green  { --tone: linear-gradient(135deg, #10b981, #34d399); --tone-soft: rgba(16, 185, 129, .14); }
.tone-amber  { --tone: linear-gradient(135deg, #f59e0b, #f97316); --tone-soft: rgba(245, 158, 11, .15); }
.tone-rose   { --tone: linear-gradient(135deg, #f43f5e, #ef4444); --tone-soft: rgba(244, 63, 94, .14); }
.tone-violet { --tone: linear-gradient(135deg, #a855f7, #ec4899); --tone-soft: rgba(168, 85, 247, .14); }

/* ---------- buttons / forms ---------- */
.btn { border-radius: 11px; font-weight: 600; padding: .55rem 1.05rem; transition: .2s var(--ease); }
.btn-brand { color: #fff; border: 0; background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 10px 22px -10px rgba(99, 102, 241, .9); }
.btn-brand:hover, .btn-brand:focus { color: #fff; transform: translateY(-1px); box-shadow: 0 14px 26px -10px rgba(99, 102, 241, 1); filter: brightness(1.06); }
.btn-soft { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.btn-soft:hover { border-color: var(--brand); color: var(--brand); background: var(--surface-2); }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; border-radius: 9px; }
.btn-icon { width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); transition: .15s; }
.btn-icon:hover { color: #fff; background: var(--brand); border-color: var(--brand); }
.btn-icon.danger:hover { background: var(--danger); border-color: var(--danger); }
.btn-icon.success:hover { background: var(--success); border-color: var(--success); }
.btn-icon.warn:hover { background: var(--warning); border-color: var(--warning); }
.form-control, .form-select { border-radius: 12px; border: 1px solid var(--border); background-color: var(--surface); color: var(--text); padding: .65rem .95rem; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); background-color: var(--surface); color: var(--text); }
.form-control.is-invalid { border-color: var(--danger); }
.form-label { font-weight: 600; font-size: .82rem; margin-bottom: .4rem; }
.input-icon { position: relative; }
.input-icon > i { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon .form-control { padding-left: 2.7rem; }
.input-icon .toggle-pass { position: absolute; right: .6rem; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--muted); padding: .35rem .5rem; }

/* ---------- badges ---------- */
.badge-soft { display: inline-flex; align-items: center; gap: .35rem; padding: .32rem .7rem; border-radius: 99px; font-size: .74rem; font-weight: 600; white-space: nowrap; }
.badge-soft::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-soft.green { color: #059669; background: rgba(16, 185, 129, .13); }
.badge-soft.red { color: #dc2626; background: rgba(239, 68, 68, .13); }
.badge-soft.amber { color: #d97706; background: rgba(245, 158, 11, .15); }
.badge-soft.blue { color: #2563eb; background: rgba(59, 130, 246, .13); }
.badge-soft.violet { color: #7c3aed; background: rgba(139, 92, 246, .14); }
.badge-soft.gray { color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); }
[data-bs-theme="dark"] .badge-soft.green { color: #34d399; } [data-bs-theme="dark"] .badge-soft.red { color: #f87171; }
[data-bs-theme="dark"] .badge-soft.amber { color: #fbbf24; } [data-bs-theme="dark"] .badge-soft.blue { color: #60a5fa; }
[data-bs-theme="dark"] .badge-soft.violet { color: #a78bfa; }

/* ---------- data table ---------- */
.pt-toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; padding: 1rem 1.4rem; border-bottom: 1px solid var(--border); }
.pt-search { position: relative; min-width: 240px; flex: 1; max-width: 360px; }
.pt-search i { position: absolute; left: .95rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.pt-search input { padding-left: 2.5rem; background-color: var(--surface-2); }
.pt-wrap { overflow-x: auto; }
.pt { width: 100%; border-collapse: separate; border-spacing: 0; }
.pt th { background: var(--surface-2); color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; padding: .85rem 1.4rem; white-space: nowrap; border-bottom: 1px solid var(--border); user-select: none; text-align: left; }
.pt th.sortable { cursor: pointer; } .pt th.sortable:hover { color: var(--brand); }
.pt th .arr { margin-left: .3rem; opacity: .4; font-size: .7rem; }
.pt th.sorted .arr { opacity: 1; color: var(--brand); }
.pt td { padding: .95rem 1.4rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.pt tbody tr { transition: background .15s; }
.pt tbody tr:hover { background: var(--brand-soft); }
.pt tbody tr:last-child td { border-bottom: 0; }
.pt .cell-user { display: flex; align-items: center; gap: .8rem; min-width: 200px; }
.pt .cell-user b { display: block; font-weight: 600; }
.pt .cell-user small, .muted { color: var(--muted); }
.pt .actions { display: flex; gap: .4rem; justify-content: flex-end; }
.pt-foot { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; padding: .9rem 1.4rem; border-top: 1px solid var(--border); color: var(--muted); font-size: .82rem; }
.pager { display: flex; gap: .3rem; }
.pager button { min-width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; font-size: .82rem; }
.pager button:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.pager button.on { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-color: transparent; }
.pager button:disabled { opacity: .4; cursor: not-allowed; }
.thumb { width: 64px; height: 44px; border-radius: 10px; flex: none; background: linear-gradient(135deg, #1e293b, #334155); display: grid; place-items: center; color: #94a3b8; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- empty / skeleton / spinners ---------- */
.empty { text-align: center; padding: 3.5rem 1rem; color: var(--muted); }
.empty i { font-size: 2.6rem; display: block; margin-bottom: .6rem; opacity: .55; }
.skel { border-radius: 8px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.3s infinite; }
.skel.line { height: 14px; } .skel.big { height: 30px; width: 90px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.spin { animation: spin .8s linear infinite; display: inline-block; } @keyframes spin { to { transform: rotate(360deg); } }

/* ---------- tabs ---------- */
.seg { display: inline-flex; padding: .3rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 13px; gap: .25rem; }
.seg button { border: 0; background: none; color: var(--muted); font-weight: 600; padding: .5rem 1rem; border-radius: 10px; transition: .2s; }
.seg button.on { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); }

/* ---------- toasts / modal ---------- */
.toast-stack { position: fixed; right: 1.2rem; bottom: 1.2rem; z-index: 2000; display: flex; flex-direction: column; gap: .6rem; }
.toast-x { min-width: 280px; max-width: 380px; display: flex; gap: .75rem; align-items: flex-start; padding: .9rem 1rem; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); animation: toastIn .35s var(--ease) both; }
.toast-x i { font-size: 1.25rem; margin-top: 1px; }
.toast-x.ok i { color: var(--success); } .toast-x.err i { color: var(--danger); } .toast-x.info i { color: var(--brand); }
.toast-x b { display: block; font-size: .86rem; } .toast-x span { color: var(--muted); font-size: .8rem; }
.toast-x.out { animation: toastOut .3s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(30px); } }
.modal-content { border-radius: 18px; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); color: var(--text); }
.modal-header, .modal-footer { border-color: var(--border); }
.confirm-icon { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-size: 1.6rem; margin: 0 auto 1rem; background: rgba(239, 68, 68, .13); color: var(--danger); }
.confirm-icon.info { background: var(--brand-soft); color: var(--brand); }

/* ---------- footer ---------- */
.footer { padding: 1.1rem 1.75rem 1.5rem; color: var(--muted); font-size: .8rem; display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem; }

/* ---------- auth pages ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; background: var(--surface); }
.auth-hero {
  position: relative; overflow: hidden; color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(900px 500px at 10% 0%, rgba(139, 92, 246, .75), transparent 60%),
              radial-gradient(700px 500px at 100% 100%, rgba(6, 182, 212, .55), transparent 55%),
              linear-gradient(160deg, #0f172a, #1e1b4b);
}
.auth-hero::before, .auth-hero::after { content: ''; position: absolute; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .12); }
.auth-hero::before { width: 520px; height: 520px; right: -180px; top: -140px; }
.auth-hero::after { width: 340px; height: 340px; left: -110px; bottom: -120px; }
.auth-hero > * { position: relative; z-index: 1; }
.auth-hero h2 { font-size: 2.3rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.15; max-width: 440px; }
.auth-hero p { color: rgba(255, 255, 255, .72); max-width: 420px; }
.auth-points { list-style: none; padding: 0; margin: 2rem 0 0; display: grid; gap: .9rem; }
.auth-points li { display: flex; align-items: center; gap: .8rem; color: rgba(255, 255, 255, .9); }
.auth-points i { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: rgba(255, 255, 255, .12); backdrop-filter: blur(6px); }
.auth-form-side { display: grid; place-items: center; padding: 2rem; background: var(--bg); position: relative; }
.auth-card { width: 100%; max-width: 440px; padding: 2.4rem; animation: fadeUp .6s var(--ease) both; }
.auth-card h1 { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; }
.auth-top { position: absolute; top: 1.2rem; right: 1.2rem; }
@media (max-width: 991.98px) { .auth { grid-template-columns: 1fr; } .auth-hero { display: none; } .auth-card { padding: 1.6rem; } }
@media print { .sidebar, .topbar, .footer, .pt-toolbar .btn, .actions { display: none !important; } .main { margin: 0 !important; } }
