:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --ink: #17222d;
  --muted: #64748b;
  --line: #dde6ee;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --sidebar: #132033;
  --sidebar-hover: #203852;
  --sidebar-text: #d8e4ee;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  margin: 0;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-strong);
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  bottom: 0;
  color: #fff;
  flex-direction: column;
  justify-content: space-between;
  left: 0;
  overflow-y: auto;
  padding: 22px 18px;
  position: fixed;
  top: 0;
  width: 284px;
  z-index: 1040;
}

.sidebar-brand {
  align-items: center;
  color: #fff;
  display: flex;
  gap: 12px;
  padding: 2px 4px 24px;
}

.sidebar-brand:hover,
.mobile-brand:hover,
.auth-brand:hover {
  color: #fff;
}

.sidebar-brand strong,
.mobile-brand,
.auth-brand {
  font-weight: 800;
  letter-spacing: 0;
}

.sidebar-brand small {
  color: #a9bbca;
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  margin-top: 2px;
}

.brand-mark {
  align-items: center;
  background: #16a085;
  border-radius: 8px;
  display: inline-flex;
  flex: 0 0 42px;
  font-size: 1.25rem;
  font-weight: 900;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.sidebar-nav {
  display: grid;
  gap: 6px;
}

.sidebar-nav .nav-link {
  align-items: center;
  border-radius: 8px;
  color: var(--sidebar-text);
  display: flex;
  font-weight: 650;
  gap: 12px;
  min-height: 44px;
  padding: 10px 12px;
}

.sidebar-nav .nav-link i {
  font-size: 1.1rem;
  text-align: center;
  width: 1.25rem;
}

.sidebar-nav .nav-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-nav .nav-link.active {
  background: #e9f7f6;
  color: var(--accent-strong);
}

.sidebar-footer {
  display: grid;
  gap: 12px;
  padding-top: 24px;
}

.user-pill {
  align-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #fff;
  display: flex;
  gap: 10px;
  min-height: 44px;
  overflow: hidden;
  padding: 10px 12px;
}

.user-pill span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-bar {
  align-items: center;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  min-height: 64px;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.mobile-brand {
  color: var(--ink);
}

.mobile-brand:hover {
  color: var(--accent-strong);
}

.sidebar-offcanvas {
  background: var(--sidebar);
  color: #fff;
}

.sidebar-offcanvas .offcanvas-body {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.page {
  margin-left: 284px;
  min-height: 100vh;
  padding: 32px;
}

.auth-page {
  align-content: start;
  display: grid;
  justify-items: center;
  margin-left: 0;
  padding: 48px 16px;
}

.auth-brand {
  background: var(--sidebar);
  border-radius: 8px;
  color: #fff;
  display: inline-flex;
  margin-bottom: 20px;
  padding: 10px 14px;
}

.messages {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}

.alert {
  border-radius: 8px;
}

.dashboard-head,
.summary-grid,
.content-grid {
  margin-bottom: 24px;
}

.dashboard-head {
  align-items: end;
  display: flex;
  gap: 20px;
  justify-content: space-between;
}

.head-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 6px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  font-weight: 850;
  letter-spacing: 0;
  line-height: 1.1;
  margin-bottom: 8px;
}

h2 {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0;
}

.muted {
  color: var(--muted);
}

.btn-primary,
.primary,
.as-link {
  --bs-btn-bg: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent-strong);
  --bs-btn-hover-border-color: var(--accent-strong);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-weight: 750;
  gap: 8px;
  justify-content: center;
  padding: 10px 15px;
}

.primary:hover,
.as-link:hover {
  background: var(--accent-strong);
  color: #fff;
  text-decoration: none;
}

.secondary-link,
.btn-outline-primary {
  --bs-btn-color: var(--accent);
  --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: #e9f7f6;
  --bs-btn-hover-border-color: var(--accent-strong);
  --bs-btn-hover-color: var(--accent-strong);
  background: #fff;
  color: var(--accent);
}

.danger {
  background: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-weight: 750;
  padding: 10px 16px;
}

.btn-danger {
  --bs-btn-bg: var(--danger);
  --bs-btn-border-color: var(--danger);
  --bs-btn-hover-bg: #8f1d14;
  --bs-btn-hover-border-color: #8f1d14;
}

.summary-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.summary-card,
.panel,
.auth-panel,
.form-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(20, 35, 50, 0.06);
}

.summary-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 150px;
  padding: 20px;
}

.summary-card strong {
  font-size: 2.45rem;
  font-weight: 850;
  line-height: 1;
}

.summary-card span {
  color: var(--muted);
}

.summary-card a:not(.btn) {
  font-weight: 750;
  margin-top: auto;
}

.content-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(260px, 0.8fr) minmax(0, 2fr);
}

.panel,
.auth-panel,
.form-panel {
  padding: 24px;
}

.subject-list {
  display: grid;
  gap: 6px;
}

.subject-row {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 9px 0;
}

.subject-row:last-child {
  border-bottom: 0;
}

.student-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.student-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 16px;
  padding: 18px;
}

.student-card h3 {
  font-size: 1.1rem;
  font-weight: 850;
  letter-spacing: 0;
  margin: 0 0 4px;
}

.student-stats {
  display: grid;
  gap: 8px;
  margin: 0;
}

.student-stats div {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding-bottom: 8px;
}

.student-stats div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.student-stats dt {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 750;
}

.student-stats dd {
  font-weight: 750;
  margin: 0;
  text-align: right;
}

.student-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
}

table {
  margin-bottom: 0;
  min-width: 760px;
  width: 100%;
}

.table > :not(caption) > * > * {
  padding: 0.85rem;
}

