/* Edu CRM theme - dark "Dataflow" style, shared by the staff portal and the admin portal. */
:root {
  /* Accent: the user's theme setting overrides these two on <html style="...">. */
  --crm-accent: #f97316;
  --crm-accent-rgb: 249, 115, 22;
  --crm-accent-dark: color-mix(in srgb, var(--crm-accent) 82%, black);
  --crm-accent-light: color-mix(in srgb, var(--crm-accent) 70%, white);
  --crm-accent-soft: color-mix(in srgb, var(--crm-accent) 12%, transparent);
  --crm-bg: #1c1c1e;
  --crm-sidebar: #0b0b0c;
  --crm-surface: #0f0f10;
  --crm-surface-2: #1a1a1c;
  --crm-border: #26262a;
  --crm-text: #f4f4f5;
  --crm-muted: #9ca3af;
  --crm-green: #22c55e;
  --crm-red: #ef4444;
  --crm-violet: #8b5cf6;
  --crm-blue: #3b82f6;
  --crm-radius: 14px;
  --crm-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  --crm-font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;

  /* aliases used by crm-admin.css */
  --crm-primary: var(--crm-accent);
  --crm-primary-dark: var(--crm-accent-dark);
  --crm-primary-soft: var(--crm-accent-soft);
}

/* ---------- Staff portal ---------- */
body.crm {
  font-family: var(--crm-font);
  background: var(--crm-bg);
  color: var(--crm-text);
  font-size: .925rem;
  --bs-body-bg: var(--crm-bg);
  --bs-body-color: var(--crm-text);
  --bs-secondary-color: var(--crm-muted);
  --bs-border-color: var(--crm-border);
  --bs-tertiary-bg: var(--crm-surface-2);
  --bs-link-color-rgb: var(--crm-accent-rgb);
  --bs-primary: var(--crm-accent);
  --bs-primary-rgb: var(--crm-accent-rgb);
}
.crm a:not(.btn) { color: var(--crm-accent); text-decoration: none; }
.crm a:not(.btn):hover { color: var(--crm-accent-light); }
.crm .text-muted { color: var(--crm-muted) !important; }

.crm-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.crm-sidebar {
  width: 260px; flex-shrink: 0; background: var(--crm-sidebar);
  border-right: 1px solid #18181b; padding: 1.1rem 0;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
}
.crm-brand { display: flex; align-items: center; gap: .6rem; padding: 0 1.4rem 1.4rem; }
.crm-brand .logo {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--crm-accent-light), var(--crm-accent-dark)); font-size: 1.15rem; color: #fff;
}
.crm-brand .name { font-weight: 800; font-size: 1.35rem; letter-spacing: -.02em; color: #fff; line-height: 1; }
.crm-brand .sub { font-size: .7rem; color: var(--crm-muted); }

.crm-inst {
  background: var(--crm-surface-2); border: 1px solid var(--crm-border);
  border-radius: 12px; padding: .65rem .8rem; margin: 0 1rem 1.2rem; font-size: .8rem;
}
.crm-inst .label { color: var(--crm-muted); font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; }
.crm-inst .val { font-weight: 600; color: #fff; }
.crm-inst .tag { display: inline-block; margin-top: .3rem; background: var(--crm-accent-soft); color: var(--crm-accent); border-radius: 6px; padding: .1rem .5rem; font-size: .7rem; font-weight: 600; }

.crm-nav-title { font-size: .66rem; text-transform: uppercase; letter-spacing: .1em; color: #52525b; padding: .9rem 1.5rem .35rem; }
.crm-sidebar a.nav-item, .crm-sidebar button.nav-item {
  display: flex; align-items: center; gap: .8rem; width: 100%;
  color: #d4d4d8; padding: .7rem 1.5rem; margin: 0; font-weight: 500;
  background: none; border: 0; border-left: 3px solid transparent; text-align: left; font-size: .92rem;
}
.crm-sidebar .nav-item i { font-size: 1.1rem; width: 1.2rem; text-align: center; }
.crm-sidebar .nav-item .chev { margin-left: auto; font-size: .8rem; opacity: .6; }
.crm-sidebar a.nav-item:hover, .crm-sidebar button.nav-item:hover { color: #fff; background: #141416; }
.crm-sidebar a.nav-item.active {
  color: var(--crm-accent); background: linear-gradient(90deg, color-mix(in srgb, var(--crm-accent) 14%, transparent), transparent);
  border-left-color: var(--crm-accent); font-weight: 600;
}
.crm-sidebar .spacer { flex: 1; }

/* Main + topbar */
.crm-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.crm-topbar {
  background: var(--crm-sidebar); border-bottom: 1px solid #18181b;
  padding: .65rem 1.5rem; display: flex; align-items: center; gap: .9rem;
  position: sticky; top: 0; z-index: 10;
}
.crm-search { position: relative; width: 320px; max-width: 40vw; }
.crm-search i { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--crm-muted); }
.crm-search input {
  width: 100%; background: var(--crm-surface-2); border: 1px solid var(--crm-border); color: var(--crm-text);
  border-radius: 10px; padding: .5rem .8rem .5rem 2.3rem; font-size: .88rem;
}
.crm-search input:focus { outline: 0; border-color: var(--crm-accent); }
.crm-icon-btn {
  position: relative; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--crm-surface-2); border: 1px solid var(--crm-border); color: #e4e4e7; font-size: 1rem;
}
a.crm-icon-btn { color: #e4e4e7 !important; }
.crm-icon-btn:hover { border-color: var(--crm-accent); color: var(--crm-accent); }
.crm-icon-btn .dot {
  position: absolute; top: -3px; right: -3px; min-width: 17px; height: 17px; border-radius: 9px; padding: 0 4px;
  background: var(--crm-accent); color: #fff; font-size: .62rem; font-weight: 700; display: grid; place-items: center;
}
.crm-topbar .switcher select { min-width: 250px; }
.crm-avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--crm-accent-light), var(--crm-accent-dark)); color: #fff; font-weight: 700; text-transform: uppercase;
}
.crm-content { padding: 1.6rem; }

