:root {
  color-scheme: light;
  --canvas: #edf3f7;
  --canvas-deep: #dfe9ef;
  --glass: rgba(255, 255, 255, .68);
  --glass-strong: rgba(255, 255, 255, .86);
  --line: rgba(124, 150, 170, .24);
  --line-strong: rgba(95, 127, 151, .42);
  --text: #1d2b39;
  --text-soft: #415667;
  --muted: #718493;
  --muted-soft: #9aaab5;
  --accent: #327b91;
  --accent-deep: #215b70;
  --accent-soft: #dff0f2;
  --ok: #267956;
  --ok-soft: #e4f3eb;
  --warn: #a36b25;
  --warn-soft: #fbefd9;
  --danger: #bd4d58;
  --danger-soft: #fae7e8;
  --shadow: 0 18px 50px rgba(55, 82, 100, .10);
  --shadow-soft: 0 8px 24px rgba(55, 82, 100, .07);
  --radius: 14px;
  --radius-sm: 9px;
  --font-body: "Noto Sans SC", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  --panel: rgba(255, 255, 255, .56);
  --panel-soft: rgba(246, 250, 251, .92);
  --primary: var(--accent);
  --primary-deep: var(--accent-deep);
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  background: radial-gradient(circle at 80% 0%, rgba(219, 239, 240, .92), transparent 35%), var(--canvas);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }
h1, h2, h3, p { margin: 0; }
label, .field { display: grid; gap: 6px; }
label > span, .field > span { color: var(--muted); font-size: 13px; }
input, select {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .72);
  color: var(--text);
  outline: none;
}
input:focus, select:focus {
  border-color: rgba(50, 123, 145, .65);
  box-shadow: 0 0 0 3px rgba(50, 123, 145, .12);
}
.glass-panel {
  border: 1px solid rgba(255, 255, 255, .72);
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.admin-shell { height: 100%; }
.login-view { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.login-panel { display: grid; width: min(400px, 100%); gap: 16px; padding: 26px; border-radius: 18px; }
.login-brand { display: flex; align-items: center; gap: 9px; color: var(--muted); font-family: var(--font-mono); font-size: 10px; letter-spacing: .08em; }
.login-panel h1 { margin-top: 14px; font-size: 26px; letter-spacing: -.04em; }
.login-panel p { margin-top: 7px; color: var(--muted); line-height: 1.65; }

.dashboard-view { display: grid; height: 100vh; min-height: 0; grid-template-columns: 176px minmax(0, 1fr); overflow: hidden; }
.dashboard-view[hidden], .login-view[hidden] { display: none; }
.sidebar {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 12px;
  padding: 17px 11px 12px;
  border-width: 0 1px 0 0;
  border-radius: 0;
  background: rgba(245, 250, 250, .72);
}
.brand-block { display: flex; align-items: center; gap: 9px; padding: 3px 5px 15px; border-bottom: 1px solid var(--line); }
.brand-block b { display: block; font-size: 15px; letter-spacing: .04em; }
.brand-block small { display: block; margin-top: 3px; color: var(--muted); font-family: var(--font-mono); font-size: 9px; letter-spacing: .08em; }
.brand-mark { display: grid; width: 31px; height: 31px; flex: 0 0 31px; place-items: center; border: 1px solid rgba(50, 123, 145, .34); border-radius: 10px; background: rgba(223, 240, 242, .82); color: var(--accent-deep); font-size: 15px; font-weight: 750; }
.nav-label { padding: 6px 8px 2px; color: var(--muted-soft); font-family: var(--font-mono); font-size: 10px; letter-spacing: .13em; }
.side-nav { display: grid; gap: 4px; }
.side-nav button {
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 9px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text-soft);
  text-align: left;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.side-nav button:hover { border-color: var(--line); background: rgba(255, 255, 255, .56); transform: translateX(1px); }
.side-nav button.active { border-color: rgba(50, 123, 145, .25); background: rgba(215, 237, 239, .82); color: var(--accent-deep); font-weight: 700; }
.nav-mark { display: grid; width: 23px; height: 23px; place-items: center; border: 1px solid currentColor; border-radius: 6px; font-family: var(--font-mono); font-size: 8px; letter-spacing: -.08em; }
.sidebar-spacer { flex: 1; }
.session-box { display: grid; gap: 4px; padding: 10px 9px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, .46); }
.session-box span, .session-box small { color: var(--muted); font-size: 11px; }
.session-box b { overflow: hidden; font-family: var(--font-mono); font-size: 11px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }

.content { display: flex; min-width: 0; min-height: 0; height: 100%; flex-direction: column; overflow: hidden; padding: 0 clamp(16px, 2.5vw, 36px) 30px; }
.content-head { display: flex; min-height: 78px; align-items: center; justify-content: space-between; gap: 15px; border-bottom: 1px solid var(--line); }
.content-head h2 { margin-top: 3px; font-size: 25px; letter-spacing: -.045em; }
.content-head p { margin-top: 4px; color: var(--muted); font-size: 13px; }
.eyebrow { color: var(--accent); font-family: var(--font-mono); font-size: 9px; letter-spacing: .14em; }
.head-actions { display: flex; align-items: center; gap: 8px; }
.preview-pill { padding: 6px 9px; border: 1px solid rgba(163, 107, 37, .2); border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-family: var(--font-mono); font-size: 9px; white-space: nowrap; }

.primary-button, .ghost-button, .small-button, .danger-button {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-weight: 650;
  white-space: nowrap;
}
.primary-button { border: 1px solid var(--accent); background: var(--accent); color: #fff; }
.primary-button:hover:not(:disabled) { border-color: var(--accent-deep); background: var(--accent-deep); }
.ghost-button, .small-button { border: 1px solid var(--line); background: rgba(255, 255, 255, .54); color: var(--text-soft); }
.ghost-button:hover:not(:disabled), .small-button:hover:not(:disabled) { border-color: var(--line-strong); background: rgba(255, 255, 255, .88); color: var(--accent-deep); }
.danger-button { border: 1px solid rgba(189, 77, 88, .25); background: var(--danger-soft); color: var(--danger); }
.small-button { min-height: 29px; padding: 0 9px; font-size: 12px; }
.button-link { border: 0; background: none; color: var(--accent-deep); font-size: 12px; font-weight: 700; }

#appRoot { min-height: 0; flex: 1; overflow: hidden; }
.page-grid { display: grid; height: 100%; min-height: 0; gap: 12px; margin-top: 15px; grid-template-rows: auto minmax(0, 1fr); }
.panel { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255, 255, 255, .56); box-shadow: var(--shadow-soft); }
.page-grid > .panel:last-child { display: flex; min-height: 0; flex-direction: column; }
.page-grid > .panel:last-child .table-wrap { min-height: 0; flex: 1; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 11px; }
.panel-head b { font-size: 14px; }
.panel-head span { color: var(--muted); font-size: 12px; }
.panel-note { color: var(--muted); font-size: 12px; }
.form-grid { display: grid; gap: 10px; grid-template-columns: 1.15fr 1.15fr .75fr .9fr 1fr auto; align-items: end; }
.wide-field { grid-column: span 2; }
.preset-buttons, .row-actions, .toolbar, .sort-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.preset-buttons .selected { border-color: rgba(50, 123, 145, .5); background: var(--accent-soft); color: var(--accent-deep); }

.table-wrap { min-height: 0; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, .52); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid rgba(124, 150, 170, .16); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; background: rgba(246, 250, 251, .92); color: var(--muted); font-size: 12px; font-weight: 700; }
td { color: var(--text-soft); font-size: 13px; }
tbody tr { transition: background 140ms ease; }
tbody tr:hover { background: rgba(225, 241, 242, .42); }
tr:last-child td { border-bottom: 0; }
.status-heading { display: inline-flex; align-items: center; gap: 5px; }
.sort-controls { gap: 2px; }
.sort-button { display: grid; width: 20px; height: 18px; place-items: center; padding: 0; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--muted-soft); font-size: 11px; line-height: 1; }
.sort-button:hover, .sort-button.active { border-color: rgba(50, 123, 145, .25); background: var(--accent-soft); color: var(--accent-deep); }
.status, .type-chip { display: inline-flex; align-items: center; min-height: 23px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.status { background: var(--ok-soft); color: var(--ok); }
.status.disabled { background: #edf0f2; color: var(--muted); }
.status.expired { background: var(--warn-soft); color: var(--warn); }
.type-chip { background: rgba(223, 240, 242, .85); color: var(--accent-deep); }
.type-chip.custom { background: #eef0f2; color: var(--muted); }
.mono { font-family: var(--font-mono); font-size: 12px; }
.empty { padding: 28px 12px; color: var(--muted); text-align: center; }

.credits-layout { display: grid; height: calc(100vh - 116px); min-height: 550px; grid-template-columns: minmax(260px, .38fr) minmax(0, .62fr); gap: 12px; margin-top: 15px; }
.account-pane, .detail-pane { display: flex; min-height: 0; flex-direction: column; }
.account-pane { overflow: hidden; }
.account-list { min-height: 0; overflow: auto; padding-right: 2px; }
.credit-account { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; width: 100%; padding: 10px; border: 1px solid transparent; border-bottom-color: rgba(124, 150, 170, .15); background: transparent; color: var(--text); text-align: left; }
.credit-account:hover { background: rgba(225, 241, 242, .44); }
.credit-account.selected { border-color: rgba(50, 123, 145, .3); border-radius: 9px; background: rgba(221, 240, 241, .78); }
.credit-account-main { display: grid; min-width: 0; gap: 4px; }
.credit-account-main b { overflow: hidden; font-family: var(--font-mono); font-size: 12px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.credit-account-main span { color: var(--muted); font-size: 12px; }
.credit-balance { color: var(--accent-deep); font-family: var(--font-mono); font-size: 15px; font-weight: 700; }
.credit-meta { grid-column: 1 / -1; display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.detail-head { display: flex; min-height: 51px; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.detail-head h3 { font-size: 15px; }
.detail-head p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.detail-actions { display: flex; align-items: center; gap: 5px; }
.detail-actions input { width: 105px; height: 29px; font-size: 12px; }
.detail-actions input + input { width: 126px; }
.detail-stack { display: grid; min-height: 0; flex: 1; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; padding-top: 10px; }
.record-panel { display: flex; min-height: 0; flex-direction: column; padding: 11px; border: 1px solid var(--line); border-radius: 11px; background: rgba(255, 255, 255, .48); }
.record-panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding-bottom: 8px; }
.record-panel-head b { font-size: 13px; }
.record-panel-head span { color: var(--muted); font-size: 11px; }
.record-scroll { min-height: 0; overflow: auto; padding-right: 2px; }
.record-row { display: grid; grid-template-columns: minmax(126px, 1.1fr) minmax(98px, .9fr) minmax(78px, .65fr) minmax(100px, 1fr); gap: 8px; padding: 8px 4px; border-top: 1px solid rgba(124, 150, 170, .14); }
.record-row > div { min-width: 0; }
.record-row b, .record-row span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-row b { color: var(--text-soft); font-size: 12px; font-weight: 650; }
.record-row span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.record-row .positive { color: var(--ok); }
.record-row .negative { color: var(--danger); }
.record-row .job-status { color: var(--accent-deep); }

.filter-bar { display: flex; align-items: end; gap: 9px; }
.filter-bar label { min-width: 190px; flex: 1; }
.filter-bar .button-field { flex: 0 0 auto; }
.failure-panel { margin-top: 15px; }

.data-center-page { display: grid; height: 100%; min-height: 0; gap: 12px; margin-top: 15px; grid-template-rows: auto minmax(0, 1fr); }
.metric-grid { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric-card { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255, 255, 255, .56); box-shadow: var(--shadow-soft); }
.metric-card span { display: block; color: var(--muted); font-size: 12px; }
.metric-card b { display: block; margin-top: 8px; color: var(--accent-deep); font-family: var(--font-mono); font-size: 22px; letter-spacing: -.04em; }
.data-center-panel { display: flex; min-height: 0; flex-direction: column; }
.data-center-panel .table-wrap { flex: 1; }
.data-center-footnote { margin-top: 8px; color: var(--muted); font-size: 11px; }

.toast-host { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 20; }
.toast { display: grid; gap: 3px; min-width: 230px; max-width: 380px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 11px; background: var(--glass-strong); box-shadow: var(--shadow); backdrop-filter: blur(14px); }
.toast.is-alert { border-color: rgba(189, 77, 88, .5); background: #fff5f5; }
.toast.is-alert b { color: var(--danger); }
.toast b { font-size: 13px; }
.toast span { color: var(--muted); font-size: 12px; }

@media (max-width: 1080px) {
  .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form-grid .wide-field { grid-column: span 2; }
  .credits-layout { height: auto; min-height: 0; grid-template-columns: 1fr; }
  .account-pane { max-height: 330px; }
  .detail-pane { min-height: 650px; }
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .dashboard-view { height: 100vh; grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .sidebar { min-height: auto; border-width: 0 0 1px; border-radius: 0; }
  .brand-block { padding-bottom: 10px; }
  .side-nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sidebar-spacer, .session-box, .logout-button { display: none; }
  .content-head { align-items: flex-start; flex-direction: column; justify-content: center; padding: 14px 0; }
  .head-actions { width: 100%; justify-content: space-between; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid .wide-field { grid-column: 1 / -1; }
  .filter-bar { align-items: stretch; flex-direction: column; }
  .filter-bar label { min-width: 0; }
  .detail-head { align-items: flex-start; flex-direction: column; }
  .detail-actions { width: 100%; }
  .detail-actions input { flex: 1; }
  .metric-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .content { padding: 0 12px 20px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide-field { grid-column: auto; }
  .preview-pill { display: none; }
  .record-row { grid-template-columns: 1fr 1fr; }
}

.status.pending { background: var(--warn-soft); color: var(--warn); }
.failure-page { height: 100%; min-height: 0; overflow-x: hidden; overflow-y: auto; padding: 15px 2px 30px 0; }
.failure-summary { display: grid; gap: 10px; margin: 0 0 14px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.failure-summary-card { display: grid; gap: 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow-soft); }
.failure-summary-card span, .failure-summary-card small, .failure-detail-head p, .failure-context-grid span, .candidate-section-head span, .failure-action-bar span { color: var(--muted); }
.failure-summary-card b { font-size: 24px; line-height: 1.1; }
.failure-filter-panel { margin-bottom: 14px; }
.failure-filters { display: grid; gap: 8px; grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) 150px auto; }
.failure-workspace { display: grid; align-items: start; gap: 14px; grid-template-columns: minmax(320px, .78fr) minmax(520px, 1.22fr); }
.failure-list-panel, .failure-detail-panel { min-width: 0; }
.failure-list { display: grid; max-height: calc(100vh - 300px); gap: 8px; overflow: auto; padding-right: 2px; }
.failure-item { display: grid; gap: 7px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, .72); cursor: pointer; text-align: left; transition: border-color .15s ease, background .15s ease, box-shadow .15s ease; }
.failure-item:hover, .failure-item.is-selected { border-color: rgba(50, 123, 145, .55); background: rgba(240, 249, 249, .92); box-shadow: var(--shadow-soft); }
.failure-item-top, .failure-item-foot, .candidate-card-top, .failure-action-bar, .failure-detail-head, .candidate-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.failure-item-top time, .failure-item-meta, .failure-item-foot, .candidate-language, .candidate-ids, .candidate-scores { color: var(--muted); font-size: 12px; }
.failure-item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.failure-item-category { overflow: hidden; color: var(--primary-deep); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.failure-item-foot span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.failure-item-foot button { flex: 0 0 auto; }
.failure-detail-panel { position: sticky; top: 16px; }
.failure-detail-head { align-items: flex-start; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.failure-detail-head > div { display: grid; min-width: 0; gap: 5px; }
.failure-head-actions { display: flex; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.failure-detail-head h3 { overflow-wrap: anywhere; font-size: 19px; }
.failure-context-grid { display: grid; gap: 10px; padding: 14px 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.failure-context-grid > div { display: grid; min-width: 0; gap: 4px; }
.failure-context-grid b { overflow-wrap: anywhere; font-size: 13px; }
.candidate-section-head { padding: 12px 0 10px; border-top: 1px solid var(--line); }
.candidate-section-head > div { display: grid; gap: 3px; }
.candidate-list { display: grid; gap: 8px; }
.manual-category-section { margin-top: 14px; padding-top: 2px; border-top: 1px dashed var(--line); }
.manual-category-search { display: flex; gap: 8px; margin-bottom: 8px; }
.manual-category-search input { min-width: 0; flex: 1; }
.manual-candidate-card { background: rgba(251, 253, 255, .8); }
.manual-category-hint { padding: 12px; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: 13px; }
.candidate-card { display: flex; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, .78); cursor: pointer; }
.candidate-card:hover, .candidate-card.is-selected { border-color: rgba(50, 123, 145, .55); background: rgba(240, 249, 249, .92); }
.candidate-card input { width: 18px; height: 18px; flex: 0 0 auto; margin: 2px 0 0; }
.candidate-card-body { display: grid; min-width: 0; gap: 5px; }
.candidate-card-body strong { overflow-wrap: anywhere; color: var(--text); font-size: 15px; }
.candidate-score { color: var(--primary-deep); font-weight: 700; }
.candidate-ids, .candidate-scores { overflow-wrap: anywhere; }
.failure-action-bar { align-items: flex-end; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.failure-action-bar > div { display: grid; min-width: 0; gap: 4px; }
.failure-action-bar > div span { max-width: 560px; font-size: 12px; line-height: 1.6; }
.failure-detail-empty { display: grid; min-height: 360px; place-items: center; }
.publish-search { display: flex; gap: 8px; }

@media (max-width: 900px) {
  .failure-workspace { grid-template-columns: 1fr; }
  .failure-detail-panel { position: static; }
  .failure-list { max-height: none; }
}

@media (max-width: 560px) {
  .failure-summary, .failure-context-grid { grid-template-columns: 1fr; }
  .publish-search, .failure-filters { display: flex; flex-direction: column; }
  .failure-detail-head, .failure-action-bar { align-items: stretch; flex-direction: column; }
}
