/*
 * ITSM shared visual shell.
 * Django templates and the Vue entry load this file last, so navigation, brand,
 * typography and responsive behavior have a single source of truth while the
 * feature-specific page styles remain in their respective app stylesheets.
 */
:root {
  color-scheme: light dark;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --page: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8f9fc;
  --surface-tint: #f1f2ff;
  --text: #1c2740;
  --muted: #657188;
  --line: #e3e8f1;
  --brand: #514bce;
  --brand-hover: #403bb9;
  --brand-contrast: #ffffff;
  --good: #19734b;
  --good-soft: #e7f6ee;
  --warning: #805a15;
  --warning-soft: #fff3d7;
  --danger: #a42d43;
  --danger-soft: #fff0f2;
  --shadow: 0 14px 34px rgb(24 39 74 / 6%);
  --shell-header-height: 70px;
  --shell-sidebar-width: 218px;
  /* Older Django feature styles use these names; aliases keep both systems in sync. */
  --bg: var(--page);
  --surface-2: var(--surface-soft);
  --border: var(--line);
  --primary: var(--brand);
  --primary-hover: var(--brand-hover);
  --primary-soft: var(--surface-tint);
  --success: var(--good);
  --success-bg: var(--good-soft);
  --warning-bg: var(--warning-soft);
  --info: #275f9f;
  --info-bg: #e5f0ff;
  --radius: 13px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #111722;
    --surface: #1c2432;
    --surface-soft: #242e3f;
    --surface-tint: #323150;
    --text: #edf1fa;
    --muted: #b1bdd1;
    --line: #344054;
    --brand: #aaa7ff;
    --brand-hover: #c0bdff;
    --brand-contrast: #1c2035;
    --good: #9fe4b9;
    --good-soft: #264133;
    --warning: #f4d084;
    --warning-soft: #4b3c26;
    --danger: #ff9aaf;
    --danger-soft: #4b2c35;
    --shadow: 0 16px 40px rgb(0 0 0 / 20%);
    --info: #9dc9ff;
    --info-bg: #23374e;
  }
}

