:root {
  --ink: #152433;
  --ink-soft: #4a5d70;
  --paper: #e6f0f7;
  --paper-2: #f6fafd;
  --rule: #c5d6e6;
  --sidebar: #0c1c2e;
  --sidebar-2: #16324a;
  --accent: #c46e38;
  --accent-2: #e8c4b0;
  --bad: #b5463a;
  --turn: #c4891a;
  --ok: #2f7a5b;
  --muted: #6a7784;
  --shadow: 0 22px 50px rgba(21, 36, 51, 0.08);
  --sans: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  display: flex;
  flex-direction: column;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(196, 110, 56, 0.12), transparent 55%),
    radial-gradient(900px 420px at 8% 0%, rgba(140, 184, 214, 0.28), transparent 50%),
    var(--paper);
}
.sidebar {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 100;
  background:
    linear-gradient(180deg, rgba(140, 184, 214, 0.12), transparent 55%),
    linear-gradient(180deg, var(--sidebar) 0%, #071320 100%);
  color: #e8f0f6;
  padding: max(10px, env(safe-area-inset-top, 0px)) 20px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  border-bottom: 1px solid rgba(140, 184, 214, 0.18);
  box-shadow: 0 10px 24px rgba(7, 19, 32, 0.18);
}
.brand { display: flex; gap: 10px; align-items: center; flex: 0 0 auto; }
.brand-mark {
  width: 40px; height: 40px;
  border: 1px solid var(--accent);
  color: var(--accent-2);
  display: grid; place-items: center;
  font-family: var(--sans);
  font-size: 12px; font-weight: 700;
  letter-spacing: 0;
  box-shadow: inset 0 0 0 3px rgba(196, 110, 56, 0.16);
}
.brand strong {
  display: block;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.25;
}
.brand em {
  display: block;
  font-style: normal;
  color: #8aa0b4;
  font-size: 11px;
  margin-top: 2px;
}
.nav { display: flex; gap: 2px; flex-wrap: wrap; align-items: center; }
.nav a, .nav-ext {
  color: #d5e4ef;
  text-decoration: none;
  padding: 6px 10px;
  font-size: 14px;
}
.nav a.active { color: #fff; border-bottom: 2px solid var(--accent); }
.sidebar-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin-left: auto;
}
.sidebar-tools .nav-ext { color: #d5e4ef; }
.nav-logout {
  appearance: none;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(240, 212, 196, 0.32);
  background: transparent;
  color: #f0d4c4;
  padding: 6px 12px;
  border-radius: 2px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.nav-logout:hover { background: var(--sidebar-2); color: #fff; }
.main { padding: 24px 28px 48px; max-width: 1200px; }
body.page-permissions .main,
body.page-accounts .main {
  max-width: none;
  width: 100%;
}
.topbar h1 { margin: 0; font-size: 28px; font-weight: 650; }
.main h2 { font-size: 18px; margin: 22px 0 8px; font-weight: 650; }
.kicker { margin: 0; font-size: 12px; letter-spacing: 0.08em; color: var(--muted); text-transform: uppercase; }
.hint { font-size: 13px; color: var(--ink-soft); margin: 0 0 16px; }
.welcome { color: var(--ink-soft); }
.muted { color: var(--muted); font-size: 13px; }
.ok { color: var(--ok); }
.site-tag {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #dce6ef;
}
.site-oa { background: #d5e4f4; }
.site-research { background: #dcecd4; }
.site-dashboard { background: #efe3cc; }
.site-trade { background: #f3d6d1; }
.bad, .error { color: var(--bad); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.wrap { word-break: break-all; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  padding: 18px;
  min-height: 160px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 6px 0 8px; }
.card p { color: var(--ink-soft); font-size: 14px; }
.empty { color: var(--muted); }
.oa-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 8px 0 12px; }
.oa-pending {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  background: rgba(196, 110, 56, 0.1);
}
.oa-pending span { color: var(--ink); font-size: 13px; }
.oa-add { display: flex; gap: 8px; }
.oa-users { width: 100%; }
.oa-users th,
.oa-users td { text-align: left; vertical-align: middle; }
.oa-users th:last-child,
.oa-users td:last-child { width: 6rem; white-space: nowrap; text-align: center; }
.oa-display { display: flex; gap: 8px; align-items: center; }
.oa-display input {
  flex: 1;
  min-width: 10rem;
  border: 1px solid var(--rule);
  background: #fff;
  padding: 8px 10px;
  font: inherit;
}
.oa-user .muted,
.oa-users .muted { color: var(--muted); font-size: 12px; }
.oa-add input, .login-form input {
  border: 1px solid var(--rule);
  background: #fff;
  padding: 8px 10px;
  font: inherit;
}
.btn {
  appearance: none;
  border: 1px solid var(--rule);
  background: #fff;
  font: inherit;
  padding: 8px 14px;
  cursor: pointer;
}
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.oa-new-grants { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 12px; }
.oa-status { color: var(--accent); min-height: 1.4em; }
.oa-del {
  appearance: none;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--bad);
  font: inherit;
  font-size: 12px;
  padding: 2px 8px;
  cursor: pointer;
}
.oa-table-wrap { overflow-x: auto; width: 100%; }
.oa-matrix {
  width: 100%;
  table-layout: fixed;
}
.oa-matrix th,
.oa-matrix td {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.oa-matrix th:first-child,
.oa-matrix td:first-child {
  width: 12%;
  min-width: 7.5rem;
  white-space: normal;
}
.oa-matrix th:not(:first-child),
.oa-matrix td:not(:first-child) {
  width: auto;
  text-align: center;
}
.oa-check input:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.oa-modules { display: flex; flex-direction: column; gap: 22px; }
.oa-module {
  margin: 0;
  padding: 16px 16px 12px;
  border: 1px solid var(--rule);
  background: var(--paper-2);
}
.oa-module > h2 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 650;
}
.oa-module > .welcome { margin: 0 0 12px; }
.oa-subs {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0;
  padding: 4px 0 0 16px;
  border-left: 3px solid var(--accent-2);
}
.oa-sub { margin: 0; }
.oa-sub h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}
.oa-matrix th.oa-l3 {
  font-weight: 500;
  color: var(--ink-soft);
}
.oa-perm {
  display: grid;
  grid-template-columns: minmax(12rem, 16rem) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.oa-perm-users,
.oa-perm-tree {
  margin: 0;
  padding: 14px 14px 12px;
  border: 1px solid var(--rule);
  background: var(--paper-2);
  min-width: 0;
}
.oa-perm-users h2,
.oa-perm-tree h2 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 650;
}
.oa-perm-tree > .welcome { margin: 0 0 12px; }
.oa-user-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.oa-user {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 8px 10px;
  cursor: pointer;
}
.oa-user strong { display: block; }
.oa-user.is-on {
  border-color: var(--accent);
  background: rgba(196, 110, 56, 0.1);
}
.oa-tree { display: flex; flex-direction: column; gap: 4px; }
.oa-tree-block { margin: 0; }
.oa-tree-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 4px 6px;
}
.oa-tree-row.is-module {
  font-weight: 650;
  background: rgba(12, 28, 46, 0.04);
}
.oa-tree-kids {
  margin: 0 0 0 14px;
  padding: 0 0 4px 10px;
  border-left: 2px solid var(--accent-2);
}
.oa-tree-twist {
  appearance: none;
  flex: 0 0 1.6rem;
  width: 1.6rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}
.oa-tree-twist.is-empty {
  display: inline-block;
  width: 1.6rem;
  flex: 0 0 1.6rem;
}
.oa-tree-mod {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 650;
  padding: 0;
  cursor: pointer;
  text-align: left;
}
.oa-tree-grant { display: inline-flex; align-items: center; gap: 8px; }
.oa-tree-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}
.oa-indent-1 { padding-left: 4px; }
.oa-indent-2 { padding-left: 4px; }
.oa-indent-3 { padding-left: 4px; }
.oa-indent-4 { padding-left: 4px; }
@media (max-width: 800px) {
  .oa-perm { grid-template-columns: 1fr; }
}
.oa-trade { margin-top: 28px; }
.oa-section { margin-top: 28px; }
.oa-trade h2, .oa-section h2 { margin: 0 0 8px; font-size: 18px; }
.oa-trade h3, .oa-section h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.oa-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border: 1px solid var(--rule);
  color: var(--muted);
  font-size: 10px;
}
.oa-tag.warn { color: var(--turn); }
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 28px 18px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--paper-2);
  border: 1px solid var(--rule);
  box-shadow: var(--shadow);
  padding: 28px 24px 22px;
}
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-soft); }
.login-form button {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: #fff;
  font: inherit;
  padding: 12px;
  cursor: pointer;
}
.login-error { color: var(--bad); }
.login-foot { color: var(--muted); font-size: 13px; }
.login-lang { text-align: right; margin: 0 0 12px; }
.login-lang a { color: var(--accent); font-size: 13px; text-decoration: none; }
.filters, .upload, .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
  align-items: center;
}
.filters input, .filters select, .upload input, .upload select, .actions button,
.filters button, .upload button, .upload label.check {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  background: #fff;
}
.filters button, .upload button, .actions button, form#enrol button {
  appearance: none;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  cursor: pointer;
}
.check { display: flex; gap: 6px; align-items: center; border: 0; background: transparent; padding: 0; }
form#enrol { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
form#enrol input { font: inherit; padding: 8px 10px; border: 1px solid var(--rule); }
.mfa-qr {
  display: inline-block;
  margin: 12px 0;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--rule);
}
.mfa-qr svg,
.mfa-qr img { display: block; width: 320px; height: 320px; background: #fff; image-rendering: pixelated; }
.mfa-qr-dialog {
  position: fixed;
  inset: 0;
  background: rgba(12, 18, 24, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}
.mfa-qr-card {
  width: min(460px, calc(100vw - 32px));
  background: var(--paper-2, #fff);
  padding: 18px 20px;
  border: 1px solid var(--rule);
}
.mfa-qr-card .mfa-qr { margin: 10px auto; }
.log {
  background: var(--sidebar);
  color: #e8f0f6;
  padding: 12px 14px;
  overflow: auto;
  max-height: 28rem;
  font-size: 13px;
  line-height: 1.45;
}
table.plain { border-collapse: collapse; width: 100%; background: var(--paper-2); }
table.plain th, table.plain td { border: 1px solid var(--rule); padding: 8px; text-align: left; font-size: 13px; vertical-align: top; }
.muted { color: var(--muted); font-size: 13px; }
body.page-files {
  height: 100dvh;
  overflow: hidden;
}
body.page-files .main {
  flex: 1;
  min-height: 0;
  max-width: none;
  width: 100%;
  padding: 12px 20px 10px;
  display: flex;
  flex-direction: column;
}
body.page-files .topbar { flex: 0 0 auto; }
body.page-files .topbar h1 { font-size: 22px; }
.files-page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.files-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.files-crumbs {
  margin: 0;
  font-size: 13px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.files-crumbs a { color: var(--accent); text-decoration: none; }
.files-sep { color: var(--muted); }
.files-toolbar input[type="search"] {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  background: #fff;
  min-width: 160px;
  flex: 0 0 220px;
}
.files-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 7fr);
  gap: 12px;
  align-items: stretch;
}
.files-left,
.files-preview-wrap {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper-2);
  border: 1px solid var(--rule);
}
.files-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
#files-table { margin: 0; }
#files-table th, #files-table td { padding: 6px 8px; font-size: 12px; }
#files-table thead th {
  position: sticky;
  top: 0;
  background: var(--paper-2);
  z-index: 1;
}
.files-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--rule);
}
.files-actions button,
.files-download {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  box-sizing: border-box;
}
.files-actions button:disabled {
  opacity: 0.45;
  cursor: default;
}
.files-preview-wrap { padding: 10px 12px; }
.files-preview-wrap .kicker { flex: 0 0 auto; margin-bottom: 8px; }
.files-preview {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.files-preview img {
  max-width: 100%;
  max-height: 100%;
  height: auto;
  object-fit: contain;
}
.files-preview .files-text,
.files-preview .log {
  flex: 1;
  max-height: none;
  margin: 0;
  min-height: 0;
}
.files-preview .files-csv,
.files-preview .oa-table-wrap { flex: 1; min-height: 0; overflow: auto; }
.files-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  height: 100%;
  border: 0;
  background: #fff;
}
#files-body tr[data-path] { cursor: pointer; }
#files-body tr[data-path]:hover { background: rgba(196, 110, 56, 0.08); }
@media (max-width: 720px) {
  body.page-files { height: auto; overflow: auto; }
  .files-layout { grid-template-columns: 1fr; min-height: 70dvh; }
  .files-left { min-height: 40dvh; }
  .files-preview-wrap { min-height: 40dvh; }
}
