/* ==========================================================================
   MERIDIAN — Research Collaboration Portal
   Design tokens: indigo-violet core, teal + coral accents, Sora/Inter/JetBrains Mono
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@400;500;600;700;800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Brand */
  --brand: #5B4FE9;
  --brand-2: #8B7FF5;
  --teal: #14B8A6;
  --coral: #E85D75;
  --amber: #F5A623;

  /* Light theme (default) */
  --bg: #F4F5FB;
  --bg-alt: #ECEDF9;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #FFFFFF;
  --border: rgba(30, 32, 60, 0.09);
  --text: #1B1D2A;
  --text-dim: #5B5E76;
  --text-faint: #9295AC;
  --shadow: 0 8px 30px rgba(30, 24, 90, 0.08);
  --shadow-lg: 0 20px 60px rgba(30, 24, 90, 0.14);

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;

  --font-display: 'Sora', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

html[data-theme="dark"] {
  --bg: #0B0C14;
  --bg-alt: #0F111C;
  --surface: rgba(24, 26, 40, 0.65);
  --surface-solid: #161826;
  --border: rgba(255, 255, 255, 0.08);
  --text: #E9E9F6;
  --text-dim: #A6A8C2;
  --text-faint: #6C6E8A;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 12% 8%, rgba(91, 79, 233, 0.14), transparent 40%),
    radial-gradient(circle at 88% 92%, rgba(20, 184, 166, 0.10), transparent 40%);
  pointer-events: none;
}

h1, h2, h3, h4, .display { font-family: var(--font-display); letter-spacing: -0.02em; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
::selection { background: var(--brand); color: #fff; }

/* Focus visibility (accessibility) */
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ==========================================================================
   Layout shell
   ========================================================================== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(20px);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 22px;
}
.sidebar-brand .mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--teal));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 15px;
  box-shadow: 0 6px 16px rgba(91,79,233,0.35);
}
.sidebar-brand .name { font-family: var(--font-display); font-weight: 700; font-size: 15.5px; }
.sidebar-brand .name span { display:block; font-family: var(--font-body); font-weight: 500; font-size: 11px; color: var(--text-faint); }

.nav-group { margin-bottom: 18px; }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--text-faint); padding: 0 10px; margin-bottom: 6px; font-weight: 600;
}
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: 14px; font-weight: 500;
  margin-bottom: 2px; position: relative;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link:hover { background: var(--bg-alt); color: var(--text); }
.nav-link.active { background: linear-gradient(135deg, rgba(91,79,233,0.14), rgba(20,184,166,0.10)); color: var(--brand); font-weight: 600; }
html[data-theme="dark"] .nav-link.active { color: var(--brand-2); }
.nav-link .badge {
  margin-left: auto; background: var(--coral); color: #fff;
  font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 20px;
}

.sidebar-footer { margin-top: auto; }
.theme-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: var(--radius-sm); background: var(--bg-alt);
  font-size: 13px; color: var(--text-dim); cursor: pointer; border: 1px solid var(--border);
}

/* Main column */
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 28px;
  background: var(--surface); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.topbar .search {
  flex: 1; max-width: 420px; display: flex; align-items: center; gap: 8px;
  background: var(--bg-alt); border: 1px solid var(--border); border-radius: 999px;
  padding: 9px 16px; color: var(--text-faint); font-size: 13.5px;
}
.topbar .search input { background: none; border: none; outline: none; color: var(--text); width: 100%; font-size: 13.5px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--bg-alt); border: 1px solid var(--border); color: var(--text-dim); cursor: pointer; position: relative;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .dot { position: absolute; top: 7px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--coral); border: 2px solid var(--surface-solid); }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px; font-family: var(--font-display); flex-shrink: 0;
}
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }

