:root {
  color-scheme: light;
  --green-950: #004b38;
  --green-900: #005a43;
  --green-800: #087052;
  --green-700: #12805d;
  --green-100: #dff1ea;
  --green-50: #f2f8f5;
  --ink: #18201d;
  --muted: #68736f;
  --border: #dfe6e2;
  --border-strong: #cbd7d1;
  --surface: #ffffff;
  --canvas: #f5f7f6;
  --orange: #e9730b;
  --red: #c9342f;
  --blue: #2563b8;
  --shadow: 0 4px 16px rgba(15, 52, 40, .045);
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--ink); background: var(--canvas); font-size: 13px; line-height: 1.45; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app-shell { width: 100%; min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); overflow-x: hidden; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; color: white; background: var(--green-950); overflow-y: auto; }
.brand { min-height: 70px; padding: 0 16px; display: flex; align-items: center; gap: 10px; color: white; border-bottom: 1px solid rgba(255,255,255,.1); text-decoration: none; font-size: 15px; font-weight: 760; white-space: nowrap; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; color: var(--green-950); border-radius: 50%; background: white; }
.nav-list { padding: 10px 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.nav-group { padding: 4px 0 9px; border-bottom: 1px solid rgba(255,255,255,.1); }
.nav-group:last-child { border-bottom: 0; }
.nav-group-label { padding: 8px 10px 5px; color: rgba(255,255,255,.58); font-size: 11px; font-weight: 650; }
.nav-item { height: 40px; padding: 0 12px; display: flex; align-items: center; gap: 11px; color: rgba(255,255,255,.84); border-radius: 7px; text-decoration: none; font-size: 13px; font-weight: 650; }
.nav-item:hover { background: rgba(255,255,255,.075); }
.nav-item.active { color: white; background: rgba(65, 170, 132, .34); box-shadow: inset 3px 0 0 white; }
.icon, [data-icon] svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-footer { margin-top: auto; min-height: 72px; padding: 13px 16px; display: flex; align-items: center; gap: 11px; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar-footer strong, .sidebar-footer small { display: block; }
.sidebar-footer strong { font-size: 13px; }
.sidebar-footer small { margin-top: 2px; color: rgba(255,255,255,.62); font-size: 11px; }
.avatar { width: 36px; height: 36px; display: grid; place-items: center; color: var(--green-950); border-radius: 50%; background: white; }

.workspace, main, .panel, .metrics, .dashboard-grid { min-width: 0; }
.workspace { overflow-x: hidden; }
.topbar { min-height: 70px; padding: 11px 24px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--border); background: white; }
.topbar h1 { margin: 0; font-size: 21px; line-height: 1.2; letter-spacing: -.01em; }
.topbar p { display: none; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.status-button { height: 34px; padding: 0 12px; display: flex; align-items: center; gap: 7px; color: var(--green-800); border: 1px solid var(--border-strong); border-radius: 7px; background: white; font-size: 12px; font-weight: 650; }
.status-button.offline { color: var(--red); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #19a56f; }
.offline .status-dot { background: var(--red); }
.icon-button { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; color: var(--ink); border: 1px solid var(--border); border-radius: 7px; background: white; }
.mobile-menu { display: none; }

main { width: 100%; max-width: 1500px; padding: 18px 24px 36px; }
.loading, .empty-state { min-height: 150px; display: grid; place-items: center; padding: 24px; color: var(--muted); text-align: center; }
.empty-guide { min-height: 176px; padding: 26px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 8px; }
.empty-guide strong { font-size: 17px; line-height: 1.3; }
.empty-guide p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.empty-guide .button { margin-top: 4px; }
.empty-compact { min-height: 130px; padding: 22px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--muted); text-align: center; }
.empty-compact strong { color: var(--ink); font-size: 13px; }
.error-state { max-width: 520px; margin: 70px auto; padding: 28px; text-align: center; border: 1px solid #f2c6c4; border-radius: var(--radius); background: #fff7f6; }
.error-state h2 { margin: 0 0 8px; font-size: 18px; }
.admin-login-panel { max-width: 440px; margin: 72px auto 0; padding: 30px; }
.admin-login-panel h2 { margin: 0 0 6px; font-size: 21px; text-align: center; }
.admin-login-panel > p { margin: 0 0 22px; text-align: center; }
.admin-login-panel form { display: grid; gap: 12px; }
.admin-login-panel label { font-weight: 700; }
.admin-login-panel input { width: 100%; min-height: 42px; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: 7px; outline: none; }
.admin-login-panel input:focus { border-color: var(--green-700); box-shadow: 0 0 0 3px rgba(18,128,93,.1); }
.admin-login-panel form .button { min-height: 42px; margin-top: 4px; }
.admin-login-error { min-height: 18px; margin: 0; color: var(--red); text-align: center; }

.metrics { display: grid; grid-template-columns: repeat(5, minmax(138px, 1fr)); overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: white; box-shadow: var(--shadow); }
.metric-strip { grid-template-columns: repeat(4, minmax(138px, 1fr)); }
.metric { min-height: 92px; padding: 14px 18px; display: flex; align-items: center; gap: 13px; border-right: 1px solid var(--border); }
.metric:last-child { border-right: 0; }
.metric-icon { width: 42px; height: 42px; flex: none; display: grid; place-items: center; color: white; border-radius: 50%; background: var(--green-700); }
.metric.warn .metric-icon { background: var(--orange); }
.metric-label { color: #4e5a55; font-size: 12px; font-weight: 650; white-space: nowrap; }
.metric-value { display: block; margin-top: 4px; color: var(--green-800); font-size: 25px; line-height: 1; }
.metric.warn .metric-value { color: var(--orange); }

.panel { margin-top: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: white; box-shadow: var(--shadow); overflow: hidden; }
.panel-header { min-height: 56px; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--border); }
.panel-header h2 { margin: 0; font-size: 16px; line-height: 1.25; }
.panel-header p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search { width: 232px; height: 34px; padding: 0 11px; color: var(--ink); border: 1px solid var(--border-strong); border-radius: 7px; background: white; outline: none; }
.search:focus, .field input:focus, .field textarea:focus, .field select:focus { border-color: var(--green-700); box-shadow: 0 0 0 3px rgba(18,128,93,.1); }
.button { min-height: 34px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--ink); border: 1px solid var(--border-strong); border-radius: 7px; background: white; font-size: 12px; font-weight: 650; }
.button:hover { border-color: #9cafA6; background: var(--green-50); }
.button.primary { color: white; border-color: var(--green-800); background: var(--green-800); }
.button.primary:hover { background: var(--green-900); }
.button.danger { color: var(--red); border-color: #efc5c2; }
.button.small { min-height: 30px; padding: 0 9px; font-size: 11px; }
.link-button { padding: 2px 4px; color: var(--green-800); border: 0; background: transparent; font-size: 12px; font-weight: 700; }
.link-button.danger { color: var(--red); }
.link-button:disabled, .button:disabled { opacity: .42; cursor: not-allowed; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 11px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { height: 42px; color: #4b5752; background: #fbfcfb; font-size: 11px; font-weight: 750; }
td { height: 52px; font-size: 12px; }
.numeric, .metric-value { font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #fbfdfc; }
tbody tr:last-child td { border-bottom: 0; }
.primary-text { color: var(--green-800); font-weight: 700; }
.muted { color: var(--muted); }
.status-tag { padding: 3px 8px; display: inline-flex; align-items: center; border-radius: 5px; color: var(--green-800); background: var(--green-100); font-size: 11px; font-weight: 750; }
.status-tag.pending { color: var(--blue); background: #e7effc; }
.status-tag.warn { color: #9a4d08; background: #fff0dc; }
.status-tag.schedule-attention { margin-left: 6px; }
.status-tag.off { color: #66716d; background: #edf0ef; }
.wrap-cell { min-width: 240px; max-width: 390px; white-space: normal; line-height: 1.45; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; }
.dashboard-grid > .panel { min-width: 0; }
.task-rail { display: flex; flex-direction: column; }
.task-group { padding: 4px 16px 12px; border-bottom: 1px solid var(--border); }
.task-group:last-child { border-bottom: 0; }
.task-group-head { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.task-group-head strong { font-size: 13px; }
.task-group-head strong span { margin-left: 4px; color: var(--orange); }
.task-item { width: 100%; padding: 10px 0; display: flex; flex-direction: column; gap: 3px; color: var(--ink); border: 0; border-top: 1px solid var(--border); background: transparent; text-align: left; }
.task-item:hover { color: var(--green-800); }
.task-item strong { color: var(--green-800); font-size: 12px; }
.task-item span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.compact-empty { min-height: 64px; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.engine-panel .engine-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 0 16px; }
.engine-row { min-height: 94px; padding: 15px 18px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 5px; border-right: 1px solid var(--border); }
.engine-row:first-child { padding-left: 0; }
.engine-row:last-child { padding-right: 0; border-right: 0; }
.engine-name { font-weight: 750; }
.engine-state { color: var(--green-700); }
.engine-state.error-text { color: var(--red); }
.engine-state.warning-text { color: #ad5500; }
.engine-detail { max-width: 100%; color: var(--muted); font-size: 11px; }
.engine-detail summary { cursor: pointer; }
.engine-detail span { display: block; padding-top: 6px; overflow-wrap: anywhere; line-height: 1.5; }

.provider-metrics { padding: 14px 16px; display: grid; grid-template-columns: repeat(5, minmax(110px, 1fr)); gap: 0; }
.provider-metrics div { padding: 8px 14px; border-right: 1px solid var(--border); }
.provider-metrics div:last-child { border-right: 0; }
.provider-metrics span, .provider-metrics strong { display: block; }
.provider-metrics span { color: var(--muted); font-size: 11px; font-weight: 650; }
.provider-metrics strong { margin-top: 4px; color: var(--green-800); font-size: 21px; }
.analytics-list { padding: 4px 16px; }
.analytics-list div { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border); }
.analytics-list div:last-child { border-bottom: 0; }
.no-top-margin { margin-top: 0; }

.tabs { min-height: 54px; padding: 0 16px; display: flex; align-items: flex-end; gap: 28px; overflow-x: auto; border-bottom: 1px solid var(--border); background: white; }
.tab { height: 54px; padding: 0 2px; flex: none; color: var(--muted); border: 0; border-bottom: 2px solid transparent; background: transparent; font-size: 13px; font-weight: 700; }
.tab.active { color: var(--green-800); border-bottom-color: var(--green-800); }
.page-tabs { margin-bottom: 16px; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.resource-panel .panel-header { min-height: 62px; }

.form-page { max-width: 1180px; }
.system-panel { margin-top: 0; }
.split-panels { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.split-panels .panel { min-width: 0; margin-top: 0; }
.form-grid { padding: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { color: #37423e; font-size: 12px; font-weight: 700; }
.field input, .field textarea, .field select { width: 100%; min-height: 36px; padding: 7px 10px; color: var(--ink); border: 1px solid var(--border-strong); border-radius: 7px; background: white; outline: none; }
.field textarea { min-height: 78px; resize: vertical; }
.field small { color: var(--muted); font-size: 11px; }
.option-field { margin: 0; padding: 0; border: 0; }
.option-field legend { margin-bottom: 7px; color: #37423e; font-size: 12px; font-weight: 700; }
.option-grid { max-height: 172px; padding: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 7px; overflow-y: auto; border: 1px solid var(--border-strong); border-radius: 7px; background: #fafcfb; }
.option-check { min-width: 0; min-height: 34px; padding: 6px 8px; display: flex; align-items: center; gap: 7px; border: 1px solid var(--border); border-radius: 6px; background: white; font-size: 12px; cursor: pointer; }
.option-check input { flex: none; }
.option-check span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field-empty { grid-column: 1 / -1; padding: 8px; color: var(--muted); font-size: 11px; text-align: center; }
.check-field { min-height: 36px; display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 650; }
.form-actions { padding: 13px 16px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); }

.drawer-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(12, 29, 23, .3); }
.drawer { position: fixed; z-index: 60; top: 0; right: 0; width: min(420px, 100vw); height: 100vh; display: flex; flex-direction: column; border-left: 1px solid var(--border); background: white; box-shadow: -14px 0 36px rgba(16,53,42,.12); transform: translateX(102%); transition: transform .2s ease; }
.drawer.open { transform: translateX(0); }
.drawer-header { min-height: 64px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.drawer-header h2 { margin: 0; font-size: 18px; }
.drawer-form { min-height: 0; flex: 1; display: flex; flex-direction: column; }
.drawer-fields { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.drawer-actions { margin-top: auto; padding: 13px 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; border-top: 1px solid var(--border); }
.order-summary { padding: 12px; display: flex; flex-direction: column; gap: 5px; border: 1px solid var(--border); border-radius: 8px; background: var(--green-50); }
.order-summary strong { color: var(--green-800); }
.order-summary span { color: var(--muted); font-size: 12px; }
.state-actions { display: grid; grid-template-columns: repeat(3,1fr); gap: 7px; }
.state-actions .button { min-width: 0; padding: 0 7px; }
.tester { padding: 16px; }
.tester-output { min-height: 82px; padding: 13px; display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--border); border-radius: 8px; background: #fafcfb; color: var(--muted); line-height: 1.5; }
.tester-output strong { color: var(--green-800); }
.tester-output small { color: var(--muted); }
.tester form { margin-top: 10px; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.tester .search { width: 100%; }
.activity-list { padding: 3px 16px; }
.activity-list > div { min-height: 48px; padding: 8px 0; display: flex; flex-direction: column; justify-content: center; gap: 3px; border-bottom: 1px solid var(--border); }
.activity-list > div:last-child { border-bottom: 0; }
.activity-list span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-list small { color: var(--muted); font-size: 11px; }
.empty-state.compact { min-height: 110px; }
.toast { position: fixed; z-index: 90; left: 50%; bottom: 24px; padding: 9px 15px; color: white; border-radius: 7px; background: #26312d; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 10px); transition: .18s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 200px minmax(0, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .task-rail { display: grid; grid-template-columns: 1fr 1fr; }
  .task-rail > .panel-header { grid-column: 1 / -1; }
  .task-rail > .empty-compact { grid-column: 1 / -1; }
  .task-group { border-right: 1px solid var(--border); border-bottom: 0; }
  .task-group:last-child { border-right: 0; }
  .split-panels { grid-template-columns: 1fr; }
  .engine-panel .engine-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .engine-row:nth-child(2n) { border-right: 0; }
  .engine-row:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 80; width: 220px; transform: translateX(-102%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: grid; }
  .topbar { min-height: 62px; padding: 9px 14px; }
  .topbar h1 { font-size: 18px; }
  .topbar p { display: none; }
  .status-button { max-width: 150px; overflow: hidden; white-space: nowrap; }
  main { padding: 14px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: hidden; }
  .metric { min-width: 0; min-height: 80px; padding: 11px 12px; border-bottom: 1px solid var(--border); }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:last-child { border-bottom: 0; }
  .metric:last-child:nth-child(odd) { grid-column: 1 / -1; justify-content: center; }
  .metric-icon { width: 36px; height: 36px; }
  .panel-header { align-items: flex-start; flex-direction: column; }
  .toolbar, .search { width: 100%; }
  .task-rail { display: block; }
  .task-group { border-right: 0; border-bottom: 1px solid var(--border); }
  .engine-panel .engine-list { grid-template-columns: 1fr; }
  .engine-row, .engine-row:first-child, .engine-row:last-child { padding: 12px 0; border-right: 0; border-bottom: 1px solid var(--border); }
  .engine-row:last-child { border-bottom: 0; }
  .provider-metrics { grid-template-columns: repeat(2, 1fr); }
  .provider-metrics div { border-bottom: 1px solid var(--border); }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .state-actions { grid-template-columns: 1fr; }
  .tester form { grid-template-columns: 1fr; }
}

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