:root {
  --bg: #f3f6f8;
  --panel: #fff;
  --ink: #172126;
  --muted: #63717a;
  --line: #d9e0e4;
  --line-strong: #bdc8ce;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #e8f0ff;
  --mint: #0f8a78;
  --mint-soft: #e2f5f1;
  --warn: #a16207;
  --warn-soft: #fff7db;
  --bad: #c2413d;
  --bad-soft: #fff0ef;
  --shadow: 0 10px 28px rgba(23, 33, 38, .08);
  --radius: 8px;
  --radius-sm: 6px;
}

html, body { background: var(--bg); color: var(--ink); }
body { font-size: 14px; }
body::before, body::after, .panel::before { display: none !important; }

button, .button-link {
  min-height: 38px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 6px;
  background: #fff; color: #27343b; box-shadow: none; font-weight: 650;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}
button:hover, .button-link:hover { transform: none; border-color: #91a2ab; background: #f6f8f9; box-shadow: none; }
button.primary { border-color: var(--accent); background: var(--accent); color: #fff; box-shadow: none; }
button.primary:hover { border-color: var(--accent-strong); background: var(--accent-strong); box-shadow: none; }
button.danger { border-color: #efb2af; background: #fff7f6; color: var(--bad); }
button.ghost { background: #fff; }
button:disabled { cursor: not-allowed; opacity: .55; }
button svg, .button-link svg { width: 17px; height: 17px; flex: 0 0 auto; }

input, select, textarea {
  border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; color: var(--ink);
  padding: 9px 10px; box-shadow: none;
}
input::placeholder, textarea::placeholder { color: #97a2a8; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
label { position: relative; color: #34434b; font-size: 12px; font-weight: 700; }

.shell { display: grid; grid-template-columns: 264px minmax(0,1fr); min-height: 100vh; background: var(--bg); }
.sidebar {
  position: sticky; top: 0; z-index: 30; display: grid; grid-template-rows: auto minmax(0,1fr) auto;
  width: auto; height: 100vh; min-width: 0; padding: 18px 12px 12px; overflow: hidden;
  border: 0; border-right: 1px solid #29353b; background: #172126; color: #f7fafb; box-shadow: none;
}
.brand { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 0 8px 14px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand::before { content: none; display: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 7px; background: #2f6fec; color: #fff; }
.brand-mark svg { width: 19px; height: 19px; }
.brand > div { display: grid; gap: 1px; }
.brand strong { color: #fff; font-size: 14px; letter-spacing: 0; }
.brand span:not(.brand-mark) { color: #9ba9b0; font-size: 11px; }

.nav { display: block; min-height: 0; padding: 8px 2px 18px; overflow: hidden auto; scrollbar-width: thin; scrollbar-color: #45535a transparent; }
.nav-group { margin: 0 0 8px; }
.nav-group-title { padding: 10px 9px 5px; color: #7f9098; font-size: 10px; font-weight: 800; text-transform: uppercase; }
.nav button {
  display: grid; grid-template-columns: 22px minmax(0,1fr); align-items: center; width: 100%; min-width: 0;
  min-height: 36px; margin: 1px 0; padding: 7px 9px; border: 0; border-radius: 6px;
  background: transparent; color: #bfccd2; box-shadow: none; text-align: left;
}
.nav button:hover { border: 0; background: #222e34; color: #fff; }
.nav button.active { border: 0; background: #2c3a41; color: #fff; box-shadow: inset 3px 0 0 #4f83f1; }
.nav-mark { display: grid; place-items: center; width: 18px; height: 18px; color: #91a4ad; font-size: 0; }
.nav button.active .nav-mark { color: #72a0ff; }
.nav-mark svg { width: 17px; height: 17px; }
.nav-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 650; }

.userbox { display: grid; grid-template-columns: minmax(0,1fr) 36px; align-items: center; gap: 8px; padding: 12px 6px 0; border-top: 1px solid rgba(255,255,255,.1); background: transparent; }
.userbox-copy { min-width: 0; line-height: 1.25; }
.userbox strong, .userbox small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userbox strong { color: #f7fafb; font-size: 12px; }
.userbox small { margin-top: 2px; color: #87979f; font-size: 10px; }
.userbox .icon-button { border-color: #3d4b52; background: #222d32; color: #c5d0d5; }

.main { min-width: 0; padding: 0 28px 48px; overflow: visible; background: var(--bg); }
#view { width: min(100%,1480px); margin: 0 auto; }
.mobile-bar, .nav-backdrop { display: none; }
.scope-bar { display: flex; align-items: center; gap: 10px; width: min(100%,1480px); min-height: 52px; margin: 0 auto; padding: 8px 2px; border-bottom: 1px solid var(--line); }
.scope-bar > svg { width: 18px; color: var(--mint); }
.scope-bar > div { display: grid; min-width: 0; }
.scope-bar strong { font-size: 12px; }
.scope-bar span { color: var(--muted); font-size: 10px; }
.scope-bar .text-button { margin-left: auto; }
.service-scope > svg { color: var(--warn); }
.text-button { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 5px 8px; border: 0; background: transparent; color: var(--accent); font-size: 11px; }
.text-button:hover { border: 0; background: var(--accent-soft); }

.compact-page-head, .dashboard-hero, .admin-hero {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; min-height: auto;
  margin: 0; padding: 24px 0 18px; border: 0; background: transparent; box-shadow: none;
}
.compact-page-head h1, .dashboard-hero h1, .admin-hero h1 { margin: 0; color: var(--ink); font-size: 26px; line-height: 1.2; letter-spacing: 0; }
.compact-page-head p, .dashboard-hero p, .admin-hero p { max-width: 760px; margin: 5px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.eyebrow, .hero-chips, .hero-analytics { display: none !important; }

.panel, .admin-kpi, .metric, .item, .integration-card, .health-check, .plan-editor, .admin-user-row {
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); box-shadow: none; backdrop-filter: none;
}
.panel { padding: 16px; }
.panel h2, .panel h3, .section-head h2, .section-head h3 { color: var(--ink); letter-spacing: 0; }
.section-head { gap: 12px; margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 15px; line-height: 1.3; }
.section-head p { margin: 3px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.item { padding: 12px; }
.item:hover { transform: none; border-color: var(--line-strong); box-shadow: none; }
.metric, .admin-kpi { padding: 14px; }
.metric strong, .admin-kpi strong { color: var(--ink); }
.metric-icon, .kpi-icon { background: #edf3ff; color: var(--accent); box-shadow: none; }
.notice, .empty { border-color: var(--line); border-radius: 6px; background: #f5f7f8; color: #526169; }
.notice.bad { border-color: #efb2af; background: var(--bad-soft); color: var(--bad); }
.notice code { overflow-wrap: anywhere; font-size: 11px; }
.error { border: 1px solid #efb2af; border-radius: 6px; background: var(--bad-soft); color: var(--bad); }
.pill, .status-chip { border-color: var(--line); border-radius: 999px; background: #f1f4f5; color: #53626a; box-shadow: none; }

.scope-warning, .confirmation-reason { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 14px; padding: 12px 14px; border: 1px solid #ecd48b; border-radius: 7px; background: var(--warn-soft); color: #704b0b; }
.scope-warning.safe { border-color: #a8d9cf; background: var(--mint-soft); color: #126a5c; }
.scope-warning svg, .confirmation-reason svg { width: 18px; height: 18px; flex: 0 0 auto; }
.scope-warning div { display: grid; gap: 2px; }
.scope-warning strong { font-size: 12px; }
.scope-warning span, .confirmation-reason span { font-size: 11px; line-height: 1.45; }
.confirmation-reason { margin: 10px 0; padding: 8px 10px; border-color: var(--line); background: #f5f7f8; color: #526169; }
.page-actions { display: flex; justify-content: flex-end; margin: -54px 0 18px; }
.page-actions button, .actions button, .section-head button, .admin-user-form > button, .admin-user-row > button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.danger-text { border-color: #efb2af; background: #fff; color: var(--bad); }
.danger-text:hover { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.manual-token-setup { padding: 12px 0 0; border-top: 1px solid var(--line); }
.manual-token-setup > summary { color: var(--muted); font-size: 11px; cursor: pointer; }

.info-tip { position: relative; display: inline-grid; place-items: center; width: 18px; height: 18px; margin: 0 4px; border-radius: 50%; color: #718089; vertical-align: middle; cursor: help; }
.info-tip svg { width: 15px; height: 15px; }
.info-tip:hover, .info-tip:focus { background: #e9eef1; color: var(--accent); outline: none; }
.info-tip::after { content: attr(data-tooltip); position: absolute; z-index: 100; left: 50%; bottom: calc(100% + 8px); width: min(280px,75vw); padding: 9px 10px; border-radius: 6px; background: #172126; color: #fff; font-size: 11px; font-weight: 500; line-height: 1.4; text-align: left; transform: translateX(-50%); visibility: hidden; opacity: 0; pointer-events: none; }
.info-tip:hover::after, .info-tip:focus::after { visibility: visible; opacity: 1; }

.subnav { display: flex; gap: 4px; margin: -4px 0 18px; padding-bottom: 10px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.subnav button { display: inline-flex; align-items: center; gap: 7px; flex: 0 0 auto; min-height: 34px; border-color: transparent; background: transparent; color: var(--muted); font-size: 11px; }
.subnav button.active { border-color: #bdd0ff; background: var(--accent-soft); color: var(--accent-strong); }
.admin-kpis { grid-template-columns: repeat(6,minmax(0,1fr)); gap: 10px; }
.admin-dashboard-grid, .workspace-grid, .grid { gap: 12px; }
.section-block { margin-top: 20px; }
.admin-create-panel { margin-bottom: 20px; }
.admin-user-form { grid-template-columns: repeat(6,minmax(120px,1fr)); align-items: end; }
.admin-user-list, .plan-editor-list, .audit-list, .health-grid, .admin-settings-groups { display: grid; gap: 10px; }
.admin-user-row { display: grid; grid-template-columns: minmax(190px,1.3fr) repeat(4,minmax(120px,1fr)) auto; align-items: end; gap: 10px; padding: 12px; }
.admin-user-identity, .plan-editor-head > div { display: grid; gap: 3px; align-self: center; min-width: 0; }
.admin-user-identity strong { overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.admin-user-identity span, .plan-editor-head span, .setting-key { color: var(--muted); font-size: 10px; }
.current-user-badge { display: inline-flex; margin-left: 6px; padding: 2px 5px; border: 1px solid #b9c8ff; border-radius: 4px; color: #2947a8; background: #edf3ff; font-size: 9px; font-style: normal; font-weight: 700; vertical-align: middle; }
.metric-mark svg, .kpi-icon svg { width: 18px; height: 18px; }
.command-label, .chat-input-label { display: grid; gap: 6px; }
.chat-input-label { min-width: 0; flex: 1; }
.chat-input-label > span { display: flex; align-items: center; font-size: 11px; font-weight: 700; color: var(--muted); }
.chat-input-label textarea { width: 100%; }
.loading-state { display: flex; align-items: center; gap: 9px; min-height: 92px; color: var(--muted); font-size: 12px; }
.loading-state svg { width: 18px; height: 18px; }
.panel-divider { height: 1px; margin: 22px 0; background: var(--line); }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.plan-editor { padding: 15px; }
.plan-editor-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.switch-label, .feature-checks label { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
.switch-label input, .feature-checks input, .checks input { width: 16px; height: 16px; margin: 0; }
.feature-checks input[type="number"], .feature-checks select { width: 100%; min-width: 0; height: 34px; }
.feature-checks label:has(input[type="number"]), .feature-checks label:has(select) { display: grid; grid-template-columns: 1fr auto; align-items: center; }
.feature-checks label:has(input[type="number"]) input, .feature-checks label:has(select) select { grid-column: 1 / -1; }
fieldset { margin: 12px 0; padding: 11px; border: 1px solid var(--line); border-radius: 7px; }
legend { padding: 0 5px; color: #34434b; font-size: 11px; font-weight: 750; }
.feature-checks { display: grid; grid-template-columns: repeat(6,minmax(110px,1fr)); gap: 8px; }
.admin-settings-groups { grid-template-columns: repeat(2,minmax(0,1fr)); }
.admin-settings-form > .section-head { position: sticky; top: 0; z-index: 10; padding: 12px 0; background: var(--bg); }
.setting-row { display: grid; gap: 3px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-row label { display: block; }
.setting-row input { margin-top: 5px; }
.health-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; color: var(--ink); }
.table th, .table td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; font-size: 11px; }
.table th { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.plan-state { display: flex; align-items: center; gap: 7px; margin-top: 12px; padding: 8px 0; color: var(--muted); font-size: 11px; }
.plan-state.active { color: var(--mint); font-weight: 700; }
.plan-state svg { width: 16px; }

.app-toast { position: fixed; z-index: 200; right: 20px; bottom: 20px; display: flex; align-items: center; gap: 9px; max-width: min(360px,calc(100vw - 24px)); padding: 11px 14px; border: 1px solid #9fd5ca; border-radius: 7px; background: #e8f7f3; color: #126a5c; box-shadow: var(--shadow); font-size: 12px; font-weight: 700; }
.app-toast.error { border-color: #efb2af; background: var(--bad-soft); color: var(--bad); }
.app-toast svg { width: 18px; height: 18px; }
.login { background: #eef2f4; }
.login-panel { border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); box-shadow: var(--shadow); }

@media (max-width: 1250px) {
  .admin-kpis { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .admin-user-form { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .admin-user-row { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .admin-user-identity { grid-column: span 2; }
  .feature-checks { grid-template-columns: repeat(4,minmax(100px,1fr)); }
}

@media (max-width: 980px) {
  .shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px,86vw); height: 100dvh; transform: translateX(-102%); transition: transform 160ms ease; }
  .nav-open .sidebar { transform: translateX(0); }
  .nav-backdrop { position: fixed; z-index: 25; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; background: rgba(23,33,38,.42); }
  .nav-open .nav-backdrop { display: block; }
  .main { padding: 0 18px 40px; }
  .mobile-bar { display: grid; grid-template-columns: 38px minmax(0,1fr) 38px; align-items: center; gap: 10px; min-height: 54px; margin: 0 -18px; padding: 8px 18px; border-bottom: 1px solid var(--line); background: #fff; }
  .mobile-bar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; font-size: 13px; }
  .mobile-bar .icon-button { border-color: var(--line-strong); background: #f5f7f8; color: var(--ink); }
  .mobile-bar .icon-button:hover { border-color: #9baab2; background: #edf1f3; color: var(--ink); }
  .icon-button { display: inline-grid; place-items: center; width: 36px; min-width: 36px; height: 36px; min-height: 36px; padding: 0; }
  .scope-bar { min-height: 48px; }
  .scope-bar .text-button { width: 34px; min-width: 34px; padding: 0; overflow: hidden; color: transparent; }
  .scope-bar .text-button svg { color: var(--accent); }
  .admin-dashboard-grid, .workspace-grid, .admin-settings-groups, .health-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .admin-user-row { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .feature-checks { grid-template-columns: repeat(3,minmax(0,1fr)); }
}

@media (max-width: 640px) {
  .main { padding: 0 12px 32px; }
  .mobile-bar { margin: 0 -12px; padding: 8px 12px; }
  .scope-bar { align-items: flex-start; padding: 9px 0; }
  .scope-bar span { display: block; line-height: 1.35; }
  .compact-page-head, .dashboard-hero, .admin-hero { padding: 18px 0 14px; }
  .compact-page-head h1, .dashboard-hero h1, .admin-hero h1 { font-size: 22px; }
  .page-actions { justify-content: stretch; margin: 0 0 12px; }
  .page-actions button { width: 100%; }
  .dashboard-kpi-grid, .admin-kpis, .grid.cols-2, .grid.cols-3, .grid.cols-4, .form-grid.two, .form-grid.three, .form-grid.four, .admin-user-form, .admin-user-row { grid-template-columns: 1fr; }
  .admin-user-identity { grid-column: auto; }
  .feature-checks { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .panel, .plan-editor, .admin-user-row { padding: 13px; }
  .section-head { align-items: flex-start; }
  .section-head > button { width: 100%; }
  .admin-settings-form > .section-head { position: static; }
  .subnav { margin-right: -12px; }
  .info-tip::after { position: fixed; right: 12px; bottom: 12px; left: 12px; width: auto; transform: none; }
}
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: 1px !important;
  max-height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
