/* NewGen unified interface layer
   Structure: tokens -> foundations -> shell -> components -> views -> overlays -> responsive */

:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-elevated: #eef3f9;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --surface-soft: #f7f9fc;
  --surface-tint: #eef3ff;
  --text: #172033;
  --text-strong: #0d172a;
  --muted: #69758a;
  --muted-strong: #4e5c72;
  --line: #dfe6ef;
  --line-strong: #cdd7e5;
  --primary: #315efb;
  --primary-hover: #244bd7;
  --primary-soft: #eaf0ff;
  --secondary: #139f92;
  --secondary-soft: #e3f7f4;
  --danger: #d94141;
  --danger-soft: #fff0f0;
  --warning: #b96d08;
  --warning-soft: #fff6df;
  --success: #14805e;
  --success-soft: #e7f7f0;
  --shadow-sm: 0 1px 2px rgba(20, 35, 60, .04), 0 7px 22px rgba(20, 35, 60, .05);
  --shadow-md: 0 18px 45px rgba(25, 42, 70, .11);
  --ring: 0 0 0 3px rgba(49, 94, 251, .2);
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --sidebar: 236px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d121c;
  --bg-elevated: #111824;
  --surface: #171f2d;
  --surface-strong: #1b2534;
  --surface-soft: #121a27;
  --surface-tint: #182442;
  --text: #e9eef6;
  --text-strong: #ffffff;
  --muted: #9da9ba;
  --muted-strong: #bdc7d5;
  --line: #293548;
  --line-strong: #38465b;
  --primary: #7896ff;
  --primary-hover: #91a9ff;
  --primary-soft: #1c2a54;
  --secondary: #42c8b8;
  --secondary-soft: #153b39;
  --danger: #ff7474;
  --danger-soft: #3b2026;
  --warning: #f3b34f;
  --warning-soft: #382d1b;
  --success: #4ed0a1;
  --success-soft: #17382f;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .18), 0 10px 28px rgba(0, 0, 0, .16);
  --shadow-md: 0 24px 60px rgba(0, 0, 0, .36);
  --ring: 0 0 0 3px rgba(120, 150, 255, .26);
}

