/* ═══════════════════════════════════════════════════════════════════════════
   Task Board Pro — Master Stylesheet v3.4
   Single source of truth for all layout, components, and responsive rules.
═══════════════════════════════════════════════════════════════════════════ */

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

/* ── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  --ff:  'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --fm:  'DM Mono', ui-monospace, 'Courier New', monospace;

  /* colours */
  --bg:          #F4F3EF;
  --surface:     #FFFFFF;
  --surface2:    #ECEAE3;
  --surface3:    #E3E1D8;
  --border:      rgba(0,0,0,.08);
  --border-med:  rgba(0,0,0,.14);
  --border-str:  rgba(0,0,0,.22);
  --text:        #181816;
  --text-2:      #5C5B56;
  --text-3:      #9B9A96;
  --blue:        #185FA5;
  --blue-light:  #E6F1FB;
  --blue-mid:    #378ADD;
  --green:       #3B6D11;
  --green-light: #EAF3DE;
  --red:         #A32D2D;
  --red-light:   #FCEBEB;
  --amber:       #854F0B;
  --amber-light: #FAEEDA;
  --teal:        #0F6E56;
  --teal-light:  #E1F5EE;
  --purple:      #534AB7;
  --purple-light:#EEEDFE;
  --coral:       #993C1D;
  --coral-light: #FAECE7;

  /* layout */
  --nav-h:      52px;   /* height of sticky top nav (nav.php) */
  --bot-h:      64px;   /* mobile bottom tab bar height */
  --sidebar-w:  220px;
  --topbar-h:   52px;   /* inner topbar inside .main */
  --r:          8px;
  --r-lg:       12px;
  --transition: .15s ease;

  /* elevation */
  --shadow:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.05);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.12), 0 4px 12px rgba(0,0,0,.07);

  /* ── Alias tokens (used by dashboard, attendance, alerts, chat, notifications) ── */

  /* colour shorthands */
  --blue-l:    #E6F1FB;   /* = --blue-light  */
  --blue-d:    #0F4A85;   /* darker blue for hover states */
  --green-l:   #EAF3DE;   /* = --green-light */
  --red-l:     #FCEBEB;   /* = --red-light   */
  --amber-l:   #FAEEDA;   /* = --amber-light */
  --purple-l:  #EEEDFE;   /* = --purple-light */
  --teal-l:    #E1F5EE;   /* = --teal-light  */

  /* text shorthands (without hyphen) */
  --text2:     #5C5B56;   /* = --text-2 */
  --text3:     #9B9A96;   /* = --text-3 */

  /* border-radius scale */
  --r-md:      10px;
  --r-xl:      18px;

  /* shadow shorthands */
  --sh-xs:     0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --sh-lg:     0 12px 40px rgba(0,0,0,.12), 0 4px 12px rgba(0,0,0,.07);
  --sh-xl:     0 20px 60px rgba(0,0,0,.16), 0 8px 20px rgba(0,0,0,.10);

  /* spacing scale */
  --sp2:  0.375rem;   /*  6px */
  --sp3:  0.625rem;   /* 10px */
  --sp4:  1rem;       /* 16px */
  --sp5:  1.375rem;   /* 22px */
  --sp6:  1.75rem;    /* 28px */

  /* typography scale */
  --ts-sm:  0.78rem;   /* ~12.5px */
  --ts-md:  0.95rem;   /* ~15px   */
  --ts-lg:  1.15rem;   /* ~18px   */
  --ts-xl:  1.4rem;    /* ~22px   */
}

/* ── Base ──────────────────────────────────────────────────────────────── */
body {
  font-family: var(--ff);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* top padding = fixed nav height from nav.php */
  padding-top: var(--nav-h);
}
/* Mobile: also pad bottom for the tab bar */
@media (max-width: 767px) {
  body {
    padding-bottom: calc(var(--bot-h) + env(safe-area-inset-bottom, 0px));
  }
}

/* ── App shell ─────────────────────────────────────────────────────────── */
.app {
  display: flex;
  min-height: calc(100vh - var(--nav-h));
}

/* ══════════════════════════════════════════════════════════════════════════
   SIDEBAR
   - Fixed position, starts below the nav bar
   - overflow-y: auto  ← THE FIX: was "hidden", causing freeze
   - Scrollable content with sticky footer
══════════════════════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border-med);
  display: flex;
  flex-direction: column;
  position: fixed;
  /* start BELOW the nav bar */
  top: var(--nav-h);
  left: 0;
  bottom: 0;
  z-index: 50;
  transition: width var(--transition), transform var(--transition);
  /* ✅ KEY FIX: allow scrolling inside sidebar */
  overflow-y: auto;
  overflow-x: hidden;
  /* smooth momentum scroll on iOS */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Collapsed state */
