/* SentinelHub shared visual foundation — 默认暗色，html[data-theme="light"] 切换浅色。
   加载顺序：位于页面内联样式之后，作为渐进增强覆盖。 */
:root {
  color-scheme: dark;
  --sh-font: "Segoe UI Variable", "Microsoft YaHei UI", "Noto Sans SC", sans-serif;
  --sh-bg: #14171c;
  --sh-surface: #1d2127;
  --sh-surface-subtle: #22272e;
  --sh-surface-hover: #2a313a;
  --sh-panel: #1d2127;
  --sh-border: #333a44;
  --sh-border-strong: #4a5462;
  --sh-primary: #479ef5;
  --sh-primary-hover: #7cb8f8;
  --sh-primary-soft: rgba(71, 158, 245, .16);
  --sh-success: #54b054;
  --sh-success-soft: rgba(84, 176, 84, .16);
  --sh-warning: #e8a33d;
  --sh-warning-soft: rgba(232, 163, 61, .16);
  --sh-error: #e0584c;
  --sh-error-soft: rgba(224, 88, 76, .16);
  --sh-text: #f1f1f1;
  --sh-muted: #9fa6b0;
  --sh-radius: 6px;
  --sh-radius-sm: 4px;
  --sh-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  --sh-focus: #479ef5;
  --sh-topbar: #111418;
  --sh-nav: #171b21;
  --sh-topbar-text: rgba(255, 255, 255, .82);
  --bg: var(--sh-bg);
  --surface: var(--sh-surface);
  --surface2: var(--sh-surface-subtle);
  --panel: var(--sh-panel);
  --border: var(--sh-border);
  --primary: var(--sh-primary);
  --success: var(--sh-success);
  --warning: var(--sh-warning);
  --error: var(--sh-error);
  --text: var(--sh-text);
  --muted: var(--sh-muted);
  --radius: var(--sh-radius);
}

html[data-theme="light"] {
  color-scheme: light;
  --sh-bg: #f5f6f8;
  --sh-surface: #ffffff;
  --sh-surface-subtle: #f8f9fa;
  --sh-surface-hover: #f0f2f4;
  --sh-panel: #ffffff;
  --sh-border: #d1d5db;
  --sh-border-strong: #aeb6c2;
  --sh-primary: #0f6cbd;
  --sh-primary-hover: #115ea3;
  --sh-primary-soft: #e9f3fc;
  --sh-success: #107c10;
  --sh-success-soft: #eaf6ea;
  --sh-warning: #8a5d00;
  --sh-warning-soft: #fff4ce;
  --sh-error: #c42b1c;
  --sh-error-soft: #fde7e9;
  --sh-text: #242424;
  --sh-muted: #616161;
  --sh-shadow: 0 8px 24px rgba(0, 0, 0, .14);
  --sh-focus: #0f6cbd;
  --sh-topbar: #242424;
  --sh-nav: #f7f8fa;
  --sh-topbar-text: rgba(255, 255, 255, .85);
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-padding-top: 56px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sh-font);
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--sh-primary-hover); }
button, input, select, textarea { font: inherit; }
button { border-radius: var(--radius); }
button:disabled { cursor: not-allowed; opacity: .55; }
input, select, textarea {
  border: 1px solid var(--border);
  border-radius: var(--sh-radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 7px 10px;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, .06);
}
html[data-theme="light"] input, html[data-theme="light"] select, html[data-theme="light"] textarea { box-shadow: inset 0 1px 1px rgba(0, 0, 0, .02); }
textarea { min-height: 72px; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: var(--sh-border-strong); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 1px var(--primary); }
:focus-visible { outline: 2px solid var(--sh-focus); outline-offset: 2px; }

.page-head { color: var(--text); }
.page-head h1 { color: var(--text); font-weight: 600; letter-spacing: -.15px; }
.back-link { color: var(--muted); }
.back-link:hover { color: var(--primary); }
.card {
  background: var(--panel);
  border-color: var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12);
}
html[data-theme="light"] .card { box-shadow: 0 1px 2px rgba(0, 0, 0, .04); }
.card h2, .card-title { color: var(--text); font-weight: 600; }
.card .desc, .desc, .muted { color: var(--muted); }
.form-row { gap: 12px; }
.form-group { gap: 5px; }
.form-group label { color: var(--muted); font-weight: 600; }