[data-surface="tinted"] {
  --bg: color-mix(in srgb, var(--primary) 7%, #f4f7fb);
  --bg-elevated: color-mix(in srgb, var(--primary) 10%, #eef3f9);
  --surface: color-mix(in srgb, var(--primary) 3%, #ffffff);
  --surface-soft: color-mix(in srgb, var(--primary) 7%, #f7f9fc);
  --surface-tint: color-mix(in srgb, var(--primary) 15%, #ffffff);
}

[data-theme="dark"][data-surface="tinted"] {
  --bg: color-mix(in srgb, var(--primary) 8%, #0d121c);
  --bg-elevated: color-mix(in srgb, var(--primary) 10%, #111824);
  --surface: color-mix(in srgb, var(--primary) 5%, #171f2d);
  --surface-soft: color-mix(in srgb, var(--primary) 7%, #121a27);
  --surface-tint: color-mix(in srgb, var(--primary) 15%, #182442);
}

[data-surface="contrast"] {
  --surface-soft: var(--surface);
  --line: color-mix(in srgb, var(--line-strong) 78%, var(--text));
  --shadow-sm: 0 1px 0 rgba(20, 35, 60, .08);
  --shadow-md: 0 14px 34px rgba(25, 42, 70, .16);
}

[data-radius="sharp"] { --radius-xs: 4px; --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; }
[data-radius="round"] { --radius-xs: 12px; --radius-sm: 16px; --radius-md: 20px; --radius-lg: 28px; }
[data-font-scale="large"] body { font-size: 16.5px; }

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  overflow: auto;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, [data-view-link], .import-label { cursor: pointer; }
button { color: inherit; }
img { max-width: 100%; }
h1, h2, h3, h4, p { overflow-wrap: anywhere; }
h1, h2, h3, h4 { color: var(--text-strong); letter-spacing: -.025em; }
small { color: var(--muted); }
::selection { color: #fff; background: var(--primary); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 99px; background: var(--line-strong); background-clip: padding-box; }
*:focus { outline: none; }
:where(button, input, select, textarea, [tabindex], [data-view-link]):focus-visible { box-shadow: var(--ring) !important; outline: 2px solid transparent; }

[data-radius] :where(.panel, .settings-card, .metric-card, .subject-card, .task-card, .planner-card, .insight-card, .activity-item, .focus-item, .risk-item, .load-item, .reward-level, .reward-mission, .friend-card, .admin-user-row, .admin-user-card, .assessment-card, .confirm-card, .command-palette-card, .chat-message, .ai-message) { border-radius: var(--radius-md); }
[data-radius] :where(button, input, select, textarea, .search-box, .soft-badge, .unread-badge, .mini-profile, .nav-item, .tiny-task, .board-task, .admin-announcement, .admin-audit-item) { border-radius: var(--radius-sm); }
[data-radius="sharp"] :where(.round-action, .icon-btn, .subject-icon, .reward-level-orb, .metric-icon) { border-radius: var(--radius-sm); }
[data-radius="round"] :where(.round-action, .icon-btn, .subject-icon, .reward-level-orb, .metric-icon) { border-radius: 999px; }

.app-hidden, [hidden] { display: none !important; }
.eyebrow {
  margin: 0;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .11em;
  text-transform: uppercase;
}

/* Icon system: consistent 20px outline icons rendered as masks. */
.nav-icon, .search-icon {
  display: inline-block;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
.icon-dashboard { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7' height='7' rx='2'/%3E%3Crect x='14' y='3' width='7' height='7' rx='2'/%3E%3Crect x='3' y='14' width='7' height='7' rx='2'/%3E%3Crect x='14' y='14' width='7' height='7' rx='2'/%3E%3C/svg%3E"); }
.icon-subjects { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 5.5A2.5 2.5 0 0 1 6.5 3H20v16H6.5A2.5 2.5 0 0 0 4 21.5z'/%3E%3Cpath d='M4 5.5v16M8 7h8'/%3E%3C/svg%3E"); }
.icon-tasks { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='4'/%3E%3Cpath d='m8 12 2.5 2.5L16.5 9'/%3E%3C/svg%3E"); }
.icon-grades { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round'%3E%3Cpath d='M4 20V10M10 20V4M16 20v-7M22 20H2'/%3E%3C/svg%3E"); }
.icon-calendar { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round'%3E%3Crect x='3' y='5' width='18' height='16' rx='3'/%3E%3Cpath d='M8 3v4M16 3v4M3 10h18'/%3E%3C/svg%3E"); }
.icon-notes { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 3h10l4 4v14H5z'/%3E%3Cpath d='M15 3v5h5M8 12h8M8 16h6'/%3E%3C/svg%3E"); }
.icon-social { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round'%3E%3Ccircle cx='9' cy='8' r='3'/%3E%3Cpath d='M3 20a6 6 0 0 1 12 0M16 5.5a3 3 0 0 1 0 5.8M17 14a5 5 0 0 1 4 5'/%3E%3C/svg%3E"); }
.icon-ai { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3l1.5 4.5L18 9l-4.5 1.5L12 15l-1.5-4.5L6 9l4.5-1.5zM18.5 15l.8 2.2 2.2.8-2.2.8-.8 2.2-.8-2.2-2.2-.8 2.2-.8zM5 14l.7 1.8 1.8.7-1.8.7L5 19l-.7-1.8-1.8-.7 1.8-.7z'/%3E%3C/svg%3E"); }
.icon-profile { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 21a8 8 0 0 1 16 0'/%3E%3C/svg%3E"); }
.icon-admin { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.9' stroke-linejoin='round'%3E%3Cpath d='M12 3 20 6v5c0 5-3.4 8.4-8 10-4.6-1.6-8-5-8-10V6z'/%3E%3Cpath d='m9 12 2 2 4-4'/%3E%3C/svg%3E"); }
.search-icon { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-4-4'/%3E%3C/svg%3E"); color: var(--muted); }

/* Notes workspace */
#notesView.view.active { height: calc(100dvh - 126px); overflow: hidden; }
.notes-workspace { height: 100%; min-height: 0; display: grid; grid-template-columns: minmax(230px, 290px) minmax(0, 1fr); gap: 12px; }
.notes-library, .notes-editor-panel { min-height: 0; overflow: hidden; }
.notes-library { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 14px; padding: 18px; background: color-mix(in srgb, var(--surface) 90%, var(--bg)); }
.notes-library-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.notes-library-head h3 { margin: 2px 0 0; }
.notes-new-btn { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: var(--surface); font-size: 22px; line-height: 1; }
.notes-new-btn:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--line)); color: var(--primary); transform: translateY(-1px); }
.notes-search { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.notes-search input { min-width: 0; padding: 0; border: 0; background: transparent; box-shadow: none; }
.notes-list { min-height: 0; display: grid; align-content: start; gap: 3px; overflow-y: auto; padding-right: 3px; }
.notes-page-row { width: 100%; display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 8px; align-items: center; padding: 9px 10px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; text-align: left; }
.notes-page-row:hover { color: var(--text); background: var(--surface-soft); }
.notes-page-row.active { color: var(--text); background: color-mix(in srgb, var(--primary) 10%, var(--surface)); }
.notes-page-icon { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; background: var(--surface); font-size: 13px; }
.notes-page-copy { min-width: 0; }
.notes-page-copy strong, .notes-page-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notes-page-copy strong { font-size: 13px; }
.notes-page-copy small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.notes-library-tip { display: grid; gap: 3px; padding: 12px; border-radius: 10px; color: var(--muted); background: var(--surface-soft); font-size: 12px; }
.notes-library-tip strong { color: var(--text); }
.notes-editor-panel { position: relative; padding: 0; background: var(--surface); }
.notes-empty { height: 100%; display: grid; place-content: center; justify-items: center; gap: 12px; max-width: 560px; margin: auto; padding: 40px; text-align: center; }
.notes-empty[hidden], .notes-editor[hidden] { display: none !important; }
.notes-empty p { margin: 0 0 8px; color: var(--muted); line-height: 1.65; }
.notes-empty-icon { width: 62px; height: 70px; border: 2px solid var(--line); border-radius: 8px 18px 8px 8px; background: linear-gradient(135deg, var(--surface-soft), transparent); transform: rotate(-3deg); }
.notes-editor { height: 100%; min-height: 0; display: grid; grid-template-rows: auto auto auto minmax(0, 1fr) auto auto; padding: 22px clamp(22px, 5vw, 74px) 16px; }
.notes-editor-top { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.notes-breadcrumb { min-width: 0; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.notes-breadcrumb b { margin: 0 6px; color: var(--line-strong); }
.notes-title-input { width: 100%; margin: 22px 0 12px; padding: 0; border: 0; border-radius: 0; color: var(--text); background: transparent; box-shadow: none !important; font-size: clamp(28px, 4vw, 44px); font-weight: 800; letter-spacing: -.035em; }
.notes-title-input::placeholder { color: color-mix(in srgb, var(--muted) 58%, transparent); }
.notes-toolbar { display: flex; align-items: center; gap: 5px; padding: 8px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.notes-toolbar button { min-height: 30px; padding: 5px 9px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 700; }
.notes-toolbar button:hover { color: var(--text); background: var(--surface-soft); }
.notes-toolbar > span { margin-left: auto; color: var(--muted); font-size: 11px; }
.notes-writing-area { position: relative; min-height: 0; }
#notesContentInput { width: 100%; height: 100%; min-height: 280px; resize: none; padding: 22px 2px; border: 0; border-radius: 0; color: var(--text); background: transparent; box-shadow: none !important; font-family: inherit; font-size: 16px; line-height: 1.75; }
#notesContentInput::placeholder { color: color-mix(in srgb, var(--muted) 60%, transparent); }
.notes-mention-menu { position: absolute; z-index: 20; top: 14px; left: 0; width: min(360px, 92%); max-height: 260px; overflow-y: auto; padding: 6px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: 0 18px 50px rgba(0, 0, 0, .16); }
.notes-mention-option { width: 100%; display: grid; grid-template-columns: 32px 1fr; align-items: center; gap: 9px; padding: 8px; border: 0; border-radius: 8px; color: var(--text); background: transparent; text-align: left; }
.notes-mention-option:hover, .notes-mention-option.active { background: var(--surface-soft); }
.notes-mention-option > span:first-child { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: color-mix(in srgb, var(--primary) 11%, var(--surface)); }
.notes-mention-option strong, .notes-mention-option small { display: block; }
.notes-mention-option small { margin-top: 2px; color: var(--muted); }
.notes-references { display: flex; min-height: 32px; flex-wrap: wrap; gap: 7px; padding-top: 8px; border-top: 1px solid var(--line); }
.notes-reference-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: var(--surface-soft); font-size: 11px; font-weight: 700; }
.notes-reference-chip:hover { color: var(--primary); border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); }
.notes-editor-footer { display: flex; justify-content: space-between; gap: 12px; padding-top: 10px; color: var(--muted); font-size: 11px; }

@media (max-width: 820px) {
  #notesView.view.active { height: auto; min-height: calc(100dvh - 170px); overflow: visible; }
  .notes-workspace { height: auto; grid-template-columns: 1fr; }
  .notes-library { grid-template-rows: auto auto auto; overflow: visible; }
  .notes-list { grid-auto-flow: column; grid-auto-columns: minmax(170px, 220px); overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; }
  .notes-library-tip { display: none; }
  .notes-editor-panel { min-height: 620px; }
  .notes-editor { min-height: 620px; padding: 18px; }
}

@media (max-width: 520px) {
  .notes-editor-panel { min-height: 560px; }
  .notes-editor { min-height: 560px; padding: 16px 14px; }
  .notes-toolbar { overflow-x: auto; }
  .notes-toolbar button { flex: 0 0 auto; }
  .notes-toolbar > span { display: none; }
  .notes-title-input { font-size: 30px; }
}

/* Landing */
.landing-page {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  padding: 24px clamp(20px, 5vw, 72px) 32px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: clamp(28px, 5vh, 56px);
  overflow: hidden;
  background: var(--bg);
}
.landing-page::before, .landing-page::after {
  content: "";
  position: absolute;
  z-index: -1;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  filter: blur(2px);
  opacity: .65;
  pointer-events: none;
}
.landing-page::before { top: -260px; left: 16%; background: radial-gradient(circle, rgba(49,94,251,.2), transparent 68%); }
.landing-page::after { right: -240px; bottom: -250px; background: radial-gradient(circle, rgba(19,159,146,.18), transparent 68%); }
.landing-page.hidden { display: none; }
.landing-nav { width: min(1240px, 100%); margin: auto; }
.landing-nav, .landing-actions, .preview-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center;
  border-radius: 13px; color: #fff; font-weight: 900; letter-spacing: -.04em;
  background: linear-gradient(145deg, var(--primary), var(--secondary));
  box-shadow: 0 10px 24px rgba(49,94,251,.22);
}
.brand strong { display: block; font-size: 17px; color: var(--text-strong); }
.brand span { display: block; color: var(--muted); font-size: 11px; }
.landing-hero { width: min(1120px, 100%); margin: auto; display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(320px, .72fr); gap: clamp(32px, 7vw, 96px); align-items: center; }
.landing-copy h1 { max-width: 760px; margin: 12px 0 20px; font-size: clamp(45px, 6.4vw, 78px); line-height: .98; letter-spacing: -.055em; }
.landing-copy > p:not(.eyebrow) { max-width: 660px; margin: 0 0 28px; color: var(--muted-strong); font-size: clamp(16px, 2vw, 19px); line-height: 1.65; }
.landing-copy .landing-actions { justify-content: flex-start; }
.landing-preview { position: relative; padding: 18px; display: grid; gap: 10px; border: 1px solid var(--line); border-radius: 26px; background: color-mix(in srgb, var(--surface) 92%, transparent); box-shadow: var(--shadow-md); transform: rotate(1deg); }
.landing-preview::before { content: ""; position: absolute; inset: 8px -10px -10px 8px; z-index: -1; border: 1px solid var(--line); border-radius: inherit; background: var(--surface-soft); }
.preview-top { padding: 4px 4px 10px; color: var(--muted); font-size: 12px; }
.preview-top strong { color: var(--text); }
.preview-card { min-height: 68px; padding: 14px 15px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.preview-card span { color: var(--muted); font-size: 12px; }
.preview-card.hot { border-color: transparent; color: #fff; background: linear-gradient(135deg, var(--primary), var(--secondary)); }
.preview-card.hot strong, .preview-card.hot span { color: #fff; }
.landing-features { width: min(1120px, 100%); margin: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.landing-features article { padding: 17px 18px; display: grid; gap: 5px; border: 1px solid var(--line); border-radius: var(--radius-md); background: color-mix(in srgb, var(--surface) 85%, transparent); }
.landing-features span { color: var(--muted); font-size: 13px; }

/* Buttons and fields */
.primary-btn, .pill-btn, .ghost-btn, .icon-btn, .round-action, .segmented button {
  border: 1px solid transparent;
  font-weight: 700;
  transition: transform 160ms var(--ease), color 160ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}
.primary-btn, .pill-btn { min-height: 40px; padding: 0 16px; border-radius: 11px; color: #fff; background: var(--primary); box-shadow: 0 7px 16px rgba(49,94,251,.18); }
.primary-btn:hover, .pill-btn:hover { background: var(--primary-hover); box-shadow: 0 9px 20px rgba(49,94,251,.24); transform: translateY(-1px); }
.ghost-btn { min-height: 38px; padding: 0 13px; border-color: var(--line); border-radius: 10px; color: var(--muted-strong); background: var(--surface); }
.ghost-btn:hover { color: var(--text); border-color: var(--line-strong); background: var(--surface-soft); transform: translateY(-1px); }
.ghost-btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 24%, var(--line)); background: var(--danger-soft); }
.primary-btn.danger { background: var(--danger); box-shadow: 0 7px 16px color-mix(in srgb, var(--danger) 24%, transparent); }
.primary-btn.danger:hover { background: color-mix(in srgb, var(--danger) 86%, #000); }
.icon-btn, .round-action { width: 40px; height: 40px; padding: 0; display: inline-grid; place-items: center; border-color: var(--line); border-radius: 11px; background: var(--surface); }
.round-action { width: 32px; height: 32px; border-radius: 9px; }
.icon-btn:hover, .round-action:hover { border-color: var(--line-strong); background: var(--surface-soft); transform: translateY(-1px); }
button:disabled { cursor: not-allowed; opacity: .55; transform: none !important; }
input, select, textarea {
  width: 100%; min-height: 42px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); background: var(--surface); box-shadow: none;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
textarea { min-height: 88px; resize: vertical; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 78%, transparent); }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: var(--ring); background: var(--surface-strong); }
label { color: var(--muted-strong); font-size: 13px; font-weight: 650; }
.form-stack, .mini-form { display: grid; gap: 11px; }
.form-row { display: flex; align-items: center; gap: 10px; }
.search-box { min-width: 210px; min-height: 40px; padding: 0 11px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); transition: border-color 150ms ease, box-shadow 150ms ease; }
.search-box:focus-within { border-color: var(--primary); box-shadow: var(--ring); }
.search-box input { min-height: 38px; padding: 0; border: 0; background: transparent; box-shadow: none !important; }
.search-box.wide { width: min(440px, 100%); }
.segmented { width: fit-content; padding: 4px; display: flex; gap: 3px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.segmented button { min-height: 32px; padding: 0 12px; border-radius: 8px; color: var(--muted); background: transparent; }
.segmented button:hover { color: var(--text); }
.segmented button.active { color: var(--text-strong); background: var(--surface); box-shadow: var(--shadow-sm); }
.soft-badge, .unread-badge { width: fit-content; padding: 4px 8px; display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 99px; color: var(--muted-strong); background: var(--surface-soft); font-size: 11px; font-weight: 750; white-space: nowrap; }
.unread-badge { min-width: 20px; justify-content: center; color: #fff; border: 0; background: var(--primary); }

/* Application shell */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); background: var(--bg); }
.sidebar { position: sticky; top: 0; z-index: 20; height: 100vh; padding: 18px 14px; display: flex; flex-direction: column; gap: 18px; border-right: 1px solid var(--line); background: var(--surface); backdrop-filter: none; }
.sidebar .brand { padding: 0 7px; }
.nav { display: grid; gap: 4px; }
.nav-item { min-height: 42px; padding: 0 10px; display: flex; align-items: center; gap: 11px; border: 0; border-radius: 11px; color: var(--muted); background: transparent; font-size: 14px; font-weight: 700; text-align: left; transition: color 150ms ease, background 150ms ease, transform 150ms var(--ease); }
.nav-item .nav-icon { width: 19px; height: 19px; }
.nav-item:hover { color: var(--text); background: var(--surface-soft); transform: translateX(2px); }
.nav-item.active { color: var(--primary); background: var(--primary-soft); }
.nav-item.active::after { content: ""; width: 5px; height: 5px; margin-left: auto; border-radius: 50%; background: var(--primary); }
.nav-item.admin-only { display: none !important; }
.admin-enabled .nav-item.admin-only { display: flex !important; }
.level-card { margin-top: auto; padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-soft); }
.level-row { margin-bottom: 9px; display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.level-row b { color: var(--text); }
.progress-track { height: 7px; overflow: hidden; border-radius: 99px; background: var(--line); }
.progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--secondary)); transition: width 400ms var(--ease); }
.main { min-width: 0; padding: 18px clamp(18px, 2.2vw, 34px) 34px; overflow: visible; }
.topbar { min-height: 62px; margin: 0 0 20px; padding: 0 0 13px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 2px 0 0; font-size: clamp(24px, 2.3vw, 32px); line-height: 1.1; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.top-actions .ghost-btn, .top-actions .pill-btn { min-height: 40px; white-space: nowrap; }
.mini-profile { min-height: 40px; padding: 4px 10px 4px 4px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--muted-strong); font-size: 13px; font-weight: 700; transition: border-color 150ms, background 150ms; }
.mini-profile:hover { border-color: var(--line-strong); background: var(--surface-soft); }
.mini-profile img { width: 31px; height: 31px; object-fit: cover; border-radius: 9px; background: var(--primary-soft); }
#themeToggle { position: relative; color: transparent; font-size: 0; }
#themeToggle::before { content: ""; width: 18px; height: 18px; background: var(--muted-strong); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M20.5 14.2A8.5 8.5 0 0 1 9.8 3.5 8.5 8.5 0 1 0 20.5 14.2Z'/%3E%3C/svg%3E") center/contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M20.5 14.2A8.5 8.5 0 0 1 9.8 3.5 8.5 8.5 0 1 0 20.5 14.2Z'/%3E%3C/svg%3E") center/contain no-repeat; }
[data-theme="dark"] #themeToggle::before { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='4'/%3E%3Cpath d='M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='4'/%3E%3Cpath d='M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4'/%3E%3C/svg%3E"); }
.cloud-status { position: relative; padding-left: 27px !important; }
.cloud-status::before { content: ""; position: absolute; left: 12px; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.cloud-status.online::before { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.cloud-status.syncing::before { background: var(--warning); animation: statusPulse 1.2s infinite; }
.view { display: none; }
.view.active { display: block; animation: viewIn 220ms var(--ease); }

/* Shared layouts and cards */
.panel { min-width: 0; margin: 0 0 14px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm); }
.panel h3 { margin: 0; font-size: 17px; }
.panel-head, .settings-head, .quick-add-head, .reward-level-head, .reward-section-title { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.content-grid, .dashboard-grid, .command-grid, .split-layout, .profile-layout { display: grid; gap: 14px; }
.content-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.command-grid { grid-template-columns: 1.15fr .85fr .85fr; }
.split-layout { grid-template-columns: minmax(260px, 320px) minmax(0, 1fr); align-items: start; }
.stats-grid, .subject-grid, .friends-grid, .badges { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.toolbar-row { margin: 0 0 13px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.empty-state { min-height: 110px; padding: 22px; display: grid; place-content: center; gap: 5px; text-align: center; border: 1px dashed var(--line-strong); border-radius: 13px; color: var(--muted); background: var(--surface-soft); }
.empty-state strong { color: var(--text); }

/* Dashboard */
.dashboard-grid { grid-template-columns: minmax(360px, 1.5fr) repeat(3, minmax(130px, .55fr)); margin-bottom: 12px; }
.hero-panel { min-height: 148px; padding: 22px; display: flex; align-items: center; justify-content: space-between; gap: 22px; border: 1px solid color-mix(in srgb, var(--primary) 20%, var(--line)); border-radius: var(--radius-lg); background: linear-gradient(135deg, var(--surface-tint), var(--surface) 65%); box-shadow: var(--shadow-sm); }
.hero-panel h2 { max-width: 620px; margin: 5px 0; font-size: clamp(25px, 2.6vw, 36px); line-height: 1.08; }
.hero-panel p:last-child { max-width: 640px; margin: 0; color: var(--muted); }
.hero-panel .primary-btn { flex: 0 0 auto; }
[data-dashboard-header="compact"] .hero-panel { min-height: auto; padding: 14px 16px; align-items: center; }
[data-dashboard-header="compact"] .hero-panel h2 { margin: 3px 0; font-size: 27px; line-height: 1.08; }
[data-dashboard-header="compact"] .hero-panel p:last-child { max-width: 760px; font-size: 13px; line-height: 1.45; }
[data-dashboard-header="compact"] .hero-panel .primary-btn { min-height: 36px; padding-inline: 12px; }
.metric-card { min-height: 148px; padding: 17px; display: flex; flex-direction: column; justify-content: space-between; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm); transition: border-color 160ms, transform 160ms var(--ease); }
.metric-card:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.metric-card > span { color: var(--muted); font-size: 12px; font-weight: 700; }
.metric-card strong { font-size: 36px; line-height: 1; color: var(--text-strong); }
.dashboard-tabs { margin: 0 0 14px; }
.dashboard-section { display: none; }
.dashboard-section.active { display: grid; }
.content-grid.two.dashboard-section.active { grid-template-columns: minmax(0, 1.1fr) minmax(300px, .9fr); }
.panel.dashboard-section.active { display: block; }
.insight-list, .activity-list, .focus-timeline, .risk-list, .load-bars, .subject-progress-list, .planner-list, .relationship-list, .search-results, .admin-list { display: grid; gap: 8px; }
.insight-card, .activity-item, .focus-item, .risk-item, .load-item, .planner-card, .user-result, .admin-user { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.insight-card, .activity-item { display: grid; gap: 3px; }
.momentum-ring { display: grid; grid-template-columns: 140px 1fr; gap: 18px; align-items: center; }
.ring { width: 128px; aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--primary) var(--progress, 0%), var(--line) 0); position: relative; }
.ring::after { content: ""; position: absolute; inset: 11px; border-radius: 50%; background: var(--surface); }
.ring span { z-index: 1; font-size: 22px; font-weight: 850; }
.load-top, .risk-top, .subject-row-top, .subject-row-bottom { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.load-bar, .badge-progress { height: 7px; margin-top: 8px; overflow: hidden; border-radius: 99px; background: var(--line); }
.load-fill, .badge-progress span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--secondary)); }

/* Tasks, subjects, grades and plan */
.task-list, .board-stack, .day-tasks, .grades-table { display: grid; gap: 8px; }
.task-card { min-width: 0; padding: 12px; display: grid; grid-template-columns: 7px minmax(0, 1fr) auto; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); transition: border-color 150ms, transform 150ms var(--ease), box-shadow 150ms; }
.task-card:hover { border-color: var(--line-strong); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.task-dot { width: 7px; height: 38px; border-radius: 99px; }
.task-main { min-width: 0; display: grid; gap: 4px; }
.task-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-meta { display: flex; flex-wrap: wrap; gap: 5px 12px; color: var(--muted); font-size: 12px; }
.task-actions, .friend-actions, .relationship-actions { display: flex; align-items: center; gap: 6px; }
.task-section { display: grid; gap: 9px; }
.task-section + .task-section { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.task-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted-strong); }
.task-section-head > div { display: flex; align-items: center; gap: 8px; }
.task-section-head > span { min-width: 28px; padding: 3px 8px; border-radius: 99px; text-align: center; color: var(--muted); background: var(--surface-soft); font-size: 11px; font-weight: 800; }
.task-section-icon { width: 9px; height: 9px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 4px var(--warning-soft); }
.task-section-icon.completed { background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
.task-card.task-completed { border-color: color-mix(in srgb, var(--success) 28%, var(--line)); background: color-mix(in srgb, var(--success-soft) 65%, var(--surface)); }
.task-card.task-completed .task-dot { background: var(--success); }
.task-card.task-completed .task-main > strong { color: var(--success); }
.task-status-done { padding: 2px 7px; border-radius: 99px; color: var(--success); background: var(--success-soft); font-weight: 800; }
.board-column-done { border-color: color-mix(in srgb, var(--success) 22%, var(--line)); background: color-mix(in srgb, var(--success-soft) 55%, var(--surface-soft)); }
.board-task.board-task-done { border-color: color-mix(in srgb, var(--success) 24%, var(--line)); border-left-color: var(--success); background: color-mix(in srgb, var(--success-soft) 65%, var(--surface)); }
.board-task-done strong { color: var(--success); }
.round-action.done { color: transparent; font-size: 0; background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 25%, var(--line)); }
.round-action.done::before { content: ""; width: 16px; height: 16px; background: var(--success); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m5 12 4 4L19 6'/%3E%3C/svg%3E") center/contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m5 12 4 4L19 6'/%3E%3C/svg%3E") center/contain no-repeat; }
.round-action[data-action="focus-task"]::before { content: ""; width: 16px; height: 16px; background: var(--primary); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='7'/%3E%3Ccircle cx='12' cy='12' r='2'/%3E%3Cpath d='M12 2v3M12 19v3M2 12h3M19 12h3'/%3E%3C/svg%3E") center/contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='7'/%3E%3Ccircle cx='12' cy='12' r='2'/%3E%3Cpath d='M12 2v3M12 19v3M2 12h3M19 12h3'/%3E%3C/svg%3E") center/contain no-repeat; }
.task-form { margin-bottom: 14px; display: grid; grid-template-columns: minmax(220px, 1.5fr) repeat(5, minmax(105px, .75fr)) auto; gap: 8px; }
.task-board { margin: 4px 0 14px; display: grid; grid-template-columns: repeat(3, minmax(220px, 1fr)); gap: 10px; }
.board-column { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-soft); }
.board-column > strong { display: block; margin-bottom: 10px; font-size: 13px; }
.board-task, .tiny-task { padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.subject-grid { margin-bottom: 12px; }
.subject-card { padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-sm); transition: transform 150ms var(--ease), border-color 150ms; }
.subject-card:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.subject-card-head { display: flex; align-items: center; gap: 10px; }
.subject-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; color: #fff; font-weight: 850; }
.subject-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.subject-row:last-child { border-bottom: 0; }
.subject-detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.color-row { display: flex; align-items: center; gap: 9px; }
.swatch { width: 29px; height: 29px; padding: 0; border: 3px solid var(--surface); border-radius: 50%; background: var(--swatch); box-shadow: 0 0 0 1px var(--line); }
.swatch.selected { box-shadow: 0 0 0 2px var(--primary); transform: scale(1.08); }
.subject-color-picker { position: relative; }
.color-palette-toggle { width: 100%; min-height: 44px; display: flex; align-items: center; gap: 10px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 11px; color: var(--text); background: var(--surface); text-align: left; }
.color-palette-toggle:hover, .color-palette-toggle[aria-expanded="true"] { border-color: color-mix(in srgb, var(--primary) 46%, var(--line)); background: var(--surface-soft); }
.color-current { width: 24px; height: 24px; flex: 0 0 auto; border: 3px solid var(--surface); border-radius: 50%; background: var(--selected-color, #5b8cff); box-shadow: 0 0 0 1px var(--line); }
.palette-icon { width: 22px; height: 22px; margin-left: auto; background: currentColor; opacity: .65; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3a9 9 0 1 0 0 18h1.2a1.8 1.8 0 0 0 0-3.6h-.7a1.5 1.5 0 0 1 0-3H15A6 6 0 0 0 15 3h-3ZM7.2 10.1a1.35 1.35 0 1 1 0-2.7 1.35 1.35 0 0 1 0 2.7Zm3.1-3.3a1.35 1.35 0 1 1 0-2.7 1.35 1.35 0 0 1 0 2.7Zm4.2.5a1.35 1.35 0 1 1 0-2.7 1.35 1.35 0 0 1 0 2.7Zm3 3a1.35 1.35 0 1 1 0-2.7 1.35 1.35 0 0 1 0 2.7Z'/%3E%3C/svg%3E") center/contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3a9 9 0 1 0 0 18h1.2a1.8 1.8 0 0 0 0-3.6h-.7a1.5 1.5 0 0 1 0-3H15A6 6 0 0 0 15 3h-3ZM7.2 10.1a1.35 1.35 0 1 1 0-2.7 1.35 1.35 0 0 1 0 2.7Zm3.1-3.3a1.35 1.35 0 1 1 0-2.7 1.35 1.35 0 0 1 0 2.7Zm4.2.5a1.35 1.35 0 1 1 0-2.7 1.35 1.35 0 0 1 0 2.7Zm3 3a1.35 1.35 0 1 1 0-2.7 1.35 1.35 0 0 1 0 2.7Z'/%3E%3C/svg%3E") center/contain no-repeat; }
.color-palette-popover { position: absolute; z-index: 35; top: calc(100% + 7px); left: 0; width: min(310px, 92vw); display: grid; grid-template-columns: repeat(8, 1fr); gap: 9px; padding: 14px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); box-shadow: 0 20px 55px rgba(0, 0, 0, .18); }
.color-palette-popover[hidden] { display: none !important; }
.color-palette-popover .swatch { width: 25px; height: 25px; justify-self: center; }
.subject-color-picker.compact .color-palette-toggle { min-height: 40px; }
.optional-label { margin-left: 5px; color: var(--muted); font-size: 11px; font-weight: 500; }

@media (max-width: 520px) {
  .color-palette-popover { position: fixed; z-index: 100; top: auto; right: 12px; bottom: calc(86px + env(safe-area-inset-bottom)); left: 12px; width: auto; grid-template-columns: repeat(8, 1fr); }
  .color-palette-popover .swatch { width: 30px; height: 30px; }
}
.grade-card, .grade-row { padding: 12px; display: grid; gap: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.grade-row { grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px; }
.grades-workspace { display: grid; grid-template-columns: minmax(280px, 390px) minmax(0, 1fr); gap: 14px; align-items: start; }
.grades-list-panel { position: sticky; top: 0; max-height: calc(100dvh - 122px); overflow: auto; }
.grades-side-stack { min-width: 0; display: grid; gap: 14px; }
.grades-side-stack .panel { margin: 0; }
.calendar-strip { margin-bottom: 12px; display: grid; grid-template-columns: repeat(7, minmax(100px, 1fr)); gap: 7px; overflow-x: auto; }
.calendar-strip > * { padding: 9px; border-radius: 10px; text-align: center; background: var(--surface-soft); }
.calendar-controls { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 7px; }
.calendar-controls select { width: auto; min-width: 138px; min-height: 38px; padding-block: 7px; }
.week-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; padding-bottom: 5px; }
.day-column { min-height: 330px; padding: 11px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-soft); }
.day-column.day-empty { opacity: .72; }
.day-column .empty-state.compact { min-height: 70px; padding: 12px; }

/* Rewards */
.reward-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 14px; align-items: start; }
.reward-main, .reward-side { min-width: 0; padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-soft); }
.reward-main h4, .reward-side h4 { margin: 0; }
.reward-level-head small, .reward-section-title small { display: block; margin-top: 2px; }
.reward-head-actions { display: flex; gap: 6px; }
.reward-level-track { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(145px, .75fr); gap: 9px; overflow-x: auto; scroll-snap-type: x proximity; padding: 3px 3px 10px; }
.reward-level { min-height: 145px; padding: 14px; display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end; gap: 3px; scroll-snap-align: start; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); opacity: .7; transition: transform 160ms var(--ease), border-color 160ms, opacity 160ms; }
.reward-level:hover { transform: translateY(-2px); opacity: 1; }
.reward-level.current { border-color: color-mix(in srgb, var(--primary) 55%, var(--line)); background: var(--primary-soft); opacity: 1; box-shadow: var(--ring); }
.reward-level.reached { opacity: 1; }
.reward-level-orb { width: 38px; height: 38px; margin-bottom: auto; display: grid; place-items: center; border-radius: 11px; color: transparent; font-size: 0; background: var(--primary-soft); }
.reward-level-orb::before { content: ""; width: 19px; height: 19px; background: var(--primary); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='m12 3 2.8 5.7 6.2.9-4.5 4.4 1.1 6.2-5.6-2.9-5.6 2.9 1.1-6.2L3 9.6l6.2-.9z'/%3E%3C/svg%3E") center/contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='m12 3 2.8 5.7 6.2.9-4.5 4.4 1.1 6.2-5.6-2.9-5.6 2.9 1.1-6.2L3 9.6l6.2-.9z'/%3E%3C/svg%3E") center/contain no-repeat; }
.reward-level.locked .reward-level-orb::before { background: var(--muted); }
.reward-section-title { margin-top: 17px; }
.reward-mission-list { display: grid; gap: 8px; }
.reward-mission { padding: 11px; display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; align-items: center; gap: 11px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); transition: border-color 150ms, transform 150ms var(--ease); }
.reward-mission:hover { border-color: var(--line-strong); transform: translateX(2px); }
.reward-mission-xp { min-height: 44px; display: grid; place-content: center; text-align: center; border-radius: 10px; color: var(--primary); background: var(--primary-soft); font-weight: 850; }
.reward-mission-body { min-width: 0; display: grid; gap: 2px; }
.reward-summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.reward-summary > div:not(.reward-summary-progress) { padding: 10px; display: grid; gap: 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.reward-summary span { color: var(--muted); font-size: 10px; }
.reward-summary-progress { grid-column: 1/-1; height: 7px; overflow: hidden; border-radius: 99px; background: var(--line); }
.reward-summary-progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); }
.reward-tip { margin-top: 10px; padding: 12px; display: grid; gap: 4px; border-radius: 11px; color: var(--success); background: var(--success-soft); }

/* Social */
.social-workspace { display: grid; grid-template-columns: minmax(245px, .8fr) minmax(245px, .9fr) minmax(330px, 1.25fr); gap: 12px; align-items: stretch; }
.social-column { min-width: 0; margin: 0; }
.social-subhead { margin-top: 18px; }
.group-create-form { margin: 8px 0 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.group-create-form[hidden] { display: none; }
.group-create-form fieldset { margin: 10px 0; padding: 0; border: 0; }
.group-create-form legend { margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 800; }
.group-member-options { max-height: 160px; display: grid; gap: 5px; overflow: auto; }
.group-member-options label { padding: 7px 8px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); cursor: pointer; }
.group-member-options input { width: auto; accent-color: var(--primary); }
.group-manage-panel { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.group-manage-row { padding: 7px 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.group-manage-row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-chat-list { display: grid; gap: 7px; }
.group-chat-row { width: 100%; padding: 10px 11px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 11px; color: var(--text); text-align: left; background: var(--surface); }
.group-chat-row:hover, .group-chat-row.active { border-color: color-mix(in srgb, var(--primary) 42%, var(--line)); background: var(--primary-soft); }
.group-chat-row small { color: var(--muted); }
.chat-sender-name { display: block; margin-bottom: 3px; color: var(--primary); font-size: 11px; }
.user-result, .friend-head { display: flex; align-items: center; gap: 10px; }
.user-result > :nth-child(2), .friend-head > :nth-child(2) { min-width: 0; flex: 1; display: grid; }
.user-result img, .friend-head img { width: 38px; height: 38px; flex: 0 0 auto; object-fit: cover; border-radius: 11px; }
.friend-card { padding: 12px; display: grid; gap: 10px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-soft); transition: border-color 150ms, transform 150ms var(--ease); }
.friend-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.friend-meta { display: flex; flex-wrap: wrap; gap: 6px; color: var(--muted); font-size: 11px; }
.friend-chat-preview { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 11px; }
.friend-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.compact-friend-action { min-height: 32px; padding: 0 8px; justify-content: center; font-size: 12px; white-space: nowrap; }
.social-notifications { display: grid; gap: 7px; margin-bottom: 9px; }
.social-notification { padding: 9px 11px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border: 1px solid color-mix(in srgb, var(--secondary) 25%, var(--line)); border-radius: 11px; background: var(--secondary-soft); }
.chat-toolbar { margin-bottom: 9px; display: flex; flex-wrap: wrap; gap: 6px; }
.chat-box { min-height: 350px; max-height: 52vh; padding: 12px; display: flex; flex-direction: column; gap: 8px; overflow: auto; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-soft); }
.chat-message { max-width: 84%; padding: 9px 11px; border-radius: 12px 12px 12px 4px; background: var(--surface); box-shadow: var(--shadow-sm); cursor: pointer; }
.chat-message.mine { align-self: flex-end; border-radius: 12px 12px 4px 12px; color: #fff; background: var(--primary); }
.chat-message.failed { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); background: var(--danger-soft); color: var(--text); }
.chat-message.ai-generated { border-color: color-mix(in srgb, var(--primary) 30%, var(--line)); background: linear-gradient(135deg, var(--primary-soft), var(--surface)); }
.chat-message.mine .chat-message-footer, .chat-message.mine .chat-delivery { color: rgba(255,255,255,.78); }
.chat-message.failed .chat-message-footer, .chat-message.failed .chat-delivery { color: var(--danger); }
.chat-message-footer { display: flex; align-items: center; gap: 6px; font-size: 10px; }
.chat-reactions, .chat-reaction-picker { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 5px; }
.chat-reaction-chip, .chat-reaction-picker button { min-height: 28px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); font-size: 12px; }
.chat-reaction-chip.active { border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); background: var(--primary-soft); color: var(--primary); }
.chat-message.mine .chat-reaction-chip, .chat-message.mine .chat-reaction-picker button { color: var(--text); background: rgba(255,255,255,.94); }
.chat-image { max-height: 260px; object-fit: cover; border-radius: 8px; }
.chat-image-preview { margin-top: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-soft); }
.chat-form { margin-top: 9px; display: grid; grid-template-columns: 1fr auto; gap: 7px; }

/* Gen AI */
#genaiView.view.active { height: calc(100dvh - 126px); overflow: hidden; }
.ai-workspace { height: 100%; min-height: 0; display: grid; grid-template-columns: minmax(230px, 285px) minmax(0, 1fr); gap: 12px; overflow: hidden; }
.ai-sidebar, .ai-chat-panel { margin: 0; min-height: 0; overflow: hidden; }
.ai-sidebar { display: flex; flex-direction: column; }
.ai-sidebar .panel-head { align-items: center; }
.ai-sidebar .primary-btn { min-height: 36px; padding-inline: 10px; }
.ai-privacy-note { margin: 0 0 12px; padding: 9px 10px; border-radius: 10px; color: var(--muted-strong); background: var(--surface-soft); font-size: 11px; }
.ai-context-toggle { margin: 0 0 12px; padding: 9px 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.ai-context-toggle span, .ai-context-toggle strong, .ai-context-toggle small { display: block; min-width: 0; }
.ai-context-toggle small { color: var(--muted); font-size: 10px; }
.ai-context-toggle input { width: auto; min-height: 0; accent-color: var(--primary); }
.ai-chat-list { min-height: 0; display: grid; align-content: start; gap: 6px; overflow: auto; }
.ai-chat-row { width: 100%; padding: 10px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; border: 1px solid transparent; border-radius: 11px; color: var(--text); text-align: left; background: transparent; }
.ai-chat-row:hover, .ai-chat-row.active { border-color: var(--line); background: var(--surface-soft); }
.ai-chat-row > span { min-width: 0; }
.ai-chat-row strong, .ai-chat-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-chat-row small { color: var(--muted); }
.ai-chat-delete { width: 34px; height: 34px; min-height: 34px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; }
.ai-chat-delete:hover { color: var(--danger); background: var(--danger-soft); }
.ai-chat-panel { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; }
.ai-chat-head { padding-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.ai-chat-head h2 { margin: 2px 0 0; font-size: 22px; }
.ai-head-controls { display: flex; align-items: center; gap: 7px; }
.ai-head-controls select { min-height: 36px; padding-block: 6px; }
.ai-suggestions { padding: 10px 0; display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; }
.ai-suggestions::-webkit-scrollbar { display: none; }
.ai-suggestions button { min-height: 36px; padding: 7px 10px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 99px; color: var(--muted-strong); background: var(--surface-soft); font-size: 11px; }
.ai-suggestions button:hover { color: var(--primary); border-color: color-mix(in srgb, var(--primary) 30%, var(--line)); }
.ai-messages { min-height: 0; padding: 14px 4px 14px 0; display: flex; flex-direction: column; gap: 10px; overflow: auto; }
.ai-message { max-width: min(82%, 720px); padding: 11px 13px; align-self: flex-start; border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; background: var(--surface-soft); }
.ai-message.user { align-self: flex-end; color: #fff; border-color: transparent; border-radius: 14px 14px 4px 14px; background: var(--primary); }
.ai-message-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; font-weight: 850; text-transform: uppercase; letter-spacing: .06em; }
.ai-message.user .ai-message-label { color: rgba(255,255,255,.74); }
.ai-message-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.ai-message time { display: block; margin-top: 5px; color: var(--muted); font-size: 9px; }
.ai-message.user time { color: rgba(255,255,255,.7); }
.ai-action-card { margin-top: 10px; padding: 10px; border: 1px solid color-mix(in srgb, var(--primary) 28%, var(--line)); border-radius: 11px; color: var(--text); background: var(--surface); }
.ai-action-card strong, .ai-action-card small { display: block; }
.ai-action-card small { margin: 3px 0 8px; color: var(--muted); }
.ai-action-list { margin: 0 0 9px; padding-left: 18px; color: var(--muted-strong); font-size: 11px; }
.ai-action-card.applied { border-color: color-mix(in srgb, var(--success) 30%, var(--line)); background: var(--success-soft); }
.ai-welcome { margin: auto; max-width: 540px; padding: 25px; text-align: center; color: var(--muted); }
.ai-welcome strong { display: block; margin-bottom: 6px; color: var(--text); font-size: 18px; }
.ai-compose { padding-top: 10px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; border-top: 1px solid var(--line); }
.ai-attachment-bar { grid-column: 1 / -1; display: flex; align-items: center; flex-wrap: wrap; gap: 7px; color: var(--muted); font-size: 11px; }
.ai-attachment-bar .ghost-btn { min-height: 34px; }
.ai-attachment-bar span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-compose textarea { min-height: 48px; max-height: 120px; resize: none; }
.ai-compose button { min-width: 92px; }

/* Profile forms */
.settings-card { height: 100%; margin: 0; display: flex; flex-direction: column; }
.settings-card > .primary-btn { width: fit-content; margin-top: auto; }
.settings-card .settings-head { padding-bottom: 11px; border-bottom: 1px solid var(--line); }
.settings-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.settings-form-grid label { display: grid; gap: 5px; }
.settings-span { grid-column: 1 / -1; }
.settings-save-row { margin-top: 13px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-toggles { display: grid; gap: 8px; }
.settings-toggles > label { padding: 10px 11px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-soft); }
.settings-toggles span { display: grid; gap: 2px; }
.settings-toggles input, .toggle-setting input { width: 18px; min-height: 18px; accent-color: var(--primary); }
.toggle-setting { min-height: 42px; padding: 9px 11px; display: flex !important; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.data-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.import-label { min-height: 38px; padding: 0 13px; display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.import-label input { display: none; }

/* Quick add and overlays */
.quick-add-panel { position: fixed; inset: 0 0 0 auto; z-index: 40; width: min(460px, 100%); height: 100vh; margin: 0; padding: 22px; overflow: auto; display: block; border: 0; border-left: 1px solid var(--line); border-radius: 0; background: var(--surface); box-shadow: var(--shadow-md); transform: translateX(105%); visibility: hidden; transition: transform 220ms var(--ease), visibility 220ms; }
.quick-add-panel.open { transform: translateX(0); visibility: visible; }
.quick-add-grid { display: grid; gap: 11px; }
.quick-add-grid .mini-form { padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-soft); }
.auth-overlay, .setup-overlay, .focus-overlay, .profile-preview-overlay { position: fixed; inset: 0; z-index: 80; padding: 18px; display: none; place-items: center; background: rgba(8, 14, 25, .6); backdrop-filter: blur(6px); }
.auth-overlay.open, .setup-overlay.open, .focus-overlay.open, .profile-preview-overlay.open { display: grid; }
.auth-card, .setup-card, .focus-card, .profile-preview-card { position: relative; width: min(520px, 100%); max-height: calc(100vh - 36px); padding: 25px; overflow: auto; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow-md); animation: dialogIn 190ms var(--ease); }
.focus-card { width: min(620px, 100%); text-align: center; }
.profile-preview-card { width: min(430px, 100%); text-align: center; }
.profile-preview-card > img { width: 92px; height: 92px; object-fit: cover; border-radius: 24px; }
.auth-close, .focus-close, .profile-preview-close { position: absolute; top: 14px; right: 14px; }
.auth-brand { margin-bottom: 18px; }
.auth-copy h2 { margin-bottom: 6px; }
.auth-copy p { color: var(--muted); }
.auth-tabs { margin: 18px 0 14px; }
.auth-actions, .auth-session, .setup-actions, .tour-actions, .focus-controls { margin-top: 14px; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.auth-session { justify-content: space-between; padding-top: 14px; border-top: 1px solid var(--line); }
.setup-progress { height: 6px; margin-bottom: 20px; overflow: hidden; border-radius: 99px; background: var(--line); }
.setup-progress div { height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); transition: width 220ms var(--ease); }
.setup-step { display: none; }
.setup-step.active { display: grid; gap: 11px; }
.setup-step label { display: grid; gap: 5px; }
.setup-summary { padding: 18px; border-radius: 12px; color: var(--primary); background: var(--primary-soft); font-weight: 800; text-align: center; }
.focus-timer { margin: 20px 0; font-size: clamp(64px, 13vw, 104px); font-weight: 850; letter-spacing: -.06em; line-height: 1; color: var(--primary); }
.focus-controls { justify-content: center; }
.tour-overlay { position: fixed; inset: 0; z-index: 70; display: none; pointer-events: none; }
.tour-overlay.open { display: block; }
.tour-card { position: absolute; right: 24px; bottom: 24px; width: min(430px, calc(100% - 48px)); padding: 21px; pointer-events: auto; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow-md); }
.tour-card h2 { margin: 7px 0; }
.tour-card > p { color: var(--muted); }
.tour-example { padding: 11px; border-radius: 11px; color: var(--primary); background: var(--primary-soft); }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 22px; max-width: min(440px, calc(100% - 32px)); padding: 10px 14px; border: 1px solid var(--line); border-radius: 11px; color: var(--text); background: var(--surface); box-shadow: var(--shadow-md); opacity: 0; transform: translate(-50%, 18px); pointer-events: none; transition: opacity 180ms, transform 180ms var(--ease); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.confetti-layer { position: fixed; inset: 0; z-index: 110; overflow: hidden; pointer-events: none; }

/* Public profile preview */
.profile-preview-card { text-align: left; }
.profile-preview-head { padding-right: 32px; display: flex; align-items: center; gap: 13px; }
.profile-preview-head > img { width: 72px; height: 72px; flex: 0 0 auto; object-fit: cover; border: 1px solid var(--line); border-radius: 17px; background: var(--primary-soft); }
.profile-preview-head > div { min-width: 0; }
.profile-preview-head h2 { margin: 2px 0; font-size: 23px; }
.profile-preview-head p:last-child { margin: 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.profile-preview-bio { margin-top: 18px; padding: 13px; display: grid; gap: 5px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.profile-preview-bio strong { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; }
.profile-preview-bio p { margin: 0; color: var(--muted-strong); line-height: 1.55; overflow-wrap: anywhere; }
.profile-preview-stats { margin-top: 9px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.profile-preview-stats > * { min-width: 0; padding: 10px 7px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); color: var(--text); font-size: 11px; font-weight: 750; text-align: center; overflow-wrap: anywhere; }
.friend-head[role="button"], .user-result[role="button"] { cursor: pointer; }

/* In-app confirmation dialog */
.confirm-overlay { position: fixed; inset: 0; z-index: 95; padding: 18px; display: none; place-items: center; background: rgba(8, 14, 25, .62); backdrop-filter: blur(6px); }
.confirm-overlay.open { display: grid; }
.confirm-card { width: min(430px, 100%); padding: 22px; display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow-md); animation: dialogIn 190ms var(--ease); }
.confirm-symbol { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: var(--danger-soft); }
.confirm-symbol::before { content: ""; width: 20px; height: 20px; background: var(--danger); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 7h16M9 7V4h6v3M7 7l1 14h8l1-14M10 11v6M14 11v6'/%3E%3C/svg%3E") center/contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 7h16M9 7V4h6v3M7 7l1 14h8l1-14M10 11v6M14 11v6'/%3E%3C/svg%3E") center/contain no-repeat; }
.confirm-copy { min-width: 0; }
.confirm-copy h2 { margin: 3px 0 6px; font-size: 20px; line-height: 1.25; }
.confirm-copy > p:last-child { margin: 0; color: var(--muted); line-height: 1.55; overflow-wrap: anywhere; white-space: pre-line; }
.confirm-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }

/* Administration workspace */
.admin-notice-tray:empty { display: none; }
.admin-notice-tray { margin: -6px 0 14px; display: grid; gap: 7px; }
.admin-notice { padding: 11px 12px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-left: 4px solid var(--primary); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-sm); }
.admin-notice.important { border-left-color: var(--warning); background: var(--warning-soft); }
.admin-notice.urgent { border-left-color: var(--danger); background: var(--danger-soft); }
.admin-notice > div { min-width: 0; display: grid; gap: 2px; }
.admin-notice > div > span { color: var(--muted-strong); overflow-wrap: anywhere; }

.admin-metrics { margin-bottom: 14px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.admin-metric { min-height: 112px; padding: 14px; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; border: 1px solid var(--line); border-radius: 14px; color: var(--text); background: var(--surface); box-shadow: var(--shadow-sm); text-align: left; transition: border-color 150ms, transform 150ms var(--ease), background 150ms; }
.admin-metric:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.admin-metric.active { border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); background: var(--primary-soft); }
.admin-metrics span, .admin-metrics small { color: var(--muted); font-size: 11px; }
.admin-metrics strong { color: var(--text-strong); font-size: 28px; line-height: 1; }
.admin-workspace { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(330px, .65fr); gap: 14px; align-items: start; }
.admin-users-panel { margin: 0; }
.admin-head-actions { display: flex; align-items: center; gap: 7px; }
.admin-search { width: 100%; margin-bottom: 12px; }
.admin-list { display: grid; gap: 8px; }
.admin-user-row { min-width: 0; padding: 11px; display: grid; grid-template-columns: minmax(180px, 1fr) minmax(210px, auto) auto; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); cursor: pointer; transition: border-color 150ms, transform 150ms var(--ease); }
.admin-user-row:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.admin-user-identity { min-width: 0; display: flex; align-items: center; gap: 9px; }
.admin-user-identity img { width: 40px; height: 40px; flex: 0 0 auto; object-fit: cover; border-radius: 11px; }
.admin-user-identity > div { min-width: 0; display: grid; }
.admin-user-identity strong, .admin-user-identity small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-user-counts { display: flex; flex-wrap: wrap; gap: 5px; }
.admin-user-counts span { padding: 4px 7px; border-radius: 99px; color: var(--muted-strong); background: var(--surface); font-size: 10px; }
.admin-user-state, .admin-detail-status { width: fit-content; padding: 5px 8px; border-radius: 99px; color: var(--success); background: var(--success-soft); font-size: 10px; font-weight: 800; }
.admin-user-state.timeout, .admin-detail-status.timeout { color: var(--warning); background: var(--warning-soft); }
.admin-user-state.banned, .admin-detail-status.banned { color: var(--danger); background: var(--danger-soft); }
.admin-side-stack { display: grid; gap: 14px; }
.admin-side-stack > .panel { margin: 0; }
.admin-operations-grid { margin: 12px 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.admin-operations-grid .panel { min-width: 0; margin: 0; }
.admin-live-list, .admin-ticket-list, .admin-trash-list { max-height: 310px; display: grid; gap: 8px; overflow: auto; }
.admin-live-row, .admin-ticket, .admin-trash-row { width: 100%; padding: 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 11px; color: var(--text); text-align: left; background: var(--surface); }
.admin-live-row { position: relative; padding-left: 25px; }
.admin-live-row::before { content: ""; position: absolute; left: 10px; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.admin-live-row[data-active="true"]::before { background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
.admin-live-row strong, .admin-live-row small, .command-palette-item strong, .command-palette-item small { display: block; }
.admin-live-row small, .admin-ticket small, .admin-trash-row small { color: var(--muted); }
.admin-ticket > div { min-width: 0; }
.admin-ticket p { margin: 5px 0 0; color: var(--muted-strong); font-size: 12px; overflow-wrap: anywhere; }
.admin-ticket.resolved { opacity: .72; }
.support-ticket-form { margin-bottom: 16px; padding-bottom: 16px; display: grid; grid-template-columns: minmax(120px, .55fr) 1fr auto; gap: 8px; align-items: end; border-bottom: 1px solid var(--line); }
.support-ticket-form label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 750; }
.support-ticket-form label:nth-child(3) { grid-column: 1 / 3; }
.command-palette-overlay { position: fixed; inset: 0; z-index: 80; padding: min(15vh, 120px) 16px 16px; display: none; place-items: start center; background: rgba(12, 20, 36, .58); backdrop-filter: blur(8px); }
.command-palette-overlay.open { display: grid; }
.command-palette-card { width: min(620px, 100%); padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow-md); }
.command-palette-head { display: flex; align-items: center; justify-content: space-between; }
.command-palette-head h2 { margin: 0 0 10px; }
.command-palette-head kbd { padding: 4px 7px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: var(--surface-soft); }
#adminCommandSearch { width: 100%; margin-bottom: 10px; }
.command-palette-list { max-height: 390px; display: grid; gap: 6px; overflow: auto; }
.command-palette-item { width: 100%; padding: 11px 12px; display: flex; justify-content: space-between; gap: 15px; border: 1px solid transparent; border-radius: 10px; color: var(--text); text-align: left; background: transparent; }
.command-palette-item:hover, .command-palette-item:focus-visible { border-color: var(--line); background: var(--surface-soft); }
.admin-compose-panel .form-row > label { min-width: 0; flex: 1; }
.admin-announcement-list, .admin-audit-list { display: grid; gap: 7px; }
.admin-announcement { padding: 10px; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; border: 1px solid var(--line); border-left: 3px solid var(--primary); border-radius: 11px; background: var(--surface-soft); }
.admin-announcement.important { border-left-color: var(--warning); }
.admin-announcement.urgent { border-left-color: var(--danger); }
.admin-announcement > div { min-width: 0; display: grid; gap: 2px; }
.admin-announcement small { overflow-wrap: anywhere; }
.admin-audit-item { padding: 9px 10px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); }
.admin-audit-item > div:first-child { min-width: 0; display: grid; gap: 2px; }
.admin-audit-side { display: grid; justify-items: end; gap: 5px; }
.admin-audit-side time { color: var(--muted); font-size: 10px; }
.admin-audit-side .ghost-btn { min-height: 30px; padding-inline: 8px; font-size: 10px; }

.admin-user-overlay { position: fixed; inset: 0; z-index: 96; padding: 18px; display: none; place-items: center; background: rgba(8, 14, 25, .62); backdrop-filter: blur(6px); }
.admin-user-overlay.open { display: grid; }
.admin-user-card { position: relative; width: min(560px, 100%); padding: 24px; border: 1px solid var(--line); border-radius: 19px; background: var(--surface); box-shadow: var(--shadow-md); animation: dialogIn 190ms var(--ease); }
.admin-user-close { position: absolute; top: 13px; right: 13px; }
.admin-user-head { padding-right: 36px; display: flex; align-items: center; gap: 13px; }
.admin-user-head img { width: 70px; height: 70px; flex: 0 0 auto; object-fit: cover; border-radius: 16px; }
.admin-user-head > div { min-width: 0; }
.admin-user-head h2 { margin: 2px 0; }
.admin-user-head p:last-child { margin: 0; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.admin-detail-bio { margin: 14px 0 0; padding: 11px; border: 1px solid var(--line); border-radius: 11px; color: var(--muted-strong); background: var(--surface-soft); line-height: 1.5; overflow-wrap: anywhere; }
.admin-detail-status { margin-top: 16px; }
.admin-detail-stats { margin-top: 9px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.admin-detail-stats > div { min-width: 0; min-height: 70px; padding: 10px; display: flex; flex-direction: column; justify-content: space-between; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-soft); }
.admin-detail-stats strong { font-size: 21px; }
.admin-detail-stats span { color: var(--muted); font-size: 10px; }
.admin-action-section { margin-top: 14px; padding-top: 14px; display: grid; gap: 8px; border-top: 1px solid var(--line); }
.admin-action-section > strong { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.admin-detail-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.admin-detail-actions.account-actions { margin-top: 2px; }
.admin-action-section.troll-mode { border-top-color: color-mix(in srgb, var(--danger) 34%, var(--line)); }

.admin-effect-overlay { position: fixed; inset: 0; z-index: 140; padding: 18px; display: none; place-items: center; pointer-events: none; }
.admin-effect-overlay.active { display: grid; }
.admin-effect-card { width: min(430px, calc(100vw - 32px)); padding: 24px; border: 1px solid var(--line); border-radius: 18px; text-align: center; background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: var(--shadow-lg); backdrop-filter: blur(10px); animation: adminEffectPop 240ms var(--ease); }
.admin-effect-card h2 { margin: 5px 0 7px; }
.admin-effect-card p:last-child { margin: 0; color: var(--muted-strong); line-height: 1.5; }
.admin-effect-overlay.effect-red { background: rgba(210, 31, 60, .28); animation: adminRedWash 760ms ease-in-out infinite; }
.admin-effect-overlay.effect-confetti .admin-effect-card { border-color: color-mix(in srgb, var(--success) 40%, var(--line)); }
.admin-effect-overlay.effect-shake .admin-effect-card { border-color: color-mix(in srgb, var(--warning) 44%, var(--line)); }
.admin-effect-overlay.effect-focus { background: rgba(12, 20, 36, .38); backdrop-filter: blur(3px); }
body.admin-effect-red-pulse::before { content: ""; position: fixed; inset: 0; z-index: 139; pointer-events: none; background: rgba(228, 43, 70, .18); animation: adminRedWash 760ms ease-in-out infinite; }
html.admin-effect-shake body { animation: adminShake 260ms ease-in-out infinite; }

/* Task-based assessments and subject editing */
.subject-card-actions { margin-left: auto; display: flex; gap: 6px; }

/* Feature layout refinements */
#subjectsView .subject-grid {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scroll-snap-type: x proximity;
  padding: 2px 2px 12px;
  scrollbar-width: thin;
}
#subjectsView .subject-card {
  flex: 0 0 clamp(230px, 31vw, 330px);
  scroll-snap-align: start;
}
.subject-grade-editor { padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-soft); }
.subject-grade-editor-head > div { display: grid; gap: 3px; }
.subject-grade-editor-head small, .manual-grade-row small { color: var(--muted); }
.manual-grade-list { max-height: 220px; margin: 12px 0; display: grid; gap: 7px; overflow: auto; }
.manual-grade-row { padding: 9px 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.manual-grade-row > div { min-width: 0; display: grid; gap: 2px; }
.manual-grade-add { display: grid; grid-template-columns: 90px minmax(130px, 1fr) auto; gap: 7px; }

#gradesView .grades-workspace {
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, .55fr);
  grid-template-areas: "grades side" "tasks side";
  align-items: start;
}
#gradesView .grades-list-panel { grid-area: grades; position: static; max-height: none; }
#gradesView .grade-task-overview { grid-area: tasks; min-width: 0; }
#gradesView .grades-side-stack { grid-area: side; }
#gradesView .grade-task-sections { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
#gradesView .grade-task-sections .task-section + .task-section { margin: 0; padding: 0; border-top: 0; border-left: 1px solid var(--line); padding-left: 16px; }
#gradesView .grade-task-sections .task-list { max-height: 430px; overflow: auto; }

.group-chat-row { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; justify-content: initial; padding: 11px; }
.group-chat-avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; color: var(--primary); background: var(--primary-soft); font-weight: 900; }
.group-chat-copy { min-width: 0; display: grid; gap: 3px; }
.group-chat-copy strong, .group-chat-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-chat-arrow { color: var(--muted); font-size: 24px; }

#adminView.view.active { overflow: auto; gap: 18px; }
#adminView .admin-metrics { grid-template-columns: repeat(4, minmax(180px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 3px; }
#adminView .admin-metric { min-height: 132px; padding: 18px; }
#adminView .admin-operations-grid { grid-template-columns: repeat(3, minmax(260px, 1fr)); gap: 16px; overflow-x: auto; }
#adminView .admin-operations-grid > .panel { min-height: 260px; padding: 20px; }
#adminView .admin-workspace { min-height: auto; grid-template-columns: minmax(520px, 1.3fr) minmax(390px, .7fr); gap: 16px; align-items: start; }
#adminView .admin-users-panel, #adminView .admin-side-stack > .panel { overflow: visible; padding: 20px; }
#adminView .admin-list { max-height: 620px; }
#adminView .admin-side-stack { grid-template-rows: none; gap: 16px; }

@media (max-width: 820px) {
  #subjectsView .subject-card { flex-basis: min(82vw, 310px); }
  .manual-grade-add { grid-template-columns: 1fr; }
  #gradesView .grades-workspace { display: grid; grid-template-columns: 1fr; grid-template-areas: "grades" "tasks" "side"; }
  #gradesView .grade-task-sections { grid-template-columns: 1fr; }
  #gradesView .grade-task-sections .task-section + .task-section { margin-top: 14px; padding: 14px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  #adminView .admin-workspace { grid-template-columns: 1fr; }
}
.round-action.edit-action::before { content: ""; width: 15px; height: 15px; background: var(--primary); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L8 18l-4 1 1-4z'/%3E%3C/svg%3E") center/contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L8 18l-4 1 1-4z'/%3E%3C/svg%3E") center/contain no-repeat; }
.subject-form-actions > * { flex: 1; }
.task-form { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.task-form input[name="title"] { grid-column: span 4; }
.task-form select[name="subjectId"], .task-form select[name="type"], .task-form input[name="dueDate"], .task-form input[name="effort"] { grid-column: span 2; }
.task-form input[name="gradeCount"], .task-form select[name="priority"] { grid-column: span 2; }
.task-test-toggle { grid-column: span 5; min-height: 42px; padding: 8px 10px; display: flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.task-test-toggle input { width: 18px; min-height: 18px; accent-color: var(--primary); }
.task-form > .primary-btn { grid-column: span 3; }
.assessment-badge, .test-pending-badge { padding: 3px 7px; border-radius: 99px; color: var(--primary); background: var(--primary-soft); font-weight: 750; }
.test-pending-badge { color: var(--warning); background: var(--warning-soft); }
.grade-flow-info p:last-child { margin-bottom: 0; color: var(--muted); line-height: 1.6; }

.assessment-overlay { position: fixed; inset: 0; z-index: 98; padding: 18px; display: none; place-items: center; background: rgba(8, 14, 25, .62); backdrop-filter: blur(6px); }
.assessment-overlay.open { display: grid; }
.assessment-card { width: min(540px, 100%); max-height: calc(100dvh - 36px); padding: 23px; overflow: auto; border: 1px solid var(--line); border-radius: 19px; background: var(--surface); box-shadow: var(--shadow-md); animation: dialogIn 190ms var(--ease); }
.assessment-card h2 { margin: 4px 0; }
.assessment-card > p:not(.eyebrow) { margin: 0; color: var(--muted); }
.assessment-fields { margin-top: 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.assessment-fields label { display: grid; gap: 5px; }
.assessment-actions { margin-top: 16px; display: flex; justify-content: flex-end; gap: 8px; }

@keyframes viewIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
@keyframes dialogIn { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes statusPulse { 50% { opacity: .35; } }
@keyframes adminEffectPop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes adminRedWash { 50% { background-color: rgba(228, 43, 70, .42); } }
@keyframes adminShake { 0%, 100% { transform: translate(0, 0); } 25% { transform: translate(3px, -2px); } 50% { transform: translate(-2px, 2px); } 75% { transform: translate(2px, 1px); } }

[data-density="compact"] .panel { padding: 14px; }
[data-density="compact"] .task-card, [data-density="compact"] .insight-card, [data-density="compact"] .activity-item { padding: 9px 10px; }
[data-density="compact"] .dashboard-grid, [data-density="compact"] .content-grid, [data-density="compact"] .social-workspace { gap: 9px; }

@media (max-width: 1280px) {
  .top-actions .search-box { min-width: 170px; width: 190px; }
  .top-actions #quickAddToggle, .top-actions #focusModeBtn { font-size: 0; width: 40px; padding: 0; }
  .top-actions #quickAddToggle::after { content: "+"; font-size: 20px; }
  .top-actions #focusModeBtn::after { content: "F"; font-size: 13px; }
  .dashboard-grid { grid-template-columns: minmax(340px, 1.4fr) repeat(3, minmax(110px, .5fr)); }
}

@media (max-width: 1060px) {
  :root { --sidebar: 204px; }
  .main { padding-inline: 18px; }
  .topbar { align-items: flex-start; }
  .top-actions { max-width: 650px; flex-wrap: wrap; }
  .top-actions .search-box { order: 5; width: 100%; }
  .dashboard-grid { grid-template-columns: repeat(3, 1fr); }
  .hero-panel { grid-column: 1 / -1; min-height: 130px; }
  .content-grid.two.dashboard-section.active, .command-grid { grid-template-columns: 1fr; }
  .reward-workspace { grid-template-columns: 1fr; }
  .reward-side { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .reward-side > h4 { grid-column: 1/-1; }
  .reward-tip { margin: 0; }
  .social-workspace { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .social-chat-panel { grid-column: 1 / -1; }
  .chat-box { max-height: 420px; }
}

@media (max-width: 820px) {
  .admin-operations-grid { grid-template-columns: 1fr 1fr; }
  .admin-live-panel { grid-column: 1 / -1; }
  .support-ticket-form { grid-template-columns: 1fr; }
  .support-ticket-form label:nth-child(3) { grid-column: auto; }
  body { padding-bottom: 69px; }
  .app-shell { display: block; min-height: auto; }
  .sidebar { position: fixed; inset: auto 0 0; z-index: 60; width: 100%; height: 69px; padding: 7px 10px max(7px, env(safe-area-inset-bottom)); display: block; border: 0; border-top: 1px solid var(--line); box-shadow: 0 -8px 28px rgba(20,35,60,.08); }
  .sidebar > .brand, .sidebar > .level-card { display: none; }
  .nav { height: 100%; display: flex; align-items: stretch; gap: 3px; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-item { min-width: 76px; min-height: 52px; padding: 5px 7px; flex: 1 0 76px; flex-direction: column; justify-content: center; gap: 3px; border-radius: 10px; font-size: 10px; }
  .nav-item:hover { transform: none; }
  .nav-item.active::after { display: none; }
  .nav-item .nav-icon { width: 19px; height: 19px; }
  .main { padding: 14px 14px 24px; }
  .topbar { min-height: auto; align-items: center; flex-wrap: wrap; gap: 10px; }
  .topbar > div:first-child { flex: 1; }
  .top-actions { max-width: none; width: auto; flex-wrap: nowrap; }
  .top-actions .search-box { position: absolute; left: 14px; right: 14px; top: 76px; width: auto; order: initial; }
  .topbar { margin-bottom: 64px; }
  .top-actions #quickAddToggle, .top-actions #focusModeBtn, .top-actions #smartPickBtn, .top-actions .mini-profile span { display: none; }
  .mini-profile { padding-right: 4px; }
  .dashboard-grid { grid-template-columns: repeat(3, 1fr); }
  .metric-card { min-height: 116px; }
  .split-layout, .content-grid.two, .profile-settings-grid { grid-template-columns: 1fr; }
  .grades-workspace { grid-template-columns: 1fr; }
  .grades-list-panel { position: static; max-height: none; overflow: visible; }
  .calendar-controls { justify-content: flex-start; }
  #profileView .profile-settings-grid > * { grid-column: 1 / -1; }
  .form-panel { position: static; }
  .task-board { grid-template-columns: repeat(3, minmax(230px, 1fr)); overflow-x: auto; }
  .task-form { grid-template-columns: 1fr 1fr; }
  .task-form > :first-child { grid-column: 1 / -1; }
  .task-form input[name="effort"], .task-form select[name="priority"] { display: block; }
  .profile-hero { grid-template-columns: 1fr; }
  .landing-hero { grid-template-columns: 1fr; }
  .landing-copy { text-align: center; }
  .landing-copy > p, .landing-copy h1 { margin-left: auto; margin-right: auto; }
  .landing-copy .landing-actions { justify-content: center; }
  .landing-preview { width: min(520px, 100%); margin: auto; transform: none; }
}

@media (max-width: 620px) {
  .admin-operations-grid { grid-template-columns: 1fr; }
  .admin-live-panel { grid-column: auto; }
  .admin-ticket, .admin-trash-row { align-items: flex-start; flex-direction: column; }
  body { font-size: 14px; }
  .landing-page { padding: 16px 14px 24px; gap: 32px; }
  .landing-nav .brand span { display: none; }
  .landing-nav .ghost-btn { display: none; }
  .landing-copy h1 { font-size: clamp(40px, 13vw, 58px); }
  .landing-features { grid-template-columns: 1fr; }
  .main { padding: 11px 10px 20px; }
  .topbar { padding-bottom: 10px; }
  .topbar h1 { font-size: 22px; }
  .topbar .eyebrow { display: none; }
  .top-actions #cloudStatusBtn { width: 40px; padding: 0 !important; color: transparent; font-size: 0; }
  .cloud-status::before { left: 16px; }
  .panel { padding: 14px; border-radius: 14px; }
  .dashboard-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
  .hero-panel { padding: 17px; display: grid; gap: 14px; }
  .hero-panel h2 { font-size: 25px; }
  .hero-panel .primary-btn { width: fit-content; }
  .metric-card { min-height: 104px; padding: 12px; }
  .metric-card > span { font-size: 10px; }
  .metric-card strong { font-size: 28px; }
  .metric-card small { font-size: 10px; }
  .dashboard-tabs { width: 100%; overflow-x: auto; }
  .dashboard-tabs button { flex: 1 0 auto; }
  .panel-head, .settings-head { align-items: flex-start; }
  .toolbar-row, .settings-save-row { align-items: stretch; flex-direction: column; }
  .search-box.wide { width: 100%; }
  .form-row { flex-direction: column; }
  .task-form { grid-template-columns: 1fr; }
  .task-form > :first-child { grid-column: auto; }
  .task-card { grid-template-columns: 6px minmax(0, 1fr); }
  .task-actions { grid-column: 2; justify-content: flex-end; }
  .grade-row { grid-template-columns: 1fr auto; }
  .grade-row > :last-child { grid-column: 1/-1; }
  .momentum-ring { grid-template-columns: 1fr; justify-items: center; }
  .social-workspace { grid-template-columns: 1fr; }
  .social-chat-panel { grid-column: auto; }
  .chat-box { min-height: 310px; }
  .reward-side { grid-template-columns: 1fr; }
  .reward-side > h4 { grid-column: auto; }
  .reward-mission { grid-template-columns: 52px minmax(0, 1fr); }
  .reward-mission-action { grid-column: 2; }
  .profile-hero { padding: 14px; gap: 14px; }
  .profile-identity { padding: 0 0 0 2px; align-items: center; }
  .profile-identity img { width: 60px; height: 60px; border-radius: 14px; }
  .profile-identity h2 { font-size: 23px; }
  .profile-level-progress { grid-template-columns: 1fr; gap: 4px; }
  .profile-level-progress small { white-space: normal; }
  .profile-quick-stats { padding: 0; grid-template-columns: repeat(4, 1fr); gap: 5px; }
  .profile-quick-stats div { min-width: 0; min-height: 64px; padding: 8px 6px; }
  .profile-quick-stats strong { font-size: 19px; }
  .settings-form-grid { grid-template-columns: 1fr; }
  .settings-span { grid-column: auto; }
  .data-tools > * { flex: 1 1 calc(50% - 8px); justify-content: center; }
  .auth-card, .setup-card, .focus-card, .profile-preview-card { padding: 20px; border-radius: 17px; }
  .focus-timer { font-size: 68px; }
  .tour-card { right: 10px; bottom: 79px; width: calc(100% - 20px); }
  .toast { bottom: 82px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }

/* Profile workspace v2: intentionally independent from the retired hero layout. */
#profileView .profile-workspace {
  width: min(1180px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 278px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

#profileView .profile-overview {
  position: sticky;
  top: 0;
  min-width: 0;
  margin: 0;
  padding: 18px;
  overflow: hidden;
}

#profileView .profile-overview::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
}

#profileView .profile-overview-head {
  min-width: 0;
  display: grid;
  justify-items: start;
  gap: 12px;
}

#profileView .profile-avatar {
  width: 68px;
  height: 68px;
  display: block;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--primary-soft);
}

#profileView .profile-overview-copy {
  width: 100%;
  min-width: 0;
}

#profileView .profile-overview-copy h2 {
  max-width: 100%;
  margin: 3px 0 2px;
  overflow: hidden;
  font-size: 23px;
  line-height: 1.18;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#profileView .profile-overview-copy > span {
  display: block;
  max-width: 100%;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

#profileView .profile-progress {
  margin-top: 18px;
  padding: 12px;
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
}

#profileView .profile-progress-label {
  min-width: 0;
  display: grid;
  gap: 2px;
}

#profileView .profile-progress-label strong { font-size: 12px; }
#profileView .profile-progress-label small { line-height: 1.35; overflow-wrap: anywhere; }

#profileView .profile-stats {
  margin-top: 9px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

#profileView .profile-stats > div {
  min-width: 0;
  min-height: 68px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
}

#profileView .profile-stats strong {
  overflow: hidden;
  color: var(--text-strong);
  font-size: 21px;
  line-height: 1.1;
  text-overflow: ellipsis;
}

#profileView .profile-stats span {
  color: var(--muted);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: .06em;
  text-transform: uppercase;
}

#profileView .profile-overview-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

#profileView .profile-content {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
}

#profileView .profile-content > * {
  min-width: 0;
  grid-column: auto;
}

#profileView .profile-content > .profile-public-card,
#profileView .profile-content > .profile-privacy-card,
#profileView .profile-content > .profile-data-card {
  grid-column: 1 / -1;
}

#profileView .settings-card {
  min-width: 0;
  height: 100%;
  margin: 0;
  padding: 18px;
  overflow: visible;
}

#profileView .settings-head {
  min-width: 0;
  align-items: flex-start;
  flex-wrap: wrap;
}

#profileView .settings-head > div { min-width: 0; }
#profileView .settings-head h3 { margin-top: 2px; line-height: 1.25; }
#profileView .settings-head .soft-badge { flex: 0 0 auto; }

#profileView .settings-form-grid,
#profileView .settings-form-grid label,
#profileView .settings-toggles label,
#profileView .settings-toggles span {
  min-width: 0;
}

