/* ==========================================================================
   Admin design system
   ========================================================================== */
:root {
  --ims-primary: #2563eb;
  --ims-primary-600: #1d4ed8;
  --ims-primary-50: #eff6ff;
  --ims-nav-bg: #0f172a;
  --ims-nav-bg-2: #111c33;
  --ims-nav-text: #94a3b8;
  --ims-nav-active: #ffffff;
  --ims-surface: #ffffff;
  --ims-page: #f4f6fa;
  --ims-border: #e5e7eb;
  --ims-text: #0f172a;
  --ims-muted: #64748b;
  --ims-radius: 10px;
  --ims-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --ims-sidebar-w: 256px;
  --bs-primary: #2563eb;
  --bs-primary-rgb: 37, 99, 235;
  --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bs-body-font-size: .875rem;
  --bs-body-color: #0f172a;
  --bs-border-color: #e5e7eb;
  --bs-link-color: #2563eb;
  --bs-link-color-rgb: 37, 99, 235;
}

body.admin { background: var(--ims-page); min-height: 100vh; }
a { text-decoration: none; }
.btn { --bs-btn-font-size: .85rem; border-radius: 8px; font-weight: 500; }
.btn-primary { --bs-btn-bg: var(--ims-primary); --bs-btn-border-color: var(--ims-primary); --bs-btn-hover-bg: var(--ims-primary-600); --bs-btn-hover-border-color: var(--ims-primary-600); --bs-btn-active-bg: var(--ims-primary-600); --bs-btn-disabled-bg: var(--ims-primary); --bs-btn-disabled-border-color: var(--ims-primary); }
.btn-outline-primary { --bs-btn-color: var(--ims-primary); --bs-btn-border-color: var(--ims-primary); --bs-btn-hover-bg: var(--ims-primary); --bs-btn-hover-border-color: var(--ims-primary); }
.btn-icon { width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.form-control, .form-select { border-radius: 8px; font-size: .875rem; border-color: #d7dce3; }
.form-control:focus, .form-select:focus { border-color: #93b4f5; box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .12); }
.form-label { font-weight: 500; font-size: .82rem; color: #334155; margin-bottom: .3rem; }
.form-label.required::after { content: " *"; color: #dc2626; }
.form-text { font-size: .76rem; }
.invalid-feedback { font-size: .78rem; }

/* ---------- Sidebar ---------- */
.ims-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--ims-sidebar-w); background: var(--ims-nav-bg);
  color: var(--ims-nav-text); z-index: 1040; display: flex; flex-direction: column; transition: width .2s ease, transform .2s ease;
}
.ims-brand { display: flex; align-items: center; gap: .65rem; padding: 1rem 1.1rem; height: 60px; border-bottom: 1px solid rgba(255,255,255,.06); color: #fff; }
.ims-brand img { width: 32px; height: 32px; object-fit: contain; border-radius: 6px; background: #fff; }
.ims-brand .mark { width: 32px; height: 32px; border-radius: 8px; background: var(--ims-primary); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.ims-brand .name { font-weight: 600; font-size: .9rem; line-height: 1.15; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ims-brand .name small { display: block; font-weight: 400; color: var(--ims-nav-text); font-size: .7rem; }
.ims-nav { overflow-y: auto; padding: .6rem .6rem 2rem; flex: 1; scrollbar-width: thin; scrollbar-color: #1e293b transparent; }
.ims-nav .nav-section { font-size: .66rem; letter-spacing: .08em; text-transform: uppercase; color: #64748b; padding: .9rem .7rem .35rem; white-space: nowrap; }
.ims-nav a { display: flex; align-items: center; gap: .7rem; color: var(--ims-nav-text); padding: .5rem .7rem; border-radius: 8px; font-size: .84rem; white-space: nowrap; }
.ims-nav a i { font-size: 1.05rem; width: 20px; text-align: center; flex-shrink: 0; }
.ims-nav a:hover { background: rgba(255,255,255,.05); color: #e2e8f0; }
.ims-nav a.active { background: var(--ims-primary); color: var(--ims-nav-active); }
.ims-nav .badge { margin-left: auto; }

.ims-main { margin-left: var(--ims-sidebar-w); transition: margin .2s ease; min-height: 100vh; display: flex; flex-direction: column; }
.ims-topbar { height: 60px; background: var(--ims-surface); border-bottom: 1px solid var(--ims-border); display: flex; align-items: center; gap: .75rem; padding: 0 1.25rem; position: sticky; top: 0; z-index: 1030; }
.ims-topbar .user-chip { display: flex; align-items: center; gap: .55rem; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--ims-primary-50); color: var(--ims-primary); display: grid; place-items: center; font-weight: 600; font-size: .8rem; flex-shrink: 0; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 96px; height: 96px; border-radius: 12px; font-size: 1.6rem; }
.ims-content { padding: 1.25rem 1.5rem 2rem; flex: 1; }
.ims-footer { padding: .9rem 1.5rem; color: var(--ims-muted); font-size: .75rem; border-top: 1px solid var(--ims-border); background: var(--ims-surface); }

body.sidebar-collapsed .ims-sidebar { width: 72px; }
body.sidebar-collapsed .ims-main { margin-left: 72px; }
body.sidebar-collapsed .ims-nav .nav-section, body.sidebar-collapsed .ims-nav a span, body.sidebar-collapsed .ims-brand .name, body.sidebar-collapsed .ims-nav .badge { display: none; }
body.sidebar-collapsed .ims-nav a { justify-content: center; }

@media (max-width: 991.98px) {
  .ims-sidebar { transform: translateX(-100%); width: var(--ims-sidebar-w) !important; }
  .ims-main, body.sidebar-collapsed .ims-main { margin-left: 0; }
  body.sidebar-open .ims-sidebar { transform: none; }
  body.sidebar-open .ims-backdrop { display: block; }
  body.sidebar-collapsed .ims-nav .nav-section, body.sidebar-collapsed .ims-nav a span, body.sidebar-collapsed .ims-brand .name { display: initial; }
  .ims-content { padding: 1rem; }
}
.ims-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1035; }

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1.1rem; }
.page-head h1 { font-size: 1.3rem; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.page-head .breadcrumb { font-size: .76rem; margin-bottom: .25rem; --bs-breadcrumb-divider-color: #94a3b8; }
.page-head .breadcrumb a { color: var(--ims-muted); }
.page-head .actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--ims-border); border-radius: var(--ims-radius); box-shadow: var(--ims-shadow); }
.card-header { background: transparent; border-bottom: 1px solid var(--ims-border); padding: .85rem 1.1rem; font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.card-header .card-title { margin: 0; font-size: .92rem; font-weight: 600; }
.card-body { padding: 1.1rem; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ims-muted); font-weight: 600; margin: 0 0 .75rem; }

.stat-card { padding: 1rem 1.1rem; display: flex; gap: .9rem; align-items: center; height: 100%; }
.stat-card .icon { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; font-size: 1.25rem; flex-shrink: 0; }
.stat-card .value { font-size: 1.4rem; font-weight: 700; line-height: 1.1; }
.stat-card .label { color: var(--ims-muted); font-size: .78rem; }
.stat-card a.stretched-link { position: absolute; inset: 0; }
.tone-blue { background: #eff6ff; color: #2563eb; }
.tone-green { background: #ecfdf5; color: #059669; }
.tone-amber { background: #fffbeb; color: #d97706; }
.tone-red { background: #fef2f2; color: #dc2626; }
.tone-violet { background: #f5f3ff; color: #7c3aed; }
.tone-slate { background: #f1f5f9; color: #475569; }
.tone-cyan { background: #ecfeff; color: #0891b2; }

/* ---------- Tables ---------- */
.table { --bs-table-color: var(--ims-text); margin-bottom: 0; font-size: .84rem; }
.table > thead th { background: #f8fafc; color: #475569; font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; border-bottom-width: 1px; white-space: nowrap; padding: .6rem .75rem; }
.table > tbody td { padding: .6rem .75rem; vertical-align: middle; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: #f8fafc; }
.sort-link { color: inherit; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .8rem 1.1rem; border-bottom: 1px solid var(--ims-border); }
.toolbar .search { position: relative; min-width: 220px; flex: 1 1 220px; max-width: 360px; }
.toolbar .search i { position: absolute; left: .65rem; top: 50%; transform: translateY(-50%); color: #94a3b8; }
.toolbar .search input { padding-left: 2rem; }
.toolbar .form-select { width: auto; min-width: 140px; }
.table-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; padding: .7rem 1.1rem; border-top: 1px solid var(--ims-border); color: var(--ims-muted); font-size: .8rem; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn { padding: .2rem .45rem; }
.text-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82em; }
.cell-title { font-weight: 600; color: var(--ims-text); }
.cell-sub { color: var(--ims-muted); font-size: .76rem; }

/* ---------- Badges ---------- */
.badge { font-weight: 600; font-size: .7rem; padding: .35em .6em; border-radius: 6px; }
.badge-soft-success { background: #dcfce7; color: #166534; }
.badge-soft-primary { background: #dbeafe; color: #1e40af; }
.badge-soft-info { background: #e0f2fe; color: #075985; }
.badge-soft-warning { background: #fef3c7; color: #92400e; }
.badge-soft-danger { background: #fee2e2; color: #991b1b; }
.badge-soft-secondary { background: #f1f5f9; color: #475569; }
.badge-soft-dark { background: #e2e8f0; color: #1e293b; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--ims-muted); }
.empty-state i { font-size: 2.2rem; color: #cbd5e1; display: block; margin-bottom: .5rem; }
.empty-state h6 { color: var(--ims-text); font-weight: 600; }

/* ---------- Detail lists ---------- */
.dl-grid { display: grid; grid-template-columns: 160px 1fr; gap: .45rem 1rem; font-size: .85rem; margin: 0; }
.dl-grid dt { color: var(--ims-muted); font-weight: 500; }
.dl-grid dd { margin: 0; word-break: break-word; }
@media (max-width: 575.98px) { .dl-grid { grid-template-columns: 1fr; } .dl-grid dd { margin-bottom: .4rem; } }

/* ---------- Toasts / loading ---------- */
.toast-container { z-index: 1090; }
.toast { border: 0; border-radius: 10px; box-shadow: 0 10px 30px rgba(15,23,42,.18); }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after { content: ""; position: absolute; inset: 0; margin: auto; width: 1rem; height: 1rem; border: 2px solid rgba(255,255,255,.7); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-light.is-loading::after, .btn-outline-secondary.is-loading::after { border-color: #64748b; border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Marks entry grid ---------- */
.marks-grid td, .marks-grid th { padding: .35rem .5rem !important; }
.marks-grid input.mark-input { width: 82px; text-align: right; padding: .25rem .4rem; font-variant-numeric: tabular-nums; }
.marks-grid select.att-select { width: 110px; padding: .25rem 1.6rem .25rem .4rem; }
.marks-grid tr.is-dirty td { background: #fffbeb; }
.marks-grid tr.has-error td { background: #fef2f2; }
.marks-grid input.is-invalid { border-color: #dc2626; }
.marks-grid .total-cell { font-weight: 600; min-width: 64px; text-align: right; }
.sticky-actions { position: sticky; bottom: 0; background: var(--ims-surface); border-top: 1px solid var(--ims-border); padding: .75rem 1.1rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; z-index: 5; }

/* ---------- Auth pages ---------- */
body.auth-page { background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 410px; background: #fff; border-radius: 14px; box-shadow: 0 25px 60px rgba(0,0,0,.25); padding: 2rem; }
.auth-card .logo { width: 56px; height: 56px; object-fit: contain; }

/* ---------- Misc ---------- */
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 1rem 1.4rem; font-size: .82rem; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--ims-primary); }
.timeline li::after { content: ""; position: absolute; left: 7.5px; top: 16px; bottom: 0; width: 1px; background: var(--ims-border); }
.timeline li:last-child::after { display: none; }
.nav-tabs .nav-link { font-size: .85rem; color: var(--ims-muted); }
.nav-tabs .nav-link.active { color: var(--ims-text); font-weight: 600; }
.img-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; border: 1px solid var(--ims-border); }
.perm-matrix th, .perm-matrix td { font-size: .8rem; }
.note-editor.note-frame { border-radius: 8px; border-color: #d7dce3; }
.ts-wrapper.form-select { padding: 0 !important; }
.ts-control { border-radius: 8px !important; border-color: #d7dce3 !important; min-height: 35px; }
.chart-box { position: relative; height: 260px; }
.kbd { font-size: .7rem; padding: .1rem .35rem; border: 1px solid var(--ims-border); border-radius: 4px; background: #f8fafc; }
@media print {
  .ims-sidebar, .ims-topbar, .ims-footer, .page-head .actions, .toolbar, .table-footer, .no-print { display: none !important; }
  .ims-main { margin: 0 !important; }
  .card { box-shadow: none; border: 0; }
}
.ims-topbar .user-chip { text-decoration: none; }
.ims-topbar .user-chip:hover .fw-semibold { color: var(--ims-primary); }