.btn, button.ghost, button.warn, button.danger {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--sh-radius-sm);
  font-weight: 500;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover:not(:disabled), button.ghost:hover:not(:disabled) { background: var(--sh-surface-hover); border-color: var(--sh-border-strong); }
.btn-primary, .btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled), .btn.primary:hover:not(:disabled) { background: var(--sh-primary-hover); border-color: var(--sh-primary-hover); }
.btn-danger, .btn.danger, button.danger { color: var(--error); border-color: color-mix(in srgb, var(--error) 45%, var(--border)); }
.btn-danger:hover:not(:disabled), .btn.danger:hover:not(:disabled), button.danger:hover:not(:disabled) { background: var(--sh-error-soft); }
.btn-ghost, .btn.ghost, button.ghost { background: transparent; }
.btn-ghost:hover:not(:disabled), .btn.ghost:hover:not(:disabled) { color: var(--primary); }
.btn.warn, button.warn { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 50%, var(--border)); }
.btn.warn:hover:not(:disabled), button.warn:hover:not(:disabled) { background: var(--sh-warning-soft); }
.btn-link, .link-button { color: var(--primary); background: transparent; border-color: transparent; }
.btn-link:hover, .link-button:hover { color: var(--sh-primary-hover); text-decoration: underline; }

.tag, .badge, .badge-adv, .role-tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--sh-surface-subtle);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
}
.badge-active, .badge.pass, .tag.tls-on, .tag.udp { color: var(--success); background: var(--sh-success-soft); border-color: color-mix(in srgb, var(--success) 35%, var(--border)); }
.badge-warn, .badge.review, .badge-adv { color: var(--warning); background: var(--sh-warning-soft); border-color: color-mix(in srgb, var(--warning) 40%, var(--border)); }
.badge-disabled, .badge.reject { color: var(--error); background: var(--sh-error-soft); border-color: color-mix(in srgb, var(--error) 35%, var(--border)); }
.badge-admin, .tag.tcp { color: var(--primary); background: var(--sh-primary-soft); border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); }

.status-bar { color: var(--muted); }
.status-item { color: var(--text); }
.dot { background: var(--muted); box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 12%, transparent); }
.dot.ok { background: var(--success); } .dot.bad { background: var(--error); }
.msg-box, .alert {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--sh-surface-subtle);
  color: var(--text);
}
.msg-box.ok, .alert.success { background: var(--sh-success-soft); border-color: color-mix(in srgb, var(--success) 35%, var(--border)); color: var(--success); }
.msg-box.warn, .alert.warn { background: var(--sh-warning-soft); border-color: color-mix(in srgb, var(--warning) 40%, var(--border)); color: var(--warning); }
.msg-box.err, .alert.error { background: var(--sh-error-soft); border-color: color-mix(in srgb, var(--error) 35%, var(--border)); color: var(--error); }
.alert.info { background: var(--sh-primary-soft); border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); color: var(--primary); }

.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
table { color: var(--text); }
th { background: var(--sh-surface-subtle); color: var(--muted); font-weight: 600; border-color: var(--border); }
td { border-color: var(--border); }
tbody tr:hover td { background: var(--sh-surface-hover); }
.pagination { color: var(--muted); }
.pagination button { border-color: var(--border); }

.modal-overlay, .modal-mask { background: rgba(0, 0, 0, .5); }
.modal {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--sh-shadow);
}
.footer, .auth-footer { color: var(--muted); }