.sidebar.collapsed { width: 56px; }
.sidebar.collapsed .brand-name,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .sidebar-section-label,
.sidebar.collapsed .filter-group,
.sidebar.collapsed .dept-filter-list,
.sidebar.collapsed .label-list,
.sidebar.collapsed .add-label-btn,
.sidebar.collapsed .stats-mini,
.sidebar.collapsed .sidebar-footer > div { display: none; }
.sidebar.collapsed .sidebar-top  { justify-content: center; padding: 12px 0; }
.sidebar.collapsed .brand        { justify-content: center; width: 100%; }
.sidebar.collapsed .nav-item     { justify-content: center; padding: 8px; }
.sidebar.collapsed .sidebar-toggle svg { transform: rotate(180deg); }

/* ── Sidebar internals ─────────────────────────────────────────────────── */
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
  /* sticky inside the scrollable sidebar */
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand-icon {
  width: 28px; height: 28px;
  background: var(--text); color: var(--surface);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-name { font-size: 13px; font-weight: 600; letter-spacing: -.2px; white-space: nowrap; }

.sidebar-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--text-3); padding: 4px; border-radius: 4px;
  display: flex; flex-shrink: 0;
  transition: color var(--transition), background var(--transition);
}
.sidebar-toggle:hover { color: var(--text); background: var(--surface2); }

.sidebar-nav {
  padding: 8px 8px 4px;
  display: flex; flex-direction: column; gap: 2px;
  flex-shrink: 0;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px;
  border: none; background: none;
  border-radius: var(--r);
  cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--text-2);
  width: 100%; text-align: left; white-space: nowrap;
  transition: background var(--transition), color var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.nav-item:hover  { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--bg); color: var(--text); }
.nav-item svg    { flex-shrink: 0; opacity: .8; }

.sidebar-section-label {
  font-size: 10px; font-weight: 600; letter-spacing: .7px;
  text-transform: uppercase; color: var(--text-3);
  padding: 12px 12px 5px;
  flex-shrink: 0;
}

.filter-group {
  padding: 0 8px;
  display: flex; flex-direction: column; gap: 1px;
  flex-shrink: 0;
}
.filter-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 8px;
  border: none; background: none;
  border-radius: var(--r);
  cursor: pointer;
  font-size: 12.5px; font-weight: 400; color: var(--text-2);
  text-align: left; width: 100%; white-space: nowrap;
  transition: background var(--transition), color var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.filter-btn:hover  { background: var(--surface2); color: var(--text); }
.filter-btn.active { background: var(--bg); color: var(--text); font-weight: 500; }
.filter-btn .dot   { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-high    { background: var(--red); }
.dot-medium  { background: var(--amber); }
.dot-low     { background: var(--green); }
.dot-overdue { background: var(--red); box-shadow: 0 0 0 2px var(--red-light); }
.dot-today   { background: var(--blue); }

.label-list {
  padding: 0 8px;
  display: flex; flex-direction: column; gap: 1px;
  flex-shrink: 0;
}
.label-item {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 8px; border-radius: var(--r);
  font-size: 12.5px; color: var(--text-2);
  cursor: pointer;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.label-item:hover  { background: var(--surface2); }
.label-item.active { background: var(--bg); color: var(--text); font-weight: 500; }
.label-dot    { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.label-delete {
  margin-left: auto; opacity: 0;
  background: none; border: none; cursor: pointer;
  color: var(--text-3); font-size: 11px; padding: 1px 3px; border-radius: 3px;
}
.label-item:hover .label-delete { opacity: 1; }

.add-label-btn {
  margin: 6px 12px 0; background: none; border: none; cursor: pointer;
  font-size: 12px; color: var(--text-3); text-align: left; padding: 4px;
  transition: color var(--transition);
  flex-shrink: 0;
}
.add-label-btn:hover { color: var(--text); }

.sidebar-footer {
  /* stick to bottom when content is short; scroll with it when content is tall */
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border);
  margin-top: auto;
  flex-shrink: 0;
}
.stats-mini { font-size: 11px; color: var(--text-3); line-height: 1.9; font-family: var(--fm); }

/* links inside sidebar-footer */
.sidebar-footer a {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-2);
  text-decoration: none;
  padding: 6px 8px; border-radius: var(--r);
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.sidebar-footer a:hover { background: var(--surface2); }

/* ── Main content area ─────────────────────────────────────────────────── */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--nav-h));
  transition: margin-left var(--transition);
  min-width: 0; /* prevent flex overflow */
}
.sidebar.collapsed ~ .main { margin-left: 56px; }