#profileView .settings-form-grid label,
#profileView .settings-toggles strong,
#profileView .settings-toggles small,
#profileView .settings-save-row small {
  line-height: 1.4;
  overflow-wrap: anywhere;
}

#profileView .profile-privacy-card .settings-toggles {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

#profileView .profile-privacy-card .settings-toggles > label {
  align-items: flex-start;
}

#profileView .profile-data-card .data-tools { align-items: center; }

@media (max-width: 1080px) {
  #profileView .profile-workspace { grid-template-columns: 230px minmax(0, 1fr); }
  #profileView .profile-content { grid-template-columns: 1fr; }
  #profileView .profile-content > * { grid-column: 1 / -1; }
  #profileView .profile-privacy-card .settings-toggles { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  #profileView .profile-workspace { grid-template-columns: 1fr; }
  #profileView .profile-overview { position: static; }
  #profileView .profile-overview-head { grid-template-columns: auto minmax(0, 1fr); align-items: center; }
  #profileView .profile-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  #profileView .profile-overview,
  #profileView .settings-card { padding: 14px; }
  #profileView .profile-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #profileView .settings-form-grid { grid-template-columns: 1fr; }
  #profileView .settings-span { grid-column: auto; }
  #profileView .settings-save-row { align-items: stretch; flex-direction: column; }
  #profileView .settings-save-row .primary-btn { width: 100%; }
  #profileView .data-tools > * { flex-basis: 100%; }
}