/* These elements exist in both shells. Their visual rules must not be forked. */
.app-shell, .app-frame { min-height: 100vh; }
.topbar {
  position: relative;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--shell-header-height);
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand, .topbar-actions, .actor-chip { display: flex; align-items: center; }
.brand { min-width: 0; gap: 10px; }
.brand .brand-mark {
  display: block;
  flex: 0 0 auto;
  width: 39px;
  height: 39px;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 7px 16px rgb(80 79 199 / 21%);
}
.brand-mark img { display: block; width: 100%; height: 100%; }
.brand .brand-copy strong, .brand .brand-copy small,
.actor-copy strong, .actor-copy small { display: block; }
.brand .brand-copy strong { font-size: 17px; font-weight: 700; letter-spacing: .02em; }
.brand .brand-copy small { margin-top: 1px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.topbar-actions { flex: 0 0 auto; gap: 10px; }
.environment-tag { padding: 5px 9px; border: 1px solid var(--warning-soft); border-radius: 999px; background: var(--warning-soft); color: var(--warning); font-size: 11px; font-weight: 650; }
.actor-chip { gap: 8px; }
.actor-avatar { display: grid; place-items: center; flex: 0 0 auto; width: 32px; height: 32px; border-radius: 50%; background: var(--surface-tint); color: var(--brand); font-weight: 750; }
.actor-copy strong { max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.actor-copy small { max-width: 160px; margin-top: 1px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.topbar .text-action { padding: 8px; border: 0; background: transparent; color: var(--muted); font-weight: 600; }
.topbar .text-action:hover { color: var(--brand); }

/* 飞书内置页交接入口在两套页面壳中共用；弹层必须高于窄屏导航。 */
.browser-handoff-panel {
  position: absolute;
  z-index: 45;
  top: calc(100% - 1px);
  right: 12px;
  display: grid;
  gap: 9px;
  width: min(350px, calc(100vw - 24px));
  max-height: min(72vh, 510px);
  overflow-y: auto;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 0 0 13px 13px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.browser-handoff-panel [data-browser-handoff-ready] { display: grid; gap: 9px; }
.browser-handoff-panel[hidden], .browser-handoff-panel [hidden] { display: none; }
.browser-handoff-panel > strong { padding-right: 24px; font-size: 14px; }
.browser-handoff-panel p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.browser-handoff-panel .browser-handoff-error { color: var(--danger); }
.browser-handoff-panel .browser-handoff-hint { font-size: 11px; }
.browser-handoff-panel .button { justify-self: start; }
.browser-handoff-close {
  position: absolute;
  top: 8px;
  right: 9px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 23px;
  line-height: 1;
}
.browser-handoff-close:hover, .browser-handoff-regenerate:hover { color: var(--brand); }
.browser-handoff-copy-label { color: var(--muted); font-size: 11px; font-weight: 650; }
.browser-handoff-copy-row { display: flex; gap: 7px; }
.browser-handoff-copy-row input {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 11px;
}
.browser-handoff-regenerate {
  justify-self: start;
  padding: 3px 0;
  border: 0;
  background: transparent;
  color: var(--brand);
  font-size: 12px;
  font-weight: 650;
}

.app-layout { min-height: calc(100vh - var(--shell-header-height)); }
.sidebar { position: relative; z-index: 25; overflow-x: auto; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--surface); overscroll-behavior-inline: contain; }
.sidebar nav, .sidebar .nav-group { display: flex; align-items: center; gap: 4px; width: max-content; }
.sidebar .nav-group-ops { margin-left: 12px; padding-left: 12px; border-left: 1px solid var(--line); }
.sidebar .nav-title, .sidebar .sidebar-help { display: none; }
.sidebar .nav-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  margin: 0;
  padding: 7px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.sidebar .nav-link:hover,
.sidebar .nav-link.is-active,
.sidebar .nav-link[aria-current="page"] { background: var(--surface-tint); color: var(--brand); }
.nav-icon { display: block; flex: 0 0 auto; width: 18px; height: 18px; color: var(--brand); fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mobile-ops { display: none; }
.demo-switch { display: flex; align-items: center; gap: 3px; width: max-content; margin-top: 8px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); }
.demo-switch > span { padding: 0 6px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.demo-switch button { min-height: 30px; padding: 4px 9px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 11px; }
.demo-switch button[aria-pressed="true"] { background: var(--surface); color: var(--brand); box-shadow: 0 2px 7px rgb(20 39 78 / 9%); }
.sidebar-help { display: none; }
.main-content { min-width: 0; max-width: 1420px; margin: 0 auto; padding: 22px 14px 42px; }
/* Keep the page title and primary actions steady when crossing Vue/Django routes. */
.page-header h1, .page-intro h1 { margin-bottom: 6px; font-size: clamp(25px, 5vw, 32px); line-height: 1.22; letter-spacing: -.025em; }
.page-header p, .page-intro p:not(.eyebrow) { line-height: 1.65; }
.button { min-height: 42px; gap: 8px; padding: 9px 16px; border-radius: 11px; font-weight: 650; line-height: 1.2; }
.button.primary, .button-primary { border-color: var(--brand); background: var(--brand); color: var(--brand-contrast); }
.button.primary:hover, .button-primary:hover { border-color: var(--brand-hover); background: var(--brand-hover); }
.panel, .table-wrap { border-color: var(--line); border-radius: 17px; box-shadow: var(--shadow); }

@media (min-width: 560px) {
  .main-content { padding: 28px 24px 54px; }
}

@media (min-width: 920px) {
  .topbar { position: sticky; top: 0; padding-inline: 24px; }
  .app-layout { display: grid; grid-template-columns: var(--shell-sidebar-width) minmax(0, 1fr); }
  .sidebar { position: sticky; top: var(--shell-header-height); height: calc(100vh - var(--shell-header-height)); overflow-y: auto; padding: 20px 12px; border-right: 1px solid var(--line); border-bottom: 0; }
  .sidebar nav, .sidebar .nav-group { display: block; width: auto; }
  .sidebar .nav-group { margin-bottom: 24px; }
  .sidebar .nav-group-ops { margin-left: 0; padding-left: 0; border-left: 0; }
  .sidebar .nav-title { display: block; margin: 0 0 8px; padding: 0 10px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .09em; }
  .sidebar .nav-link { display: flex; margin: 2px 0; }
  .demo-switch { justify-content: center; width: 100%; margin-top: 8px; }
  .sidebar .sidebar-help { display: block; margin-top: 28px; padding: 15px 11px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
  .sidebar-help strong { font-size: 12px; }
  .sidebar-help p { margin: 6px 0 12px; color: var(--muted); font-size: 11px; line-height: 1.5; }
  .sidebar-help .button { display: flex; width: 100%; min-height: 35px; align-items: center; justify-content: center; padding: 7px 10px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--text); font-size: 11px; font-weight: 650; }
  .sidebar-help .button:hover { border-color: var(--brand); background: var(--surface-soft); }
  .main-content { width: 100%; padding: 31px 30px 64px; }
}

@media (max-width: 919px) {
  .sidebar { overflow: visible; }
  .sidebar .nav-group-ops { display: none; }
  .sidebar .mobile-ops { position: relative; display: block; min-width: 0; }
  .sidebar .mobile-ops summary { display: flex; align-items: center; gap: 7px; min-height: 40px; padding: 7px 12px; border-radius: 10px; color: var(--muted); font-weight: 600; list-style: none; cursor: pointer; white-space: nowrap; }
  .sidebar .mobile-ops summary::-webkit-details-marker { display: none; }
  .sidebar .mobile-ops[open] summary, .sidebar .mobile-ops summary:hover { background: var(--surface-tint); color: var(--brand); }
  .sidebar .mobile-ops-menu { position: absolute; top: calc(100% + 8px); right: 0; z-index: 30; width: min(72vw, 230px); max-height: min(65vh, 460px); overflow-y: auto; padding: 7px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
  .sidebar .mobile-ops-menu a { display: flex; flex-direction: row; align-items: center; justify-content: flex-start; gap: 9px; min-height: 39px; padding: 8px 9px; border-radius: 8px; color: var(--text); font-size: 12px; font-weight: 600; text-align: left; white-space: nowrap; }
  .sidebar .mobile-ops-menu a:hover, .sidebar .mobile-ops-menu a[aria-current="page"] { background: var(--surface-tint); color: var(--brand); }
  .sidebar .mobile-ops-menu .nav-icon { width: 18px; height: 18px; }
}

@media (max-width: 559px) {
  .sidebar { padding: 7px 8px; }
  .sidebar nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 3px; width: 100%; }
  .sidebar nav.has-ops { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  /* 无智能问答权限时只摆放剩余入口，避免小屏留下一个空白导航格。 */
  .sidebar nav.without-qa { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sidebar nav.without-qa.has-ops { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sidebar .nav-group { display: contents; }
  .sidebar .nav-group-ops { display: none; }
  .sidebar .nav-link { display: flex; flex-direction: column; justify-content: center; gap: 1px; min-width: 0; min-height: 48px; padding: 4px 2px; text-align: center; font-size: 11px; }
  .sidebar .mobile-ops summary { flex-direction: column; justify-content: center; gap: 1px; min-height: 48px; padding: 4px 2px; font-size: 11px; }
  .demo-switch { margin-inline: auto; }
}

@media (max-width: 460px) {
  .brand .brand-copy small, .actor-copy { display: none; }
  /* 增加改密和外部浏览器入口后允许顶栏换行，避免小屏上操作按钮溢出。 */
  .topbar { flex-wrap: wrap; row-gap: 3px; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; max-width: 100%; margin-left: auto; gap: 3px; }
  .topbar .text-action { white-space: nowrap; }
}
