/* ============================================================
   MLAM — MD3 布局样式
   令牌：Google @material/web 2.5.0（assets/md3/，Apache-2.0）
   布局：顶部 App Bar + 左侧 Navigation Rail + 右侧内容面板
   ============================================================ */

/* ------------------------------------------------------------
   1. 主题（Material Theme Builder 深色蓝灰方案）
   ------------------------------------------------------------ */

:root {
  color-scheme: dark;

  --md-sys-color-primary:                    #a8c7fa;
  --md-sys-color-on-primary:                 #0b2b4f;
  --md-sys-color-primary-container:          #234a75;
  --md-sys-color-on-primary-container:       #d6e3ff;
  --md-sys-color-surface-tint:               #a8c7fa;

  --md-sys-color-surface:                    #111318;
  --md-sys-color-on-surface:                 #e3e2e6;
  --md-sys-color-surface-dim:                #111318;
  --md-sys-color-surface-bright:             #37393e;

  /* 层次：画布 < 侧栏 < 卡片 < 悬浮层，与 Chrome 设置页的明暗关系一致 */
  --md-sys-color-surface-container-lowest:   #17191d;
  --md-sys-color-surface-container-low:      #1b1e22;
  --md-sys-color-surface-container:          #1f2226;
  --md-sys-color-surface-container-high:     #26292e;
  --md-sys-color-surface-container-highest:  #2e3138;

  --md-sys-color-on-surface-variant:         #c3c6d0;
  --md-sys-color-outline:                    #8d9199;
  --md-sys-color-outline-variant:            #43474e;

  --md-sys-color-error:                      #ffb4ab;
  --md-sys-color-on-error:                   #690005;
  --md-sys-color-error-container:            #93000a;
  --md-sys-color-on-error-container:         #ffdad6;

  --md-sys-color-inverse-surface:            #e3e2e6;
  --md-sys-color-inverse-on-surface:         #2f3033;
  --md-sys-color-scrim:                      #000;
  --md-sys-color-shadow:                     #000;

  /* 扩展语义色 */
  --app-color-success:           #7ad0a0;
  --app-color-warning:           #f2c464;
  --app-color-warning-container: rgba(242, 196, 100, 0.12);

  --md-ref-typeface-mono: "JetBrains Mono", ui-monospace, SFMono-Regular,
    "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --app-ease-standard:   cubic-bezier(.2, 0, 0, 1);
  --app-ease-emphasized: cubic-bezier(.2, 0, 0, 1);
  --app-dur-short2:      100ms;
  --app-dur-short4:      200ms;
  --app-dur-medium2:     300ms;

  --app-appbar-h:  64px;
  --app-rail-w:    280px;
}

/* ------------------------------------------------------------
   2. 基础
   ------------------------------------------------------------ */

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-ref-typeface-plain, "Roboto", "Noto Sans",
    "PingFang SC", "Microsoft YaHei", system-ui, sans-serif);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

