:root {
  color-scheme: light;
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #dbe3ee;
  --text: #0f172a;
  --muted: #475569;
  --navy: #0f4c81;
  --navy-hover: #0c3d68;
  --emerald: #0f766e;
  --emerald-soft: #ecfdf5;
  --warn-bg: #fffbeb;
  --warn-border: #f59e0b;
  --warn-text: #92400e;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}

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

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.48;
  -webkit-text-size-adjust: 100%;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: #eef2f7;
  padding: 1px 5px;
  border-radius: 5px;
  color: #0f172a;
}

.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.login-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px 18px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 14px 0 6px;
  font-size: 20px;
}

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

.brand-row > div {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.brand-row strong {
  font-size: 16px;
}

.brand-row small {
  font-size: 11px;
  color: var(--muted);
}

.brand-badge {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
}

.ghost-link {
  color: var(--navy);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
}

.app-shell {
  min-height: 100dvh;
  padding-bottom: calc(74px + env(safe-area-inset-bottom, 0px));
}

.m-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.m-topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.m-topbar-left > div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.m-topbar-title {
  font-size: 15px;
  white-space: nowrap;
}

.m-topbar-left small {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.m-topbar-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #94a3b8;
  flex-shrink: 0;
}

.status-dot.is-ok {
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}

.status-dot.is-err {
  background: #ef4444;
}

.m-main {
  max-width: 680px;
  margin: 0 auto;
  padding: 12px;
}

.m-tab-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.role-helper-card {
  max-width: 656px;
  margin: 12px auto 0;
  border-color: var(--warn-border);
  background: var(--warn-bg);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.card-head h2 {
  margin: 2px 0 0;
  font-size: 16px;
  line-height: 1.35;
}

.muted-note {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
}

.compact-top {
  margin-top: 10px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.kpi-card span {
  font-size: 12px;
  color: var(--muted);
}

.kpi-card strong {
  font-size: 21px;
  color: var(--text);
  font-weight: 700;
}

.kpi-card small {
  font-size: 12px;
  color: var(--emerald);
}

.quick-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.quick-btn {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.quick-btn strong {
  font-size: 15px;
}

.quick-btn span {
  font-size: 12px;
  color: var(--muted);
}

.quick-btn.is-emerald {
  background: var(--emerald-soft);
  border-color: #99f6e4;
}

.quick-btn.is-emerald strong {
  color: var(--emerald);
}

.quick-btn.is-navy {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.quick-btn.is-navy strong {
  color: var(--navy);
}

.seg-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  background: #e2e8f0;
  padding: 4px;
  border-radius: 12px;
}

.seg-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 8px;
  border-radius: 9px;
  cursor: pointer;
}

.seg-btn.is-active {
  background: var(--surface);
  color: var(--navy);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
}

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

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field > span {
  font-size: 13px;
  font-weight: 600;
  color: #1e293b;
}

.field input,
.field select,
.search-row input {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  font-size: 16px;
  color: var(--text);
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  appearance: none;
}

.field input:focus,
.field select:focus,
.search-row input:focus {
  outline: 2px solid rgba(15, 76, 129, 0.25);
  border-color: var(--navy);
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  padding: 4px 0;
}

.check-row input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex-shrink: 0;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.chip-accent {
  background: var(--emerald-soft);
  border-color: #99f6e4;
  color: var(--emerald);
}

.btn {
  min-height: 42px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--navy-hover);
}

.btn-emerald {
  background: var(--emerald);
  border-color: var(--emerald);
  color: #fff;
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
}

.btn-danger-outline {
  color: var(--danger);
  border-color: #fecaca;
  background: var(--danger-bg);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-row > .btn {
  flex: 1;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #e2e8f0;
  color: #334155;
}

.tag-emerald {
  background: #d1fae5;
  color: #065f46;
}

.tag-navy {
  background: #dbeafe;
  color: #1e40af;
}

.tag-warn {
  background: #fef3c7;
  color: #92400e;
}

.tag-danger {
  background: #fee2e2;
  color: #991b1b;
}

.notice {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-top: 10px;
}

.notice p {
  margin: 4px 0 0;
}

.notice-info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
}

.notice-warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
}

.toast {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
}

.toast.is-success {
  background: #ecfdf5;
  border-color: #6ee7b7;
  color: #065f46;
}

.toast.is-error {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}

.m-global-toast {
  max-width: 656px;
  margin: 10px auto 0;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-card {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 11px;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.item-title {
  font-weight: 700;
  font-size: 14px;
}

.item-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.empty-box {
  padding: 18px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.m-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.98);
  border-top: 1px solid var(--border);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
}

.m-nav-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 2px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.m-nav-icon {
  font-size: 17px;
  line-height: 1;
}

.m-nav-btn.is-active {
  color: var(--navy);
  background: #eff6ff;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.52);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}

.sheet-card {
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.25);
}

.code-box-list {
  margin-top: 10px;
  max-height: 44dvh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.code-row strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  letter-spacing: 0.6px;
  color: #0f172a;
}

@media (max-width: 420px) {
  .grid-3 {
    grid-template-columns: 1fr 1fr;
  }
  .m-topbar-left small {
    max-width: 110px;
  }
}

.adv-details { border: 1px dashed #cbd5e1; border-radius: 12px; padding: 10px 12px; background: #f8fafc; }
.adv-details summary { font-size: 13px; font-weight: 600; color: #475569; cursor: pointer; }
.code-row-meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.code-link-line { word-break: break-all; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.code-row-btns { display: flex; gap: 6px; flex-shrink: 0; }