/* Dashboard height guard: keep the lower panels from becoming tiny scroll boxes
   on shorter desktop viewports, browser zoom, or compact laptop screens. */
#dashboardView.view.active {
  display: block;
  min-height: 0;
  overflow: auto;
}

#dashboardView .dashboard-grid {
  grid-template-columns: minmax(280px, 1fr) repeat(3, minmax(108px, 136px));
  gap: 10px;
  margin-bottom: 10px;
}

#dashboardView .hero-panel {
  min-height: 112px;
  padding: 16px 18px;
  gap: 16px;
}

#dashboardView .hero-panel h2 {
  max-width: 560px;
  font-size: clamp(21px, 1.8vw, 28px);
  line-height: 1.12;
}

#dashboardView .hero-panel p:last-child {
  max-width: 580px;
  font-size: 13px;
}

[data-dashboard-header="compact"] #dashboardView .hero-panel {
  min-height: 76px;
  padding: 10px 14px;
}

[data-dashboard-header="compact"] #dashboardView .hero-panel h2 {
  font-size: clamp(18px, 1.35vw, 23px);
}

[data-dashboard-header="compact"] #dashboardView .hero-panel p:last-child {
  font-size: 12px;
  line-height: 1.35;
}

#dashboardView .metric-card {
  min-height: 112px;
  padding: 14px;
}