.crm h3 { font-weight: 700; letter-spacing: -.01em; color: #fff; }
.crm h6 { font-weight: 600; margin-bottom: .9rem; color: #fff; font-size: 1.02rem; }

/* Cards, tables, forms (Bootstrap overrides) */
.crm .card {
  background: var(--crm-surface); color: var(--crm-text);
  border: 1px solid var(--crm-border); border-radius: var(--crm-radius); box-shadow: var(--crm-shadow) !important;
}
.crm .card-header { background: var(--crm-surface); color: var(--crm-text); border-bottom: 1px solid var(--crm-border); border-radius: var(--crm-radius) var(--crm-radius) 0 0 !important; }
.crm .table {
  --bs-table-bg: transparent; --bs-table-color: var(--crm-text); --bs-table-border-color: var(--crm-border);
  --bs-table-hover-bg: #17171a; --bs-table-hover-color: #fff; --bs-table-striped-bg: #141416;
  margin-bottom: 0; color: var(--crm-text);
}
.crm .table > :not(caption) > * > * { padding: .75rem .9rem; border-color: var(--crm-border); background-color: transparent; color: inherit; }
.crm .table thead th, .crm .table-light th {
  background: var(--crm-surface-2) !important; color: var(--crm-muted) !important; font-weight: 600;
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
}
.crm .card > .table { border-radius: var(--crm-radius); overflow: hidden; }
/* Wide tables scroll sideways inside their card (overflow-y stays visible for dropdowns). */
.crm .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--crm-radius); }
.crm .table-responsive { scrollbar-width: thin; scrollbar-color: var(--crm-muted) var(--crm-surface-2); }
.crm .table-responsive::-webkit-scrollbar { height: 10px; background: var(--crm-surface-2); }
.crm .table-responsive::-webkit-scrollbar-thumb { background: var(--crm-border); border-radius: 10px; }
.crm .table-responsive::-webkit-scrollbar-thumb:hover { background: var(--crm-muted); }
/* Roles & permissions: keep the module column in view while scrolling */
.perm-table th:first-child, .perm-table td:first-child {
  position: sticky; left: 0; z-index: 2; background: var(--crm-surface) !important; min-width: 210px;
  box-shadow: 1px 0 0 var(--crm-border);
}
.perm-table thead th:first-child { background: var(--crm-surface-2) !important; }
.perm-table td, .perm-table th { white-space: nowrap; }
.crm .list-group { --bs-list-group-bg: transparent; --bs-list-group-color: var(--crm-text); --bs-list-group-border-color: var(--crm-border); }
.crm .form-control, .crm .form-select, .crm .input-group-text {
  background-color: var(--crm-surface-2); color: var(--crm-text); border-color: #303035; border-radius: 10px;
}
.crm .input-group > .input-group-text { border-radius: 10px 0 0 10px; }
.crm .input-group > .form-control { border-radius: 0 10px 10px 0; }
.crm .form-control::placeholder { color: #6b6b73; }
.crm .form-control:focus, .crm .form-select:focus {
  background-color: var(--crm-surface-2); color: #fff;
  border-color: var(--crm-accent); box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--crm-accent) 18%, transparent);
}
.crm .form-select { --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e"); }
.crm .form-check-input { background-color: var(--crm-surface-2); border-color: #45454b; }
.crm .form-check-input:checked { background-color: var(--crm-accent); border-color: var(--crm-accent); }
.crm .btn { border-radius: 10px; font-weight: 600; }
.crm .btn-primary { background: var(--crm-accent); border-color: var(--crm-accent); color: #fff; }
.crm .btn-primary:hover, .crm .btn-primary:focus { background: var(--crm-accent-dark); border-color: var(--crm-accent-dark); color: #fff; }
.crm .btn-outline-primary { color: var(--crm-accent); border-color: var(--crm-accent); }
.crm .btn-outline-primary:hover { background: var(--crm-accent); color: #fff; }
.crm .btn-outline-secondary { color: #d4d4d8; border-color: #3f3f46; }
.crm .btn-outline-secondary:hover { background: #27272a; color: #fff; border-color: #52525b; }
.crm .btn-light { background: var(--crm-surface-2); border-color: var(--crm-border); color: #fff; }
.crm .btn-link { color: var(--crm-accent); }
.crm .badge { font-weight: 600; border-radius: 6px; padding: .38em .62em; }
.crm .bg-secondary { background-color: #3f3f46 !important; }
.crm .alert { border-radius: 12px; border: 1px solid var(--crm-border); background: var(--crm-surface); color: var(--crm-text); }
.crm .alert-success { border-left: 4px solid var(--crm-green); }
.crm .alert-danger { border-left: 4px solid var(--crm-red); }
.crm .alert-warning { border-left: 4px solid #eab308; }
.crm .alert-info { border-left: 4px solid var(--crm-blue); }
.crm .progress { background: #27272a; }
.crm .page-link { background: var(--crm-surface); border-color: var(--crm-border); color: var(--crm-accent); }
.crm .page-item.disabled .page-link { background: var(--crm-surface); color: var(--crm-muted); }
.crm .border, .crm .rounded.border { border-color: var(--crm-border) !important; }
.crm hr { border-color: var(--crm-border); }

/* Dashboard */
.stat { padding: 1.15rem 1.2rem .6rem !important; overflow: hidden; }
.stat .ico {
  width: 46px; height: 46px; display: grid; place-items: center; font-size: 1.25rem; color: #fff;
  clip-path: polygon(50% 0, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%); flex-shrink: 0;
}
.stat .label { color: #d4d4d8; font-size: .85rem; }
.stat .trend { font-size: .8rem; font-weight: 700; margin-left: .4rem; white-space: nowrap; }
.stat .num { font-size: 1.45rem; font-weight: 700; line-height: 1.25; color: #fff; }
.stat .spark { height: 64px; margin: .6rem -.4rem 0; }
.ico-green { background: #22c55e; }
.ico-orange { background: var(--crm-accent); }
.ico-violet { background: #8b5cf6; }
.ico-blue { background: #3b82f6; }
.up { color: var(--crm-green); }
.down { color: var(--crm-red); }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: .35rem; }
.big-num { font-size: 1.4rem; font-weight: 700; color: #fff; }
.chart-box { position: relative; height: 300px; }
.donut-box { position: relative; height: 240px; }
.donut-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; pointer-events: none; }
.pipe-box { background: var(--crm-surface-2); border: 1px solid var(--crm-border); border-radius: 12px; padding: .7rem 1rem; text-align: center; min-width: 95px; flex: 1; }
.pipe-box .n { font-weight: 700; font-size: 1.3rem; color: #fff; }
.top-item { display: flex; align-items: center; gap: .8rem; padding: .7rem 0; border-bottom: 1px solid var(--crm-border); }
.top-item:last-child { border-bottom: 0; }
.top-item .thumb {
  width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; color: #fff; flex-shrink: 0;
}

/* Kanban */
.kanban { overflow-x: auto; }
.kanban .col-k { min-width: 240px; background: var(--crm-surface); border: 1px solid var(--crm-border); border-radius: 14px; padding: .8rem; }
.lead-card { font-size: .88rem; border-radius: 10px !important; background: var(--crm-surface-2) !important; box-shadow: none !important; }

/* Login */
.crm-login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.crm-login .hero {
  background: radial-gradient(circle at 20% 20%, color-mix(in srgb, var(--crm-accent) 35%, transparent), transparent 45%),
              radial-gradient(circle at 80% 80%, rgba(139, 92, 246, .3), transparent 45%), #0b0b0c;
  color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: center;
}
.crm-login .hero h1 { font-weight: 800; font-size: 2.4rem; letter-spacing: -.02em; }
.crm-login .hero .pill { background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .1); border-radius: 999px; padding: .38rem .95rem; font-size: .85rem; display: inline-flex; gap: .4rem; align-items: center; }
.crm-login .panel { display: flex; align-items: center; justify-content: center; padding: 2rem; background: var(--crm-surface); }
.crm-login .panel form { width: 100%; max-width: 360px; }

/* Mobile */
.crm-menu-btn { display: none !important; }
@media (max-width: 991px) {
  .crm-sidebar { position: fixed; left: -270px; z-index: 1040; transition: left .2s; }
  .crm-sidebar.open { left: 0; }
  .crm-menu-btn { display: grid !important; }
  .crm-search { display: none; }
  .crm-topbar .switcher select { min-width: 0; }
  .crm-login { grid-template-columns: 1fr; }
  .crm-login .hero { display: none; }
}

/* Sidebar collapse toggle (static/js/crm-sidebar.js) - same button in both portals */
.crm-collapse-btn {
  width: 34px; height: 34px; border-radius: 9px; display: inline-grid; place-items: center; flex-shrink: 0;
  background: var(--crm-surface-2); border: 1px solid var(--crm-border); color: #e4e4e7; font-size: .9rem; cursor: pointer;
}
.crm-collapse-btn:hover { border-color: var(--crm-accent); color: var(--crm-accent); }
.crm-collapse-btn i { transition: transform .2s; }
.crm-collapsed .crm-collapse-btn i { transform: rotate(180deg); }

/* Staff portal: icon-only rail when collapsed */
.crm-sidebar { transition: width .2s; }
.crm-collapsed .crm-sidebar { width: 76px; }
.crm-collapsed .crm-brand { padding: 0 0 1.4rem; justify-content: center; }
.crm-collapsed .crm-brand > div:last-child,
.crm-collapsed .crm-inst,
.crm-collapsed .crm-nav-title,
.crm-collapsed .crm-sidebar .txt,
.crm-collapsed .crm-sidebar .chev { display: none; }
.crm-collapsed .crm-sidebar a.nav-item, .crm-collapsed .crm-sidebar button.nav-item { justify-content: center; padding: .8rem 0; }
.crm-collapsed .crm-sidebar .nav-item i { font-size: 1.2rem; }
@media (max-width: 991px) { .crm-collapse-btn { display: none; } }

/* Phones: tables marked .table-stack become one card per row. Each <td data-label="..."> shows its label;
   td.stack-main is the row's title (no label), td.stack-actions holds the buttons. */
@media (max-width: 767.98px) {
  .crm-content { padding: 1rem; }
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: .75rem 1rem; border-bottom: 1px solid var(--crm-border); }
  .table-stack tr:last-child { border-bottom: 0; }
  .table-stack td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; border: 0 !important; padding: .22rem 0 !important; text-align: right !important; }
  .table-stack td::before { content: attr(data-label); color: var(--crm-muted); font-size: .78rem; font-weight: 600; text-align: left; flex: none; }
  .table-stack td.stack-main { display: block; text-align: left !important; padding-bottom: .4rem !important; }
  .table-stack td.stack-main::before, .table-stack td.stack-actions::before, .table-stack td[colspan]::before { display: none; }
  .table-stack td.stack-actions { justify-content: flex-start; flex-wrap: wrap; padding-top: .5rem !important; }
  .table-stack td[colspan] { display: block; text-align: center !important; }
  .table-stack td:empty, .table-stack td.stack-hide-empty:empty { display: none; }
  .table-responsive:has(> .table-stack) { overflow: visible; }
  /* Card headers with a title and a filter form stack on small screens */
  .card-header.d-flex form { width: 100%; }
  .card-header.d-flex form .form-control, .card-header.d-flex form .form-select { flex: 1 1 auto; width: auto !important; min-width: 0; }
  .crm-topbar .switcher { min-width: 0; flex: 1 1 auto; }
  .crm-topbar .switcher .form-select { max-width: 100%; }
}

/* Super admin website editor on phones: settings tabs scroll sideways, list rows keep their text */
@media (max-width: 991.98px) {
  .cms-tabs .list-group { flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .cms-tabs .list-group-item { white-space: nowrap; border: 0 !important; padding: .7rem 1rem !important; }
}
@media (max-width: 575.98px) {
  .cms-row-actions .btn { padding: .2rem .4rem; }
  .cms-row-actions { display: flex; gap: .25rem; }
  .cms-row-actions form { display: flex; gap: .25rem; }
}

/* Attendance on phones: short headers (P / A / L / Lv), tight cells so all four choices fit */
@media (max-width: 575.98px) {
  .att-table th, .att-table td { padding: .55rem .35rem; }
  .att-table td:nth-child(2) { font-size: .9rem; }
  .att-table .form-check-input { width: 1.25rem; height: 1.25rem; }
}