/* ── Inner topbar (inside .main) ───────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; gap: 12px;
  position: sticky;
  top: 52px; /* sit below the outer nav */
  z-index: 40;
  flex-shrink: 0;
}
.topbar-left  { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.menu-btn {
  display: none;
  background: none; border: none; cursor: pointer;
  color: var(--text-2); padding: 6px; border-radius: var(--r);
  -webkit-tap-highlight-color: transparent;
}
.view-title { font-size: 15px; font-weight: 600; letter-spacing: -.2px; white-space: nowrap; }

.search-wrap {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r); padding: 0 10px; height: 32px;
  transition: border-color var(--transition);
}
.search-wrap:focus-within { border-color: var(--blue-mid); background: var(--surface); }
.search-icon  { color: var(--text-3); flex-shrink: 0; }
.search-input {
  background: none; border: none; outline: none;
  font-size: 13px; color: var(--text); width: 160px;
  font-family: var(--ff);
}
.search-input::placeholder { color: var(--text-3); }
.search-kbd {
  font-size: 10px; color: var(--text-3); font-family: var(--fm);
  border: 1px solid var(--border-med); border-radius: 3px; padding: 1px 4px;
}
.sort-wrap  { display: flex; align-items: center; gap: 6px; }
.sort-label { font-size: 12px; color: var(--text-3); }
.sort-select {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r); font-size: 12px; color: var(--text);
  padding: 4px 8px; cursor: pointer; font-family: var(--ff); outline: none;
}
.btn-add-task {
  padding: 7px 14px; background: var(--text); color: var(--surface);
  border: none; border-radius: var(--r);
  font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: opacity var(--transition); font-family: var(--ff);
  -webkit-tap-highlight-color: transparent;
}
.btn-add-task:hover { opacity: .82; }

