:root {
  --primary: #0572EC;
  --primary-hover: #0461CB;
  --primary-soft: #E7F1FD;
  --primary-soft-strong: #D3E6FC;
  --danger: #D92D20;
  --danger-hover: #B42318;
  --danger-soft: #FEF0EF;
  --success: #12805C;
  --text: #1B1D21;
  --text-2: #5E6470;
  --text-3: #8A909C;
  --border: #E2E5EA;
  --border-strong: #CED3DB;
  --bg: #F6F7F9;
  --bg-sidebar: #EEF0F3;
  --bg-card: #FFFFFF;
  --bg-hover: #F1F3F6;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, .08), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 48px rgba(16, 24, 40, .18), 0 2px 8px rgba(16, 24, 40, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sidebar-w: 248px;
  --list-w: 360px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { display: block; }

.boot { display: grid; place-items: center; height: 100vh; }
.boot-spinner, .spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--primary-soft-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons & inputs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
  font-weight: 500;
  white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--bg-hover); }
.btn:focus-visible, .icon-btn:focus-visible, .nav-item:focus-visible, .list-item:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-danger-outline { color: var(--danger); border-color: #F4C7C3; }
.btn-danger-outline:hover { background: var(--danger-soft); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; height: 40px; }
.btn .icon { width: 16px; height: 16px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; flex: none;
  border: 0; border-radius: var(--radius);
  background: transparent; color: var(--text-2);
}
.icon-btn:hover { background: rgba(0, 0, 0, .06); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn .icon { width: 18px; height: 18px; }

.input {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(5, 114, 236, .18); }
.input::placeholder { color: var(--text-3); }

.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-row label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.form-error { color: var(--danger); font-size: 13px; min-height: 20px; margin: -4px 0 8px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }

.icon { width: 18px; height: 18px; flex: none; }

/* ---------- Login ---------- */

.auth-page {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 16px;
  background:
    radial-gradient(1200px 600px at 10% -10%, #DCEBFD 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #E8E4FF 0%, transparent 55%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px;
  padding: 36px 32px 28px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
}
.auth-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.auth-logo .brand-mark { width: 52px; height: 52px; border-radius: 14px; }
.auth-logo .brand-mark .icon { width: 28px; height: 28px; }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; font-weight: 650; text-align: center; letter-spacing: .2px; }
.auth-card .auth-sub { margin: 0 0 24px; color: var(--text-2); text-align: center; }
.auth-switch { margin-top: 18px; text-align: center; color: var(--text-2); font-size: 13px; }
.auth-switch button { border: 0; background: none; color: var(--primary); padding: 0 2px; font-weight: 500; }
.auth-footer { margin-top: 20px; color: var(--text-3); font-size: 12px; }

/* ---------- Shell ---------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: flex; flex-direction: column;
  min-width: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 14px 10px 10px;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark {
  display: grid; place-items: center;
  width: 32px; height: 32px; flex: none;
  border-radius: 9px;
  background: linear-gradient(145deg, #2A8BFF, var(--primary));
  color: #fff;
  box-shadow: 0 2px 6px rgba(5, 114, 236, .35);
}
.brand-mark .icon { width: 18px; height: 18px; }
.brand-name { font-weight: 650; font-size: 16px; letter-spacing: .2px; }

.nav-label { padding: 12px 10px 6px; font-size: 11px; font-weight: 600; letter-spacing: .6px; color: var(--text-3); text-transform: uppercase; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 10px;
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
}
.nav-item:hover { background: rgba(0, 0, 0, .05); text-decoration: none; }
.nav-item .icon { color: var(--text-2); }
.nav-item.active { background: #fff; color: var(--primary); box-shadow: var(--shadow-sm); }
.nav-item.active .icon { color: var(--primary); }
.nav-item .nav-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.nav-item.active .nav-count { color: var(--primary); }

.sidebar-footer { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }
.account-chip { display: flex; align-items: center; gap: 10px; padding: 6px 4px 2px 6px; min-width: 0; }
.account-meta { flex: 1; min-width: 0; }
.account-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-role { font-size: 12px; color: var(--text-3); }

.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.page { flex: 1; min-height: 0; display: grid; grid-template-columns: var(--list-w) minmax(0, 1fr); }
.page.single { grid-template-columns: minmax(0, 1fr); }

/* ---------- List pane ---------- */

.list-pane {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: #fff;
  border-right: 1px solid var(--border);
}
.list-header { padding: 16px 16px 10px; border-bottom: 1px solid var(--border); }
.list-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; min-height: 30px; }
.list-title { margin: 0; font-size: 18px; font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-title small { font-size: 13px; color: var(--text-3); font-weight: 500; margin-left: 6px; }
.search { position: relative; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); width: 16px; height: 16px; pointer-events: none; }
.search .input { padding-left: 34px; height: 36px; background: var(--bg); border-color: transparent; }
.search .input:focus { background: #fff; border-color: var(--primary); }
.list-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; font-size: 12px; color: var(--text-3); }
.select {
  height: 28px; padding: 0 26px 0 8px;
  border: 1px solid transparent; border-radius: 6px;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%235E6470' stroke-width='1.6'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E") no-repeat right 6px center / 14px;
  color: var(--text-2); font-size: 12px; font-weight: 500;
  appearance: none; -webkit-appearance: none;
  cursor: pointer;
}
.select:hover { background-color: var(--bg-hover); }

.list-body { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 8px 16px; }
.group-header {
  position: sticky; top: -6px; z-index: 1;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 8px 4px;
  background: #fff;
  font-size: 12px; font-weight: 600; color: var(--text-3);
}
.group-header span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 8px 10px;
  border: 0; border-radius: var(--radius);
  background: transparent;
  text-align: left;
  color: inherit; text-decoration: none;
}
.list-item:hover { background: var(--bg-hover); text-decoration: none; }
.list-item.selected { background: var(--primary-soft); }
.list-item.selected .item-title { color: var(--primary); }
.item-main { flex: 1; min-width: 0; }
.item-title { display: flex; align-items: center; gap: 6px; font-weight: 600; min-width: 0; }
.item-title .text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { color: var(--text-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { color: var(--text-3); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center;
  height: 18px; padding: 0 6px; flex: none;
  border-radius: 4px;
  background: var(--primary-soft); color: var(--primary);
  font-size: 11px; font-weight: 600; line-height: 1;
}
.badge.gray { background: #EEF0F3; color: var(--text-2); }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 48px 24px;
  color: var(--text-3); text-align: center;
}
.empty .empty-icon {
  display: grid; place-items: center;
  width: 56px; height: 56px;
  border-radius: 16px;
  background: #fff; border: 1px solid var(--border);
  color: var(--text-3);
}
.empty .empty-icon .icon { width: 26px; height: 26px; }
.empty .empty-title { color: var(--text-2); font-weight: 600; font-size: 15px; }
.empty .empty-text { max-width: 320px; font-size: 13px; }
.loading { display: grid; place-items: center; padding: 48px; }

/* ---------- Avatars ---------- */

.avatar {
  position: relative;
  display: grid; place-items: center;
  width: 36px; height: 36px; flex: none;
  border-radius: var(--radius);
  color: #fff; font-weight: 650; font-size: 15px;
  overflow: hidden;
  user-select: none;
}
.avatar.round { border-radius: 50%; }
.avatar.sm { width: 28px; height: 28px; font-size: 13px; border-radius: 7px; }
.avatar.sm.round { border-radius: 50%; }
.avatar.lg { width: 56px; height: 56px; font-size: 24px; border-radius: 12px; }
.avatar.lg.round { border-radius: 50%; }
.avatar img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  padding: 18%;
  background: #fff;
  object-fit: contain;
  opacity: 0;
}
.avatar.has-icon { box-shadow: inset 0 0 0 1px var(--border); }
.avatar.has-icon img { opacity: 1; }

/* ---------- Detail pane ---------- */

.detail-pane { min-width: 0; min-height: 0; overflow-y: auto; background: var(--bg); }
.detail { max-width: 720px; margin: 0 auto; padding: 28px 32px 48px; }
.detail-back { display: none; margin: -8px 0 12px -8px; }
.detail-back .btn { border: 0; background: transparent; color: var(--primary); padding: 0 8px; }
.detail-head { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; min-width: 0; }
.detail-head-main { flex: 1; min-width: 0; }
.detail-title { margin: 0; font-size: 22px; font-weight: 650; line-height: 1.3; overflow-wrap: anywhere; }
.detail-subtitle { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 4px; color: var(--text-2); font-size: 13px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

.section-title { margin: 0 0 8px 2px; font-size: 12px; font-weight: 600; color: var(--text-3); letter-spacing: .3px; }
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow: hidden;
}
.field {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  min-height: 58px;
  border-top: 1px solid var(--border);
}
.field:first-child { border-top: 0; }
.field-main { flex: 1; min-width: 0; }
.field-label { font-size: 12px; color: var(--text-3); margin-bottom: 2px; }
.field-value { font-size: 14px; color: var(--text); overflow-wrap: anywhere; }
.field-value.muted { color: var(--text-3); }
.field-value.mono { font-family: var(--mono); font-size: 13px; }
.field-actions { display: flex; gap: 2px; opacity: .55; transition: opacity .12s; }
.field:hover .field-actions, .field-actions:focus-within { opacity: 1; }
.field .input { margin-top: 4px; }
.label-edit { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.label-edit .input { margin-top: 0; flex: 1; min-width: 0; }

.danger-zone { display: flex; justify-content: flex-start; margin-top: 8px; }

.subitem {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px 10px 16px;
  border-top: 1px solid var(--border);
  min-width: 0;
}
.subitem:first-child { border-top: 0; }

/* ---------- Single content pages ---------- */

.content { min-width: 0; min-height: 0; overflow-y: auto; }
.content-inner { max-width: 760px; margin: 0 auto; padding: 32px 32px 56px; }
.page-title { margin: 0 0 4px; font-size: 24px; font-weight: 650; }
.page-sub { margin: 0 0 24px; color: var(--text-2); }
.steps { list-style: none; margin: 0; padding: 0; }
.step { display: flex; gap: 14px; padding: 14px 16px; border-top: 1px solid var(--border); }
.step:first-child { border-top: 0; }
.step-num {
  display: grid; place-items: center;
  width: 26px; height: 26px; flex: none;
  border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  font-weight: 650; font-size: 13px;
}
.step-main { flex: 1; min-width: 0; padding-top: 2px; }
.step-title { font-weight: 600; }
.step-text { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.kbd {
  display: inline-block; padding: 0 6px;
  border: 1px solid var(--border); border-radius: 5px;
  background: var(--bg); font-family: var(--mono); font-size: 12px; color: var(--text);
  overflow-wrap: anywhere;
}
.download-card { display: flex; align-items: center; gap: 16px; padding: 18px 16px; flex-wrap: wrap; }
.download-card .dl-text { flex: 1; min-width: 200px; }
.download-card .dl-title { font-weight: 600; }
.download-card .dl-sub { color: var(--text-2); font-size: 13px; }
.notice { padding: 12px 16px; border-radius: var(--radius); background: #FFF8E6; color: #7A5300; font-size: 13px; border: 1px solid #F5E1A8; }
.form-card { padding: 20px 16px 6px; }
.form-card .form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-bottom: 14px; }

/* ---------- Modal & toast ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(17, 24, 39, .38);
  animation: fade .12s ease-out;
}
.modal {
  width: 100%; max-width: 420px;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: pop .14s ease-out;
}
.modal-head { padding: 20px 20px 4px; }
.modal-title { margin: 0; font-size: 17px; font-weight: 650; }
.modal-body { padding: 8px 20px 4px; color: var(--text-2); overflow-wrap: anywhere; }
.modal-body p { margin: 0 0 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 20px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }

#toast-root {
  position: fixed; left: 50%; bottom: 24px; z-index: 200;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: #1F2329; color: #fff;
  box-shadow: var(--shadow-md);
  font-size: 13px; font-weight: 500;
  animation: pop .16s ease-out;
}
.toast .icon { width: 16px; height: 16px; color: #5FD4A0; }
.toast.error .icon { color: #FF8A80; }

.nav-scrim { display: none; }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  :root { --sidebar-w: 220px; --list-w: 320px; }
  .detail { padding: 24px 24px 40px; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: 272px; max-width: 85vw;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
  }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .nav-scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(17, 24, 39, .3); }
  .topbar {
    display: flex; align-items: center; gap: 8px;
    height: 52px; padding: 0 8px; flex: none;
    background: #fff;
    border-bottom: 1px solid var(--border);
  }
  .topbar-title { flex: 1; min-width: 0; font-weight: 650; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* The top bar already shows the page title. */
  .list-title, .page-title { display: none; }
  .list-title-row { justify-content: flex-end; }
  .list-title-row:not(:has(.btn)) { display: none; }
  .content-inner { padding-top: 20px; }
}

@media (max-width: 680px) {
  .page { grid-template-columns: minmax(0, 1fr); }
  .page.has-selection .list-pane { display: none; }
  .page:not(.has-selection):not(.single) .detail-pane { display: none; }
  .list-pane { border-right: 0; }
  .detail { padding: 16px 16px 40px; }
  .detail-back { display: block; }
  .detail-head { gap: 12px; margin-bottom: 18px; }
  .detail-title { font-size: 19px; }
  .avatar.lg { width: 48px; height: 48px; font-size: 21px; }
  .content-inner { padding: 20px 16px 40px; }
  .page-title { font-size: 20px; }
  .field { padding: 10px 12px; }
  .field-actions { opacity: 1; }
  .auth-card { padding: 28px 20px 22px; }
  #toast-root { bottom: 16px; }
}