th {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

td {
  vertical-align: middle;
}

.actions {
  white-space: nowrap;
}

.actions a + a {
  margin-left: 10px;
}

.empty {
  color: var(--muted);
  padding: 32px 16px;
  text-align: center;
}

.auth-panel {
  max-width: 480px;
  width: min(100%, 480px);
}

.register-panel {
  max-width: 620px;
  width: min(100%, 620px);
}

.form-panel {
  margin: 0 auto;
  max-width: 920px;
  width: 100%;
}

.wide-form-panel {
  max-width: 1180px;
}

.compact-panel {
  max-width: 600px;
}

.form-stack,
.entry-form,
.exam-form,
.study-plan-form {
  display: grid;
  gap: 16px;
}

.entry-form,
.exam-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mini-subjects {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.82rem;
  gap: 6px 12px;
  margin-top: 6px;
}

.study-plan-top {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(220px, 2fr) repeat(2, minmax(160px, 1fr));
}

.study-builder,
.study-table-section {
  display: grid;
  gap: 16px;
}

.study-plan-modal .modal-dialog {
  max-width: min(1600px, 96vw);
}

.study-plan-modal .modal-body {
  min-height: min(68vh, 760px);
}

.study-step {
  display: grid;
  gap: 10px;
}

.study-step h2,
.study-table-section h2 {
  margin-bottom: 0;
}

.study-subject-picker {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.study-subject-choice {
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: row;
  font-size: 0.94rem;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
}

.study-subject-choice input {
  min-height: auto;
  width: auto;
}

.study-table-hint {
  background: #f8fafc;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 16px;
  text-align: center;
}

.study-plan-table-wrap {
  overflow-x: auto;
}

.study-plan-matrix {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 900px;
}

.study-plan-matrix th,
.study-plan-matrix td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  min-width: 190px;
  padding: 10px;
  vertical-align: top;
}

.study-plan-matrix thead th {
  background: var(--sidebar);
  color: #fff;
  font-size: 0.84rem;
}

.study-plan-matrix tr > :first-child {
  border-left: 1px solid var(--line);
  left: 0;
  min-width: 140px;
  position: sticky;
  z-index: 1;
}

.study-plan-matrix thead tr > :first-child {
  z-index: 2;
}

.study-plan-matrix tbody th {
  background: #f8fafc;
  color: var(--ink);
}

.study-plan-matrix tbody th span {
  color: var(--muted);
  display: block;
  font-size: 0.78rem;
  margin-top: 3px;
  text-transform: capitalize;
}

.topic-combo {
  display: grid;
  gap: 8px;
}

.topic-combo select,
.topic-combo input {
  min-height: 40px;
}

.study-progress {
  background: #edf2f7;
  height: 10px;
}

.study-progress .progress-bar {
  background: var(--accent);
}

.study-tracking-matrix td {
  background: #fff;
}

.study-tracking-matrix td.is-complete {
  background: #edf8f5;
}

.completion-check {
  align-items: center;
  color: var(--ink);
  display: flex;
  flex-direction: row;
  font-size: 0.9rem;
  gap: 8px;
  margin-bottom: 8px;
}

.completion-check input {
  min-height: auto;
  width: auto;
}

.topic-title {
  display: block;
  font-size: 0.9rem;
  line-height: 1.35;
  margin-bottom: 8px;
}

.completion-note {
  font-size: 0.85rem;
  min-height: 38px;
  padding: 8px 10px;
}

.book-chip {
  align-items: center;
  background: #eef4f7;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: inline-flex;
  font-size: 0.86rem;
  font-weight: 700;
  gap: 8px;
  padding: 6px 8px 6px 10px;
}

.book-chip button {
  align-items: center;
  background: transparent;
  border: 0;
  color: var(--danger);
  cursor: pointer;
  display: inline-flex;
  font-size: 1.1rem;
  font-weight: 800;
  height: 22px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 22px;
}

.book-tracker-matrix td.is-complete {
  background: #edf8f5;
}

.study-subjects {
  display: grid;
  gap: 12px;
}

.study-subjects h2 {
  margin-bottom: 0;
}

.study-subject {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.study-subject.is-selected {
  border-color: rgba(15, 118, 110, 0.45);
}

.study-subject-toggle {
  align-items: center;
  background: #f8fafc;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: row;
  font-size: 1rem;
  gap: 10px;
  min-height: 48px;
  padding: 12px 14px;
}

.study-subject-toggle input {
  min-height: auto;
  width: auto;
}

.study-subject-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.study-subject-body[hidden] {
  display: none;
}

.topic-grid > div {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.topic-grid label {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: row;
  font-size: 0.9rem;
  gap: 8px;
  min-height: 42px;
  padding: 8px 10px;
}

.topic-grid input {
  min-height: auto;
  width: auto;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 0.92rem;
  font-weight: 700;
  gap: 7px;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 44px;
  min-width: 0;
  padding: 10px 12px;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.2rem rgba(15, 118, 110, 0.14);
  outline: 0;
}

textarea {
  resize: vertical;
}

.module-select label {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-direction: row;
  gap: 8px;
}

.module-select select {
  min-width: 190px;
}

.wide,
.form-actions {
  grid-column: 1 / -1;
}

.form-actions,
.inline-actions {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.errorlist {
  color: var(--danger);
  font-size: 0.85rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.entry-form > .errorlist,
.exam-form > .errorlist,
.form-stack > .errorlist {
  grid-column: 1 / -1;
}

@media (max-width: 1199.98px) {
  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 991.98px) {
  .page {
    margin-left: 0;
    padding: 24px 16px 32px;
  }
}

@media (max-width: 820px) {
  .dashboard-head,
  .head-actions,
  .form-actions,
  .inline-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .entry-form,
  .exam-form,
  .study-plan-top {
    grid-template-columns: 1fr;
  }
}