a { color: var(--md-sys-color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 3px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* ------------------------------------------------------------
   3. App Bar（MD3 小顶栏 64px，无边框线，靠底色分层）
   ------------------------------------------------------------ */

.app-bar {
  flex: 0 0 auto;
  height: var(--app-appbar-h);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 16px 0 8px;
  background: var(--md-sys-color-surface-container);
  position: sticky;
  top: 0;
  z-index: 30;
}

.app-bar__menu { flex: 0 0 auto; }

.app-bar__titles { min-width: 0; display: flex; align-items: baseline; gap: 10px; }

.app-bar__title {
  margin: 0;
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--md-sys-color-on-surface);
  line-height: 1.3;
}

.app-bar__subtitle {
  margin: 0;
  font-size: 12.5px;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------------------------------------
   4. Shell 布局
   ------------------------------------------------------------ */

.shell {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

/* ------------------------------------------------------------
   5. 左侧导航
   ------------------------------------------------------------ */

.nav-rail {
  flex: 0 0 var(--app-rail-w);
  width: var(--app-rail-w);
  display: flex;
  flex-direction: column;
  background: var(--md-sys-color-surface-container);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 8px;
}

.nav-rail__head {
  display: flex;
  align-items: center;
  padding: 16px 12px 6px 20px;
}

.nav-rail__label {
  flex: 1 1 auto;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
}

.nav-rail__close { display: none; }

.nav-rail__list {
  flex: 1 1 auto;
  padding: 0 8px;
  --md-list-container-color: transparent;
}

/* 导航项：单行，与 Chrome 设置页一致 */
.nav-item__headline {
  font-size: 13.5px;
  font-weight: 400;
  line-height: 1.45;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item__badge {
  font-family: var(--md-ref-typeface-mono);
  font-size: 11px;
  color: var(--md-sys-color-on-surface-variant);
  font-variant-numeric: tabular-nums;
  opacity: .7;
}

md-list-item {
  --md-list-item-label-text-color: var(--md-sys-color-on-surface);
  --md-list-item-supporting-text-color: var(--md-sys-color-on-surface-variant);
  --md-list-item-trailing-supporting-text-color: var(--md-sys-color-on-surface-variant);
  --md-list-item-one-line-container-height: 42px;
  --md-list-item-two-line-container-height: 56px;
  --md-list-item-leading-space: 16px;
  --md-list-item-trailing-space: 16px;
}

/* md-list-item 本身没有 selected 状态（这是 MD3 的既定设计），
   导航选中态由外壳元素提供 —— 与 Chrome 设置页一致：
   浅色胶囊底 + 主题色文字 + 无边框 */
.nav-rail__list md-list-item.nav-item--active {
  background: var(--md-sys-color-primary-container);
  border-radius: 999px;
  --md-list-item-label-text-color: var(--md-sys-color-on-primary-container);
  --md-list-item-supporting-text-color: var(--md-sys-color-on-primary-container);
  --md-list-item-trailing-supporting-text-color: var(--md-sys-color-on-primary-container);
}

.nav-rail__list md-list-item.nav-item--active .nav-item__badge {
  color: var(--md-sys-color-on-primary-container);
  border-color: currentColor;
  opacity: .65;
}

.nav-rail__list md-list-item {
  border-radius: 999px;
}

.nav-rail__foot {
  padding: 12px 16px 18px;
  margin-top: 8px;
}

.nav-rail__foot md-divider { margin-bottom: 12px; }

.nav-rail__meta {
  margin: 0;
  font-size: 11.5px;
  color: var(--md-sys-color-on-surface-variant);
}

/* 遮罩：仅窄屏 */
.nav-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--md-sys-color-scrim);
  opacity: 0.55;
  border: 0;
}

/* ------------------------------------------------------------
   6. 内容区
   ------------------------------------------------------------ */

.content {
  flex: 1 1 auto;
  min-width: 0;
  overflow-y: auto;
  padding: 0 24px 64px;
  scroll-behavior: smooth;
}

/* 内容区宽度约束，避免超宽屏行文过长 */
.panel {
  max-width: 1040px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  padding: 24px 0 2px;
}

.panel-title {
  margin: 0;
  font-size: 22px;
  font-weight: 400;
  color: var(--md-sys-color-on-surface);
  line-height: 1.35;
  letter-spacing: 0.005em;
}

.panel-id {
  font-family: var(--md-ref-typeface-mono);
  font-size: 11px;
  color: var(--md-sys-color-on-surface-variant);
  opacity: .7;
}

.panel-note {
  margin: 12px 0 0;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--md-sys-color-surface-container-low);
  border-left: 3px solid var(--md-sys-color-primary);
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--md-sys-color-on-surface-variant);
}

.panel-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  margin: 14px 0 4px;
  font-size: 11.5px;
  color: var(--md-sys-color-on-surface-variant);
}

/* 空状态 / 错误 */
.state-loading {
  padding: 40px 16px;
  text-align: center;
  font-size: 13.5px;
  color: var(--md-sys-color-on-surface-variant);
}

