:root {
  --page: #f5f7f8;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --text: #182126;
  --text-soft: #5f6b71;
  --text-faint: #8a969c;
  --line: #dfe5e8;
  --line-strong: #cbd4d8;
  --accent: #087f72;
  --accent-strong: #06675e;
  --accent-soft: #e6f5f2;
  --blue: #2f69bd;
  --blue-soft: #eaf1fb;
  --amber: #9a6008;
  --amber-soft: #fff4dc;
  --red: #b74437;
  --red-soft: #fff0ee;
  --sidebar: #17272c;
  --shadow: 0 16px 42px rgba(27, 41, 47, 0.16);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--text); background: var(--page); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid rgba(8, 127, 114, .35); outline-offset: 2px; }
svg { width: 18px; height: 18px; stroke-width: 1.8; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

.admin-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; min-height: 560px; display: flex; flex-direction: column; padding: 18px 12px; color: #d5dfe1; background: var(--sidebar); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 20px; color: #fff; text-decoration: none; }
.brand > span { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 8px; color: #fff; background: var(--accent); font-size: 13px; font-weight: 800; }
.brand strong { font-size: 16px; }
.main-nav, .sidebar-bottom { display: grid; gap: 5px; }
.main-nav button, .sidebar-bottom > button { width: 100%; min-height: 42px; display: flex; align-items: center; gap: 11px; padding: 9px 11px; border: 0; border-radius: 7px; color: #aebdc1; background: transparent; font-size: 12px; font-weight: 700; text-align: left; }
.main-nav button:hover, .main-nav button.active, .sidebar-bottom > button:hover { color: #fff; background: #294047; }
.sidebar-bottom { margin-top: auto; }
.admin-profile { display: flex; align-items: center; gap: 10px; margin-top: 8px; padding: 13px 10px 0; border-top: 1px solid #30454b; }
.admin-profile > span { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 7px; color: #153136; background: #cdebe5; font-size: 12px; font-weight: 800; }
.admin-profile div { min-width: 0; display: grid; gap: 2px; }
.admin-profile strong { color: #edf3f4; font-size: 11px; }
.admin-profile small { color: #82969b; font-size: 9px; }

.main-area { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 10; height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 28px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); }
.breadcrumb, .top-actions { display: flex; align-items: center; gap: 9px; }
.breadcrumb { color: var(--text-faint); font-size: 11px; }
.breadcrumb svg { width: 14px; height: 14px; }
.breadcrumb strong { color: var(--text); }
.top-actions { margin-left: auto; }
.icon-button { position: relative; width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 7px; color: var(--text-soft); background: var(--panel); }
.icon-button:hover { border-color: var(--line-strong); color: var(--text); background: var(--panel-soft); }
.page-actions, .row-actions { display: flex; align-items: center; gap: 7px; }
.alert-dot { position: absolute; top: 7px; right: 7px; width: 5px; height: 5px; border-radius: 50%; background: #df6655; }
.connection-badge { display: flex; align-items: center; gap: 7px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; color: var(--text-soft); background: var(--panel-soft); font-size: 10px; font-weight: 700; }
.connection-badge > span { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
.connection-badge.live > span { background: var(--accent); }
.connection-badge.error > span { background: var(--red); }
.mobile-menu { display: none; }

.view { display: none; width: min(1440px, 100%); margin: 0 auto; padding: 30px 34px 48px; }
.view.active { display: block; }
.page-heading { min-height: 68px; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.eyebrow { display: block; margin-bottom: 5px; color: var(--text-faint); font-size: 9px; font-weight: 800; text-transform: uppercase; }
h1, h2, p { margin: 0; }
.page-heading h1 { font-size: 25px; line-height: 1.2; }
.page-heading p { margin-top: 7px; color: var(--text-soft); font-size: 11px; }
.primary-button, .secondary-button, .text-button { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 7px 12px; border-radius: 7px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.primary-button { border: 1px solid var(--accent); color: #fff; background: var(--accent); }
.primary-button:hover { background: var(--accent-strong); }
.secondary-button { border: 1px solid var(--line); color: var(--text-soft); background: var(--panel); }
.text-button { border: 0; color: var(--accent-strong); background: transparent; }
.primary-button svg, .secondary-button svg, .text-button svg { width: 15px; height: 15px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 28px; }
.metric-grid article { min-width: 0; display: flex; align-items: center; gap: 13px; padding: 17px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.metric-icon { width: 40px; height: 40px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 7px; }
.metric-icon.green { color: var(--accent); background: var(--accent-soft); }
.metric-icon.blue { color: var(--blue); background: var(--blue-soft); }
.metric-icon.amber { color: var(--amber); background: var(--amber-soft); }
.metric-icon.red { color: var(--red); background: var(--red-soft); }
.metric-grid article > div:last-child { min-width: 0; display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 8px; }
.metric-grid span { grid-column: 1 / -1; color: var(--text-soft); font-size: 10px; font-weight: 700; }
.metric-grid strong { font-size: 24px; line-height: 1.25; }
.metric-grid small { overflow: hidden; color: var(--text-faint); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, .8fr); gap: 22px; }
.section-block { min-width: 0; }
.section-title { min-height: 48px; display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.section-title h2 { font-size: 15px; }
.section-title p { margin-top: 4px; color: var(--text-faint); font-size: 10px; }
.resource-list { display: grid; }
.resource-row { min-width: 0; display: grid; grid-template-columns: 34px minmax(0, 1fr) auto auto; align-items: center; gap: 12px; padding: 13px 4px; border-bottom: 1px solid var(--line); }
.resource-row > .resource-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 7px; color: var(--blue); background: var(--blue-soft); }
.resource-row > .resource-icon svg { width: 16px; height: 16px; }
.resource-copy { min-width: 0; display: grid; gap: 3px; }
.resource-copy strong, .resource-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resource-copy strong { font-size: 11px; }
.resource-copy span { color: var(--text-faint); font-size: 9px; }
.resource-time { color: var(--text-faint); font-size: 9px; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 7px; border-radius: 5px; color: var(--accent-strong); background: var(--accent-soft); font-size: 9px; font-weight: 800; }
.status-pill.draft { color: var(--amber); background: var(--amber-soft); }
.status-pill.disabled { color: var(--text-soft); background: #edf0f2; }
.capability-block { padding-left: 8px; }
.capability-list { display: grid; }
.capability-item { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; align-items: center; gap: 9px; padding: 13px 2px; border-bottom: 1px solid var(--line); }
.capability-item svg { width: 16px; height: 16px; }
.capability-item.live svg { color: var(--accent); }
.capability-item.pending svg { color: var(--text-faint); }
.capability-item div { min-width: 0; display: grid; gap: 3px; }
.capability-item strong { font-size: 10px; }
.capability-item span { color: var(--text-faint); font-size: 9px; }
.capability-item small { color: var(--text-faint); font-size: 8px; font-weight: 800; }

.resource-tabs { display: flex; gap: 3px; overflow-x: auto; margin-bottom: 16px; padding-bottom: 1px; border-bottom: 1px solid var(--line); }
.resource-tabs button { min-height: 38px; flex: 0 0 auto; padding: 8px 13px; border: 0; border-bottom: 2px solid transparent; color: var(--text-soft); background: transparent; font-size: 10px; font-weight: 800; }
.resource-tabs button.active { border-bottom-color: var(--accent); color: var(--accent-strong); }
.table-section { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }
.table-tools { min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.search-box { width: min(360px, 100%); min-height: 36px; display: grid; grid-template-columns: 17px minmax(0,1fr); align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; color: var(--text-faint); background: var(--panel-soft); }
.search-box input { min-width: 0; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 10px; }
.table-tools > select { min-height: 36px; padding: 0 28px 0 10px; border: 1px solid var(--line); border-radius: 7px; color: var(--text-soft); background: var(--panel); font-size: 10px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--text-faint); background: var(--panel-soft); font-size: 9px; font-weight: 800; }
td { color: var(--text-soft); font-size: 10px; }
th:first-child { width: 30%; }
th:last-child { width: 54px; }
td strong { display: block; overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
td small { display: block; margin-top: 3px; overflow: hidden; color: var(--text-faint); font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
.row-action { width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 6px; color: var(--text-faint); background: transparent; }
.row-action:hover { color: var(--text); background: var(--panel-soft); }
.table-empty { display: grid; place-items: center; gap: 7px; padding: 52px 20px; color: var(--text-faint); }
.table-empty svg { width: 28px; height: 28px; }
.table-empty strong { color: var(--text-soft); font-size: 11px; }
.table-empty span { font-size: 9px; }
.inline-empty { min-height: 96px; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--text-faint); font-size: 10px; }
.inline-empty svg { width: 17px; height: 17px; }

.policy-form { max-width: 760px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }
.policy-form > header, .policy-form > footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; }
.policy-form > header { border-bottom: 1px solid var(--line); }
.policy-form > header h2 { font-size: 15px; }
.policy-form > header p { margin-top: 5px; color: var(--text-faint); font-size: 10px; }
.scope-label { max-width: 52%; overflow: hidden; padding: 5px 8px; border-radius: 5px; color: var(--text-soft); background: var(--panel-soft); font-size: 9px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.role-segment { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0; padding: 20px; border: 0; }
.role-segment label { min-width: 0; cursor: pointer; }
.role-segment input { position: absolute; opacity: 0; pointer-events: none; }
.role-segment label > span { min-height: 92px; display: grid; grid-template-columns: 28px minmax(0, 1fr); align-content: center; gap: 3px 10px; padding: 15px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
.role-segment i { grid-row: 1 / 3; align-self: center; color: var(--text-faint); }
.role-segment strong, .role-segment small { grid-column: 2; }
.role-segment strong { font-size: 11px; }
.role-segment small { color: var(--text-faint); font-size: 9px; }
.role-segment input:checked + span { border-color: #75bcb2; background: var(--accent-soft); box-shadow: 0 0 0 2px rgba(8,127,114,.08); }
.role-segment input:checked + span i { color: var(--accent); }
.policy-form > footer { border-top: 1px solid var(--line); }
.policy-form > footer > span { color: var(--text-faint); font-size: 9px; }
.policy-form button:disabled { cursor: wait; opacity: .65; }

.operation-list { display: grid; gap: 10px; }
.operation-row { min-width: 0; display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 13px; padding: 15px 17px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.operation-row > span:first-child { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 7px; color: var(--accent); background: var(--accent-soft); }
.operation-row.pending > span:first-child { color: var(--text-faint); background: #edf0f2; }
.operation-row div { min-width: 0; display: grid; gap: 4px; }
.operation-row strong { font-size: 11px; }
.operation-row p { overflow: hidden; color: var(--text-faint); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(23,33,38,.28); }
.editor-drawer { position: fixed; top: 0; right: 0; z-index: 31; width: min(460px, 100vw); height: 100vh; transform: translateX(102%); border-left: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow); transition: transform .2s ease; }
.editor-drawer.open { transform: translateX(0); }
.editor-drawer form { height: 100%; display: grid; grid-template-rows: auto minmax(0,1fr) auto; }
.editor-drawer header, .editor-drawer footer, .modal-dialog header, .modal-dialog footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 17px 19px; }
.editor-drawer header, .modal-dialog header { border-bottom: 1px solid var(--line); }
.editor-drawer footer, .modal-dialog footer { justify-content: flex-end; border-top: 1px solid var(--line); }
.editor-drawer h2, .modal-dialog h2 { font-size: 17px; }
.drawer-content, .modal-content { min-height: 0; display: grid; align-content: start; gap: 16px; padding: 20px; overflow-y: auto; }
.drawer-content label, .modal-content label { display: grid; gap: 7px; color: var(--text-soft); font-size: 10px; font-weight: 800; }
.drawer-content input, .drawer-content select, .drawer-content textarea, .modal-content input { width: 100%; min-height: 40px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 7px; outline: 0; color: var(--text); background: var(--panel); font-size: 11px; resize: vertical; }
.drawer-content input:focus, .drawer-content select:focus, .drawer-content textarea:focus, .modal-content input:focus { border-color: #81c9c0; }
.drawer-content label > small { color: var(--text-faint); font-size: 9px; font-weight: 600; }
.role-editor-fields { display: grid; gap: 16px; padding-top: 4px; }
.role-editor-heading, .role-examples-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.role-editor-heading > div, .role-examples-heading > div { min-width: 0; display: grid; gap: 3px; }
.role-editor-heading strong, .role-examples-heading strong { color: var(--text); font-size: 11px; }
.role-editor-heading span, .role-examples-heading span { color: var(--text-faint); font-size: 9px; font-weight: 600; }
.role-editor-heading > svg { width: 19px; height: 19px; color: var(--gold); }
.role-field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.role-examples { display: grid; gap: 9px; }
.role-examples:empty::after { padding: 16px; border: 1px dashed var(--line-strong); border-radius: 6px; color: var(--text-faint); font-size: 9px; text-align: center; content: "暂无示例对话"; }
.role-example-row { display: grid; grid-template-columns: 88px minmax(0, 1fr) 38px; align-items: start; gap: 7px; }
.role-example-row select, .role-example-row textarea { min-height: 38px; }
.role-example-row .icon-button { width: 38px; height: 38px; color: var(--red); }
.role-knowledge-entries { display: grid; gap: 12px; }
.role-knowledge-entries:empty::after { padding: 16px; border: 1px dashed var(--line-strong); border-radius: 6px; color: var(--text-faint); font-size: 9px; text-align: center; content: "暂无角色知识"; }
.role-knowledge-row { display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.role-knowledge-controls { display: grid; grid-template-columns: minmax(0, 1fr) 92px 76px 38px; gap: 7px; }
.role-knowledge-controls .icon-button { width: 38px; height: 38px; color: var(--red); }
.modal-dialog { width: min(440px, calc(100vw - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: var(--panel); box-shadow: var(--shadow); }
.modal-dialog::backdrop { background: rgba(23,33,38,.38); }
.modal-content p { color: var(--text-faint); font-size: 9px; line-height: 1.55; }
.switch-row { grid-template-columns: 1fr auto !important; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch-row span { display: grid; gap: 3px; }
.switch-row strong { color: var(--text); font-size: 10px; }
.switch-row small { color: var(--text-faint); font-size: 8px; font-weight: 500; }
.switch-row input { width: 16px; min-height: 16px; accent-color: var(--accent); }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 50; max-width: 340px; padding: 10px 13px; border: 1px solid #a9d8d2; border-radius: 7px; color: var(--accent-strong); background: var(--panel); box-shadow: var(--shadow); font-size: 10px; }
.toast.error { border-color: #efbcb6; color: var(--red); }
.spinning { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1080px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .overview-grid { grid-template-columns: 1fr; }
  .capability-block { padding-left: 0; }
}

@media (max-width: 760px) {
  .admin-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; width: 224px; transform: translateX(-102%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: translateX(0); }
  .mobile-menu { display: grid; }
  .topbar { padding: 0 14px; }
  .connection-badge { display: none; }
  .view { padding: 22px 14px 36px; }
  .page-heading { align-items: flex-start; }
  .page-heading h1 { font-size: 21px; }
  .metric-grid { gap: 9px; }
  .metric-grid article { padding: 13px; }
  .metric-grid small { display: none; }
  .resource-row { grid-template-columns: 34px minmax(0,1fr) auto; }
  .resource-time { display: none; }
  .table-tools { align-items: stretch; flex-direction: column; }
  .role-segment { grid-template-columns: 1fr; }
  .search-box { width: 100%; }
  table { min-width: 720px; }
}

@media (max-width: 480px) {
  .metric-grid { grid-template-columns: 1fr; }
  .metric-grid article { min-height: 68px; }
  .page-heading { min-height: 0; flex-direction: column; margin-bottom: 20px; }
  .page-heading .primary-button { width: 100%; }
  .breadcrumb span, .breadcrumb svg { display: none; }
}

@media (max-width: 520px) {
  .role-field-grid { grid-template-columns: 1fr; }
  .role-example-row { grid-template-columns: 78px minmax(0, 1fr) 38px; }
  .role-knowledge-controls { grid-template-columns: minmax(0, 1fr) 82px 68px 38px; }
}

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

.model-gateway-form {
  display: grid;
  gap: 22px;
  max-width: 1040px;
}

.model-config-section {
  border-top: 1px solid #cfd6d0;
  padding-top: 20px;
}

.model-config-section > header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.model-config-section > header h2 { color: #1b221f; font-size: 15px; }
.model-config-section > header p { margin-top: 5px; color: #7d8882; font-size: 10px; }
.model-config-section > header > svg { width: 19px; height: 19px; color: #9a7731; }

.model-field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 20px;
}

.model-field-grid > label { min-width: 0; display: grid; align-content: start; gap: 7px; color: #59645e; font-size: 10px; font-weight: 800; }
.model-field-grid > label.wide-field { grid-column: 1 / -1; }
.model-field-grid input:not([type="range"]), .model-field-grid select {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid #ccd3cd;
  border-radius: 6px;
  color: #1c2421;
  background: #fcfdfb;
}

.model-field-grid textarea {
  width: 100%;
  resize: vertical;
  padding: 10px 11px;
  border: 1px solid #ccd3cd;
  border-radius: 6px;
  color: #1c2421;
  background: #fcfdfb;
  line-height: 1.55;
}

.model-field-grid input:focus, .model-field-grid select:focus {
  border-color: #9b7e48;
  box-shadow: 0 0 0 3px rgba(217, 168, 79, .08);
}

.model-field-grid textarea:focus { border-color: #9b7e48; box-shadow: 0 0 0 3px rgba(217, 168, 79, .08); outline: none; }
.profile-search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.profile-search-row input { width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid #ccd3cd; border-radius: 6px; background: #fcfdfb; }
.profile-form textarea:disabled, .profile-form input:disabled { color: #8a948f; background: #f1f3f0; }

.model-field-grid label > small { color: #89938e; font-size: 9px; font-weight: 600; }
.secret-input { display: grid; grid-template-columns: minmax(0, 1fr) 40px; gap: 7px; }
.secret-input .icon-button { width: 40px; height: 40px; }

.model-command-row {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding: 10px 12px;
  border: 1px solid #d8ddd8;
  border-radius: 6px;
  background: #f2f4f1;
}

.model-command-row > span, .model-form-actions > span { color: #77827c; font-size: 10px; }
.model-parameter-grid { grid-template-columns: minmax(280px, 1.4fr) repeat(2, minmax(150px, .7fr)); }
.temperature-field > div { min-height: 40px; display: grid; grid-template-columns: minmax(120px, 1fr) 76px; align-items: center; gap: 10px; }
.temperature-field input[type="range"] { width: 100%; accent-color: #9a7731; }
.model-field-grid .model-enabled { grid-column: 1 / -1; min-height: 64px; padding: 11px 13px; border: 1px solid #d4dad5; border-radius: 6px; background: #f7f8f5; }

.model-form-actions {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-top: 18px;
  border-top: 1px solid #cfd6d0;
}

.model-form-actions > div { display: flex; gap: 9px; }
.model-gateway-form button:disabled { cursor: wait; opacity: .6; }
.managed-records-section { margin-top: 24px; }
.managed-records-section .table-tools { flex-wrap: wrap; gap: 10px; }
.managed-records-section .table-tools > div { margin-right: auto; display: grid; gap: 3px; }
.managed-records-section .table-tools strong { font-size: 13px; }
.managed-records-section .table-tools small { color: var(--text-soft); font-size: 10px; }
.managed-records-section td code { color: var(--text-soft); font-size: 10px; }
.managed-records-section td small { display: block; max-width: 260px; margin-top: 3px; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.managed-send-status { color: var(--accent-strong); font-size: 10px; font-weight: 800; }
.managed-send-status.failed { color: var(--red); }
.memory-candidates-section .table-tools { flex-wrap: wrap; gap: 10px; }
.memory-candidates-section .table-tools > div { margin-right: auto; display: grid; gap: 3px; }
.memory-candidates-section .table-tools strong { font-size: 13px; }
.memory-candidates-section .table-tools small, .memory-candidates-section td small { display: block; margin-top: 3px; color: var(--text-soft); font-size: 10px; }
.memory-candidates-section td code { color: var(--text-soft); font-size: 10px; }
.retention-cutoff input { min-width: 172px; }
.memory-summary { min-width: 280px; max-width: 460px; }
.memory-summary strong { display: block; line-height: 1.55; white-space: normal; }
.status-pill.memory-restricted { color: var(--red); background: var(--red-soft); }
.memory-actions { width: 132px; white-space: nowrap; }
.memory-actions .icon-button { display: inline-grid; margin-left: 5px; }
.memory-actions .accept { color: var(--accent-strong); }
.memory-actions .reject { color: var(--red); }

@media (max-width: 760px) {
  .model-field-grid, .model-parameter-grid { grid-template-columns: 1fr; }
  .model-field-grid > label.wide-field, .model-field-grid .model-enabled { grid-column: auto; }
  .model-command-row, .model-form-actions { align-items: stretch; flex-direction: column; }
  .model-command-row button, .model-form-actions > div, .model-form-actions button { width: 100%; }
  .profile-search-row { grid-template-columns: 1fr; }
}

.session-loading .admin-auth-screen,
.session-loading .admin-shell { visibility: hidden; }
.session-authenticated .admin-auth-screen { display: none; }
.session-anonymous .admin-shell { display: none; }
.admin-auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 28px 20px; background: #edf2f1; }
.admin-auth-card { width: min(420px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 18px 50px rgba(22,50,54,.12); }
.admin-auth-brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.admin-auth-brand span { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 7px; color: #fff; background: var(--accent); font-size: 12px; font-weight: 900; }
.admin-auth-brand strong { font-size: 16px; }
.admin-auth-heading { margin: 42px 0 26px; }
.admin-auth-heading > span { display: block; margin-bottom: 7px; color: var(--accent); font-size: 9px; font-weight: 900; text-transform: uppercase; }
.admin-auth-heading h1 { font-size: 25px; }
.admin-auth-heading p { margin-top: 8px; color: var(--text-soft); font-size: 11px; }
#adminLoginForm { display: grid; gap: 17px; }
#adminLoginForm > label:not(.admin-remember) { display: grid; gap: 7px; color: var(--text-soft); font-size: 10px; font-weight: 800; }
#adminLoginForm input[type="email"], #adminLoginForm input[type="password"] { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 7px; outline: 0; color: var(--text); background: #fff; }
#adminLoginForm input:focus { border-color: #75bcb2; box-shadow: 0 0 0 3px rgba(8,127,114,.08); }
.admin-remember { display: flex; align-items: center; gap: 7px; color: var(--text-soft); font-size: 10px; }
.admin-remember input { accent-color: var(--accent); }
#adminLoginSubmit { width: 100%; height: 44px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 7px; color: #fff; background: var(--accent); font-size: 11px; font-weight: 900; }
#adminLoginSubmit:hover { background: var(--accent-strong); }
#adminLoginSubmit:disabled { cursor: wait; opacity: .65; }
#adminLoginSubmit svg { width: 15px; height: 15px; }
.login-error { padding: 9px 11px; border: 1px solid #efc1bc; border-radius: 6px; color: #a33c31; background: #fff4f2; font-size: 10px; line-height: 1.5; }
.back-to-chat { display: inline-flex; align-items: center; gap: 6px; margin-top: 28px; color: var(--text-soft); font-size: 10px; font-weight: 700; text-decoration: none; }
.back-to-chat:hover { color: var(--accent-strong); }
.back-to-chat svg { width: 14px; height: 14px; }

@media (max-width: 480px) {
  .admin-auth-screen { padding: 0; background: #fff; }
  .admin-auth-card { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 28px 22px; border: 0; box-shadow: none; }
}

/* Dramalink control workspace */
:root {
  --page: #e9ece9;
  --panel: #fcfdfb;
  --panel-soft: #f2f4f1;
  --text: #171d1b;
  --text-soft: #58625e;
  --text-faint: #87918c;
  --line: #d9dfda;
  --line-strong: #c6cec7;
  --accent: #0b7b6d;
  --accent-strong: #075f55;
  --accent-soft: #e2f1ed;
  --gold: #d9a84f;
  --gold-soft: #f7edd9;
  --blue: #356fa7;
  --blue-soft: #e6eff7;
  --amber: #a46d18;
  --amber-soft: #f8edd6;
  --red: #b64b3d;
  --red-soft: #f8e8e5;
  --sidebar: #111715;
  --sidebar-raised: #1a211f;
  --shadow: 0 18px 44px rgba(17, 23, 21, .14);
}

body {
  color: var(--text);
  background: var(--page);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline-color: rgba(217, 168, 79, .48);
}

.admin-shell {
  grid-template-columns: 248px minmax(0, 1fr);
  background: var(--page);
}

.sidebar {
  position: sticky;
  isolation: isolate;
  padding: 22px 14px 16px;
  border-right: 1px solid #2c3632;
  color: #dce3df;
  background: var(--sidebar);
}

.sidebar::before {
  position: absolute;
  z-index: -1;
  top: 0;
  right: 0;
  left: 0;
  height: 118px;
  border-bottom: 1px solid rgba(217, 168, 79, .12);
  background: #0e1412;
  content: "";
}

.brand {
  min-height: 52px;
  gap: 12px;
  padding: 0 8px 24px;
}

.brand > span,
.admin-auth-brand > span {
  width: 42px;
  height: 42px;
  border: 1px solid #edc97f;
  border-radius: 8px;
  color: #18201d;
  background: var(--gold);
  box-shadow: 0 9px 24px rgba(0, 0, 0, .2);
}

.brand > span svg,
.admin-auth-brand > span svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.1;
}

.brand strong,
.admin-auth-brand strong {
  display: grid;
  gap: 2px;
  color: #f5f7f6;
  font-size: 17px;
}

.brand small,
.admin-auth-brand small {
  color: #9f8350;
  font-size: 8px;
  font-weight: 900;
}

.main-nav {
  gap: 7px;
  margin-top: 20px;
}

.main-nav button,
.sidebar-bottom > button {
  position: relative;
  min-height: 44px;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid transparent;
  color: #8f9b95;
  background: transparent;
}

.main-nav button:hover,
.main-nav button.active,
.sidebar-bottom > button:hover {
  border-color: #333e39;
  color: #f2f5f3;
  background: #202825;
}

.main-nav button.active::before {
  position: absolute;
  left: -15px;
  width: 3px;
  height: 24px;
  background: var(--gold);
  content: "";
}

.main-nav button.active svg { color: #e6bc6c; }
.sidebar-bottom { gap: 8px; }

.admin-profile {
  margin-top: 4px;
  padding: 15px 10px 2px;
  border-top-color: #303a36;
}

.admin-profile > span {
  border: 1px solid rgba(217, 168, 79, .35);
  border-radius: 7px;
  color: #231c10;
  background: var(--gold);
}

.admin-profile strong { color: #f0f4f2; }
.admin-profile small { color: #78847e; }

.main-area {
  min-height: 100vh;
  background: var(--page);
}

.topbar {
  height: 70px;
  padding: 0 32px;
  border-bottom-color: #d4dad5;
  background: rgba(249, 250, 247, .96);
  box-shadow: 0 5px 20px rgba(17, 23, 21, .04);
  backdrop-filter: blur(16px);
}

.breadcrumb { color: #8a948f; }
.breadcrumb span { font-weight: 700; }
.breadcrumb strong { color: #1b221f; }
.breadcrumb svg { color: #b19a6e; }

.icon-button {
  border-color: #d2d8d3;
  border-radius: 7px;
  color: #64706a;
  background: #fbfcfa;
}

.icon-button:hover {
  border-color: #b48c45;
  color: #745619;
  background: var(--gold-soft);
}

.connection-badge {
  border-color: #d3dad4;
  color: #5d6862;
  background: #f1f4f0;
}

.connection-badge.live > span {
  background: #249482;
  box-shadow: 0 0 0 3px rgba(36, 148, 130, .1);
}

.view {
  width: min(1500px, 100%);
  padding: 36px 40px 54px;
}

.page-heading {
  min-height: 76px;
  align-items: flex-end;
  margin-bottom: 28px;
  padding-left: 16px;
  border-left: 3px solid var(--gold);
}

.eyebrow {
  color: #98762f;
  font-size: 9px;
}

.page-heading h1 {
  color: #141a18;
  font-size: 27px;
}

.page-heading p {
  color: #68736d;
  font-size: 11px;
}

.primary-button,
.secondary-button,
.text-button {
  min-height: 38px;
  border-radius: 6px;
}

.primary-button {
  border-color: var(--gold);
  color: #171d1b;
  background: var(--gold);
}

.primary-button:hover { background: #e6b963; }

.secondary-button {
  border-color: #cbd2cc;
  background: #fbfcfa;
}

.text-button { color: #7c5a1b; }

.metric-grid {
  gap: 16px;
  margin-bottom: 32px;
}

.metric-grid article {
  position: relative;
  min-height: 92px;
  gap: 15px;
  padding: 18px;
  border-color: #d4dad5;
  border-radius: 7px;
  background: #f9faf7;
  box-shadow: 0 8px 22px rgba(17, 23, 21, .04);
  overflow: hidden;
}

.metric-grid article::after {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 34px;
  height: 3px;
  background: var(--line-strong);
  content: "";
}

.metric-grid article:nth-child(1)::after { background: var(--accent); }
.metric-grid article:nth-child(2)::after { background: var(--blue); }
.metric-grid article:nth-child(3)::after { background: var(--gold); }
.metric-grid article:nth-child(4)::after { background: var(--red); }

.metric-icon {
  width: 42px;
  height: 42px;
  border-radius: 7px;
}

.metric-grid strong {
  color: #151b19;
  font-size: 25px;
}

.overview-grid { gap: 28px; }

.section-title {
  min-height: 52px;
  border-bottom-color: #cfd6d0;
}

.section-title h2 { color: #1b221f; font-size: 15px; }
.section-title p { color: #7d8882; }

.resource-row {
  min-height: 66px;
  padding: 14px 4px;
  border-bottom-color: #d6dcd7;
}

.resource-row > .resource-icon { border-radius: 6px; }
.status-pill { border-radius: 4px; }
.capability-item { min-height: 60px; border-bottom-color: #d6dcd7; }

.resource-tabs {
  gap: 8px;
  margin-bottom: 18px;
  border-bottom-color: #cfd6d0;
}

.resource-tabs button {
  min-height: 42px;
  padding: 8px 14px;
}

.resource-tabs button.active {
  border-bottom-color: var(--gold);
  color: #78591d;
}

.table-section {
  border-color: #cfd6d0;
  border-radius: 7px;
  background: #f9faf7;
  box-shadow: 0 10px 28px rgba(17, 23, 21, .05);
}

.table-tools {
  min-height: 66px;
  border-bottom-color: #d6dcd7;
  background: #f5f7f4;
}

.search-box {
  min-height: 38px;
  border-color: #ccd3cd;
  border-radius: 6px;
  background: #fcfdfb;
}

.search-box:focus-within {
  border-color: #9b7e48;
  box-shadow: 0 0 0 3px rgba(217, 168, 79, .08);
}

.table-tools > select {
  min-height: 38px;
  border-color: #ccd3cd;
  border-radius: 6px;
  background: #fcfdfb;
}

th, td {
  padding: 13px 14px;
  border-bottom-color: #dce1dc;
}

th {
  color: #75817b;
  background: #eef1ed;
}

tbody tr:hover td { background: #f4f6f3; }

.policy-form {
  max-width: 820px;
  border-color: #cfd6d0;
  border-radius: 7px;
  background: #f9faf7;
  box-shadow: 0 10px 28px rgba(17, 23, 21, .05);
}

.policy-form > header,
.policy-form > footer { padding: 20px 22px; }
.policy-form > header { border-bottom-color: #d6dcd7; }
.policy-form > footer { border-top-color: #d6dcd7; background: #f2f4f1; }
.scope-label { color: #75571d; background: var(--gold-soft); }

.role-segment { gap: 12px; padding: 22px; }

.role-segment label > span {
  min-height: 98px;
  border-color: #d3d9d4;
  border-radius: 7px;
  background: #fcfdfb;
}

.role-segment input:checked + span {
  border-color: #a7894e;
  background: var(--gold-soft);
  box-shadow: 0 0 0 2px rgba(217, 168, 79, .09);
}

.role-segment input:checked + span i { color: #8e681f; }

.operation-list { gap: 11px; }

.operation-row {
  min-height: 76px;
  border-color: #d1d8d2;
  border-radius: 7px;
  background: #f9faf7;
  box-shadow: 0 7px 18px rgba(17, 23, 21, .035);
}

.operation-row > span:first-child { border-radius: 6px; }

.drawer-backdrop { background: rgba(8, 12, 10, .62); }

.editor-drawer {
  width: min(490px, 100vw);
  border-left-color: #343e3a;
  background: #f8faf7;
  box-shadow: 0 0 70px rgba(8, 12, 10, .36);
}

.editor-drawer header,
.modal-dialog header {
  border-bottom-color: #303a36;
  color: #eff3f1;
  background: #171e1b;
}

.editor-drawer header .eyebrow,
.modal-dialog header .eyebrow { color: #c3a365; }

.editor-drawer footer,
.modal-dialog footer {
  border-top-color: #d4dad5;
  background: #f1f4f0;
}

.drawer-content input,
.drawer-content select,
.drawer-content textarea,
.modal-content input {
  border-color: #cbd2cc;
  border-radius: 6px;
  background: #fff;
}

.drawer-content input:focus,
.drawer-content select:focus,
.drawer-content textarea:focus,
.modal-content input:focus {
  border-color: #987b46;
  box-shadow: 0 0 0 3px rgba(217, 168, 79, .08);
}

.modal-dialog {
  border-color: #303a36;
  border-radius: 7px;
  background: #f9faf7;
  box-shadow: 0 28px 70px rgba(8, 12, 10, .36);
}

.modal-dialog::backdrop { background: rgba(8, 12, 10, .68); }
.toast { border-color: #9d834f; color: #eac578; background: #171e1b; }

.admin-auth-screen {
  position: relative;
  isolation: isolate;
  min-height: 100svh;
  place-items: center end;
  overflow: hidden;
  padding: 36px clamp(30px, 8vw, 120px);
  background: #111715;
}

.admin-auth-media,
.admin-auth-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.admin-auth-media {
  z-index: -3;
  object-fit: cover;
  object-position: center 48%;
  filter: saturate(.76) contrast(1.04);
}

.admin-auth-overlay {
  z-index: -2;
  background:
    linear-gradient(90deg, rgba(10, 15, 13, .48) 0%, rgba(10, 15, 13, .28) 50%, rgba(10, 15, 13, .9) 100%),
    linear-gradient(180deg, rgba(10, 15, 13, .2), rgba(10, 15, 13, .72));
}

.admin-auth-card {
  width: min(430px, 100%);
  padding: 32px;
  border-color: rgba(255, 255, 255, .13);
  color: #eef3f0;
  background: rgba(17, 23, 21, .9);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
  backdrop-filter: blur(18px);
}

.admin-auth-brand { gap: 12px; }
.admin-auth-heading { margin: 46px 0 27px; }
.admin-auth-heading > span { color: #d7ae61; }
.admin-auth-heading h1 { color: #f6f8f7; font-size: 26px; }
.admin-auth-heading p { color: rgba(232, 239, 235, .56); }

#adminLoginForm > label:not(.admin-remember) { color: rgba(232, 239, 235, .7); }

#adminLoginForm input[type="email"],
#adminLoginForm input[type="password"] {
  border-color: rgba(255, 255, 255, .17);
  color: #fff;
  background: rgba(7, 11, 9, .26);
}

#adminLoginForm input::placeholder { color: rgba(232, 239, 235, .34); }

#adminLoginForm input:focus {
  border-color: rgba(217, 168, 79, .7);
  box-shadow: 0 0 0 3px rgba(217, 168, 79, .1);
}

.admin-remember { color: rgba(232, 239, 235, .56); }
.admin-remember input { accent-color: var(--gold); }

#adminLoginSubmit {
  border: 1px solid #e4ba6b;
  color: #171d1b;
  background: var(--gold);
}

#adminLoginSubmit:hover { background: #e7ba68; }
.back-to-chat { color: rgba(232, 239, 235, .52); }
.back-to-chat:hover { color: #efc87e; }

@media (max-width: 1080px) {
  .admin-shell { grid-template-columns: 224px minmax(0, 1fr); }
  .view { padding-right: 28px; padding-left: 28px; }
}

@media (max-width: 760px) {
  .admin-shell { display: block; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 40;
    width: 244px;
    height: 100dvh;
    box-shadow: 18px 0 52px rgba(8, 12, 10, .3);
  }

  .topbar { height: 64px; padding: 0 14px; }
  .view { padding: 24px 14px 38px; }

  .page-heading {
    min-height: 0;
    padding-left: 12px;
  }

  .admin-auth-screen { place-items: center; padding: 20px; }
}

@media (max-width: 480px) {
  .admin-auth-screen { padding: 0; background: #111715; }

  .admin-auth-card {
    min-height: 100svh;
    justify-content: center;
    padding: 28px 22px;
    border: 0;
    border-radius: 0;
    background: rgba(15, 21, 19, .88);
    box-shadow: none;
  }

  .page-heading { gap: 18px; }
  .metric-grid { grid-template-columns: 1fr; }
}
