/* ========= Theme tokens =========
 * 默认 dark；通过 html[data-theme="light"] 切换到 light。
 */
:root {
  color-scheme: dark;
  --shell-topbar-height: 58px;
  --shell-bg: #0b1220;
  --shell-fg: #e8eefc;
  --shell-muted: rgba(232, 238, 252, 0.7);
  --shell-border: rgba(255, 255, 255, 0.08);
  --shell-border-strong: rgba(255, 255, 255, 0.14);
  --shell-surface: #121a2c;
  --shell-surface-2: #0f172a;
  --shell-shadow: rgba(0, 0, 0, 0.45);
  --shell-accent: #fffc00;
  --shell-accent-fg: #111;
  --shell-accent-border: rgba(255, 252, 0, 0.35);
  --shell-accent-focus: rgba(255, 252, 0, 0.45);
  --shell-accent-ring: rgba(255, 252, 0, 0.12);
  --shell-danger: #ff6b6b;
  --shell-danger-border: rgba(255, 107, 107, 0.45);
  --shell-danger-bg: rgba(255, 107, 107, 0.15);
  --shell-link: var(--shell-accent);
}

html[data-theme="light"] {
  color-scheme: light;
  --shell-bg: #f7f8fb;
  --shell-fg: #0f172a;
  --shell-muted: rgba(15, 23, 42, 0.68);
  --shell-border: rgba(15, 23, 42, 0.12);
  --shell-border-strong: rgba(15, 23, 42, 0.18);
  --shell-surface: #ffffff;
  --shell-surface-2: #f1f5f9;
  --shell-shadow: rgba(2, 6, 23, 0.18);
  /* light 下仍保留品牌黄，但降低“刺眼” */
  --shell-accent: #f2e500;
  --shell-accent-fg: #111;
  --shell-accent-border: rgba(242, 229, 0, 0.55);
  --shell-accent-focus: rgba(242, 229, 0, 0.55);
  --shell-accent-ring: rgba(242, 229, 0, 0.18);
  --shell-danger: #e11d48;
  --shell-danger-border: rgba(225, 29, 72, 0.35);
  --shell-danger-bg: rgba(225, 29, 72, 0.10);
  --shell-link: #1d4ed8;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial;
  background: var(--shell-bg);
  color: var(--shell-fg);
  /* 采用“主内容区内部滚动”，侧栏固定在视口高度内 */
  height: 100vh;
  overflow: hidden;
}

a {
  color: var(--shell-link);
  text-decoration: none;
}

.topbar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--shell-border);
  background: color-mix(in srgb, var(--shell-bg) 82%, var(--shell-surface) 18%);
}

.topbar .brand {
  font-weight: 800;
}

.topbar .tabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.tab {
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--shell-border-strong);
  color: color-mix(in srgb, var(--shell-fg) 86%, transparent);
}

.tab.active {
  border-color: color-mix(in srgb, var(--shell-accent) 60%, var(--shell-border-strong));
  color: var(--shell-accent);
}

.layout {
  --shell-sidebar-width: 200px;
  display: grid;
  grid-template-columns: var(--shell-sidebar-width) minmax(0, 1fr);
  height: calc(100vh - var(--shell-topbar-height, 58px));
  min-height: 0;
  overflow: hidden;
  transition: grid-template-columns 0.22s ease;
}

/* 窄栏：仅图标 + 底部切换（不占满 0 宽） */
.layout.sidebar-rail {
  --shell-sidebar-width: 56px;
}

#sidebar {
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.sidebar-toggle {
  flex: 0 0 auto;
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--shell-border-strong);
  background: var(--shell-surface-2);
  color: color-mix(in srgb, var(--shell-fg) 92%, transparent);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  font-weight: 700;
}

.sidebar-toggle:hover {
  border-color: var(--shell-accent-border);
  color: var(--shell-accent);
}

.sidebar-toggle-icon-rail {
  display: none;
}

.layout.sidebar-rail .sidebar-toggle-icon-expanded {
  display: none;
}

.layout.sidebar-rail .sidebar-toggle-icon-rail {
  display: inline;
}

.sidebar {
  border-right: 1px solid var(--shell-border);
  padding: 14px;
  box-sizing: border-box;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.sidebar-footer {
  flex-shrink: 0;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--shell-border);
}