/* ── Progress banner ───────────────────────────────────────────────────── */
.progress-banner {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 20px;
  flex-shrink: 0;
}
.progress-info { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.progress-label { font-size: 12px; color: var(--text-2); }
.progress-pct   { font-size: 12px; font-weight: 600; font-family: var(--fm); color: var(--green); }
.progress-track { height: 4px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.progress-fill  { height: 100%; background: var(--green); border-radius: 99px; transition: width .4s ease; width: 0%; }

/* ── View containers ───────────────────────────────────────────────────── */
.view-container { padding: 20px; flex: 1; }
.view-container.hidden { display: none; }
.loading-state { padding: 3rem; text-align: center; color: var(--text-3); font-size: 13px; }

/* ── Board ─────────────────────────────────────────────────────────────── */
.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}
.col {
  background: var(--surface2); border-radius: var(--r-lg);
  padding: 14px; min-height: 160px;
  transition: background var(--transition);
}
.col.drag-over { background: color-mix(in srgb, var(--blue-mid) 8%, var(--surface2)); }
.col-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.col-label  { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; }
.col-dot    { width: 8px; height: 8px; border-radius: 50%; }
.col-dot-todo  { background: #888780; }
.col-dot-doing { background: var(--blue); }
.col-dot-done  { background: var(--green); }
.col-count {
  font-size: 11px; background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px; padding: 2px 8px; color: var(--text-2); font-family: var(--fm);
}
.col-wip-warn { font-size: 10px; color: var(--amber); font-weight: 500; background: var(--amber-light); padding: 2px 6px; border-radius: 4px; }
.tasks { display: flex; flex-direction: column; gap: 8px; min-height: 40px; }

/* ── Task card ─────────────────────────────────────────────────────────── */
.task-card {
  background: var(--surface); border-radius: var(--r);
  border: 1px solid var(--border); padding: 12px 13px;
  cursor: grab; box-shadow: var(--shadow);
  transition: border-color var(--transition), box-shadow var(--transition),
              opacity var(--transition), transform var(--transition);
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.task-card:hover   { border-color: var(--border-med); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.task-card.dragging { opacity: .3; cursor: grabbing; transform: rotate(2deg); }
.task-card.done-card { opacity: .65; }
.task-card.done-card .task-title { text-decoration: line-through; color: var(--text-2); }

.task-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.task-left { flex: 1; min-width: 0; }
.task-checkbox {
  width: 15px; height: 15px; border-radius: 4px;
  border: 1.5px solid var(--border-str); background: none; cursor: pointer;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  transition: border-color var(--transition), background var(--transition);
  margin-top: 1px;
}
.task-checkbox.checked { border-color: var(--green); background: var(--green); }
.task-checkbox.checked::after {
  content: ''; display: block; width: 8px; height: 8px;
  background: url("data:image/svg+xml,%3Csvg width='8' height='7' viewBox='0 0 8 7' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 3.5L3.2 6L7 1' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center;
}
.task-title  { font-size: 13px; font-weight: 500; line-height: 1.4; word-break: break-word; }
.task-desc   { font-size: 12px; color: var(--text-2); margin-top: 3px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.task-actions { display: flex; gap: 2px; flex-shrink: 0; }
.btn-icon {
  background: none; border: none; cursor: pointer;
  color: var(--text-3); font-size: 12px; padding: 3px 5px;
  border-radius: 4px; display: flex; align-items: center; justify-content: center;
  transition: color var(--transition), background var(--transition);
}
.btn-icon:hover     { color: var(--text); background: var(--surface2); }
.btn-icon.del:hover { color: var(--red); }

.task-footer { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
.badge { font-size: 10px; font-weight: 600; border-radius: 4px; padding: 2px 6px; text-transform: uppercase; letter-spacing: .3px; font-family: var(--fm); }
.badge-high   { background: var(--red-light);   color: var(--red); }
.badge-medium { background: var(--amber-light);  color: var(--amber); }
.badge-low    { background: var(--green-light);  color: var(--green); }

.task-date          { font-size: 11px; color: var(--text-3); font-family: var(--fm); }
.task-date.overdue  { color: var(--red);  font-weight: 500; }
.task-date.today    { color: var(--blue); font-weight: 500; }

.task-labels { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.task-label  { font-size: 10px; border-radius: 99px; padding: 1.5px 7px; font-weight: 500; }

.task-meta-row { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.task-assignee-chip { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-2); }
.avatar { width: 18px; height: 18px; border-radius: 50%; background: var(--surface2); border: 1px solid var(--border-med); display: flex; align-items: center; justify-content: center; font-size: 8px; font-weight: 600; color: var(--text-2); flex-shrink: 0; }
.task-estimate { font-size: 10px; color: var(--text-3); font-family: var(--fm); }

.subtask-progress-bar  { height: 3px; background: var(--surface2); border-radius: 99px; overflow: hidden; margin-top: 7px; }
.subtask-progress-fill { height: 100%; background: var(--green); border-radius: 99px; transition: width .3s; }

/* ── Drop hint ─────────────────────────────────────────────────────────── */
.drop-hint {
  border: 1.5px dashed var(--border-med); border-radius: var(--r); height: 56px;
  display: none; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text-3);
}
.drag-active .drop-hint { display: flex; }

/* ── List view ─────────────────────────────────────────────────────────── */
.list-wrap { display: flex; flex-direction: column; gap: 14px; }
.list-section { background: var(--surface); border-radius: var(--r-lg); border: 1px solid var(--border); overflow: hidden; }
.list-section-header { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 12.5px; font-weight: 600; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 13px; cursor: pointer; transition: background var(--transition); }
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--surface2); }
.list-row.done-row .list-title { text-decoration: line-through; color: var(--text-2); }
.list-title     { flex: 1; font-weight: 400; min-width: 0; }
.list-col-pill  { font-size: 10px; padding: 2px 7px; border-radius: 99px; font-weight: 500; white-space: nowrap; }
.list-col-todo  { background: var(--surface3); color: var(--text-2); }
.list-col-doing { background: var(--blue-light); color: var(--blue); }
.list-col-done  { background: var(--green-light); color: var(--green); }
.list-date     { font-size: 11px; color: var(--text-3); font-family: var(--fm); min-width: 70px; text-align: right; white-space: nowrap; }
.list-date.overdue { color: var(--red); }
.list-assignee { font-size: 11px; color: var(--text-2); min-width: 80px; white-space: nowrap; }

/* ── Analytics view ────────────────────────────────────────────────────── */
.analytics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.stat-card          { background: var(--surface); border-radius: var(--r-lg); border: 1px solid var(--border); padding: 18px 20px; }
.stat-card-label    { font-size: 11px; color: var(--text-3); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.stat-card-value    { font-size: 28px; font-weight: 600; font-family: var(--fm); letter-spacing: -.5px; }
.stat-card-sub      { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.chart-card         { background: var(--surface); border-radius: var(--r-lg); border: 1px solid var(--border); padding: 18px 20px; grid-column: span 2; }
.chart-card-title   { font-size: 13px; font-weight: 600; margin-bottom: 14px; }
.bar-chart          { display: flex; align-items: flex-end; gap: 10px; height: 100px; }
.bar-group          { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.bar-stack          { display: flex; flex-direction: column; justify-content: flex-end; width: 100%; border-radius: 4px 4px 0 0; overflow: hidden; }
.bar-label          { font-size: 10px; color: var(--text-3); font-family: var(--fm); }
.heatmap-card       { background: var(--surface); border-radius: var(--r-lg); border: 1px solid var(--border); padding: 18px 20px; grid-column: span 2; }
.heatmap-title      { font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.heatmap-grid       { display: flex; gap: 3px; overflow-x: auto; }
.heatmap-col        { display: flex; flex-direction: column; gap: 3px; }
.heatmap-cell       { width: 14px; height: 14px; border-radius: 3px; background: var(--surface2); flex-shrink: 0; }
.heatmap-cell.lv1   { background: var(--green-light); }
.heatmap-cell.lv2   { background: #C0DD97; }
.heatmap-cell.lv3   { background: #97C459; }
.heatmap-cell.lv4   { background: #639922; }

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.42);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 1rem;
  opacity: 0; pointer-events: none;
  transition: opacity .18s;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface); border-radius: var(--r-lg);
  border: 1px solid var(--border-med);
  width: 100%; max-width: 480px; max-height: 88vh;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  transform: translateY(10px) scale(.98);
  transition: transform .18s;
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }
.modal-sm { max-width: 340px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; margin-bottom: 14px; }
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-3); padding: 4px; border-radius: 4px; display: flex; transition: color var(--transition), background var(--transition); }
.modal-close:hover { color: var(--text); background: var(--surface2); }

.field { padding: 0 20px 12px; }
.field label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; font-weight: 500; }
.req { color: var(--red); }
.field input[type="text"],
.field input[type="date"],
.field input[type="number"],
.field textarea,
.field select {
  width: 100%; padding: 8px 10px;
  font-size: 13px; border: 1px solid var(--border-med);
  border-radius: var(--r); background: var(--surface);
  color: var(--text); outline: none; font-family: var(--ff);
  transition: border-color var(--transition);
  -webkit-appearance: none;
}
.field textarea { resize: vertical; min-height: 72px; line-height: 1.5; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--blue-mid); }
.field-row { display: flex; gap: 0; }
.field-row .field { flex: 1; }
.modal-footer { display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); margin-top: 4px; }
.spacer { flex: 1; }
.btn-ghost {
  padding: 7px 14px; font-size: 13px; font-family: var(--ff);
  background: none; border: 1px solid var(--border-med);
  border-radius: var(--r); color: var(--text-2); cursor: pointer;
  transition: background var(--transition), color var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-primary {
  padding: 7px 18px; font-size: 13px; font-weight: 500; font-family: var(--ff);
  background: var(--text); color: var(--surface);
  border: none; border-radius: var(--r); cursor: pointer;
  transition: opacity var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:hover    { opacity: .82; }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

/* ── Label picker ──────────────────────────────────────────────────────── */
.label-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.label-chip { font-size: 11px; padding: 3px 10px; border-radius: 99px; cursor: pointer; border: 1.5px solid transparent; font-weight: 500; transition: opacity var(--transition); opacity: .55; }
.label-chip.selected { opacity: 1; border-color: rgba(0,0,0,.2); }

/* ── Color swatches ────────────────────────────────────────────────────── */
.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch { width: 24px; height: 24px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: border-color var(--transition), transform var(--transition); }
.color-swatch:hover    { transform: scale(1.15); }
.color-swatch.selected { border-color: var(--text); transform: scale(1.1); }

/* ── Subtasks ──────────────────────────────────────────────────────────── */
.subtask-list { display: flex; flex-direction: column; gap: 5px; margin-bottom: 8px; }
.subtask-item { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.subtask-cb   { accent-color: var(--green); width: 14px; height: 14px; cursor: pointer; }
.subtask-text { flex: 1; }
.subtask-text.done { text-decoration: line-through; color: var(--text-3); }
.subtask-del  { background: none; border: none; cursor: pointer; color: var(--text-3); font-size: 11px; }
.subtask-add-row { display: flex; gap: 8px; }
.subtask-add-row input { flex: 1; padding: 6px 10px; font-size: 12px; border: 1px solid var(--border-med); border-radius: var(--r); background: var(--surface); color: var(--text); outline: none; font-family: var(--ff); }
.btn-add-subtask { padding: 6px 12px; font-size: 12px; font-family: var(--ff); background: var(--surface2); border: 1px solid var(--border); border-radius: var(--r); cursor: pointer; color: var(--text-2); transition: background var(--transition); }
.btn-add-subtask:hover { background: var(--surface3); }

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast-stack { position: fixed; bottom: calc(var(--bot-h) + env(safe-area-inset-bottom,0px) + 12px); right: 1rem; display: flex; flex-direction: column; gap: 8px; z-index: 500; }
@media (min-width: 768px) { .toast-stack { bottom: 1.5rem; right: 1.5rem; } }
.toast { background: var(--text); color: var(--surface); font-size: 13px; padding: 10px 15px; border-radius: var(--r); box-shadow: var(--shadow-md); max-width: 300px; display: flex; align-items: center; gap: 8px; animation: toastIn .2s ease forwards; }
.toast.error   { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes toastIn  { from { opacity:0; transform:translateY(8px);  } to { opacity:1; transform:translateY(0);   } }
@keyframes toastOut { from { opacity:1; transform:translateY(0);   } to { opacity:0; transform:translateY(8px);  } }
.toast.out { animation: toastOut .2s ease forwards; }

/* ── Dept filter ───────────────────────────────────────────────────────── */
.dept-filter-list      { display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; flex-shrink: 0; }
.dept-filter-item      { border-radius: 6px; overflow: hidden; }
.dept-filter-row       { display: flex; align-items: center; gap: 7px; padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 12.5px; color: var(--text-2); font-weight: 500; transition: background .12s; position: relative; -webkit-tap-highlight-color: transparent; }
.dept-filter-row:hover { background: var(--surface3); }
.dept-filter-item.active > .dept-filter-row { background: var(--surface3); }
.subdept-filter-item        { display: flex; align-items: center; gap: 6px; padding: 4px 8px 4px 22px; font-size: 11.5px; color: var(--text-3); cursor: pointer; border-radius: 5px; transition: background .12s; }
.subdept-filter-item:hover  { background: var(--surface3); color: var(--text-2); }
.subdept-filter-item.active { background: var(--surface3); font-weight: 500; }
.subdept-indent             { font-size: 10px; color: var(--text-3); margin-right: 2px; flex-shrink: 0; }
.task-dept-chip {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10px; font-weight: 500;
  color: var(--dept-color, #185FA5);
  background: color-mix(in srgb, var(--dept-color, #185FA5) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--dept-color, #185FA5) 25%, transparent);
  border-radius: 4px; padding: 2px 6px; margin-top: 5px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dept-sep { opacity: .5; font-size: 9px; }
.subdept-manage-list { display: flex; flex-direction: column; gap: 4px; max-height: 140px; overflow-y: auto; }
.dept-filter-row .label-delete,
.subdept-filter-item .label-delete { margin-left: auto; opacity: 0; transition: opacity .15s; flex-shrink: 0; }
.dept-filter-row:hover .label-delete,
.subdept-filter-item:hover .label-delete { opacity: 1; }

/* ── Sidebar mobile overlay ────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 49;
  -webkit-
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
═══════════════════════════════════════════════════════════════════════════ */

/* ── Tablet ─────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sidebar-w: 200px; }
  .board { grid-template-columns: repeat(2, 1fr); }
  .chart-card, .heatmap-card { grid-column: span 1; }
}

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  :root { --sidebar-w: 260px; } /* wider drawer on mobile */

  /* Sidebar becomes off-canvas drawer */
  .sidebar {
    top: 0; /* cover full height including nav area */
    z-index: 200;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    /* override overflow so drawer itself scrolls */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar-overlay.visible { display: block; }

  /* Main takes full width */
  .main { margin-left: 0 !important; }

  /* Show hamburger */
  .menu-btn { display: flex !important; }

  /* Inner topbar sits at top (no outer nav offset on mobile since nav is global) */
  .topbar {
    top: var(--nav-h);
    padding: 0 12px;
    height: 48px;
  }

  /* Board: single column */
  .board {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
    /* extra bottom space for mobile tab bar */
    padding-bottom: calc(var(--bot-h) + env(safe-area-inset-bottom,0px) + 12px);
  }

  /* Task cards: larger tap targets */
  .task-card { padding: 12px; }

  /* Search compact */
  .search-wrap { max-width: 140px; }
  .search-input { width: 90px; font-size: 13px; }
  .search-kbd { display: none; }
  .sort-wrap  { display: none; }

  /* Progress banner */
  .progress-banner { padding: 6px 12px; }

  /* View containers */
  .view-container { padding: 0; }
  .analytics-grid { gap: 10px; padding: 12px; padding-bottom: calc(var(--bot-h) + env(safe-area-inset-bottom,0px) + 12px); }
  .list-wrap { padding-bottom: calc(var(--bot-h) + env(safe-area-inset-bottom,0px) + 12px); }

  /* Modals slide up from bottom */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    border-radius: 18px 18px 0 0 !important;
    max-height: 90vh;
    max-width: 100%;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateY(100%) !important;
    transition: transform .25s cubic-bezier(.32,1,.23,1) !important;
  }
  .modal-backdrop.open .modal { transform: translateY(0) !important; }
  .modal-sm { max-width: 100%; border-radius: 18px 18px 0 0 !important; }

  /* Field rows stack vertically */
  .field-row { flex-direction: column; }

  /* Prevent iOS font zoom on inputs */
  .field input, .field select, .field textarea { font-size: 16px !important; }

  /* Toasts above tab bar */
  .toast-stack { bottom: calc(var(--bot-h) + env(safe-area-inset-bottom,0px) + 8px); right: 12px; }

  /* Analytics chart cards */
  .chart-card, .heatmap-card { grid-column: span 1; }

  /* List view rows */
  .list-row { padding: 10px 14px; gap: 8px; }
  .list-date, .list-assignee { display: none; }
}

/* ── Small mobile ───────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .topbar { padding: 0 10px; }
  .board  { padding: 10px; gap: 8px; }
  .btn-add-task { padding: 6px 10px; font-size: 12px; }
  .view-title   { font-size: 14px; }
}

/* ── Animations ─────────────────────────────────────────────────────────── */
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

/* ═══════════════════════════════════════════════════════════════════════════
   GLOBAL SHARED COMPONENTS
   Required by: attendance, alerts, notifications, chat, dashboard, etc.
═══════════════════════════════════════════════════════════════════════════ */

/* ── Base .btn system ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .4rem; padding: .5rem 1.1rem;
  border: none; border-radius: var(--r); cursor: pointer;
  font-size: .85rem; font-weight: 600; font-family: var(--ff);
  text-decoration: none; white-space: nowrap;
  transition: opacity .15s, background .15s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.4;
}
.btn:active { transform: scale(.97); }
.btn:disabled, .btn[disabled] { opacity: .45; cursor: not-allowed; pointer-events: none; }

.btn-blue   { background: var(--blue);   color: #fff; }
.btn-blue:hover   { opacity: .88; }
.btn-green  { background: var(--green);  color: #fff; }
.btn-green:hover  { opacity: .88; }
.btn-red    { background: var(--red);    color: #fff; }
.btn-red:hover    { opacity: .88; }
.btn-amber  { background: var(--amber);  color: #fff; }
.btn-amber:hover  { opacity: .88; }
.btn-teal   { background: var(--teal);   color: #fff; }
.btn-teal:hover   { opacity: .88; }
.btn-purple { background: var(--purple); color: #fff; }
.btn-purple:hover { opacity: .88; }

/* size modifiers */
.btn-sm  { padding: .3rem .75rem; font-size: .78rem; }
.btn-lg  { padding: .7rem 1.5rem; font-size: .95rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Base form elements (global, not scoped to .field) ─────────────────── */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="tel"],
input[type="search"],
select,
textarea {
  width: 100%; padding: .5rem .75rem;
  font-size: .88rem; font-family: var(--ff);
  border: 1px solid var(--border-med); border-radius: var(--r);
  background: var(--surface); color: var(--text);
  outline: none; -webkit-appearance: none;
  transition: border-color .15s, box-shadow .15s;
  line-height: 1.5;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue-mid);
  box-shadow: 0 0 0 3px rgba(24,95,165,.10);
}
textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; }
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface2); color: var(--text-3); cursor: not-allowed;
}
@media (max-width: 767px) {
  input, select, textarea { font-size: 16px !important; } /* prevent iOS zoom */
}

/* ── .form-group ───────────────────────────────────────────────────────── */
.form-group {
  display: flex; flex-direction: column; gap: .35rem;
  margin-bottom: .65rem;
}
.form-group:last-child { margin-bottom: 0; }
.form-group label {
  font-size: .8rem; font-weight: 600; color: var(--text-2);
}
.form-group .hint {
  font-size: .75rem; color: var(--text-3); margin-top: .15rem;
}

/* ── Page wrapper (used by attendance, alerts, notifications, etc.) ─────── */
.page-wrap {
  max-width: 1100px; margin: 0 auto;
  padding: var(--sp6);
}
@media (max-width: 900px) { .page-wrap { padding: var(--sp5); } }
@media (max-width: 600px) { .page-wrap { padding: var(--sp4); } }

/* ── Shared .card (used outside .modal, in page body) ──────────────────── */
.card {
  background: var(--surface); border-radius: var(--r-lg);
  border: 1px solid var(--border); box-shadow: var(--sh-xs);
  overflow: hidden;
}
.card-pad { padding: var(--sp5); }
@media (max-width: 600px) { .card-pad { padding: var(--sp4); } }

/* ── Shared table styles ───────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tbl th {
  padding: .55rem .85rem; text-align: left;
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-3);
  border-bottom: 2px solid var(--border); white-space: nowrap;
  background: var(--surface);
}
.tbl td {
  padding: .6rem .85rem; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: var(--bg); }
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 600px) { .tbl th, .tbl td { padding: .5rem .65rem; } }

/* ── Page tabs ─────────────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: .2rem; flex-wrap: wrap;
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--sp5);
}
.tab-btn {
  background: none; border: none; cursor: pointer;
  padding: .5rem 1rem .6rem; font-size: .85rem; font-weight: 500;
  color: var(--text-2); border-bottom: 2px solid transparent;
  margin-bottom: -2px; border-radius: var(--r) var(--r) 0 0;
  transition: color .15s, border-color .15s;
  font-family: var(--ff); white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn:hover { color: var(--text); background: var(--surface2); }
.tab-btn.active {
  color: var(--blue); border-bottom-color: var(--blue); font-weight: 600;
}

/* ── Status badges ─────────────────────────────────────────────────────── */
.pill {
  display: inline-block; padding: .2rem .65rem; border-radius: 99px;
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; white-space: nowrap;
}
.pill-green  { background: var(--green-l);  color: var(--green);  }
.pill-red    { background: var(--red-l);    color: var(--red);    }
.pill-blue   { background: var(--blue-l);   color: var(--blue);   }
.pill-amber  { background: var(--amber-l);  color: var(--amber);  }
.pill-purple { background: var(--purple-l); color: var(--purple); }
.pill-teal   { background: var(--teal-l);   color: var(--teal);   }
.pill-grey   { background: var(--surface3); color: var(--text-2); }

/* ── Alert / flash messages ────────────────────────────────────────────── */
.flash-msg {
  padding: var(--sp3) var(--sp4); border-radius: var(--r-md);
  font-size: .85rem; font-weight: 500; margin-bottom: var(--sp4);
  display: flex; align-items: center; gap: .5rem;
}
.flash-msg.success { background: var(--green-l);  color: var(--green);  border: 1px solid rgba(59,109,17,.2); }
.flash-msg.error   { background: var(--red-l);    color: var(--red);    border: 1px solid rgba(163,45,45,.2); }
.flash-msg.info    { background: var(--blue-l);   color: var(--blue);   border: 1px solid rgba(24,95,165,.2); }
.flash-msg.warning { background: var(--amber-l);  color: var(--amber);  border: 1px solid rgba(133,79,11,.2); }

/* ── Toggle switch ─────────────────────────────────────────────────────── */
.toggle { position: relative; width: 40px; height: 22px; flex-shrink: 0; display: inline-flex; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.slider {
  position: absolute; inset: 0; background: var(--surface3);
  border-radius: 99px; transition: .25s; cursor: pointer;
}
.slider::before {
  content: ''; position: absolute;
  height: 16px; width: 16px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: .25s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .slider { background: var(--blue); }
.toggle input:checked + .slider::before { transform: translateX(18px); }

