/* 颜色全部来自 themes.css 里的 --md-sys-color-*（M3 的颜色角色）和 --app-ok / --app-warn 两组状态色。
   material-web 没有表格、顶栏、横幅和状态标签，这几样在这里手写，用的也是同一套颜色和形状。 */
:root {
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --md-ref-typeface-brand: var(--sans);
  --md-ref-typeface-plain: var(--sans);
  --shape-s: 8px; --shape-m: 12px; --shape-l: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--md-sys-color-surface); color: var(--md-sys-color-on-surface);
  font: 14px/1.6 var(--sans); -webkit-font-smoothing: antialiased;
}
code, .mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--md-sys-color-on-surface-variant); }
.error { color: var(--md-sys-color-error); margin: 0; }
:focus-visible { outline: 3px solid var(--md-sys-color-secondary); outline-offset: 2px; }
md-outlined-text-field.dense { --md-outlined-text-field-top-space: 10px; --md-outlined-text-field-bottom-space: 10px; }

md-text-button.compact {
  --md-text-button-container-height: 32px; --md-text-button-leading-space: 10px; --md-text-button-trailing-space: 10px;
}
md-text-button.danger {
  --md-text-button-label-text-color: var(--md-sys-color-error);
  --md-text-button-hover-label-text-color: var(--md-sys-color-error);
  --md-text-button-focus-label-text-color: var(--md-sys-color-error);
  --md-text-button-pressed-label-text-color: var(--md-sys-color-error);
  --md-text-button-hover-state-layer-color: var(--md-sys-color-error);
  --md-text-button-pressed-state-layer-color: var(--md-sys-color-error);
}

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--md-sys-color-surface-container-low); }
.login-card {
  width: min(400px, 100%); background: var(--md-sys-color-surface-container-lowest); border-radius: 28px;
  border: 1px solid var(--md-sys-color-outline-variant); padding: 32px 28px 28px; display: grid; gap: 16px;
}
.login-card h1 { margin: 0 0 4px; }
.login-card md-filled-button { margin-top: 4px; }

/* top app bar */
/* 顶栏和底部条用 z-index 1：md-dialog 的遮罩不进浏览器顶层，是个 z-index 1 的 fixed 层，
   它在 DOM 里排在这两条后面，同为 1 才盖得住。内容区用 isolation 把组件自己的 z-index 关在里面 */
.top {
  position: sticky; top: 0; z-index: 1; background: var(--md-sys-color-surface);
  padding-top: env(safe-area-inset-top, 0px); transition: background-color .2s;
}
body.scrolled .top { background: var(--md-sys-color-surface-container); }
.top-row {
  max-width: 1180px; margin: 0 auto; min-height: 64px; padding: 8px 8px 8px 16px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 20px;
}
.brand { font-family: var(--mono); font-weight: 600; }
.top-info { display: flex; flex-wrap: wrap; gap: 0 20px; color: var(--md-sys-color-on-surface-variant); }
.top-actions { margin-left: auto; display: flex; gap: 4px; }
#top-progress { position: absolute; left: 0; right: 0; bottom: 0; --md-linear-progress-track-height: 3px; --md-linear-progress-active-indicator-height: 3px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 8px 16px 140px; isolation: isolate; }

.banner {
  border-radius: var(--shape-m); padding: 8px 8px 8px 16px; margin: 8px 0 16px; min-height: 48px;
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}
.banner-text { flex: 1 1 200px; }
.banner.warn { background: var(--app-warn-container); color: var(--app-on-warn-container); }
.banner.bad { background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }
.banner.info { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.banner md-text-button { --md-text-button-label-text-color: currentColor; }

md-tabs { margin-bottom: 16px; background: transparent; }
.tab { animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; } }

