:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --ink: #17212b;
  --muted: #657384;
  --line: #d7dde5;
  --accent: #236b5d;
  --accent-strong: #154c43;
  --accent-soft: #d9ebe7;
  --warn: #b25b12;
  --warn-soft: #fff0dd;
  --danger: #a83737;
  --danger-soft: #fde7e7;
  --blue: #2e5f9f;
  --blue-soft: #e2ecf8;
  --shadow: 0 18px 48px rgba(31, 43, 55, 0.12);
  --radius: 8px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

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

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

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(140deg, rgba(35, 107, 93, 0.16), transparent 42%),
    var(--bg);
}

.login-card {
  display: grid;
  gap: 18px;
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.login-card h1 {
  margin: 0;
  font-size: 1.85rem;
  letter-spacing: 0;
}

.login-copy,
.login-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.login-card .form-alert {
  margin: 0;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  background: #26323f;
  color: #f8fafc;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: #e6b655;
  color: #19212a;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.sidebar-note span {
  margin-top: 2px;
  color: #c8d1dd;
  font-size: 0.86rem;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 12px;
  background: transparent;
  color: #dbe4ef;
  text-align: left;
}

.nav-item span {
  display: grid;
  place-items: center;
  width: 24px;
  color: #e6b655;
}

.nav-item:hover,
.nav-item:focus-visible,
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  outline: none;
}

.sidebar-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.07);
}

.sidebar-note strong {
  display: block;
  margin-top: 8px;
  font-size: 0.92rem;
}

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

.topbar,
.section-toolbar,
.panel-header,
.modal-header,
.modal-actions,
.item-name,
.activity-row,
.risk-row,
.school-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  min-height: 68px;
  margin-bottom: 24px;
}

.topbar h1,
.section-toolbar h2,
.panel h2,
.modal h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(1.65rem, 2vw, 2.2rem);
}

.section-toolbar {
  margin-bottom: 16px;
}

.section-toolbar h2,
.panel h2,
.modal h2 {
  font-size: 1.08rem;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.current-user {
  display: grid;
  min-height: 40px;
  justify-items: end;
  color: var(--muted);
  font-size: 0.78rem;
}

.current-user strong {
  color: var(--ink);
  font-size: 0.88rem;
}

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

.section-help {
  margin: -6px 0 16px;
  color: var(--muted);
  font-size: 0.88rem;
}

.language-toggle {
  display: inline-flex;
  min-height: 40px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.language-option {
  min-width: 44px;
  border: 0;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 850;
}

.language-option:hover,
.language-option:focus-visible {
  background: #f3f6f9;
  color: var(--ink);
  outline: none;
}

.language-option.active {
  background: var(--accent);
  color: #ffffff;
}

.primary-action,
.secondary-action,
.text-action,
.icon-button,
.table-action {
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 750;
}

.primary-action {
  background: var(--accent);
  color: #ffffff;
}

.primary-action:hover,
.primary-action:focus-visible {
  background: var(--accent-strong);
  outline: none;
}

.secondary-action {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.secondary-action:hover,
.secondary-action:focus-visible,
.icon-button:hover,
.icon-button:focus-visible,
.table-action:hover,
.table-action:focus-visible {
  border-color: #aeb9c7;
  background: #f3f6f9;
  outline: none;
}

.table-action.danger {
  color: var(--danger);
}

.table-action.danger:hover,
.table-action.danger:focus-visible {
  border-color: #e4aaaa;
  background: var(--danger-soft);
}

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

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  padding: 0;
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.2rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.metric {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--surface);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 1.65rem;
  line-height: 1;
}

.metric em {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-style: normal;
}

.dashboard-grid,
.reports-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  gap: 18px;
}

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

.panel-header {
  min-height: 70px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.risk-list,
.activity-list,
.report-list,
.category-report {
  display: grid;
}

.risk-row,
.activity-row,
.report-row,
.category-row {
  min-height: 72px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.risk-row:last-child,
.activity-row:last-child,
.report-row:last-child,
.category-row:last-child {
  border-bottom: 0;
}

.risk-row strong,
.activity-row strong,
.report-row strong,
.school-card strong {
  display: block;
}

.risk-row span,
.activity-row span,
.report-row span,
.school-card span,
.item-name span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
}

.stock-meter {
  position: relative;
  width: 130px;
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5eaf0;
}

.stock-meter i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--danger);
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 190px 180px;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.role-search-panel {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto;
  align-items: end;
  gap: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--surface);
  box-shadow: 0 4px 12px rgba(31, 43, 55, 0.06);
}

