:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  font-size: 15px;
  color: #18283f;
  background: #f4f7fc;
  --ink: #18283f;
  --muted: #536783;
  --surface: #fff;
  --line: #e1e8f1;
  --accent: #2558d4;
  --accent-hover: #1b45ad;
  --sidebar: #122139;
  --sidebar-text: #c5d3e8;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
:focus-visible { outline: 3px solid #709bfa; outline-offset: 3px; }

.layout { min-height: 100vh; min-height: 100dvh; }
.workspace-open { display: grid; grid-template-columns: 238px minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 26px 16px 18px;
  gap: 29px;
  overflow: auto;
  color: #fff;
  background: var(--sidebar);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  font-size: 1.08rem;
  line-height: 1.35;
}

.sidebar > .brand { margin-inline: 8px; }
.brand-mark, .identity-avatar {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  background: var(--accent);
}

.icon {
  position: relative;
  display: inline-block;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}

.icon::before, .icon::after { content: ""; position: absolute; }
.icon-monitor::before {
  inset: 2px 1px 6px;
  border: 1.6px solid currentColor;
  border-radius: 3px;
}
.icon-monitor::after {
  inset: auto 6px 2px;
  height: 4px;
  border-bottom: 1.6px solid currentColor;
  background: linear-gradient(currentColor, currentColor) center bottom / 1.6px 4px no-repeat;
}
.icon-user::before {
  inset: 2px 6px auto;
  height: 8px;
  border: 1.6px solid currentColor;
  border-radius: 50%;
}
.icon-user::after {
  inset: 11px 3px 2px;
  border: 1.6px solid currentColor;
  border-radius: 7px 7px 2px 2px;
}
.icon-lock::before {
  inset: 9px 3px 2px;
  border: 1.6px solid currentColor;
  border-radius: 3px;
}
.icon-lock::after {
  inset: 2px 6px auto;
  height: 8px;
  border: 1.6px solid currentColor;
  border-bottom: 0;
  border-radius: 5px 5px 0 0;
}
.icon-clock::before {
  inset: 2px;
  border: 1.6px solid currentColor;
  border-radius: 50%;
}
.icon-clock::after {
  inset: 5px auto auto 9px;
  width: 5px;
  height: 6px;
  border-left: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
}
.icon-file::before {
  inset: 1px 3px;
  border: 1.6px solid currentColor;
  border-radius: 3px;
}
.icon-file::after {
  inset: 6px 7px auto;
  height: 1.6px;
  border-radius: 1px;
  background: currentColor;
  box-shadow: 0 3px currentColor, 0 6px currentColor;
}

.module-nav { display: grid; gap: 4px; }
.module-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 12px;
  background: transparent;
  color: var(--sidebar-text);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.module-nav a:hover { background: #1e304c; color: #fff; }
.module-nav a[aria-current="page"] { background: #264374; border-color: #365685; color: #fff; }
.module-nav a[aria-current="page"] .icon { color: #bbd2ff; }

.identity {
  display: grid;
  gap: 14px;
  margin-top: auto;
  border-top: 1px solid #30415d;
  padding: 16px 8px 0;
}
.identity-details { display: flex; align-items: center; gap: 10px; min-width: 0; color: #fff; text-decoration: none; border-radius: 8px; }
.identity-details:hover, .identity-details[aria-current="page"] { background: #243753; }
.identity-avatar { background: #263b5d; color: #d9e6ff; overflow: hidden; }
.identity-avatar img, .profile-avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.identity-name { display: grid; gap: 2px; min-width: 0; }
#operator { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#operator-role { color: var(--sidebar-text); font-size: .83rem; }
.identity #logout { border-color: #4d5f7c; color: #e3edff; background: transparent; }
.identity #logout:hover { border-color: #7184a2; background: #243753; }

.main {
  width: 100%;
  max-width: 1440px;
  min-width: 0;
  margin-inline: auto;
  padding: 36px clamp(20px, 3.5vw, 56px) 48px;
}

.layout:not(.workspace-open) .main {
  display: grid;
  align-content: center;
  max-width: 474px;
  min-height: 100vh;
  min-height: 100dvh;
  padding-inline: 18px;
}

.module { display: grid; gap: 18px; min-width: 0; }
h1, h2, p { margin: 0; }
h1 {
  width: fit-content;
  max-width: 100%;
  color: var(--ink);
  font-size: clamp(1.5rem, 1.15rem + 1vw, 1.95rem);
  line-height: 1.3;
  font-weight: 700;
}
h2 { margin-bottom: 16px; font-size: 1.12rem; line-height: 1.45; }

.panel {
  min-width: 0;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 2px 6px rgb(27 53 94 / 4%);
}
.table-panel { padding: 20px; }
.panel.auth { padding: clamp(21px, 5vw, 31px); }
.auth .brand { margin-bottom: 23px; }
.auth h1 { margin-bottom: 19px; font-size: 1.65rem; }
.auth form { display: grid; gap: 14px; }

form, fieldset { margin: 0; padding: 0; }
fieldset { min-width: 0; border: 0; }
.form-row { display: flex; flex-wrap: wrap; align-items: end; gap: 13px; }
label { min-width: 0; display: grid; gap: 6px; color: #334965; font-weight: 600; }
.form-row label { flex: 1 1 10rem; max-width: 19rem; }

input, select, button, a.button {
  min-height: 40px;
  border-radius: 7px;
  padding: 8px 12px;
  font: inherit;
}
input, select { width: 100%; border: 1px solid #b8c5d8; color: var(--ink); background: #fff; }
button, a.button { border: 1px solid transparent; background: var(--accent); color: #fff; cursor: pointer; font-weight: 600; }
a.button { display: inline-flex; align-items: center; text-decoration: none; }
button:not(:disabled):hover, a.button:hover { background: var(--accent-hover); }
button.secondary { border-color: #c5d2e5; color: #274b7c; background: #fff; }
button.secondary:not(:disabled):hover { border-color: #a7bada; color: #173d77; background: #eef4ff; }
button:disabled, input:disabled, select:disabled { cursor: not-allowed; color: #586a83; background: #eef2f8; }
.hint { margin-top: 12px; color: var(--muted); font-size: .9rem; }
.profile-avatar-row { display: flex; align-items: center; flex-wrap: wrap; gap: 16px; }
.profile-avatar {
  display: grid;
  width: 76px;
  height: 76px;
  flex: 0 0 auto;
  place-items: center;
  overflow: hidden;
  border-radius: 16px;
  background: #e9f1ff;
  color: #274b7c;
}
.profile-avatar .icon { transform: scale(1.5); }
.avatar-editor {
  display: grid;
  grid-template-columns: minmax(0, 256px) minmax(0, 270px);
  align-items: center;
  gap: 20px;
  margin-top: 16px;
  padding: 16px;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f6f8fc;
}
#avatar-crop {
  display: block;
  width: 100%;
  max-width: 256px;
  height: auto;
  border-radius: 8px;
  background: conic-gradient(#e9eef6 25%, #fff 0 50%, #e9eef6 0 75%, #fff 0) 0 0 / 16px 16px;
  box-shadow: 0 0 0 1px #d3ddea;
  cursor: grab;
  touch-action: none;
}
#avatar-crop:active { cursor: grabbing; }
.avatar-controls { min-width: 0; }
.avatar-controls h3 { margin: 0; font-size: 1rem; }
.avatar-controls .hint { margin: 7px 0 16px; }
#avatar-zoom { min-height: 28px; padding: 0; accent-color: var(--accent); }
.avatar-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.avatar-feedback:empty { margin: 0; }
.avatar-feedback.error { color: #9e2331; }
.profile-account { margin-bottom: 14px; color: var(--muted); }

.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #f5f8fd; color: #435875; font-size: .89rem; font-weight: 650; white-space: nowrap; }
td { overflow-wrap: anywhere; }
tbody tr:last-child td { border-bottom: 0; }
td button, td a.button { min-height: 32px; padding: 4px 8px; font-size: .86rem; white-space: nowrap; }
td :is(button, a.button) + :is(button, a.button) { margin-inline-start: 6px; }
td.empty { color: var(--muted); padding-block: 22px; }
#devices td:nth-child(2), #sessions td:nth-child(n+2):nth-child(-n+6) {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.muted { color: var(--muted); }
.invite-code { display: inline-block; padding: 3px 5px; margin-inline-end: 6px; background: #edf4ff; color: #193f74; border-radius: 4px; }
.invite-table td:nth-child(2) { min-width: 12rem; }
.invite-table td:nth-child(3) { white-space: nowrap; }
.invite-actions { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.invite-actions select { width: auto; min-height: 32px; padding: 4px 7px; font-size: .86rem; }
.invite-actions button + button { margin-inline-start: 0; }

.status {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  border-radius: 6px;
  padding: 3px 7px;
  background: #edf1f6;
  color: #42536c;
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.active { background: #e4f5eb; color: #176443; }
.status.pending { background: #fff3d5; color: #785400; }

details { margin-top: 18px; padding-top: 15px; border-top: 1px solid var(--line); }
details form { margin-top: 12px; }
summary { color: #2453ae; cursor: pointer; font-weight: 600; }
#notice {
  margin-bottom: 16px;
  border: 1px solid #bfd2f3;
  border-radius: 8px;
  padding: 11px 13px;
  background: #e9f1ff;
  color: #193f74;
}
#notice.error { border-color: #ebc3c3; background: #fff0f0; color: #8b2c2c; }
output {
  flex: 1 1 100%;
  overflow-wrap: anywhere;
  border: 1px solid #d3e1fa;
  border-radius: 7px;
  padding: 9px 11px;
  background: #edf4ff;
  color: #193f74;
  font-family: ui-monospace, Consolas, monospace;
}

@media (max-width: 1040px) {
  .workspace-open { grid-template-columns: 199px minmax(0, 1fr); }
}

@media (max-width: 720px) {
  .workspace-open { display: block; }
  .sidebar {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    overflow: visible;
    gap: 12px 8px;
    padding: 13px;
  }
  .sidebar > .brand { margin-inline: 0; }
  .brand { gap: 8px; font-size: .95rem; }
  .brand-mark { width: 32px; height: 32px; border-radius: 8px; }
  .identity { grid-area: 1 / 2; display: flex; align-items: center; gap: 8px; margin: 0; padding: 0; border: 0; }
  .identity-details { gap: 5px; }
  .identity-avatar { width: 26px; height: 26px; border-radius: 7px; }
  .identity-avatar .icon { transform: scale(.8); }
  #operator-role { display: none; }
  #operator { max-width: 20vw; font-size: .85rem; }
  .identity #logout { padding: 4px 7px; min-height: 32px; font-size: .8rem; }
  .module-nav {
    grid-column: 1 / -1;
    display: flex;
    gap: 4px;
    overflow: auto;
    padding: 3px;
  }
  .module-nav a {
    flex: 1 0 60px;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    min-height: 52px;
    padding: 5px 4px;
    font-size: .8rem;
  }
  .main { padding: 22px 14px 36px; }
  .module { gap: 14px; }
  .panel, .table-panel { padding: 14px; }
  th, td { padding: 9px; }
}

@media (max-width: 460px) {
  .form-row label { flex-basis: 100%; max-width: none; }
}

@media (max-width: 650px) {
  .avatar-editor { grid-template-columns: minmax(0, 256px); gap: 16px; }
}