.state-error {
  margin: 8px 0;
  padding: 16px 18px;
  border-radius: 12px;
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  font-family: var(--md-ref-typeface-mono);
  font-size: 12.5px;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* ------------------------------------------------------------
   7. 版本卡片
   ------------------------------------------------------------ */

.version {
  margin-top: 20px;
  border-radius: 12px;
  background: var(--md-sys-color-surface-container-low);
  /* MD3 卡片：无描边，靠底色 + 轻微高度差区分 */
  /* 不设 overflow:hidden，避免裁剪 tooltip；圆角交给子元素 */
}

.version > .version-head:first-child { border-radius: 11px 11px 0 0; }

.version-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.version-number {
  font-family: var(--md-ref-typeface-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

.channel {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid currentColor;
}

.channel--release  { color: var(--app-color-success); }
.channel--beta     { color: var(--app-color-warning); }
.channel--snapshot { color: var(--md-sys-color-on-surface-variant); }

.version-date {
  font-family: var(--md-ref-typeface-mono);
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  font-variant-numeric: tabular-nums;
}

.version-flag {
  margin-left: auto;
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 4px;
  color: var(--app-color-warning);
  background: var(--app-color-warning-container);
  border: 1px solid currentColor;
}

/* ------------------------------------------------------------
   8. 文件表
   ------------------------------------------------------------ */

.file-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  border-radius: 0 0 11px 11px;
  overflow: hidden;
  display: table;
}

.file-table thead th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
  opacity: .75;
  padding: 8px 18px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  white-space: nowrap;
}

.file-table thead th:nth-child(3),
.file-table thead th:last-child { text-align: right; }

.file-table tbody td {
  padding: 12px 18px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  vertical-align: middle;
}

.file-table tbody tr:last-child td { border-bottom: none; }

.file-table tbody tr {
  transition: background var(--app-dur-short2) var(--app-ease-standard);
}

.file-table tbody tr:hover { background: var(--md-sys-color-surface-container-high); }

.file-name {
  font-family: var(--md-ref-typeface-mono);
  font-size: 12.5px;
  color: var(--md-sys-color-on-surface);
  word-break: break-all;
  line-height: 1.45;
}

.file-platform {
  white-space: nowrap;
  font-size: 12.5px;
  color: var(--md-sys-color-on-surface-variant);
}

.file-size {
  white-space: nowrap;
  font-family: var(--md-ref-typeface-mono);
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.file-action {
  white-space: nowrap;
  text-align: right;
  padding-right: 10px !important;
}

/* ------------------------------------------------------------
   9. 哈希
   ------------------------------------------------------------ */

.hash-cell { min-width: 0; }

.hash-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hash-value {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--md-ref-typeface-mono);
  font-size: 11px;
  line-height: 1.45;
  color: var(--md-sys-color-on-surface-variant);
  word-break: break-all;
  letter-spacing: -0.01em;
}

.hash-warn {
  flex: 0 0 auto;
  color: var(--app-color-warning);
  font-size: 13px;
  line-height: 1;
  cursor: help;
  padding: 0 2px;
  border-radius: 4px;
}

.hash-warn:focus-visible {
  outline: 2px solid var(--app-color-warning);
  outline-offset: 2px;
}

/* 全局浮层 tooltip */
.tooltip-layer {
  position: fixed;
  z-index: 9999;
  max-width: 280px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  font-size: 12px;
  line-height: 1.55;
  box-shadow: 0 3px 6px rgba(0,0,0,.3), 0 6px 14px rgba(0,0,0,.25);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px) scale(.97);
  transition: opacity var(--app-dur-short2) var(--app-ease-standard),
              transform var(--app-dur-short2) var(--app-ease-standard);
}

.tooltip-layer.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.tooltip-layer::before {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  background: var(--md-sys-color-inverse-surface);
  transform: rotate(45deg);
  left: var(--arrow-left, 50%);
  margin-left: -4.5px;
  top: -4.5px;
}

.tooltip-layer.is-flipped::before {
  top: auto;
  bottom: -4.5px;
}

/* ------------------------------------------------------------
   10. MD3 组件尺寸微调
   ------------------------------------------------------------ */