.content { padding: 28px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ==========================================================================
   Cards, glassmorphism
   ========================================================================== */
.card {
  background: var(--surface); backdrop-filter: blur(16px);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 22px;
}
.card-flat { background: var(--surface-solid); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; margin: 0 0 4px; }
.page-head p { margin: 0; color: var(--text-dim); font-size: 14px; }
.eyebrow {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700;
  color: var(--brand); display: flex; align-items: center; gap: 6px; margin-bottom: 6px;
}

.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-value { font-family: var(--font-display); font-size: 30px; font-weight: 700; margin: 8px 0 2px; }
.stat-card .stat-label { color: var(--text-dim); font-size: 13px; }
.stat-card .stat-icon {
  position: absolute; top: 18px; right: 18px; width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.stat-card .stat-icon svg { width: 19px; height: 19px; }
.trend { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; margin-top: 4px; }
.trend.up { color: var(--teal); }
.trend.down { color: var(--coral); }

/* Project cards */
.project-card {
  border-radius: var(--radius-lg); overflow: hidden; background: var(--surface-solid);
  border: 1px solid var(--border); box-shadow: var(--shadow); transition: transform 0.18s ease, box-shadow 0.18s ease;
  display: flex; flex-direction: column;
}
.project-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.project-cover { height: 84px; position: relative; }
.grad-1 { background: linear-gradient(135deg, #5B4FE9, #8B7FF5); }
.grad-2 { background: linear-gradient(135deg, #14B8A6, #5EEAD4); }
.grad-3 { background: linear-gradient(135deg, #E85D75, #F5A6B4); }
.grad-4 { background: linear-gradient(135deg, #F5A623, #FFD08A); }
.grad-5 { background: linear-gradient(135deg, #4F8EF7, #9FC2FB); }
.project-body { padding: 16px 18px 18px; flex: 1; display: flex; flex-direction: column; }
.project-body h3 { font-size: 15.5px; margin: 0 0 6px; }
.project-body p { font-size: 13px; color: var(--text-dim); margin: 0 0 14px; line-height: 1.5; flex: 1; }
.project-meta { display: flex; align-items: center; justify-content: space-between; }
.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-left: -8px; border: 2px solid var(--surface-solid); }
.avatar-stack .avatar:first-child { margin-left: 0; }

.status-pill { font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 999px; text-transform: capitalize; }
.status-planning { background: rgba(245,166,35,0.15); color: #B36B00; }
.status-active { background: rgba(20,184,166,0.15); color: #0D8A7C; }
.status-on_hold { background: rgba(232,93,117,0.15); color: #C43F58; }
.status-completed { background: rgba(91,79,233,0.15); color: var(--brand); }
html[data-theme="dark"] .status-planning { color: #F5A623; }
html[data-theme="dark"] .status-active { color: #2DD4BF; }
html[data-theme="dark"] .status-on_hold { color: #F87A93; }
html[data-theme="dark"] .status-completed { color: #A79BFF; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 11px; font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; transition: all 0.15s ease; white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: linear-gradient(135deg, var(--brand), #7A6FF0); color: #fff; box-shadow: 0 6px 18px rgba(91,79,233,0.32); }
.btn-primary:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn-ghost { background: var(--bg-alt); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-outline { background: transparent; border-color: var(--brand); color: var(--brand); }
.btn-danger { background: rgba(232,93,117,0.12); color: var(--coral); }
.btn-sm { padding: 7px 13px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Forms */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--text-dim); }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-alt); color: var(--text); font-size: 14px; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); background: var(--surface-solid); }
.field textarea { resize: vertical; min-height: 90px; }
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }
.role-choice { display: flex; gap: 10px; }
.role-choice label {
  flex: 1; text-align: center; padding: 12px; border-radius: 10px; border: 1.5px solid var(--border);
  cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--text-dim); transition: all .15s ease;
}
.role-choice input { display: none; }
.role-choice input:checked + span { color: var(--brand); }
.role-choice label:has(input:checked) { border-color: var(--brand); background: rgba(91,79,233,0.08); color: var(--brand); }

.alert { padding: 12px 15px; border-radius: 10px; font-size: 13.5px; margin-bottom: 16px; display:flex; gap:8px; align-items:center; }
.alert-error { background: rgba(232,93,117,0.12); color: #C43F58; }
.alert-success { background: rgba(20,184,166,0.12); color: #0D8A7C; }
html[data-theme="dark"] .alert-error { color: #F87A93; }
html[data-theme="dark"] .alert-success { color: #2DD4BF; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; color: var(--text-faint); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; padding: 10px 12px; border-bottom: 1px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }

/* Kanban */
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .kanban { grid-template-columns: repeat(2, 1fr); } }
.kanban-col { background: var(--bg-alt); border-radius: var(--radius); padding: 14px; min-height: 120px; }
.kanban-col-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-weight: 700; font-size: 13px; }
.kanban-col-head .count { background: var(--surface-solid); border-radius: 20px; padding: 1px 9px; font-size: 11.5px; color: var(--text-dim); }
.task-card {
  background: var(--surface-solid); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  margin-bottom: 10px; cursor: grab; box-shadow: var(--shadow);
}
.task-card:active { cursor: grabbing; }
.task-card h4 { font-size: 13.5px; margin: 0 0 8px; }
.task-card .meta { display: flex; align-items: center; justify-content: space-between; }
.priority-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.priority-low { background: var(--teal); } .priority-medium { background: var(--amber); } .priority-high { background: var(--coral); }
.dragover { outline: 2px dashed var(--brand); outline-offset: -6px; }

/* Chat */
.chat-shell { display: flex; height: calc(100vh - 140px); border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow); }
.chat-list { width: 300px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
.chat-list-item { display: flex; gap: 11px; padding: 13px 16px; cursor: pointer; border-bottom: 1px solid var(--border); align-items: center; }
.chat-list-item:hover, .chat-list-item.active { background: var(--bg-alt); }
.chat-list-item .name { font-weight: 600; font-size: 13.5px; }
.chat-list-item .preview { font-size: 12px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.chat-main { flex: 1; display: flex; flex-direction: column; background: var(--bg); }
.chat-header { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; background: var(--surface); }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 62%; padding: 10px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.5; }
.msg.mine { align-self: flex-end; background: linear-gradient(135deg, var(--brand), #7A6FF0); color: #fff; border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; background: var(--surface-solid); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg .ts { font-size: 10px; opacity: 0.7; margin-top: 4px; display: block; }
.chat-input { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border); background: var(--surface); }
.chat-input input { flex: 1; padding: 11px 16px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-alt); color: var(--text); outline: none; }

/* Calendar */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.calendar-dow { text-align: center; font-size: 11px; color: var(--text-faint); font-weight: 700; text-transform: uppercase; padding-bottom: 6px; }
.calendar-cell { min-height: 92px; border-radius: 12px; background: var(--bg-alt); border: 1px solid var(--border); padding: 8px; font-size: 12px; }
.calendar-cell.today { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.calendar-cell .daynum { font-weight: 700; font-size: 12.5px; margin-bottom: 5px; }
.calendar-cell .evt { background: rgba(91,79,233,0.15); color: var(--brand); border-radius: 6px; padding: 2px 6px; font-size: 10.5px; margin-bottom: 3px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html[data-theme="dark"] .calendar-cell .evt { color: var(--brand-2); }
.calendar-cell.dim { opacity: 0.35; }

/* Notifications dropdown */
.notif-panel { position: absolute; top: 52px; right: 0; width: 340px; max-height: 420px; overflow-y: auto; z-index: 40; }
.notif-item { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.notif-item:last-child { border-bottom: none; }
.notif-item .t { font-weight: 600; margin-bottom: 2px; }
.notif-item .m { color: var(--text-dim); font-size: 12px; }
.notif-item.unread { background: rgba(91,79,233,0.06); }

/* Signature: orbit / network motif (used on auth page + dashboard header) */
.orbit-wrap { position: relative; width: 100%; height: 100%; min-height: 320px; }
.orbit-node { position: absolute; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 700; color: #fff; box-shadow: 0 10px 30px rgba(0,0,0,0.25); animation: float 6s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0px); } 50% { transform: translateY(-10px); } }
.orbit-line { position: absolute; height: 1px; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent); transform-origin: left center; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.empty-state svg { width: 48px; height: 48px; color: var(--text-faint); margin-bottom: 14px; }
.empty-state h3 { margin: 0 0 6px; font-size: 15px; color: var(--text); }
.empty-state p { margin: 0 0 18px; font-size: 13.5px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab { padding: 10px 16px; font-size: 13.5px; font-weight: 600; color: var(--text-dim); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--brand); border-color: var(--brand); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(10,10,20,0.5); backdrop-filter: blur(3px); z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--surface-solid); border-radius: var(--radius-lg); padding: 26px; width: 460px; max-width: 92vw; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close { cursor: pointer; color: var(--text-faint); background: none; border: none; font-size: 20px; }

.hidden { display: none !important; }

#menuToggle { display: none; }
.mobile-tabbar { display: none; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 900px) {
  html { -webkit-text-size-adjust: 100%; }
  body { padding-bottom: env(safe-area-inset-bottom); }

  .sidebar { position: fixed; left: -260px; z-index: 60; transition: left .22s ease; top: 0; height: 100vh; width: 248px; }
  .sidebar.open { left: 0; box-shadow: var(--shadow-lg); }
  #menuToggle { display: flex; }
  .content { padding: 16px 14px 90px; }

  /* Dim backdrop behind the open mobile sidebar */
  .sidebar::before {
    content: "";
    position: fixed;
    inset: 0 0 0 248px;
    background: rgba(0,0,0,0);
    pointer-events: none;
    transition: background .22s ease;
  }
  .sidebar.open::before { background: rgba(10,10,20,0.4); pointer-events: auto; }

  /* Topbar: compact — search collapses, actions stay reachable */
  .topbar { padding: 12px 14px; gap: 10px; }
  .topbar .search { display: none; }
  .topbar-actions { gap: 10px; }

  /* Page headers stack instead of squeezing; action buttons/groups become full-width */
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 18px; }
  .page-head h1 { font-size: 21px; }
  .page-head .btn { width: 100%; justify-content: center; }
  .page-head > div:last-child { display: flex; flex-direction: column; gap: 8px; width: 100%; }
  .page-head form { width: 100%; }

  /* Cards & grids: single column, tighter padding — overrides any inline grid-template-columns too */
  .card { padding: 16px; border-radius: var(--radius); }
  .grid { grid-template-columns: 1fr !important; }
  .stat-card .stat-value { font-size: 26px; }

  /* Tabs scroll horizontally instead of wrapping awkwardly */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex-shrink: 0; padding: 9px 13px; }

  /* Tables scroll horizontally rather than break layout */
  table { min-width: 560px; }

  /* Kanban becomes a horizontal swipe/snap carousel — far better than 4 stacked lists */
  .kanban {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 82%;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    margin: 0 -14px;
    padding-left: 14px;
    padding-right: 14px;
  }
  .kanban-col { scroll-snap-align: start; }

  /* Chat: show either the list or the open conversation, never both squeezed together */
  .chat-shell { height: calc(100vh - 230px); position: relative; border-radius: var(--radius); }
  .chat-list { position: absolute; inset: 0; width: 100%; z-index: 2; background: var(--surface-solid); transition: transform .22s ease; }
  .chat-list.chat-list-hidden { transform: translateX(-100%); }
  .chat-main { position: absolute; inset: 0; width: 100%; z-index: 1; }
  .chat-back-btn { display: flex; align-items: center; gap: 4px; background: none; border: none; color: var(--brand); font-weight: 600; font-size: 13.5px; cursor: pointer; padding: 4px 2px; margin-right: 2px; flex-shrink: 0; }
  .chat-back-btn svg { width: 18px; height: 18px; }
  .msg { max-width: 82%; }

  /* Modals become bottom sheets: easier to reach with a thumb, feels native */
  .modal-backdrop { align-items: flex-end; }
  .modal {
    width: 100%; max-width: 100%; border-radius: 20px 20px 0 0;
    max-height: 88vh; overflow-y: auto;
    animation: sheet-up .22s ease;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  }
  @keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
  .field-row { flex-direction: column; gap: 0; }

  /* Calendar: tighter cells, smaller type so 7 columns stay comfortable */
  .calendar-grid { gap: 5px; }
  .calendar-cell { min-height: 62px; padding: 5px; border-radius: 9px; }
  .calendar-cell .daynum { font-size: 11px; }
  .calendar-cell .evt { display: none; }
  .calendar-cell.today .daynum { color: var(--brand); }
  .calendar-dow { font-size: 9.5px; }

  /* Project cards, avatars, buttons: comfortable tap targets */
  .btn { padding: 11px 16px; }
  .avatar-stack .avatar { margin-left: -10px; }

  /* Bottom tab bar — the primary mobile navigation */
  .mobile-tabbar {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 55;
    background: var(--surface); backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    padding: 8px 6px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .mobile-tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    color: var(--text-faint); font-size: 10px; font-weight: 600; flex: 1;
    padding: 4px 2px; border-radius: 10px;
  }
  .mobile-tabbar a svg { width: 21px; height: 21px; }
  .mobile-tabbar a.active { color: var(--brand); }
  html[data-theme="dark"] .mobile-tabbar a.active { color: var(--brand-2); }

  /* Hide the sidebar's own nav groups from view since bottom bar covers primary nav;
     sidebar remains reachable via hamburger for secondary items (profile, sign out, theme). */
  .sidebar { padding-top: 18px; }
}

@media (min-width: 901px) {
  .chat-back-btn { display: none !important; }
  .mobile-tabbar { display: none !important; }
}