/* ==================== 应用壳层：顶栏 + 侧边导航 ==================== */
.sh-appbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  background: var(--sh-topbar);
  color: var(--sh-topbar-text);
  z-index: 500;
  min-width: 0;
}
.sh-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px 0 6px;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: .1px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.sh-brand-mark {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: var(--sh-primary);
  display: grid;
  place-items: center;
  color: #fff;
  flex: 0 0 auto;
}
.sh-brand-mark svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sh-product {
  font-size: 12px;
  font-weight: 400;
  color: rgba(255, 255, 255, .55);
  border-left: 1px solid rgba(255, 255, 255, .18);
  padding-left: 10px;
  white-space: nowrap;
}
.sh-spacer { flex: 1 1 0; min-width: 0; }
.sh-iconbtn {
  width: 34px; height: 34px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--sh-topbar-text);
  cursor: pointer;
  flex: 0 0 auto;
}
.sh-iconbtn:hover { background: rgba(255, 255, 255, .09); color: #fff; }
.sh-iconbtn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sh-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px 0 8px;
  font-size: 13px;
  color: #fff;
  white-space: nowrap;
  flex: 0 0 auto;
}
.sh-user .sh-role {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  color: var(--sh-primary);
  background: var(--sh-primary-soft);
  border: 1px solid color-mix(in srgb, var(--sh-primary) 35%, transparent);
}
.sh-user .sh-act {
  border: 1px solid rgba(255, 255, 255, .25);
  background: transparent;
  color: var(--sh-topbar-text);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: var(--sh-radius-sm);
  cursor: pointer;
}
.sh-user .sh-act:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.sh-user .sh-act.danger:hover { background: var(--sh-error-soft); border-color: var(--sh-error); color: var(--sh-error); }

.sh-sidebar {
  position: fixed;
  top: 48px; left: 0; bottom: 0;
  width: 240px;
  background: var(--sh-nav);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 490;
  padding: 10px 8px 18px;
  transition: width .18s ease, transform .18s ease;
}
.sh-nav-group {
  margin: 12px 8px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
  color: var(--sh-muted);
  white-space: nowrap;
}
.sh-nav-group:first-child { margin-top: 2px; }
.sh-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 2px 0;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
  font-size: 13.5px;
  text-decoration: none;
  white-space: nowrap;
}
.sh-nav-item:hover { background: var(--sh-surface-hover); color: var(--text); }
.sh-nav-item.active {
  background: var(--sh-primary-soft);
  color: var(--sh-primary);
  font-weight: 600;
}
.sh-nav-item svg { width: 17px; height: 17px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sh-nav-label { overflow: hidden; text-overflow: ellipsis; }
.sh-nav-footer {
  margin-top: 14px;
  padding: 10px 10px 0;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--sh-muted);
  white-space: nowrap;
}

