:root {
  --bg: #f3f6f4;
  --card: #ffffff;
  --ink: #14201c;
  --muted: #5b6b64;
  --line: #d7e2dc;
  --accent: #0f766e;
  --accent-soft: #d8f3ee;
  --hover: #f5faf8;
  --danger: #be123c;
  --danger-soft: #ffe4e6;
  --warn: #b45309;
  --shadow: 0 8px 24px rgba(16, 35, 31, 0.06);
  --radius: 14px;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}
body.booting #view-app,
body.booting #view-auth { visibility: hidden; }
.boot-screen {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center; align-content: center; gap: 8px;
  background: var(--bg);
}
.boot-screen.hidden { display: none !important; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.5; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .input,
.row > select.input,
.row > textarea.input {
  width: auto;
  min-width: 0;
  flex: 1 1 160px;
}
.row > .input.grow { flex: 1 1 220px; }
.row > .input.create-pass {
  flex: 1 1 260px;
  width: auto;
  min-width: 200px;
  max-width: 100%;
}
.row > .input.create-app,
.row > select.create-app {
  flex: 1 1 200px;
  width: auto;
  min-width: 160px;
  max-width: 280px;
}
.stack { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

.brand {
  font-size: 28px; font-weight: 800; letter-spacing: -0.03em;
  display: inline-flex; align-items: center; gap: 10px; color: var(--ink);
}
.brand-home { text-decoration: none; color: inherit; cursor: pointer; }
.brand-home:hover { opacity: 0.92; }
.brand-text { display: inline-flex; align-items: baseline; gap: 0.28em; }
.brand-ggtk { color: var(--ink); }
.brand-tools { color: var(--accent); }
.brand.sm { font-size: 22px; gap: 10px; white-space: nowrap; }
.brand-mark {
  width: 28px; height: 28px; flex-shrink: 0; border-radius: 8px;
  display: block;
}
.brand.sm .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
.brand:not(.sm) .brand-mark { width: 40px; height: 40px; border-radius: 12px; }

.input, select.input, textarea.input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  outline: none;
}
.input:focus, select.input:focus, textarea.input:focus {
  border-color: #7bc4b8;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}
.btn {
  border: 0;
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}
.btn:hover { filter: brightness(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.is-loading {
  opacity: 0.85;
  cursor: wait;
  pointer-events: none;
}
.btn.is-loading::before {
  content: '';
  width: 12px;
  height: 12px;
  margin-right: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.warn { background: #fff7ed; color: var(--warn); }
.btn.sm {
  padding: 5px 9px; font-size: 12px; white-space: nowrap; font-weight: 600;
  min-height: 0; height: auto; border-radius: 8px;
}
.btn.block { width: 100%; min-height: 42px; font-size: 15px; }

.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 100; background: #10352f; color: #fff; padding: 10px 16px;
  border-radius: 999px; font-size: 13px; box-shadow: var(--shadow);
}
.toast.err { background: #7f1d1d; }

.auth-shell {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.auth-card {
  width: min(420px, 100%); background: var(--card); border-radius: 18px;
  padding: 32px 28px 28px; box-shadow: var(--shadow);
  border: 1px solid rgba(215, 226, 220, 0.9);
  display: grid; gap: 14px; justify-items: stretch;
}
.auth-card .auth-brand {
  justify-content: center;
  width: 100%;
}
.auth-card .sub {
  margin: -2px 0 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
}
.auth-card .auth-tabs {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 4px;
  background: #eef5f3;
  border-radius: 12px;
}
.auth-card .auth-tabs.single {
  display: none;
}
.tabs { display: flex; gap: 8px; }
.tabs button {
  border: 0; border-radius: 999px; padding: 8px 14px; cursor: pointer;
  background: #eef5f3; color: var(--accent); font-weight: 600;
}
.tabs button.on { background: var(--accent); color: #fff; }
.auth-card .auth-tabs button {
  width: 100%;
  border-radius: 9px;
  padding: 9px 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}
.auth-card .auth-tabs button.on {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(16, 35, 31, 0.08);
}

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.app-frame {
  width: min(1280px, 100%);
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar,
.admin-top {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 18px 20px;
  min-height: 72px;
  background: transparent;
}
.top-left, .top-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.nav { display: flex; gap: 6px; align-items: center; }
.nav-btn {
  border: 0; background: transparent; padding: 10px 16px; border-radius: 10px;
  cursor: pointer; color: var(--muted); font-weight: 600; font-size: 15px;
  text-decoration: none; display: inline-flex; align-items: center; height: 44px;
  box-sizing: border-box;
}
.nav-btn.on, .nav-btn.active { background: var(--accent-soft); color: var(--accent); }
.who { font-size: 14px; color: var(--muted); }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 0 14px 0 5px;
  border-radius: 999px;
  background: #eef5f3;
  border: 1px solid var(--line);
  box-sizing: border-box;
  flex-shrink: 0;
}
.user-chip-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #d7e2dc;
  color: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.user-chip-avatar svg { width: 16px; height: 16px; display: block; }
.user-chip-name {
  font-size: 15px;
  font-weight: 700;
  color: #3d4f49;
  line-height: 1;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .btn,
.admin-top .btn {
  height: 44px;
  min-height: 44px;
  padding: 0 18px;
  font-size: 15px;
  border-radius: 12px;
}

.main { padding: 0 16px 16px; flex: 1; }
.page { height: calc(100vh - 92px); }
.split { display: grid; grid-template-columns: 340px 1fr; gap: 14px; height: 100%; }
.side, .content, .panel {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid rgba(215, 226, 220, 0.85);
}
.side { display: flex; flex-direction: column; overflow: hidden; }
.toolbar { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.side-meta { padding: 8px 12px; font-size: 12px; color: var(--muted); }
.acc-list { list-style: none; margin: 0; padding: 10px; overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.acc-item {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px 10px;
  background: #fff;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.acc-item:hover {
  border-color: #b9d5cd;
  background: #fbfdff;
  box-shadow: 0 2px 10px rgba(15, 118, 110, 0.06);
}
.acc-item.on {
  border-color: #8ec9bf;
  background: linear-gradient(165deg, #f4fbf9 0%, #eef8f5 100%);
  box-shadow: 0 0 0 1px rgba(15, 118, 110, 0.1);
}
.acc-item.on::before {
  content: '';
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.acc-item.dragging { opacity: 0.55; }
.acc-item.drag-over { border-color: var(--accent); }
.acc-row { display: flex; gap: 8px; align-items: flex-start; }
.acc-body { flex: 1; min-width: 0; display: grid; gap: 0; }
.drag-handle {
  flex-shrink: 0; width: 16px; margin-top: 3px;
  color: #9aada4; cursor: grab; user-select: none; letter-spacing: -2px;
  font-size: 13px; line-height: 1.2; text-align: center;
  opacity: 0.7;
}
.acc-item:hover .drag-handle { opacity: 1; color: var(--accent); }
.drag-handle:active { cursor: grabbing; }
.acc-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.acc-item .email {
  font-weight: 700;
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink);
  word-break: break-all;
  min-width: 0;
}
.acc-sub {
  margin-top: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.acc-item.on .acc-sub { color: #3d5c55; }
.acc-item .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag {
  display: inline-flex; align-items: center; flex-shrink: 0;
  font-size: 10px; font-weight: 700; letter-spacing: 0.02em;
  padding: 2px 7px; border-radius: 999px; line-height: 1.4;
  background: #e8f5f1; color: var(--accent);
}
.tag.ok { background: #e8f5f1; color: var(--accent); }
.tag.warn { background: #fff7ed; color: #c2410c; }
.tag.admin { background: var(--accent-soft); color: var(--accent); }
.acc-actions {
  display: flex;
  gap: 2px;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid rgba(215, 226, 220, 0.85);
  flex-wrap: wrap;
}
.acc-actions .btn-link {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.3;
}
.acc-actions .btn-link:hover { background: var(--accent-soft); }
.acc-actions .btn-link.danger { color: var(--danger); }
.acc-actions .btn-link.danger:hover { background: var(--danger-soft); }
.group-acc-list .acc-actions {
  display: flex;
  gap: 2px;
  width: 100%;
}
.group-acc-list .acc-actions button {
  width: auto;
}
.pager {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border-top: 1px solid var(--line); font-size: 12px;
}

.content { padding: 16px; overflow: auto; }
.content-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.content-head h2 { margin: 0 0 4px; font-size: 18px; }
.code-box {
  background: #0f1f1c; color: #d7fff4; border-radius: 12px; padding: 14px; margin-bottom: 14px;
}
.code { font-size: 32px; font-weight: 800; letter-spacing: 0.2em; margin-top: 6px; }
.mail-list { display: grid; gap: 8px; }
.mail {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.mail:hover { border-color: #99d5cb; background: #f7fbf9; }
.mail .subj { font-weight: 700; }
.mail .from { font-size: 12px; color: var(--muted); margin-top: 4px; }
.mail .preview { font-size: 13px; color: var(--muted); margin-top: 6px; line-height: 1.45; }
.mail-detail {
  border: 1px solid var(--line); border-radius: 12px; padding: 0; background: #fff;
  overflow: hidden; display: flex; flex-direction: column; min-height: 420px;
}
.mail-detail .detail-head {
  display: flex; justify-content: space-between; gap: 10px; align-items: flex-start;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: #f7faf8;
}
.mail-detail .detail-meta { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.mail-detail .detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mail-detail .detail-frame-wrap { flex: 1; min-height: 360px; background: #fff; }
.mail-detail iframe.mail-frame {
  width: 100%; height: 58vh; min-height: 360px; border: 0; display: block; background: #fff;
}
.mail-detail .detail-body-text {
  white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.55;
  padding: 16px; max-height: 58vh; overflow: auto;
}

.panel { padding: 16px; max-width: 900px; }
.panel h2 { margin: 0 0 6px; }
.groups-split {
  height: calc(100vh - 92px);
  grid-template-columns: 1fr 340px;
}
.page#page-groups .groups-main {
  display: block;
  overflow: auto;
  min-height: 0;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}
.page#page-groups .groups-panel {
  max-width: none;
  margin: 0;
  min-height: calc(100vh - 92px - 0px);
}
.page#page-groups .groups-acc-side {
  min-height: 0;
}
.page#page-groups .groups-acc-side .toolbar {
  display: grid;
  gap: 6px;
}
.group-main-list {
  margin-top: 14px;
}
.group-main-list .group-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  background: #fff;
  cursor: pointer;
}
.group-main-list .group-item:hover { background: var(--hover); }
.group-main-list .group-item.on {
  border-color: #99d5cb;
  background: #f0faf7;
}
.group-main-list .group-item[draggable="true"] { cursor: grab; }
.group-main-list .group-item.dragging { opacity: 0.55; }
.group-main-list .group-item.drag-over { border-color: var(--accent); }
.group-main-list .group-pick {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0;
}
.group-main-list .group-pick strong { font-size: 15px; }
.group-main-list .drag-handle { margin-top: 0; }
.group-main-list .drag-handle.spacer { visibility: hidden; width: 18px; }
.group-main-list .sys-tag {
  font-size: 12px;
  color: var(--muted);
}
.group-acc-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 0;
  box-shadow: none;
  background: transparent;
  padding: 10px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  list-style: none;
}
.group-acc-list .acc-item { padding: 11px 12px 10px; }
.workspace-empty {
  flex: 1;
  min-height: 360px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  text-align: center;
  padding: 32px 16px;
}
.workspace-empty .logo {
  width: 64px;
  height: 64px;
  display: block;
  margin: 0 auto 4px;
}
.workspace-empty h3 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.03em;
}
.workspace-empty h3 .brand-ggtk { color: var(--ink); }
.workspace-empty h3 .brand-tools { color: var(--accent); }
.workspace-idle {
  flex: 1;
  min-height: 240px;
}
.list-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px 12px;
  color: var(--muted);
  font-size: 13px;
  list-style: none;
}
.list-loading .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.workspace-empty .sub { color: var(--muted); font-size: 13px; }
.workspace-empty .hint { color: var(--accent); font-size: 13px; margin-top: 4px; }
.workspace-empty .tip {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
  max-width: 320px;
  line-height: 1.5;
}
.page#page-accounts .content {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.page#page-accounts .content-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.nice-select {
  position: relative;
  width: 100%;
}
.nice-select-btn {
  width: 100%;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #fff;
}
.nice-select-btn::after {
  content: '';
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #6b7c75;
  flex-shrink: 0;
  transition: transform .15s;
}
.nice-select.open .nice-select-btn::after {
  transform: rotate(180deg);
}
.nice-select-menu {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  max-height: 280px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(16, 35, 31, 0.12);
  padding: 6px;
}
.nice-select-item {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 0;
  border-bottom: 1px solid #e8efeb;
}
.nice-select-item:last-child { border-bottom: 0; }
.nice-select-item:hover {
  background: var(--hover);
}
.nice-select-item.on {
  background: #f0faf7;
  color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
  font-weight: 700;
}
.nice-select-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nice-select-count {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.nice-select-item.on .nice-select-count { color: var(--accent); }
.group-main-list .group-count {
  margin-left: auto;
  font-size: 13px;
}
.group-main-list .group-pick {
  width: auto;
  flex: 1;
}
.modal-card.modal-sm { width: min(420px, 100%); }
.modal-card label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.simple-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.simple-list li,
.simple-list .group-item {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap;
  background: #fff;
}
.simple-list .group-item { cursor: grab; }
.simple-list .group-item.dragging { opacity: 0.55; cursor: grabbing; }
.simple-list .group-item.drag-over { border-color: var(--accent); }
.simple-list .group-item .group-name { flex: 1; min-width: 120px; }
.simple-list .group-item .drag-handle { margin-top: 0; }
.codeblock {
  background: #0f1f1c; color: #d7fff4; border-radius: 12px; padding: 14px;
  overflow: auto; font-size: 12px; line-height: 1.55;
}

.modal {
  position: fixed; inset: 0; background: rgba(15, 30, 27, 0.35);
  display: grid; place-items: center; z-index: 50; padding: 16px;
}
.modal-card {
  width: min(560px, 100%); background: #fff; border-radius: 16px;
  padding: 16px; box-shadow: var(--shadow);
  display: grid; gap: 12px; max-height: 90vh; overflow: auto;
  border: 1px solid var(--line);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
label { font-size: 12px; color: var(--muted); }

.user-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fff; margin-bottom: 8px;
}
.user-main {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.user-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
  width: auto;
  margin-top: 0;
}
.user-actions .btn { width: auto; }
.user-left { display: flex; gap: 10px; align-items: center; min-width: 0; flex: 1; }
.id-box {
  min-width: 22px; height: 22px; padding: 0 5px; border-radius: 6px; flex-shrink: 0;
  background: #eef5f3; border: 1px solid var(--line); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
}
.user-info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.identity { display: inline-flex; align-items: center; gap: 8px; }
.user-card .title { font-weight: 700; font-size: 15px; color: var(--ink); }
.user-card .meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.token-row {
  margin-top: 10px; display: flex; gap: 8px; align-items: stretch;
  padding-top: 10px; border-top: 1px solid #eef3f1;
}
.token {
  flex: 1; min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; color: #0f766e; background: #f3faf8; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; word-break: break-all;
  display: flex; align-items: center;
}

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; height: auto; }
  .groups-split { grid-template-columns: 1fr; height: auto; }
  .page#page-groups .groups-panel { min-height: 0; }
  .page { height: auto; }
  .side { max-height: 420px; }
  .topbar { align-items: flex-start; }
}
