:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f5f6f8;
  color: #20242b;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: #f5f6f8; }
button, input, select { font: inherit; letter-spacing: 0; }
button { min-height: 38px; padding: 0 16px; border: 1px solid #cdd2da; border-radius: 6px; background: #fff; color: #292e36; cursor: pointer; font-weight: 600; }
button:hover { border-color: #8b94a3; background: #f8f9fa; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(24, 112, 86, .2); outline-offset: 1px; }
button.primary { border-color: #126b50; background: #126b50; color: #fff; }
button.primary:hover { background: #0e5a43; }
button.quiet { background: transparent; }
button.danger { border-color: #c84343; color: #b52f2f; background: #fff; }
button.icon-button { width: 38px; padding: 0; font-size: 25px; line-height: 1; border: 0; background: transparent; }
button.full { width: 100%; }
button:disabled { opacity: .55; cursor: not-allowed; }
input, select { width: 100%; min-height: 40px; border: 1px solid #cdd2da; border-radius: 5px; padding: 8px 11px; background: #fff; color: #20242b; }
label { display: grid; gap: 7px; font-size: 13px; color: #525966; font-weight: 600; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eceff2; }
.login-panel { width: min(390px, 100%); background: #fff; border: 1px solid #d8dde4; border-radius: 8px; padding: 34px; box-shadow: 0 12px 32px rgba(29, 35, 44, .09); display: grid; gap: 18px; }
.login-panel h1 { margin: 0; text-align: center; font-size: 25px; }
.login-panel > p { margin: -12px 0 4px; text-align: center; color: #68707e; }
.brand-mark { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto; border-radius: 7px; background: #b52f2f; color: #fff; font-weight: 800; font-size: 19px; }
.brand-mark.small { width: 42px; height: 42px; margin: 0; font-size: 15px; }
.form-error { min-height: 20px; color: #b52f2f; font-size: 13px; text-align: center; }

.app-shell { min-height: 100vh; }
.app-header { height: 72px; padding: 0 28px; background: #20242b; color: #fff; display: flex; align-items: center; justify-content: space-between; }
.brand-inline { display: flex; align-items: center; gap: 12px; }
.brand-inline h1 { margin: 0; font-size: 18px; }
.brand-inline p { margin: 3px 0 0; color: #b6bdc8; font-size: 12px; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.app-header button { color: #fff; border-color: #59606d; }
.save-state { color: #b8c0ca; font-size: 13px; }
.save-state.dirty { color: #ffd074; }

.summary-bar { display: grid; grid-template-columns: repeat(5, minmax(140px, 1fr)); border-bottom: 1px solid #d8dde4; background: #fff; padding: 18px 28px; }
.summary-bar > div { display: grid; gap: 5px; padding-right: 24px; border-right: 1px solid #e2e6eb; }
.summary-bar > div + div { padding-left: 24px; }
.summary-bar > div:last-child { border-right: 0; }
.summary-bar span { font-size: 12px; color: #747c89; }
.summary-bar strong { font-size: 20px; }

.toolbar { min-height: 66px; padding: 12px 28px; display: flex; align-items: center; gap: 9px; border-bottom: 1px solid #d8dde4; background: #f9fafb; }
.toolbar-spacer { flex: 1; }
.search-box { width: min(360px, 35vw); position: relative; }
.search-box span { position: absolute; left: 12px; top: 7px; font-size: 22px; color: #737b88; }
.search-box input { padding-left: 38px; }
.toolbar select { width: 150px; }

.table-region { padding: 0 28px 40px; overflow-x: auto; }
table { width: 100%; min-width: 850px; border-collapse: collapse; background: #fff; }
thead { position: sticky; top: 0; z-index: 1; }
th { height: 44px; padding: 0 14px; background: #eef1f4; border-bottom: 1px solid #d5dae1; color: #606875; font-size: 12px; text-align: left; }
td { height: 58px; padding: 8px 14px; border-bottom: 1px solid #e4e7eb; font-size: 14px; vertical-align: middle; }
tbody tr:hover { background: #f7f9fa; }
.number-column { width: 90px; }
.action-column { width: 92px; text-align: right; }
.channel-number { font-variant-numeric: tabular-nums; font-weight: 700; }
.channel-name { font-weight: 650; }
.muted { color: #7b8390; }
.source-count { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 4px; background: #e7f1ed; color: #126b50; font-size: 12px; font-weight: 700; }
.source-count.none { background: #f4e8e8; color: #a53d3d; }
.health-badge { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 4px; background: #edf0f3; color: #626b78; font-size: 12px; font-weight: 700; white-space: nowrap; }
.health-badge.healthy { background: #e7f1ed; color: #126b50; }
.health-badge.degraded { background: #fff3d8; color: #8b6100; }
.health-badge.unavailable { background: #f4e8e8; color: #a53d3d; }
.empty-state { padding: 70px 20px; text-align: center; background: #fff; color: #737b88; }

dialog { padding: 0; border: 1px solid #cfd5dd; border-radius: 8px; box-shadow: 0 20px 55px rgba(20, 25, 32, .28); color: #20242b; }
dialog::backdrop { background: rgba(20, 24, 30, .62); }
.editor-dialog { width: min(900px, calc(100vw - 40px)); max-height: calc(100vh - 40px); }
.editor-dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 42px); }
.dialog-header { min-height: 72px; padding: 15px 22px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #dfe3e8; background: #f8f9fa; }
.dialog-header h2 { margin: 0; font-size: 19px; }
.dialog-header p { margin: 4px 0 0; color: #727a87; font-size: 12px; }
.editor-content { padding: 22px; overflow-y: auto; display: grid; gap: 20px; }
.field-grid { display: grid; grid-template-columns: 150px 1fr 1.5fr 1fr; gap: 14px; }
.source-heading { display: flex; align-items: end; justify-content: space-between; padding-top: 4px; }
.source-heading h3 { margin: 0; font-size: 16px; }
.source-heading p { margin: 4px 0 0; color: #727a87; font-size: 12px; }
.source-list { display: grid; gap: 9px; }
.source-row { display: grid; grid-template-columns: 40px minmax(200px, 1fr) auto auto auto auto; gap: 7px; align-items: center; }
.source-index { display: grid; place-items: center; height: 40px; border-radius: 4px; background: #eef1f4; color: #626b78; font-size: 12px; font-weight: 700; }
.source-row button { width: 40px; padding: 0; }
.source-row .test-source { width: auto; padding: 0 12px; }
.source-result { grid-column: 2 / -1; min-height: 18px; color: #737b88; font-size: 12px; }
.source-result.ok { color: #126b50; }
.source-result.failed { color: #b52f2f; }
.dialog-footer { min-height: 68px; padding: 14px 22px; display: flex; align-items: center; gap: 9px; border-top: 1px solid #dfe3e8; background: #f8f9fa; }

.history-dialog { width: min(640px, calc(100vw - 40px)); }
.history-list { max-height: 60vh; overflow-y: auto; }
.history-row { display: grid; grid-template-columns: 100px 1fr 120px auto; align-items: center; gap: 16px; min-height: 62px; padding: 10px 20px; border-bottom: 1px solid #e1e5ea; }
.history-row strong { font-size: 15px; }
.history-row span { color: #727a87; font-size: 13px; }

.toast { position: fixed; right: 24px; bottom: 24px; min-width: 240px; max-width: 420px; padding: 13px 16px; border-radius: 6px; background: #20242b; color: #fff; box-shadow: 0 9px 24px rgba(20, 25, 32, .25); transform: translateY(30px); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.visible { transform: translateY(0); opacity: 1; }
.toast.error { background: #a22f2f; }

@media (max-width: 900px) {
  .summary-bar { grid-template-columns: repeat(2, 1fr); gap: 16px 0; }
  .summary-bar > div:nth-child(even) { border-right: 0; }
  .toolbar { flex-wrap: wrap; }
  .toolbar-spacer { display: none; }
  .search-box { width: 100%; }
  .toolbar select { width: 100%; }
  .field-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .app-header, .toolbar, .summary-bar { padding-left: 16px; padding-right: 16px; }
  .table-region { padding-left: 0; padding-right: 0; }
  .summary-bar { grid-template-columns: 1fr; }
  .summary-bar > div, .summary-bar > div + div { padding: 0 0 12px; border-right: 0; border-bottom: 1px solid #e2e6eb; }
  .summary-bar > div:last-child { border-bottom: 0; }
  .save-state { display: none; }
  .field-grid { grid-template-columns: 1fr; }
  .source-row { grid-template-columns: 36px minmax(150px, 1fr) 38px 38px; }
  .source-row .test-source { grid-column: 2 / 3; }
  .source-result { grid-column: 2 / -1; }
}
