/* NEST Central — Design System + Sidebar Layout */

/* ── Design tokens ── */
:root {
  --teal:         #1B9AA0;
  --teal-light:   #22b5bc;
  --teal-dark:    #0D524F;
  --gold:         #C9A84C;
  --gold-light:   #d4b85a;
  --cream:        #F4EFE6;
  --cream-dark:   #ede6d8;
  --charcoal:     #2C2C2C;
  --white:        #ffffff;
  --surface:      #f8f7f4;
  --danger:       #ef4444;
  --danger-light: #fee2e2;
  --success:      #059669;
  --success-light:#d1fae5;
  --warning:      #f59e0b;
  --warning-light:#fef3c7;
  --border:       #e5e3df;
  --text:         #1a1a1a;
  --text-muted:   #6b6b6b;
  --radius:       6px;
  --shadow:       0 2px 8px rgba(0,0,0,0.10);
  --font-serif:   'Playfair Display', Georgia, serif;
  --font-sans:    'Inter', system-ui, sans-serif;
}

/* ── Base reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--surface);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--font-serif); font-weight: 700; line-height: 1.2; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: 0.9rem; font-weight: 600;
  cursor: pointer; border: none;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-teal    { background: var(--teal); color: #fff; }
.btn-teal:hover:not(:disabled) { background: var(--teal-light); }
.btn-gold    { background: var(--gold); color: #fff; }
.btn-gold:hover:not(:disabled) { background: var(--gold-light); }
.btn-outline { background: transparent; border: 2px solid var(--teal); color: var(--teal); }
.btn-outline:hover:not(:disabled) { background: var(--teal); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-sm   { padding: 6px 16px; font-size: 0.82rem; }
.btn-full { width: 100%; }

/* ── Card ── */
.card    { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; }
.card-sm { padding: 20px; }

/* ── Form ── */
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block; font-size: 0.82rem; font-weight: 600;
  color: var(--charcoal); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.form-control {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: 0.95rem; font-family: var(--font-sans);
  background: #fff; color: var(--charcoal);
  transition: border-color 0.2s; appearance: none;
}
.form-control:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(27,154,160,0.12); }
.form-control.is-error { border-color: var(--danger); }
.form-control:disabled { background: var(--cream); cursor: not-allowed; }
.form-control-sm { padding: 6px 10px; font-size: 0.85rem; }
select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%231B9AA0' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px;
}

/* ── Alerts ── */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 0.88rem; margin-bottom: 16px;
  display: flex; align-items: flex-start; gap: 8px;
}
.alert-error   { background: var(--danger-light);  color: var(--danger);  border-left: 3px solid var(--danger); }
.alert-success { background: var(--success-light); color: var(--success); border-left: 3px solid var(--success); }
.alert-warning { background: var(--warning-light); color: var(--warning); border-left: 3px solid var(--warning); }
.alert:empty { display: none; }