.sidebar-toggle-collapse {
  width: 100%;
  box-sizing: border-box;
}

.layout.sidebar-rail .sidebar-toggle-collapse {
  padding-left: 6px;
  padding-right: 6px;
}

.navlink {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  color: color-mix(in srgb, var(--shell-fg) 86%, transparent);
  border: 1px solid transparent;
}

.navlink-icon {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}

.navlink-icon-svg {
  width: 22px;
  height: 22px;
  display: block;
}

.navlink-text {
  min-width: 0;
}

.layout.sidebar-rail .navlink {
  justify-content: center;
  padding: 10px 8px;
}

.layout.sidebar-rail .navlink-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.layout.sidebar-rail .sidebar-footer {
  padding-left: 6px;
  padding-right: 6px;
}

.layout.sidebar-rail .sidebar {
  padding-left: 8px;
  padding-right: 8px;
}

.navlink.active {
  border-color: var(--shell-border-strong);
  background: color-mix(in srgb, var(--shell-fg) 6%, transparent);
}

.main {
  padding: 18px;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.card {
  background: var(--shell-surface);
  border: 1px solid var(--shell-border);
  border-radius: 14px;
  padding: 16px;
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  box-shadow: 0 10px 30px var(--shell-shadow);
}

.muted {
  color: var(--shell-muted);
  font-size: 13px;
  line-height: 1.5;
}

.dev-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  text-align: center;
  gap: 12px;
}

.dev-placeholder-icon {
  font-size: 48px;
  line-height: 1;
  opacity: 0.85;
}

.dev-placeholder-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.dev-placeholder-desc {
  max-width: 420px;
}

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

button {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--shell-border-strong);
  background: var(--shell-surface-2);
  color: var(--shell-fg);
  cursor: pointer;
}

button.primary {
  border-color: var(--shell-accent-border);
  background: var(--shell-accent);
  color: var(--shell-accent-fg);
  font-weight: 800;
}

button.danger {
  border-color: var(--shell-danger-border);
  background: var(--shell-danger-bg);
  color: color-mix(in srgb, var(--shell-danger) 70%, var(--shell-fg));
}

input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--shell-border-strong);
  background: var(--shell-surface-2);
  color: var(--shell-fg);
}

select {
  padding: 10px 36px 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--shell-border-strong);
  background-color: var(--shell-surface-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a8b4d0' d='M2.5 4.25 6 7.75 9.5 4.25'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  color: var(--shell-fg);
  font-size: 14px;
  line-height: 1.3;
  min-height: 40px;
  cursor: pointer;
  appearance: none;
  max-width: 100%;
}

select:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.22);
}

select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

select:focus,
input:focus {
  outline: none;
  border-color: var(--shell-accent-focus);
  box-shadow: 0 0 0 3px var(--shell-accent-ring);
}

select option {
  background: var(--shell-surface-2);
  color: var(--shell-fg);
}

input[type='date'] {
  min-width: 156px;
  color-scheme: inherit;
}

input[type='date']::-webkit-calendar-picker-indicator {
  filter: invert(0.25);
  opacity: 0.75;
  cursor: pointer;
}

html[data-theme="dark"] input[type='date']::-webkit-calendar-picker-indicator,
:root:not([data-theme="light"]) input[type='date']::-webkit-calendar-picker-indicator {
  filter: invert(0.85);
}

/* 数据查看等页面：字段横排对齐 */
.form-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 20px;
  align-items: flex-end;
  margin-bottom: 14px;
}