#dashboardView .metric-card strong {
  font-size: 29px;
}

#dashboardView .dashboard-tabs {
  margin-bottom: 10px;
}

#dashboardView .dashboard-section.active,
#dashboardView .dashboard-section.active .panel {
  height: auto;
  min-height: 0;
  overflow: visible;
}

#dashboardView .content-grid.two.dashboard-section.active {
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  align-items: start;
}

#dashboardView .dashboard-section.active .task-list,
#dashboardView .dashboard-section.active .subject-progress-list,
#dashboardView .dashboard-section.active .focus-timeline,
#dashboardView .dashboard-section.active .risk-list,
#dashboardView .dashboard-section.active .load-bars,
#dashboardView .dashboard-section.active .activity-list,
#dashboardView .dashboard-section.active .insight-list,
#dashboardView .dashboard-section.active .badges {
  max-height: none;
  overflow: visible;
}

@media (max-width: 1180px) {
  #dashboardView .dashboard-grid,
  #dashboardView .content-grid.two.dashboard-section.active {
    grid-template-columns: 1fr;
  }

  #dashboardView .hero-panel {
    display: grid;
  }
}

@media (min-width: 821px) {
  #dashboardView.view.active {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
  }

  #dashboardView .dashboard-section.active {
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }

  #dashboardView .content-grid.dashboard-section.active,
  #dashboardView .content-grid.two.dashboard-section.active,
  #dashboardView .command-grid.dashboard-section.active {
    min-height: 0;
    height: 100%;
    align-items: stretch;
  }

  #dashboardView .dashboard-section.active > .panel,
  #dashboardView .dashboard-section.active .panel {
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  #dashboardView .dashboard-section.active .panel-head {
    flex: 0 0 auto;
  }

  #dashboardView .dashboard-section.active .task-list,
  #dashboardView .dashboard-section.active .subject-progress-list,
  #dashboardView .dashboard-section.active .focus-timeline,
  #dashboardView .dashboard-section.active .risk-list,
  #dashboardView .dashboard-section.active .load-bars,
  #dashboardView .dashboard-section.active .activity-list,
  #dashboardView .dashboard-section.active .insight-list,
  #dashboardView .dashboard-section.active .stats-grid,
  #dashboardView .dashboard-section.active .momentum-ring {
    min-height: 0;
    overflow: auto;
    padding-right: 4px;
  }

  #dashboardView .momentum-ring {
    grid-template-columns: minmax(116px, 140px) minmax(0, 1fr);
  }
}

