.admin-page { min-height: 100vh; }
.admin-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 64px 0 100px; overflow: visible; }
.admin-intro { display: flex; justify-content: space-between; align-items: end; gap: 32px; margin-bottom: 36px; }
.admin-intro h1 { margin: 0; font-family: "STSong", "Songti SC", serif; font-size: clamp(38px, 5vw, 62px); letter-spacing: -.04em; }
.admin-intro p:last-child { max-width: 700px; margin: 16px 0 0; color: var(--muted); line-height: 1.8; }
.auth-panel { display: grid; grid-template-columns: 1fr minmax(300px, 430px); gap: 50px; align-items: end; padding: 34px; border: 1px solid var(--line); background: var(--paper); }
.auth-panel h2 { margin: 0 0 10px; font-family: "STSong", "Songti SC", serif; font-size: 28px; }
.auth-panel p { color: var(--muted); }
.auth-form { display: flex; gap: 10px; align-items: end; }
.auth-form label { flex: 1; }
.auth-form label span, .form-grid label > span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 700; }
.auth-form input, .form-grid input, .form-grid select, .admin-filter input, .endpoint-row input { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 3px; padding: 0 12px; color: var(--ink); background: var(--white); outline: 0; }
.auth-form input:focus, .form-grid input:focus, .form-grid select:focus, .admin-filter input:focus, .endpoint-row input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(24,60,52,.08); }
.form-message { min-height: 18px; margin: 12px 0 0; color: #a24838; font-size: 12px; }
.auth-panel > .form-message { grid-column: 1 / -1; margin: -30px 0 0; }

.admin-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 28px; margin-bottom: 34px; }
.admin-metrics { flex: 1; display: grid; grid-template-columns: repeat(4, minmax(100px, 1fr)); border: 1px solid var(--line); background: var(--paper); }
.admin-metrics article { min-height: 88px; padding: 18px; border-right: 1px solid var(--line); }
.admin-metrics article:last-child { border-right: 0; }
.admin-metrics strong { display: block; font-family: Georgia, serif; font-size: 27px; font-weight: 500; }
.admin-metrics span { color: var(--muted); font-size: 10px; }
.toolbar-actions { display: flex; gap: 10px; }
.health-monitor { display: grid; grid-template-columns: minmax(230px, .7fr) 1.3fr; gap: 28px; margin-bottom: 34px; padding: 23px; border: 1px solid var(--line); background: var(--paper); }
.health-monitor h2 { margin: 0; font-family: "STSong", "Songti SC", serif; font-size: 25px; }
.health-monitor p:last-child { margin: 8px 0 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.health-events { display: grid; gap: 6px; }
.health-event { padding: 9px 11px; border-left: 3px solid #b67d49; background: var(--white); }
.health-event.alert { border-color: #a24838; background: #f8e9e1; }
.health-event.recovered { border-color: #378363; background: var(--green-soft); }
.health-event strong, .health-event span { display: block; }
.health-event strong { font-size: 10px; }
.health-event span, .health-empty { margin-top: 4px; color: var(--muted); font-size: 9px; line-height: 1.5; }
.ai-monitor { margin-bottom: 34px; padding: 23px; border: 1px solid var(--line); background: var(--paper); }
.ai-monitor-heading { display: flex; justify-content: space-between; align-items: center; gap: 24px; }
.ai-monitor-heading h2 { margin: 0; font-family: "STSong", "Songti SC", serif; font-size: 25px; }
.ai-monitor-heading p:last-child { margin: 8px 0 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.ai-analysis-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 18px; }
.ai-analysis-item { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 13px; padding: 13px; border: 1px solid var(--line); background: var(--white); }
.ai-analysis-item.high, .ai-analysis-item.urgent { border-left: 4px solid #a24838; }
.ai-analysis-item.medium { border-left: 4px solid #b67d49; }
.ai-score { display: grid; align-content: center; justify-items: center; min-height: 50px; color: var(--cream); background: var(--ink); }
.ai-score strong { font: 20px Georgia, serif; }
.ai-score span { font-size: 8px; }
.ai-analysis-item a { color: var(--ink); font-size: 11px; font-weight: 800; line-height: 1.5; text-decoration: none; }
.ai-analysis-item a:hover { text-decoration: underline; }
.ai-analysis-item p { margin: 5px 0; color: var(--ink-2); font-size: 9px; line-height: 1.55; }
.ai-analysis-item small { color: var(--muted); font-size: 8px; }
.source-admin-heading { display: flex; justify-content: space-between; align-items: end; gap: 30px; margin-bottom: 16px; }
.source-admin-heading h2 { margin: 0; font-family: "STSong", "Songti SC", serif; font-size: 30px; }
.source-admin-heading p { margin: 7px 0 0; color: var(--muted); font-size: 11px; }
.admin-filter { width: min(340px, 100%); }

.managed-source-list { display: grid; gap: 10px; }
.managed-source { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 17px; align-items: center; padding: 19px 20px; border: 1px solid var(--line); background: var(--paper); }
.managed-source.disabled { opacity: .7; background: #eeeae0; }
.managed-source.deleted { border-style: dashed; opacity: .62; }
.managed-source .source-badge { width: 42px; height: 42px; }
.managed-copy { min-width: 0; }
.managed-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.managed-title h3 { margin: 0; font-family: "STSong", "Songti SC", serif; font-size: 17px; }
.source-kind { padding: 3px 7px; border-radius: 2px; color: var(--ink-2); background: var(--green-soft); font-size: 9px; }
.source-kind.custom { color: #9d452c; background: var(--accent-soft); }
.managed-meta { display: flex; flex-wrap: wrap; gap: 7px 12px; margin-top: 8px; color: var(--muted); font-size: 10px; }
.managed-health { margin-top: 8px; font-size: 10px; }
.managed-health.ok { color: #378363; }
.managed-health.error { color: #a24838; }
.managed-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 6px; max-width: 330px; }
.small-button, .text-button, .icon-button { border: 1px solid var(--line); border-radius: 3px; color: var(--ink); background: transparent; cursor: pointer; }
.small-button { min-height: 34px; padding: 0 10px; font-size: 10px; }
.small-button:hover, .text-button:hover { border-color: var(--ink); background: var(--green-soft); }
.small-button.danger { color: #a24838; }
.empty-admin { padding: 50px 20px; border: 1px dashed var(--line); color: var(--muted); background: var(--paper); text-align: center; }

.source-dialog { width: min(820px, calc(100% - 28px)); max-height: calc(100vh - 34px); border: 0; padding: 0; color: var(--ink); background: var(--paper); box-shadow: 0 30px 100px rgba(24,60,52,.22); }
.source-dialog::backdrop { background: rgba(16, 39, 34, .58); backdrop-filter: blur(5px); }
.source-dialog form { padding: 28px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.dialog-heading h2 { margin: 0; font-family: "STSong", "Songti SC", serif; font-size: 29px; }
.icon-button { width: 38px; height: 38px; font-size: 25px; line-height: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; padding: 24px 0; }
.form-grid .span-2 { grid-column: 1 / -1; }
.check-label { display: flex; align-items: center; gap: 9px; align-self: end; min-height: 44px; }
.check-label input { width: 17px; min-height: 17px; accent-color: var(--ink); }
.check-label span { margin: 0 !important; }
.advanced-settings { margin-bottom: 23px; border: 1px solid var(--line); background: #f6f3eb; }
.advanced-settings summary { padding: 14px 16px; cursor: pointer; font-size: 12px; font-weight: 700; }
.advanced-grid { padding: 0 16px 17px; }
.endpoint-editor { padding-top: 22px; border-top: 1px solid var(--line); }
.endpoint-heading { display: flex; justify-content: space-between; gap: 20px; align-items: start; }
.endpoint-heading h3 { margin: 0; font-size: 15px; }
.endpoint-heading p { margin: 5px 0 0; color: var(--muted); font-size: 10px; }
.text-button { padding: 7px 10px; font-size: 10px; }
.endpoint-row { display: grid; grid-template-columns: 26px minmax(120px, .55fr) minmax(220px, 1.3fr) auto; gap: 8px; align-items: start; margin-top: 12px; padding: 12px; border: 1px solid var(--line); background: var(--white); }
.endpoint-index { width: 26px; height: 26px; display: grid; place-items: center; margin-top: 8px; border-radius: 50%; color: var(--cream); background: var(--ink); font: 11px Georgia, serif; }
.endpoint-fields { display: contents; }
.endpoint-options { grid-column: 2 / 4; display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.endpoint-options label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 9px; }
.endpoint-options label input[type="checkbox"] { width: 15px; min-height: 15px; }
.endpoint-actions { display: flex; gap: 4px; }
.endpoint-actions button { width: 30px; height: 30px; border: 1px solid var(--line); background: transparent; cursor: pointer; }

.test-panel { margin-top: 22px; padding: 16px; border-left: 4px solid var(--ink); background: var(--green-soft); }
.test-panel.failed { border-left-color: var(--accent); background: var(--accent-soft); }
.test-heading { display: flex; justify-content: space-between; gap: 12px; }
.test-heading span { color: var(--muted); font-size: 10px; }
.test-panel > p { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.test-preview { display: grid; gap: 6px; margin-top: 12px; }
.preview-item { padding: 9px 11px; border: 1px solid rgba(24,60,52,.12); background: rgba(255,255,255,.62); font-size: 10px; line-height: 1.5; }
.dialog-actions { display: flex; justify-content: end; gap: 10px; padding-top: 18px; border-top: 1px solid var(--line); }
.history-shell { padding: 28px; }
.history-note { margin: 15px 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.history-list { display: grid; gap: 8px; }
.history-item { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 13px 14px; border: 1px solid var(--line); background: var(--white); }
.history-item strong { display: block; font-size: 11px; }
.history-item span { display: block; margin-top: 5px; color: var(--muted); font-size: 9px; }

@media (max-width: 850px) {
  .admin-intro, .admin-toolbar, .source-admin-heading, .ai-monitor-heading { align-items: stretch; flex-direction: column; }
  .auth-panel { grid-template-columns: 1fr; gap: 22px; }
  .auth-panel > .form-message { margin: 0; }
  .admin-metrics { width: 100%; }
  .toolbar-actions { justify-content: end; }
  .admin-filter { width: 100%; }
  .managed-source { grid-template-columns: 42px 1fr; }
  .managed-actions { grid-column: 1 / -1; justify-content: start; max-width: none; }
  .health-monitor { grid-template-columns: 1fr; }
  .ai-analysis-list { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .admin-shell { width: min(100% - 24px, 1180px); padding-top: 38px; }
  .admin-intro .button { width: 100%; }
  .auth-panel { padding: 22px; }
  .auth-form { align-items: stretch; flex-direction: column; }
  .admin-metrics { grid-template-columns: repeat(2, 1fr); }
  .admin-metrics article:nth-child(2) { border-right: 0; }
  .admin-metrics article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .toolbar-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .source-dialog form { padding: 20px 16px; }
  .history-shell { padding: 20px 16px; }
  .history-item { align-items: start; flex-direction: column; }
  .endpoint-row { grid-template-columns: 26px 1fr auto; }
  .endpoint-fields { display: grid; grid-column: 2; gap: 8px; }
  .endpoint-options { grid-column: 2 / -1; grid-template-columns: 1fr; }
  .endpoint-actions { grid-column: 3; grid-row: 1; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .button { width: 100%; }
}