/* 内容工作区：对应样稿的 workspace，旧页面统一放入其中，消除各页独立限宽与 body 内边距。 */
body.sh-on { padding: 48px 0 0 240px; min-height: 100vh; max-width: none; margin: 0; }
body.sh-on.sh-collapsed { padding-left: 56px; }
.sh-workspace {
  width: 100%;
  min-height: calc(100vh - 48px);
  padding: 0 24px 32px;
  background: var(--sh-bg);
  overflow: hidden;
}
body.sh-on .sh-workspace > .page-head,
body.sh-on .sh-workspace > .topbar {
  min-height: 92px;
  margin: 0 -24px 20px;
  padding: 22px 24px 18px;
  background: var(--sh-surface);
  border-bottom: 1px solid var(--sh-border);
  box-shadow: none;
}
body.sh-on .sh-workspace > .page-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
body.sh-on .sh-workspace > .topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
body.sh-on .sh-workspace > .page-head h1,
body.sh-on .sh-workspace > .topbar h1 { font-size: 22px; line-height: 30px; }
body.sh-on .sh-workspace > .page-head .back-link { margin-left: auto; }
body.sh-on .sh-workspace > .card,
body.sh-on .sh-split > .card {
  max-width: none;
  margin: 0 0 16px;
  padding: 18px;
  background: var(--sh-panel);
  border: 1px solid var(--sh-border);
  border-radius: var(--sh-radius);
}
/* 功能页首屏采用「状态 / 主要操作」左右分块：信息更聚焦、操作更靠近当前上下文。 */
.sh-split {
  display: grid;
  grid-template-columns: minmax(250px, .72fr) minmax(0, 1.28fr);
  gap: 16px;
  align-items: stretch;
}
.sh-split > .card {
  height: 100%;
  margin-bottom: 16px;
}
.sh-split > .card h2,
.sh-split > .card .card-title {
  margin-top: 0;
}
.sh-split > .card:first-child {
  background: linear-gradient(145deg, var(--sh-panel), var(--sh-surface-subtle));
}
.sh-split > .card:first-child .status-bar {
  min-height: 72px;
  display: flex;
  align-items: center;
}
body.sh-on .sh-workspace > .footer { padding: 12px 0 0; }
/* index 首页和 hash 工具页的历史内容无需再以 body 为窄容器。 */
body.sh-on:has(#toolbox_home) .sh-workspace { max-width: none; }
body.sh-on:has(#toolbox_home) .home-hero {
  margin: 0 -24px 22px;
  padding: 30px 24px 24px;
  background: var(--sh-surface);
  border-bottom: 1px solid var(--sh-border);
}
body.sh-on:has(#toolbox_home) .tool-grid { max-width: 1160px; }
body.sh-on:has(#toolbox_home) .card { max-width: none; }
body.sh-collapsed .sh-sidebar { width: 56px; padding: 10px 6px 18px; }
body.sh-collapsed .sh-nav-group { margin: 10px 0 2px; text-align: center; font-size: 10px; letter-spacing: 0; overflow: hidden; }
body.sh-collapsed .sh-nav-item { justify-content: center; padding: 9px 0; gap: 0; }
body.sh-collapsed .sh-nav-label, body.sh-collapsed .sh-nav-footer { display: none; }

/* 页内旧元素避让 */
body.sh-on .user-bar { display: none !important; }
body.sh-on .topbar .topbar-right { display: none; }
body.sh-on .topbar, body.sh-on .page-head { padding-left: 24px; }
html.sh-scroll { scroll-padding-top: 56px; }

/* 移动端抽屉 */
.sh-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 480;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}
@media (max-width: 900px) {
  body.sh-on, body.sh-on.sh-collapsed { padding-left: 0; }
  .sh-workspace { padding: 0 16px 24px; }
  body.sh-on .sh-workspace > .page-head,
  body.sh-on .sh-workspace > .topbar { margin-left: -16px; margin-right: -16px; padding-left: 16px; padding-right: 16px; }
  body.sh-on:has(#toolbox_home) .home-hero { margin-left: -16px; margin-right: -16px; padding-left: 16px; padding-right: 16px; }
  .sh-split { grid-template-columns: 1fr; gap: 0; }
  .sh-split > .card { height: auto; }
  body.sh-collapsed .sh-sidebar { width: 240px; padding: 10px 8px 18px; }
  body.sh-collapsed .sh-nav-group { margin: 12px 8px 4px; text-align: left; font-size: 11px; letter-spacing: .5px; }
  body.sh-collapsed .sh-nav-item { justify-content: flex-start; padding: 8px 10px; gap: 10px; }
  body.sh-collapsed .sh-nav-label, body.sh-collapsed .sh-nav-footer { display: block; }
  .sh-sidebar, body.sh-collapsed .sh-sidebar { transform: translateX(-102%); width: 240px; box-shadow: var(--sh-shadow); }
  body.sh-drawer .sh-sidebar { transform: none; }
  body.sh-drawer .sh-mask { opacity: 1; pointer-events: auto; }
  .sh-product { display: none; }
  .sh-user .sh-act.pwd { display: none; }
}
@media (max-width: 640px) {
  .sh-user .sh-uname, .sh-user .sh-role { display: none; }
  .sh-user .sh-act { padding: 4px 8px; }
}

@media (max-width: 640px) {
  body { font-size: 14px; }
  .page-head { gap: 10px; }
  .card { border-radius: var(--sh-radius-sm); }
  .table-wrap { border-radius: var(--sh-radius-sm); }
  input, select, textarea { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