.toolbar { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar md-outlined-text-field { width: min(300px, 100%); }
.hint { color: var(--md-sys-color-on-surface-variant); margin: 12px 4px 0; }

/* 表格：M3 的描边卡片 */
.table-wrap {
  overflow-x: auto; background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant); border-radius: var(--shape-m);
}
table.grid { border-collapse: collapse; width: 100%; }
.grid th {
  text-align: left; font-size: 12px; font-weight: 500; line-height: 16px; letter-spacing: .5px;
  color: var(--md-sys-color-on-surface-variant); padding: 14px 16px; white-space: nowrap;
  border-bottom: 1px solid var(--md-sys-color-outline-variant); background: var(--md-sys-color-surface-container-low);
}
.grid td { padding: 10px 16px; border-bottom: 1px solid var(--md-sys-color-outline-variant); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid tbody tr:not(.editor):hover td { background: var(--md-sys-color-surface-container-low); }
.grid td.key { font-family: var(--mono); font-size: 13px; white-space: nowrap; font-weight: 500; }
.grid td.val { font-family: var(--mono); font-size: 13px; word-break: break-all; max-width: 380px; }
.grid td.acts { white-space: nowrap; text-align: right; padding-right: 8px; }
.grid tr.dirty td, .grid tbody tr.dirty:hover td { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.grid tr.editor td { background: var(--md-sys-color-surface-container); }
.editor-box { display: grid; gap: 8px; padding: 6px 0; }
.editor-box md-outlined-text-field {
  --md-outlined-text-field-input-text-font: var(--mono); --md-outlined-text-field-input-text-size: 13px;
  --md-outlined-text-field-container-shape: var(--shape-s);
}
.editor-box .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.new-val { color: var(--md-sys-color-primary); display: block; margin-top: 2px; font-weight: 500; }
.dirty .new-val { color: var(--md-sys-color-on-secondary-container); }
.del-val { color: var(--md-sys-color-error); display: block; margin-top: 2px; font-weight: 500; }
.masked { color: var(--md-sys-color-on-surface-variant); }

/* 状态标签：不能点，所以不用 md 的 chip，照 M3 标签的尺寸手写 */
.chip {
  display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: var(--shape-s);
  font: 500 12px/16px var(--sans); letter-spacing: .3px; white-space: nowrap; vertical-align: middle;
}
.chip.ok { color: var(--app-on-ok-container); background: var(--app-ok-container); }
.chip.warn { color: var(--app-on-warn-container); background: var(--app-warn-container); }
.chip.bad { color: var(--md-sys-color-on-error-container); background: var(--md-sys-color-error-container); }
.chip.mute { color: var(--md-sys-color-on-surface-variant); background: var(--md-sys-color-surface-container-highest); }
.chip.acc { color: var(--md-sys-color-on-primary-container); background: var(--md-sys-color-primary-container); }

@media (max-width: 640px) {
  .grid thead { display: none; }
  table.grid, .grid tbody, .grid tr, .grid td { display: block; width: 100%; }
  .grid tr { padding: 12px 16px; border-bottom: 1px solid var(--md-sys-color-outline-variant); }
  .grid tr:last-child { border-bottom: 0; }
  .grid tr.dirty { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
  .grid tr.editor { background: var(--md-sys-color-surface-container); }
  .grid td, .grid tr:last-child td, .grid tbody tr:not(.editor):hover td, .grid tbody tr.dirty:hover td {
    border: 0; padding: 2px 0; max-width: none; background: none;
  }
  .grid td.key { padding-bottom: 6px; }
  .grid td[data-label]::before {
    content: attr(data-label); display: inline-block; width: 4.8em; color: var(--md-sys-color-on-surface-variant);
    font-family: var(--sans); font-size: 12px;
  }
  .grid td.acts { text-align: left; padding-top: 6px; margin-left: -10px; }
  .top-row { padding-left: 16px; }
  /* 选择器多写一层：typescale 的 class 在 adoptedStyleSheets 里，排在这份后面，同级会被它盖掉 */
  .top-row .top-info { order: 3; width: 100%; font-size: 12px; line-height: 18px; }
}

/* 底部待应用条：M3 底部栏的底色和阴影 */
.draft {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1; background: var(--md-sys-color-surface-container);
  padding: 12px 16px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); --md-elevation-level: 2;
}
/* 备注框下面有一行 20px 的字数计数，按钮和文字对着上面 44px 的输入框居中，不对着整个框 */
.draft-inner { position: relative; max-width: 1180px; margin: 0 auto; display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.draft-inner md-outlined-text-field { flex: 1 1 220px; }
.draft-inner > strong { line-height: 44px; }
.draft-inner > :is(md-filled-button, md-text-button) { margin-top: 2px; }

/* history */
.history { display: grid; grid-template-columns: minmax(260px, 360px) 1fr; gap: 16px; align-items: start; }
.history-list {
  padding: 4px 0; border-radius: var(--shape-m); border: 1px solid var(--md-sys-color-outline-variant);
  --md-list-container-color: var(--md-sys-color-surface-container-lowest); overflow: hidden;
}
.history-list md-list-item { --md-list-item-top-space: 10px; --md-list-item-bottom-space: 10px; }
.history-list md-list-item.on {
  background: var(--md-sys-color-secondary-container);
  --md-list-item-label-text-color: var(--md-sys-color-on-secondary-container);
  --md-list-item-supporting-text-color: var(--md-sys-color-on-secondary-container);
}
.history-list .line1 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.history-list .line1 .muted { font-size: 13px; }
.history-list md-list-item.on .muted { color: inherit; }
.history-detail {
  background: var(--md-sys-color-surface-container-lowest); border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-m); padding: 16px 20px; min-height: 120px;
}
.history-detail h3 { margin: 0 0 8px; display: flex; gap: 10px; align-items: center; }
.history-detail p { margin: 6px 0; }
.changes { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.changes li { font-size: 13.5px; }
.changes code {
  background: var(--md-sys-color-surface-container-high); padding: 1px 6px; border-radius: 6px;
}
@media (max-width: 760px) { .history { grid-template-columns: 1fr; } }

/* dialogs */
md-dialog { width: min(640px, calc(100vw - 32px)); max-width: none; --md-dialog-container-color: var(--md-sys-color-surface-container-high); }
.progress-body { display: grid; gap: 12px; }
.steps { margin: 0; padding-left: 22px; display: grid; gap: 4px; font-size: 13.5px; max-height: 40vh; overflow: auto; }
.steps li.note { color: var(--app-warn); }
details summary { cursor: pointer; color: var(--md-sys-color-primary); font-weight: 500; }
md-dialog pre {
  background: var(--md-sys-color-surface-container-highest); border-radius: var(--shape-s); padding: 10px 12px;
  font-size: 12px; max-height: 240px; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 8px 0 0;
}
.result { border-radius: var(--shape-m); padding: 12px 16px; font-weight: 500; }
.result.ok { background: var(--app-ok-container); color: var(--app-on-ok-container); }
.result.bad { background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }
.callout { border-radius: var(--shape-m); padding: 10px 14px; margin: 12px 0 0; font-size: 13.5px; }
.callout.warn { background: var(--app-warn-container); color: var(--app-on-warn-container); }
.callout.ok { background: var(--app-ok-container); color: var(--app-on-ok-container); }

/* 主题菜单里的色块 */
.swatch { width: 20px; height: 20px; border-radius: 50%; display: inline-block; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .12); }