.role-search-panel label {
  grid-template-columns: 230px minmax(220px, 360px);
  align-items: center;
  color: var(--ink);
}

.danger-lite {
  border-color: #d9aaaa;
  background: #b32d2d;
  color: #ffffff;
}

.danger-lite:hover,
.danger-lite:focus-visible {
  border-color: #9d2424;
  background: #9d2424;
  color: #ffffff;
}

.add-action {
  background: #3d8424;
}

.search-action {
  background: #3e91d8;
  color: #ffffff;
}

.simple-list-table tr:nth-child(even),
.permission-table tr:nth-child(even) {
  background: #f1f1f1;
}

.role-link {
  border: 0;
  padding: 0;
  background: transparent;
  color: #348bd8;
  font-weight: 650;
  text-decoration: underline;
}

.role-editor-panel {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--surface);
  box-shadow: 0 4px 12px rgba(31, 43, 55, 0.06);
}

.role-name-row {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.permission-table-wrap {
  max-height: 520px;
}

.permission-table {
  min-width: 960px;
}

.permission-table th,
.permission-table td {
  text-align: center;
}

.permission-table th:nth-child(2),
.permission-table td:nth-child(2) {
  text-align: left;
}

.permission-table input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.matrix-check {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: inherit;
  font-size: inherit;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cbd3dd;
  border-radius: var(--radius);
  padding: 0 12px;
  background: #ffffff;
  color: var(--ink);
}

textarea {
  min-height: 88px;
  padding-top: 10px;
  resize: vertical;
}

.checkbox-field {
  grid-template-columns: auto 1fr;
  align-items: center;
  justify-content: start;
  min-height: 42px;
  color: var(--ink);
}

.checkbox-field input {
  width: 18px;
  min-height: 18px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(35, 107, 93, 0.16);
  outline: none;
}

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

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f5f7fa;
  color: #4b5a69;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #fbfcfe;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.item-name {
  justify-content: flex-start;
}

.item-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 850;
}

.qty-cell {
  font-weight: 850;
}

.actions-col {
  width: 210px;
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.table-action {
  min-height: 34px;
  padding: 0 10px;
  border-color: var(--line);
  background: #ffffff;
  color: #26323f;
  font-size: 0.85rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.badge.ok {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.badge.low,
.badge.out {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.neutral {
  background: #e9edf2;
  color: #4b5a69;
}

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

.school-card {
  min-height: 156px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--surface);
}

.school-code {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  background: #f2e6c7;
  color: #624913;
  font-weight: 850;
}

.school-meta {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.school-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.report-row,
.category-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

.category-bar {
  display: grid;
  gap: 8px;
}

.category-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6ebf1;
}

.category-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.modal {
  width: min(720px, calc(100vw - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  background: transparent;
}

.modal::backdrop {
  background: rgba(18, 27, 38, 0.48);
}

.modal-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-header {
  min-height: 72px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

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

.wide-field {
  grid-column: 1 / -1;
}

.modal-actions {
  justify-content: flex-end;
  padding: 16px 18px 18px;
  border-top: 1px solid var(--line);
}

.form-alert {
  display: none;
  margin: 0 18px 12px;
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 750;
}

.form-alert.active {
  display: block;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 5;
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  border-radius: var(--radius);
  padding: 12px 14px;
  background: #17212b;
  color: #ffffff;
  box-shadow: var(--shadow);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

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

.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 4;
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 16px;
  }

  .nav-list {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
  }

  .sidebar-note {
    display: none;
  }

  .workspace {
    padding: 20px;
  }

  .metrics-grid,
  .dashboard-grid,
  .reports-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar,
  .section-toolbar,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .section-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .primary-action,
  .secondary-action {
    flex: 1 1 auto;
  }

  .metrics-grid,
  .dashboard-grid,
  .reports-grid,
  .filter-bar,
  .role-search-panel,
  .role-name-row,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .role-search-panel label {
    grid-template-columns: 1fr;
  }

  .risk-row,
  .activity-row,
  .report-row,
  .category-row {
    align-items: flex-start;
    grid-template-columns: 1fr;
  }

  .stock-meter {
    width: 100%;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions button {
    width: 100%;
  }
}
