:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --panel-2: #eef2f7;
  --text: #172033;
  --muted: #5e687a;
  --line: #d8dee8;
  --accent: #1b6b68;
  --accent-strong: #145451;
  --danger: #b42318;
  --warn: #9a6700;
  --shadow: 0 14px 40px rgba(23, 32, 51, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0 26px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.1;
}

.brand p,
.muted {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.button:hover {
  background: var(--accent-strong);
}

.button.secondary {
  background: var(--panel-2);
  color: var(--text);
}

.button.danger {
  background: var(--danger);
  color: #fff;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card {
  width: min(440px, 100%);
  margin: 46px auto 0;
  padding: 28px;
}

/* ── Password change modal overlay ────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  width: min(440px, 100%);
  padding: 28px;
}

.confirm-card h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.confirm-details {
  display: grid;
  gap: 6px;
  margin: 14px 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.confirm-details div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.86rem;
}

.confirm-details span {
  color: var(--muted);
}

.confirm-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

.login-card h2,
.section h2 {
  margin: 0 0 18px;
  font-size: 1.15rem;
}

.form-grid {
  display: grid;
  gap: 14px;
}

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

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
}

.status {
  min-height: 22px;
  color: var(--muted);
  font-size: 0.92rem;
}

.status.error {
  color: var(--danger);
}

.status.ok {
  color: var(--accent);
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.app-card {
  display: grid;
  align-content: space-between;
  min-height: 156px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.app-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.app-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.app-card.locked {
  background: #f4f6fa;
  color: #6c7586;
}

.badge {
  justify-self: start;
  margin-top: 16px;
  border-radius: 999px;
  padding: 5px 9px;
  background: #ddeeea;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
}

.locked .badge {
  background: #eceff5;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.section {
  padding: 18px;
}

.account-list {
  display: grid;
  gap: 8px;
  max-height: 620px;
  overflow: auto;
}

.account-button {
  display: block;
  width: 100%;
  padding: 11px;
  border-radius: 8px;
  background: #f4f6fa;
  color: var(--text);
  text-align: left;
}

.account-button.active {
  background: #ddeeea;
  outline: 2px solid var(--accent);
}

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 6px;
  text-align: left;
}

.table th {
  color: var(--muted);
  font-size: 0.82rem;
}

.hidden {
  display: none !important;
}

@media (max-width: 760px) {
  .topbar,
  .layout,
  .teacher-layout,
  .split {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .actions {
    justify-content: stretch;
  }

  .button {
    width: 100%;
  }
}

/* ── Apps section labels ───────────────────────────────────────────── */
.apps-section-label {
  margin: 28px 0 12px;
  font-size: 1rem;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

/* ── Profile dropdown ─────────────────────────────────────────────── */
.profile-menu {
  position: relative;
}

.profile-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 100;
  min-width: 200px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.profile-dropdown-header {
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  background: var(--panel-2);
}

.profile-divider {
  margin: 0;
  border: none;
  border-top: 1px solid var(--line);
}

.profile-dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  background: none;
  color: var(--text);
  font-size: 0.9rem;
  border-radius: 0;
}

.profile-dropdown-item:hover {
  background: var(--panel-2);
}

/* ── Change password panel header row ─────────────────────────────── */
.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.panel-title-row h2 {
  margin: 0;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  flex-shrink: 0;
}

.icon-button:hover {
  background: var(--line);
}

/* ── Admin sidebar ────────────────────────────────────────────────── */
.layout {
  grid-template-columns: 360px minmax(0, 1fr);
}

.sidebar {
  padding: 14px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sidebar-title {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.tree-search {
  width: 100%;
  margin-bottom: 10px;
  min-height: 34px;
  font-size: 0.9rem;
}

.sidebar-button {
  width: 100%;
  justify-content: center;
  margin-bottom: 10px;
}

.add-btn {
  background: var(--panel-2);
  font-size: 1.2rem;
  line-height: 1;
  width: 24px;
  height: 24px;
  border-radius: 5px;
  flex-shrink: 0;
}

.add-btn:hover {
  background: #ddeeea;
  color: var(--accent-strong);
}

/* ── Tree ─────────────────────────────────────────────────────────── */
.tree {
  display: grid;
  gap: 2px;
}

.tree-group {
  display: grid;
}

.tree-node {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  width: 100%;
}

.tree-node:hover {
  background: var(--panel-2);
}

.tree-course {
  font-weight: 700;
  font-size: 0.9rem;
}

.tree-period {
  font-size: 0.88rem;
  padding-left: 18px;
}

.tree-account {
  font-size: 0.85rem;
  padding-left: 36px;
  color: var(--muted);
  cursor: pointer;
}

.tree-account:hover {
  color: var(--text);
  background: var(--panel-2);
}

.tree-toggle {
  font-size: 0.6rem;
  color: var(--muted);
  flex-shrink: 0;
  transition: transform 0.15s;
  display: inline-block;
}

.tree-toggle.open {
  transform: rotate(90deg);
}

.tree-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-count {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 400;
  flex-shrink: 0;
}

.tree-add {
  margin-left: auto;
  opacity: 0;
  transition: opacity 0.1s;
}

.tree-node:hover .tree-add {
  opacity: 1;
}

.tree-children {
  display: grid;
  gap: 1px;
}

/* ── Main area ────────────────────────────────────────────────────── */
.main-area {
  padding: 22px;
  min-height: 400px;
}

.main-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.main-form h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

/* ── Compact forms ────────────────────────────────────────────────── */
.form-compact {
  display: grid;
  gap: 12px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  align-items: start;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.form-divider {
  margin: 20px 0;
  border: none;
  border-top: 1px solid var(--line);
}

/* ── Toggle checkboxes ────────────────────────────────────────────── */
.toggle-label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toggle-input {
  appearance: none;
  width: 40px !important;
  height: 22px;
  border-radius: 999px;
  background: var(--line);
  border: none;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
  min-height: unset;
  padding: 0;
}

.toggle-input::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}

.toggle-input:checked {
  background: var(--accent);
}

.toggle-input:checked::after {
  transform: translateX(18px);
}

/* ── Password reveal ──────────────────────────────────────────────── */
.input-reveal {
  display: flex;
  gap: 6px;
}

.input-reveal input {
  flex: 1;
  min-width: 0;
}

.reveal-btn {
  flex-shrink: 0;
  min-width: 58px;
  height: 40px;
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 0.82rem;
  font-weight: 700;
  border: 1px solid var(--line);
}

/* ── Collapsible sections ─────────────────────────────────────────── */
.collapsible {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 12px;
  overflow: hidden;
}

.collapsible summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  background: var(--panel-2);
  list-style: none;
}

.collapsible summary::-webkit-details-marker { display: none; }

.collapsible summary::before {
  content: '▶';
  font-size: 0.6rem;
  color: var(--muted);
  transition: transform 0.15s;
}

.collapsible[open] summary::before {
  transform: rotate(90deg);
}

.collapsible > .form-compact,
.collapsible > form {
  padding: 14px;
}

/* ── Help icon ────────────────────────────────────────────────────── */
.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  cursor: help;
  flex-shrink: 0;
}

/* ── App permissions list ─────────────────────────────────────────── */
.perm-row {
  padding: 5px 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--line);
}