/* ── Badge ── */
.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.badge-pass { background: var(--success-light); color: var(--success); }
.badge-fail { background: var(--danger-light);  color: var(--danger); }
.badge-gold { background: #fef3c7; color: var(--warning); }
.badge-warn { background: var(--warning-light); color: var(--warning); }

/* ── Table wrapper — horizontal scroll on small screens ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Data table ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; min-width: 600px; }
.data-table thead th {
  background: var(--teal); color: #fff;
  padding: 10px 14px; text-align: left;
  font-size: 0.78rem; text-transform: uppercase;
  letter-spacing: 0.05em; white-space: nowrap;
}
.data-table tbody tr { border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover { background: var(--cream); }
.data-table td { padding: 10px 14px; vertical-align: middle; }

/* ── Generic table fallback (pages using bare <table>) ── */
table.styled { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.styled thead th { background: var(--teal); color: #fff; padding: 10px 12px; text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
table.styled tbody tr { border-bottom: 1px solid var(--border); }
table.styled tbody tr:hover { background: var(--cream); }
table.styled td { padding: 9px 12px; vertical-align: middle; }

/* ── Stat cards ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-card .stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .stat-value { font-family: var(--font-serif); font-size: 1.8rem; color: var(--teal); font-weight: 700; }
.stat-card .stat-sub   { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

/* ── Progress ── */
.progress-wrap { margin-bottom: 8px; }
.progress-label { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 6px; }
.progress-bar-track { background: var(--cream-dark); border-radius: 20px; height: 8px; overflow: hidden; }
.progress-bar-fill  { background: var(--gold); height: 100%; border-radius: 20px; transition: width 0.4s ease; }

/* ── Section label ── */
.section-label {
  font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--gold); font-weight: 700; margin-bottom: 4px;
}
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }

/* ── Spinner ── */
.spinner { width: 32px; height: 32px; border: 3px solid var(--cream-dark); border-top-color: var(--teal); border-radius: 50%; animation: spin 0.7s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-wrap { text-align: center; padding: 40px; color: var(--text-muted); }

/* ── Login page ── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--teal-dark) 0%, #0a3d3b 100%);
  padding: 20px;
}
.login-card { width: 100%; max-width: 400px; }
.login-logo { text-align: center; margin-bottom: 28px; color: #fff; }
.login-logo .logo-dot-lg {
  width: 64px; height: 64px;
  background: url('/assets/logo-n.svg') center/contain no-repeat;
  font-size: 0; margin: 0 auto 12px;
  filter: brightness(0) invert(1);
}
.login-logo h1 { font-size: 1.6rem; }
.login-logo p  { font-size: 0.85rem; opacity: 0.8; margin-top: 4px; }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab-btn { background: none; border: none; padding: 10px 16px; font-size: .88rem; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; border-radius: var(--radius) var(--radius) 0 0; transition: color .15s, border-color .15s; }
.tab-btn:hover { color: var(--teal); }
.tab-btn.active { color: var(--teal); border-bottom-color: var(--teal); background: var(--cream); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Charts / reports ── */
.chart-wrap { position: relative; height: 300px; }
.risk-item { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.risk-name { font-weight: 600; font-size: .92rem; }
.risk-detail { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }
.risk-score { font-weight: 700; color: var(--danger); font-size: .95rem; }
td.at-risk { color: var(--danger); font-weight: 700; }
td.top-score { color: var(--success); font-weight: 700; }

/* ── Responsive grid utilities ── */
.grid-2 { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.grid-3 { display:grid; grid-template-columns:1fr 1fr 1fr; gap:12px; }
.grid-4 { display:grid; grid-template-columns:repeat(4,1fr); gap:14px; }
/* Filter bars: label+select+select+button rows */
.filter-bar { display:grid; gap:12px; align-items:flex-end; }

@media (max-width: 640px) {
  .grid-2 { grid-template-columns:1fr; }
  .grid-3 { grid-template-columns:1fr; }
  .grid-4 { grid-template-columns:1fr 1fr; }
  .filter-bar { grid-template-columns:1fr !important; }
  .filter-bar > * { width:100%; }
  /* Stat grids inside inline styles */
  .stat-grid { grid-template-columns:1fr 1fr !important; }
}

/* ── Responsive base ── */
@media (max-width: 640px) {
  h1 { font-size: 1.5rem; }
  .card { padding: 20px 16px; }
}

/* ── Sidebar Layout + Breadcrumb + Topbar ── */

/* ── Shell ── */
.erp-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
  height: 56px;
  background: #ffffff;
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  box-shadow: 0 1px 0 var(--border), 0 2px 12px rgba(0,0,0,0.06);
  gap: 12px;
  border-bottom: 2px solid var(--teal);
}
.topbar-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}
.topbar-brand .logo-dot {
  width: 32px; height: 32px;
  background: url('/assets/logo-n.svg') center/contain no-repeat;
  border-radius: 0;
  font-size: 0;
  display: block;
  flex-shrink: 0;
}
.topbar-brand .brand-name {
  font-family: var(--font-sans);
  color: #1B9AA0;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.topbar-divider {
  width: 1px; height: 24px;
  background: var(--border);
  flex-shrink: 0;
}
.topbar-breadcrumb {
  flex: 1;
  display: flex; align-items: center; gap: 6px;
  font-size: 0.8rem;
  overflow: hidden;
}
.topbar-breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s;
}
.topbar-breadcrumb a:hover { color: var(--teal); }
.topbar-breadcrumb .bc-sep {
  color: var(--border);
  font-size: 0.7rem;
}
.topbar-breadcrumb .bc-current {
  color: var(--teal);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-user {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.topbar-user .user-name {
  color: var(--charcoal);
  font-size: 0.8rem;
  font-weight: 600;
  display: none;
}
@media (min-width: 900px) {
  .topbar-user .user-name { display: block; }
}
.topbar-user .user-role {
  font-size: 0.68rem;
  background: var(--cream);
  color: var(--teal);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.btn-topbar-action {
  background: var(--teal);
  border: 1px solid var(--teal);
  color: var(--white);
  padding: 5px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn-topbar-action:hover {
  background: var(--teal-light);
  border-color: var(--teal-light);
}
/* Sidebar close button — mobile only */
@media (max-width: 768px) {
  #sb-close-btn { display: block !important; }
}

/* Sidebar collapse tab — desktop only */
@media (min-width: 769px) {
  .sidebar { transition: width 0.25s ease; overflow: hidden; }
  .main-content { transition: margin-left 0.25s ease; }
  body.sb-collapsed .sidebar { width: 0; border-right: none; }
  body.sb-collapsed .main-content { margin-left: 0; }

  /* Tab fixed to sidebar right edge, always visible */
  #sb-collapse-tab {
    display: flex !important;
    position: fixed;
    top: 50%;
    left: 240px;
    transform: translateY(-50%);
    width: 20px; height: 44px;
    background: var(--white);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    font-size: .75rem;
    color: var(--text-muted);
    z-index: 160;
    align-items: center;
    justify-content: center;
    transition: left 0.25s ease, background 0.15s;
    padding: 0;
  }
  #sb-collapse-tab:hover { background: var(--cream); color: var(--teal); }
  body.sb-collapsed #sb-collapse-tab {
    left: 0;
    border-left: 1px solid var(--border);
    border-radius: 6px;
  }
}

/* Sidebar mobile action buttons */
.sf-actions { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.sf-actions .btn-sf { display: block; width: 100%; padding: 8px; border-radius: var(--radius); font-size: .82rem; font-weight: 600; cursor: pointer; text-align: center; border: none; }
.sf-actions .btn-sf-outline { background: none; border: 1px solid var(--border); color: var(--charcoal); }
.sf-actions .btn-sf-teal   { background: var(--teal); color: #fff; }
.sf-actions .btn-sf-learn  { color: #8e44ad; font-size: .78rem; text-decoration: none; padding: 4px; }

/* Hamburger (mobile only) */
.hamburger {
  display: flex;
  flex-direction: column; justify-content: center; align-items: center;
  gap: 5px;
  width: 36px; height: 36px;
  background: none; border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius);
  flex-shrink: 0;
  transition: background 0.15s;
}
.hamburger:hover { background: var(--cream); }
.hamburger span {
  display: block;
  width: 20px; height: 2px;
  background: var(--teal);
  border-radius: 2px;
  transition: transform 0.25s, opacity 0.25s;
}
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
@media (min-width: 769px) { .hamburger { display: none; } }

/* ── Body area (below topbar) ── */
.erp-body {
  display: flex;
  padding-top: 52px;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: 240px;
  background: var(--white);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 52px; left: 0; bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 150;
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,0.12);
  }
  .sidebar.open { transform: translateX(0); }
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 140;
}
.sidebar-overlay.active { display: block; }

/* Sidebar nav */
.sidebar-nav { flex: 1; padding: 12px 0 20px; }
.sidebar-group { margin-bottom: 4px; }

.sidebar-group-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px 6px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  border-radius: 0;
  transition: color 0.15s;
}
.sidebar-group-header:hover { color: var(--teal); }
.sidebar-group-header .group-arrow {
  font-size: 0.6rem;
  transition: transform 0.2s;
}
.sidebar-group.collapsed .group-arrow { transform: rotate(-90deg); }
.sidebar-group.collapsed .sidebar-group-items { display: none; }

.sidebar-group-items { padding-bottom: 4px; }

.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px 8px 20px;
  font-size: 0.875rem;
  color: var(--charcoal);
  text-decoration: none;
  border-radius: 0 6px 6px 0;
  margin-right: 10px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.sidebar-link .link-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.sidebar-link:hover {
  background: var(--cream);
  color: var(--teal);
  text-decoration: none;
}
.sidebar-link.active {
  background: rgba(13,82,79,0.08);
  color: var(--teal);
  font-weight: 600;
  border-left: 3px solid var(--teal);
  padding-left: 17px;
}
.sidebar-link .link-badge {
  margin-left: auto;
  font-size: 0.68rem;
  background: var(--gold);
  color: var(--white);
  padding: 1px 7px;
  border-radius: 20px;
  font-weight: 700;
}

/* Sidebar bottom — user block */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
}
.sidebar-footer .sf-name { font-weight: 600; color: var(--charcoal); }
.sidebar-footer .sf-email { color: var(--text-muted); font-size: 0.75rem; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Main content ── */
.main-content {
  flex: 1;
  margin-left: 240px;
  min-width: 0;
  padding: 32px 28px 60px;
}
@media (max-width: 768px) {
  .main-content {
    margin-left: 0;
    padding: 20px 16px 48px;
  }
}

/* ── Page header ── */
.page-header {
  margin-bottom: 28px;
}
.page-header .page-title {
  font-family: var(--font-serif);
  font-size: 1.65rem;
  color: var(--charcoal);
  line-height: 1.2;
}
.page-header .page-subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 4px;
}

/* ── Breadcrumb (standalone, below topbar on pages that want it) ── */
.breadcrumb-bar {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.8rem;
  margin-bottom: 20px;
  color: var(--text-muted);
}
.breadcrumb-bar a { color: var(--teal); }
.breadcrumb-bar .bc-sep { color: var(--border); }
.breadcrumb-bar .bc-current { color: var(--charcoal); font-weight: 600; }

/* ── Role-based visibility ── */
[data-roles] { display: none; }

/* ── Import column mapper ── */
.col-mapper { border-collapse: collapse; width: 100%; font-size: 0.875rem; }
.col-mapper th { background: var(--cream-dark); padding: 8px 12px; text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.col-mapper td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.col-mapper select { padding: 4px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 0.82rem; }

/* ── Preview table ── */
.preview-table-wrap { overflow-x: auto; margin-top: 16px; max-height: 240px; overflow-y: auto; }
.preview-table { font-size: 0.8rem; }
.preview-table th { background: var(--teal); color: var(--white); padding: 7px 10px; }
.preview-table td { padding: 6px 10px; }

/* ── Student list table actions ── */
.action-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search-input { padding: 8px 12px; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: 0.875rem; width: 220px; }
.search-input:focus { outline: none; border-color: var(--teal); }

/* ── Coming soon placeholder ── */
.coming-soon {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.coming-soon .cs-icon { font-size: 3rem; margin-bottom: 12px; }
.coming-soon h2 { color: var(--charcoal); margin-bottom: 8px; }