.download-btn {
  --md-filled-button-container-height: 30px;
  --md-filled-button-leading-space: 18px;
  --md-filled-button-trailing-space: 18px;
  --md-filled-button-label-text-size: .8125rem;
  --md-filled-button-label-text-weight: 500;
}

.unavailable-btn {
  --md-outlined-button-container-height: 30px;
  --md-outlined-button-leading-space: 16px;
  --md-outlined-button-trailing-space: 16px;
  --md-outlined-button-label-text-size: .8125rem;
  --md-outlined-button-label-text-color: var(--md-sys-color-on-surface-variant);
  --md-outlined-button-outline-color: var(--md-sys-color-outline);
  --md-outlined-button-hover-label-text-color: var(--app-color-warning);
  --md-outlined-button-hover-outline-color: var(--app-color-warning);
}

.copy-btn {
  --md-text-button-container-height: 24px;
  --md-text-button-leading-space: 8px;
  --md-text-button-trailing-space: 8px;
  --md-text-button-label-text-size: .6875rem;
  --md-text-button-label-text-color: var(--md-sys-color-on-surface-variant);
  --md-text-button-hover-label-text-color: var(--md-sys-color-primary);
  flex: 0 0 auto;
}

.copy-btn.copied {
  --md-text-button-label-text-color: var(--app-color-success);
  --md-text-button-hover-label-text-color: var(--app-color-success);
}

md-dialog {
  --md-dialog-container-shape: 28px;
  --md-dialog-container-color: var(--md-sys-color-surface-container-high);
  --md-dialog-headline-color: var(--md-sys-color-on-surface);
  --md-dialog-supporting-text-color: var(--md-sys-color-on-surface-variant);
  --md-dialog-supporting-text-font: 400 .875rem/1.6rem var(--md-ref-typeface-plain);
}

md-dialog [slot="content"] {
  max-height: 50vh;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.7;
}

/* ------------------------------------------------------------
   11. 页脚
   ------------------------------------------------------------ */

.site-footer {
  flex: 0 0 auto;
  background: var(--md-sys-color-surface-container-lowest);
  border-top: 1px solid var(--md-sys-color-outline-variant);
  padding: 20px 24px 26px;
}

.site-footer__disclaimer {
  margin: 0 0 6px;
  font-size: 12.5px;
  color: var(--md-sys-color-on-surface);
}

.site-footer__meta {
  margin: 0;
  font-size: 11.5px;
  color: var(--md-sys-color-on-surface-variant);
}

/* ------------------------------------------------------------
   12. 响应式：窄屏抽屉
   ------------------------------------------------------------ */

@media (max-width: 900px) {
  .nav-rail {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    width: min(300px, 84vw);
    flex-basis: auto;
    border-radius: 0 16px 16px 0;
    box-shadow: 0 8px 24px rgba(0,0,0,.5);
    transform: translateX(-102%);
    transition: transform var(--app-dur-medium2) var(--app-ease-emphasized);
  }

  .nav-rail.is-open { transform: translateX(0); }

  .nav-rail__close { display: inline-flex; }

  .nav-scrim:not([hidden]) { display: block; }

  body.nav-open { overflow: hidden; }

  .content { padding: 16px 14px 48px; }

  .file-table thead { display: none; }

  .file-table,
  .file-table tbody,
  .file-table tr,
  .file-table td {
    display: block;
    width: 100%;
  }

  .file-table tbody tr {
    padding: 12px 14px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
  }

  .file-table tbody td { padding: 2px 0; border: none; }

  .file-table tbody tr:last-child { border-bottom: none; }

  .file-size { text-align: left; }
  .file-size::before {
    content: "大小：";
    color: var(--md-sys-color-on-surface-variant);
  }

  .file-action { text-align: left; padding-top: 10px !important; }

  .tooltip-layer { max-width: 240px; }

  .panel-title { font-size: 19px; }
}

/* 宽屏无需关闭按钮，也不显示遮罩 */
@media (min-width: 901px) {
  .nav-scrim { display: none !important; }
  .nav-rail__close { display: none !important; }
}

/* ------------------------------------------------------------
   13. 减少动效
   ------------------------------------------------------------ */

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