:root {
  color-scheme: light;
  --ink: #1d252c;
  --muted: #66717c;
  --line: #dfe5e9;
  --panel: #ffffff;
  --paper: #f5f7f4;
  --accent: #176b5b;
  --accent-dark: #0f4c41;
  --amber: #c98321;
  --blue: #396fa8;
  --rose: #b75563;
  --shadow: 0 16px 40px rgba(28, 39, 49, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(23, 107, 91, 0.08), transparent 38%),
    linear-gradient(315deg, rgba(201, 131, 33, 0.12), transparent 34%),
    var(--paper);
  color: var(--ink);
}

body.locked .app-shell {
  display: none;
}

body:not(.locked) .login-screen {
  display: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(430px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-brand {
  margin-bottom: 6px;
}

.login-help {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  padding: 24px 18px;
  backdrop-filter: blur(14px);
}

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

.brand strong {
  display: block;
  font-size: 1.12rem;
}

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

.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 9px);
  gap: 5px;
  align-content: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbf8;
}

.brand-mark span {
  width: 9px;
  height: 26px;
  border-radius: 8px;
}

.brand-mark span:nth-child(1) {
  background: var(--accent);
}

.brand-mark span:nth-child(2) {
  height: 18px;
  background: var(--amber);
}

.brand-mark span:nth-child(3) {
  height: 31px;
  background: var(--blue);
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 10px 12px;
  text-align: left;
}

.nav-tab:hover,
.nav-tab.active {
  background: #e9f1ed;
  color: var(--accent-dark);
}

.icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  font-weight: 700;
}

.sidebar-footer {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.user-box {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.user-box span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.user-box strong {
  overflow-wrap: anywhere;
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.75rem, 3vw, 2.45rem);
  line-height: 1.05;
}

h2 {
  font-size: 1rem;
}

.topbar p {
  margin-top: 8px;
  color: var(--muted);
}

.primary-button,
.secondary-button,
.ghost-button,
.text-button,
.icon-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 14px;
  font-weight: 700;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 20px rgba(23, 107, 91, 0.18);
}

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

.secondary-button,
.ghost-button {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost-button {
  width: 100%;
}

.ghost-button.danger {
  color: #9f2436;
}

.text-button {
  min-height: 32px;
  background: transparent;
  color: var(--accent);
  padding: 4px 0;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: #f3f6f4;
  color: var(--ink);
  font-size: 1.35rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

.metric {
  padding: 18px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
}

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 18px;
}

.panel {
  padding: 18px;
}

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

.panel-subheader {
  margin-top: 20px;
}

.timeline,
.entity-list,
.bars {
  display: grid;
  gap: 12px;
}

.request-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.records {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.summary-card,
.entity-card,
.timeline-item,
.request-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.summary-card,
.request-card {
  display: grid;
  gap: 10px;
}

.request-card.collapsed .chip-row,
.request-card.collapsed .chat-thread,
.request-card.collapsed .chat-reply {
  display: none;
}

.request-card .record-top {
  cursor: pointer;
}

.records .summary-card {
  grid-template-columns: minmax(130px, 0.7fr) minmax(180px, 1fr) minmax(180px, 1fr) minmax(220px, 2fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}

.records .summary-card .record-top {
  display: contents;
}

.records .summary-card .record-title,
.records .summary-card .record-meta,
.records .summary-card .chip-row,
.records .summary-card p {
  min-width: 0;
}

.records .summary-card .chip-row {
  flex-wrap: nowrap;
  overflow: hidden;
}

.records .summary-card .chip {
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.records .summary-card p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.records .summary-card .muted {
  display: none;
}

.record-top,
.entity-top,
.timeline-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.record-title,
.entity-name {
  font-weight: 800;
}

.record-meta,
.entity-meta,
.timeline-meta,
.message-meta,
.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.status-control {
  min-width: 160px;
}

.status-control select {
  padding: 7px 9px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  background: #eef4f1;
  color: var(--accent-dark);
  padding: 4px 10px;
  font-size: 0.84rem;
  font-weight: 700;
}

.chip.amber {
  background: #fff2df;
  color: #84520e;
}

.chip.blue {
  background: #eaf2fb;
  color: #28557f;
}

.chip.rose {
  background: #fff0f2;
  color: #8d2636;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 240px) minmax(180px, 240px);
  gap: 12px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 7px;
}

[data-profile-for] {
  display: none;
}

body[data-role="teacher"] [data-profile-for~="teacher"],
body[data-role="student"] [data-profile-for~="student"] {
  display: grid;
}

label span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

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

.profile-panel {
  max-width: 760px;
}

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

.trash-grid h2 {
  margin-bottom: 12px;
}

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

.entity-card {
  display: grid;
  gap: 10px;
}

.inline-edit {
  display: grid;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.inline-edit[hidden] {
  display: none;
}

.entity-actions,
.record-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.small-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 6px 10px;
  font-weight: 700;
}

.small-button.danger {
  color: #9f2436;
}

.assignment-box {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.associate-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.check-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--ink);
}

.check-pill input {
  width: auto;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(100px, 150px) 1fr 32px;
  align-items: center;
  gap: 10px;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: #edf1ef;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--amber));
}

.chat-thread {
  display: grid;
  gap: 8px;
}

.message {
  display: grid;
  gap: 4px;
  max-width: 92%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
  padding: 9px 10px;
}

.message.own {
  justify-self: end;
  background: #eef4f1;
  border-color: #cfe0da;
}

.message.system {
  justify-self: center;
  max-width: 100%;
  background: #fff8ec;
  border-color: #f0d7ad;
  text-align: center;
}

.message-text {
  line-height: 1.4;
}

.chat-reply {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.empty-state {
  display: grid;
  gap: 4px;
  place-items: center;
  min-height: 150px;
  border: 1px dashed #cbd5d9;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 100;
  transform: translateY(14px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid #bcd8ce;
  border-radius: 8px;
  background: #eef8f4;
  color: var(--accent-dark);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-weight: 800;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

dialog {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.24);
}

dialog::backdrop {
  background: rgba(17, 24, 29, 0.42);
}

.modal {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.modal-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-actions {
  justify-content: flex-end;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.modal-grid.two-columns {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 12px;
  }

  .brand {
    min-width: 170px;
  }

  .nav-tabs {
    display: flex;
    min-width: max-content;
  }

  .sidebar-footer {
    grid-auto-flow: column;
    margin-left: auto;
    min-width: max-content;
  }

  .user-box,
  .sidebar-footer .ghost-button.danger,
  #exportCsv {
    display: none;
  }

  .main {
    padding: 20px;
  }

  .metric-grid,
  .dashboard-layout,
  .split-layout,
  .request-list,
  .trash-grid,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .records .summary-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar,
  .record-top,
  .entity-top,
  .timeline-top,
  .chat-reply,
  .modal-header,
  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .chat-reply {
    display: flex;
  }

  .modal-grid,
  .modal-grid.two-columns {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .nav-tab span:last-child {
    display: none;
  }
}