.form-field-inline {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

/* 覆盖同类上的 display（例如 form-field-inline 的 flex），否则 HTML hidden 无效仍占位可见 */
[hidden] {
  display: none !important;
}

.form-field-inline label {
  font-size: 12px;
  font-weight: 700;
  color: color-mix(in srgb, var(--shell-fg) 90%, transparent);
  letter-spacing: 0.02em;
}

.form-field-inline .hint {
  font-size: 12px;
  font-weight: 400;
  color: color-mix(in srgb, var(--shell-muted) 88%, transparent);
  max-width: 420px;
  line-height: 1.45;
}

.select-wide {
  min-width: min(360px, 92vw);
}

.select-account {
  min-width: min(320px, 92vw);
}

p.hint {
  color: color-mix(in srgb, var(--shell-muted) 88%, transparent);
  font-size: 12px;
  line-height: 1.45;
}

/* 外框：不参与横向 overflow，避免遮挡「视口顶吸附」类脚本方案。
 * 横向滚动放在 .table-scroll-x，表格保持自然高度占满内容区。 */
.table-scroll {
  margin-top: 10px;
  border-radius: 10px;
  border: 1px solid var(--shell-border);
  max-width: 100%;
}

.table-scroll-x {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.table-scroll table {
  margin-top: 0;
  min-width: max(100%, 720px);
  /* collapse 下部分浏览器布局异常；separate + spacing 0 保持视觉与 collapse 接近 */
  border-collapse: separate;
  border-spacing: 0;
}

.table-scroll th:first-child,
.table-scroll td:first-child {
  white-space: nowrap;
}

.table-scroll .col-nameid {
  white-space: nowrap;
}

.table-scroll td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.card-tabstrip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--shell-border);
}

.card-tabstrip .card-tab {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--shell-border-strong);
  background: transparent;
  color: color-mix(in srgb, var(--shell-fg) 86%, transparent);
  cursor: pointer;
  font-size: 13px;
}

.card-tabstrip .card-tab:hover {
  border-color: rgba(255, 255, 255, 0.22);
}

.card-tabstrip .card-tab.active {
  border-color: color-mix(in srgb, var(--shell-accent) 55%, var(--shell-border-strong));
  color: var(--shell-accent);
  font-weight: 700;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 13px;
}

th, td {
  border-bottom: 1px solid var(--shell-border);
  padding: 10px 8px;
  vertical-align: top;
}

th {
  text-align: left;
  color: color-mix(in srgb, var(--shell-fg) 76%, transparent);
  font-weight: 700;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .track {
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--shell-fg) 14%, transparent);
  border: 1px solid var(--shell-border-strong);
  box-sizing: border-box;
  position: relative;
  transition: background 120ms ease, border-color 120ms ease, opacity 120ms ease;
}

.switch .thumb {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--shell-fg) 92%, transparent);
  position: absolute;
  top: 1px;
  left: 1px;
  transition: transform 120ms ease, background 120ms ease;
}

.switch input:checked + .track {
  background: color-mix(in srgb, var(--shell-accent) 88%, transparent);
  border-color: color-mix(in srgb, var(--shell-accent) 60%, transparent);
}

.switch input:checked + .track .thumb {
  background: var(--shell-accent-fg);
  transform: translateX(16px);
}

.switch input:disabled + .track {
  opacity: 0.55;
}

.err {
  margin-top: 10px;
  color: var(--shell-danger);
  font-size: 12px;
  white-space: pre-wrap;
}

/* 简单表单弹层：用于「添加组织」等，避免顶栏输入框像搜索框 */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(0, 0, 0, 0.55);
}

.modal-backdrop.open {
  display: flex;
}

.modal-panel {
  width: min(440px, 100%);
  background: var(--shell-surface);
  border: 1px solid var(--shell-border-strong);
  border-radius: 14px;
  padding: 18px 20px 16px;
  box-shadow: 0 16px 48px var(--shell-shadow);
}

.modal-panel-xl {
  width: calc(100vw - 24px);
  max-width: 1560px;
  height: calc(100vh - 24px);
  max-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
  padding: 18px 20px 0;
  overflow: hidden;
}

.modal-panel-xl .modal-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-bottom: 16px;
  -webkit-overflow-scrolling: touch;
}

.modal-panel-xl .modal-foot {
  margin-top: auto;
  padding: 12px 0 16px;
  border-top: 1px solid var(--shell-border);
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--shell-surface) 0%, transparent),
    color-mix(in srgb, var(--shell-surface) 68%, transparent) 18%,
    color-mix(in srgb, var(--shell-surface) 92%, transparent)
  );
}

.modal-panel h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 800;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-field label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: color-mix(in srgb, var(--shell-fg) 86%, transparent);
  margin-bottom: 6px;
}

.form-field input {
  width: 100%;
  box-sizing: border-box;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
  flex-wrap: wrap;
}