#dashboardView .ring {
  background: conic-gradient(var(--primary) var(--progress, var(--ring, 0%)), var(--line) 0);
}

@media (min-width: 821px) {
  #socialView.view.active {
    height: calc(100dvh - 104px);
    min-height: 0;
    overflow: hidden;
  }

  #socialView .social-workspace {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(230px, .8fr) minmax(240px, .85fr) minmax(360px, 1.35fr);
    gap: 12px;
    align-items: stretch;
    overflow: hidden;
  }

  #socialView .social-column {
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  #socialView .social-column > .panel-head,
  #socialView .social-column > form,
  #socialView .social-column > .chat-toolbar,
  #socialView .social-column > .chat-image-preview,
  #socialView .social-column > .chat-form {
    flex: 0 0 auto;
  }

  #socialView .search-results,
  #socialView .relationship-list,
  #socialView .friends-grid,
  #socialView .group-chat-list,
  #socialView .social-notifications {
    min-height: 0;
    overflow: auto;
    padding-right: 4px;
  }

  #socialView .search-results {
    max-height: min(26vh, 240px);
  }

  #socialView .relationship-list {
    max-height: min(23vh, 220px);
  }

  #socialView .friends-grid.social-friends-list {
    flex: 1 1 auto;
    align-content: start;
  }

  #socialView .group-chat-list {
    max-height: min(24vh, 230px);
  }

  #socialView .social-chat-panel {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    gap: 8px;
  }

  #socialView .social-chat-panel > .panel-head,
  #socialView .chat-toolbar,
  #socialView .chat-image-preview,
  #socialView .chat-form {
    margin: 0;
  }

  #socialView .chat-box {
    min-height: 0;
    height: auto;
    max-height: none;
    overflow: auto;
  }

  #socialView .chat-form {
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding-top: 0;
    background: transparent;
  }

  #socialView .chat-form input {
    min-width: 0;
  }

  #tasksView.view.active,
  #calendarView.view.active,
  #gradesView.view.active {
    height: calc(100dvh - 104px);
    min-height: 0;
    overflow: hidden;
  }

  #tasksView > .panel,
  #calendarView > .panel {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  #tasksView > .panel > .panel-head,
  #tasksView > .panel > .toolbar-row,
  #tasksView > .panel > .task-form,
  #calendarView > .panel > .panel-head,
  #calendarView > .panel > .calendar-strip {
    flex: 0 0 auto;
  }

  #tasksView .task-board {
    flex: 0 0 min(34vh, 330px);
    min-height: 0;
    overflow: auto;
  }

  #tasksView .task-list.spacious {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow: auto;
    padding-right: 4px;
  }

  #calendarView .week-grid {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding-right: 4px;
  }

  #calendarView .day-column {
    min-height: 180px;
  }

  #gradesView .grades-workspace {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
  }

  #gradesView .grades-list-panel {
    position: static;
    max-height: none;
    height: 100%;
    min-height: 0;
    overflow: auto;
  }

  #gradesView .grades-side-stack {
    min-height: 0;
    overflow: auto;
    padding-right: 4px;
  }
}