.perm-yes {
  color: var(--accent);
  font-weight: 700;
}

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

/* ── Teacher portal ───────────────────────────────────────────────── */
.teacher-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.teacher-tools {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.teacher-card {
  background: var(--panel-2);
  padding: 14px;
  border: 0;
  box-shadow: none;
}

.teacher-card h3 {
  margin: 0;
  font-size: 0.96rem;
}

textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  resize: vertical;
  color: var(--text);
  font: inherit;
}

.student-list {
  display: grid;
  gap: 10px;
}

.student-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.student-inactive {
  background: #f4f6fa;
}

.student-card-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.student-card-title span {
  color: var(--muted);
  font-size: 0.86rem;
}

.status-badge {
  border-radius: 999px;
  padding: 4px 8px;
  background: #eceff5;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.student-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
}

.student-action-details {
  margin-top: 0;
}

.teacher-action-panel {
  margin-top: 0;
  background: var(--panel);
}

.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: min(100%, 280px);
}

.inline-form input,
.inline-form select {
  min-height: 34px;
}

/* ── App defaults checkboxes ──────────────────────────────────────── */
.app-defaults-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--panel-2);
}

.app-defaults-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.app-defaults-hint {
  font-size: 0.78rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
}

.app-checkbox-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.teacher-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.teacher-picker-item {
  max-width: 100%;
}

.teacher-picker-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-schedule {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 2px;
}

.schedule-chip {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 5px 8px;
}

.audit-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.audit-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
}

.audit-row div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.audit-row div:first-child span {
  color: var(--muted);
  font-size: 0.84rem;
}

.audit-row pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.raw-details {
  margin-top: 8px;
}

.raw-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.app-checkbox-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}

.app-checkbox-item:has(input:checked) {
  border-color: var(--accent);
  background: #ddeeea;
  color: var(--accent-strong);
}

.app-checkbox-item input.app-checkbox {
  appearance: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--line);
  border-radius: 3px;
  background: #fff;
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
  min-height: unset;
  padding: 0;
}

.app-checkbox-item:has(input:checked) input.app-checkbox {
  background: var(--accent);
  border-color: var(--accent);
}

.app-checkbox-item input.app-checkbox:checked::after {
  content: '✓';
  position: absolute;
  top: -2px;
  left: 1px;
  font-size: 11px;
  color: #fff;
  font-weight: 900;
}

.inherited-tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