@media (min-width: 821px) {
  #gradesView.view.active {
    height: auto;
    min-height: calc(100dvh - 104px);
    overflow: visible;
  }

  #gradesView .grades-workspace {
    height: auto;
    overflow: visible;
    align-items: start;
  }

  #gradesView .grades-list-panel {
    height: auto;
    max-height: 520px;
  }

  #gradesView .grades-side-stack {
    position: sticky;
    top: 0;
    max-height: calc(100dvh - 112px);
  }
}
/* Account applications */
.application-overlay,
.admin-application-overlay {
  position: fixed;
  inset: 0;
  z-index: 180;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(12, 18, 32, .66);
  backdrop-filter: blur(12px);
}

.application-overlay.open,
.admin-application-overlay.open { display: grid; }

.application-card,
.admin-application-dialog {
  position: relative;
  width: min(620px, 100%);
  max-height: min(860px, 92vh);
  overflow: auto;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: 0 28px 90px rgba(0, 0, 0, .28);
}

.application-close,
.admin-application-close { position: absolute; top: 18px; right: 18px; }
.application-progress { height: 6px; margin: 28px 0 20px; overflow: hidden; border-radius: 99px; background: var(--surface-2); }
.application-progress > div { height: 100%; width: 33.333%; border-radius: inherit; background: var(--primary); transition: width .25s ease; }
.application-step { display: none; gap: 16px; }
.application-step.active { display: grid; }
.application-step > p { margin: -6px 0 6px; color: var(--muted); }
.application-step label,
.admin-application-note { display: grid; gap: 8px; font-weight: 700; }
.application-actions,
.application-status-actions,
.admin-application-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.application-summary { display: grid; gap: 10px; padding: 18px; border-radius: 18px; background: var(--surface-2); }
.application-summary div { display: grid; grid-template-columns: 130px 1fr; gap: 12px; }
.application-summary span { color: var(--muted); }
.application-confirm { display: flex !important; grid-template-columns: auto 1fr; align-items: center; }
#applicationError,
#applicationStatusError { display: block; min-height: 20px; margin-top: 12px; color: var(--danger); }
.application-status-view { text-align: center; }
.application-status-symbol { width: 72px; height: 72px; margin: 10px auto 20px; border-radius: 24px; background: color-mix(in srgb, var(--primary) 16%, transparent); }
.application-status-view[data-status="approved"] .application-status-symbol { background: color-mix(in srgb, #19a974 20%, transparent); }
.application-status-view[data-status="rejected"] .application-status-symbol { background: color-mix(in srgb, var(--danger) 18%, transparent); }
.application-rejection { margin: 18px 0; padding: 16px; border-radius: 16px; color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
#applicationActivationForm { margin-top: 24px; text-align: left; }

.admin-application-panel { grid-column: 1 / -1; }
.admin-application-list { display: grid; gap: 10px; }
.admin-application-row { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; padding: 14px 16px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface-2); text-align: left; }
.admin-application-row small { display: block; margin-top: 4px; color: var(--muted); }
.admin-application-state { padding: 6px 10px; border-radius: 99px; font-size: 12px; font-weight: 800; background: color-mix(in srgb, var(--primary) 12%, transparent); }
.admin-application-state.approved { color: #16845e; background: rgba(22, 132, 94, .12); }
.admin-application-state.rejected { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.admin-application-details { display: grid; gap: 12px; margin: 20px 0; }
.admin-application-details div { display: grid; grid-template-columns: 140px 1fr; gap: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.admin-application-details span { color: var(--muted); }

.application-demo-banner { display: none; }
body.readonly-demo .application-demo-banner {
  position: fixed;
  z-index: 160;
  top: 14px;
  left: 50%;
  display: flex;
  width: min(760px, calc(100% - 28px));
  transform: translateX(-50%);
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 14px 12px 18px;
  border: 1px solid color-mix(in srgb, var(--primary) 34%, var(--border));
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 16px 50px rgba(0, 0, 0, .18);
}
body.readonly-demo .application-demo-banner div { display: grid; gap: 2px; }
body.readonly-demo .application-demo-banner span { color: var(--muted); font-size: 13px; }
body.readonly-demo .quick-add-panel,
body.readonly-demo #quickAddToggle,
body.readonly-demo #focusModeBtn,
body.readonly-demo #smartPickBtn { display: none !important; }
body.readonly-demo form:not(#applicationActivationForm) { opacity: .62; }

@media (max-width: 700px) {
  .application-overlay, .admin-application-overlay { padding: 0; align-items: end; }
  .application-card, .admin-application-dialog { max-height: 94dvh; padding: 26px 20px; border-radius: 26px 26px 0 0; }
  .application-step .form-row { grid-template-columns: 1fr; }
  .application-summary div, .admin-application-details div { grid-template-columns: 1fr; gap: 4px; }
  body.readonly-demo .application-demo-banner { top: 8px; align-items: flex-start; }
  body.readonly-demo .application-demo-banner span { display: none; }
}
