/* 智境引擎 · 视觉精修层
 * Existing DOM, layout, spacing, type sizes and responsive breakpoints stay in
 * their owning stylesheets. This layer changes material and interaction states.
 * Three edge levels: panel / control / focus. No external font or asset request.
 */
:root {
  color-scheme: light;
  --bg: #f3f6f7;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --sunk: #edf2f4;
  --border: #dce4e8;
  --border-strong: #aebec7;
  --text: #17323b;
  --text-2: #51636d;
  --text-3: #63747e;
  --brand: #087f8c;
  --brand-hover: #066773;
  --brand-soft: #e7f4f5;
  --brand-ink: #ffffff;
  --ink: #17323b;
  --ink-hover: #244954;
  --side: #f8fafb;
  --side-2: #edf2f4;
  --side-text: #51636d;
  --side-active: #17323b;
  --green: #14633f; --green-bg: #edf8f1;
  --amber: #8b520c; --amber-bg: #fff7e8;
  --red: #b02f36; --red-bg: #fff0f0;
  --blue: #225da0; --blue-bg: #edf4fc;
  --violet: #694994; --violet-bg: #f5f0fa;
  --gray: #51636d; --gray-bg: #eef2f4;
  --r-sm: 8px; --r: 14px; --r-lg: 20px;
  --polish-hover: #f0f5f6;
  --polish-selected: #e5eff1;
  --polish-row: #f6f9fa;
  --polish-rule: #eaf0f2;
  --polish-motion: 160ms;
  --polish-shadow-control: 0 1px 2px #17323b0c, inset 0 1px 0 #ffffff26;
  --polish-shadow-float: 0 16px 48px -12px #17323b30, 0 4px 12px #17323b0c;
  --shadow-sm: none;
  --shadow: 0 2px 8px #17323b08;
  --shadow-lg: var(--polish-shadow-float);
  --focus: 0 0 0 3px #087f8c24;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #141719; --surface: #1c2023; --surface-2: #22272a; --sunk: #2a3034;
    --border: #353d42; --border-strong: #62717a;
    --text: #eef3f5; --text-2: #bdc9cf; --text-3: #a1b0b9;
    --brand: #80d6dd; --brand-hover: #a3e6eb; --brand-soft: #203d42; --brand-ink: #10282c;
    --ink: #e3edef; --ink-hover: #ffffff;
    --side: #1a1e21; --side-2: #2a3034; --side-text: #bdc9cf; --side-active: #eef3f5;
    --green: #91d9b0; --green-bg: #21382c;
    --amber: #e8c483; --amber-bg: #3b3020;
    --red: #f3a7aa; --red-bg: #40282b;
    --blue: #9bc4ee; --blue-bg: #233447;
    --violet: #cab4e8; --violet-bg: #322a40;
    --gray: #bdc9cf; --gray-bg: #2a3034;
    --polish-hover: #293136; --polish-selected: #2e3d42; --polish-row: #242c30;
    --polish-rule: #2d353a;
    --polish-shadow-control: 0 1px 2px #0003, inset 0 1px 0 #ffffff0a;
    --polish-shadow-float: 0 16px 48px -12px #0009, 0 4px 12px #0004;
    --shadow: 0 2px 8px #0002;
    --focus: 0 0 0 3px #80d6dd30;
  }
}
body { -webkit-font-smoothing: antialiased; }
::selection { background: var(--brand-soft); color: var(--text); }

:where(button, input, select, textarea, a, summary) { -webkit-tap-highlight-color: transparent; }
:where(button, [role=button], a, summary):focus-visible {
  outline: 2px solid var(--brand); outline-offset: 3px;
}
:where(button, input, select, textarea):disabled { cursor: not-allowed; }
:where(button, [role=button], a)[aria-disabled=true] { cursor: not-allowed; }
:where(input[type=checkbox], input[type=radio]) { accent-color: var(--brand); }
:where(.table-wrap, .dd-list, .modal, .chat-log, #nav .nav-links) {
  scrollbar-color: var(--border-strong) transparent;
}

/* The original shell's dimensions and group hierarchy are deliberately retained. */
#nav, .workspace-topbar { background: var(--side); border-color: var(--border); }
#nav .brand b { color: var(--text); }
#nav a { transition: background-color var(--polish-motion), color var(--polish-motion), border-color var(--polish-motion); }
#nav a:hover:not(.active) { background: var(--polish-hover); border-color: var(--border); }
#nav a.active { background: var(--polish-selected); border-color: var(--border); color: var(--text); }
#nav a.active .i { color: var(--brand); }
#nav a:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
#nav .nav-group { color: var(--text); }
.workspace-status { background: var(--surface); border-color: var(--border); box-shadow: var(--polish-shadow-control); }
.workspace-status:hover { background: var(--brand-soft); border-color: var(--brand); }
.avatar { background: var(--brand-soft); color: var(--brand); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 15%, transparent); }
.page-head { border-bottom-color: var(--border); }
.page-head h1 { color: var(--text); }
.page-head .sub, .crumb { color: var(--text-2); }
.card { border-color: var(--border); box-shadow: none; }
.card-head, .card-foot { background: var(--surface-2); border-color: var(--border); }
.card-head h2, .card-head h3 { color: var(--text); }

/* Buttons: the same geometry, with an identifiable rest, hover, press and focus. */
.btn {
  --button-bg: var(--ink); --button-fg: var(--surface); --button-edge: var(--ink);
  background: var(--button-bg); color: var(--button-fg); border-color: var(--button-edge);
  box-shadow: var(--polish-shadow-control);
  transition: background-color var(--polish-motion), color var(--polish-motion), border-color var(--polish-motion), box-shadow var(--polish-motion);
}
.btn:hover:not(:disabled):not([aria-disabled=true]) {
  background: var(--ink-hover); border-color: var(--ink-hover);
  box-shadow: var(--polish-shadow-control);
}
.btn.ghost { --button-bg: var(--surface); --button-fg: var(--text); --button-edge: var(--border-strong); }
.btn.ghost:hover:not(:disabled):not([aria-disabled=true]) { background: var(--polish-hover); border-color: var(--text-3); }
.btn.ai { --button-bg: var(--brand); --button-fg: var(--brand-ink); --button-edge: var(--brand); }
.btn.ai:hover:not(:disabled):not([aria-disabled=true]) { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.danger { --button-bg: var(--surface); --button-fg: var(--red); --button-edge: color-mix(in srgb, var(--red) 38%, var(--border)); }
.btn.danger:hover:not(:disabled):not([aria-disabled=true]) { background: var(--red-bg); border-color: var(--red); }
.btn.danger-solid { --button-bg: #b02f36; --button-fg: #fff; --button-edge: #b02f36; }
.btn:is(.ghost, .ai, .danger, .danger-solid) { background: var(--button-bg); color: var(--button-fg); border-color: var(--button-edge); }
.btn.danger-solid:hover:not(:disabled):not([aria-disabled=true]) { background: #95262d; border-color: #95262d; }
.btn:active:not(:disabled):not([aria-disabled=true]) { filter: none; box-shadow: inset 0 2px 4px #0002; }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
.btn:disabled, .btn[aria-disabled=true], .btn:disabled:hover, .btn[aria-disabled=true]:hover {
  background: var(--button-bg); color: var(--button-fg); border-color: var(--button-edge);
  opacity: .48; box-shadow: none; filter: none;
}
.btn.is-busy:disabled, .btn.is-busy[aria-disabled=true] { opacity: .82; cursor: progress; }
.btn .i, .icon-btn .i, .link-btn .i { stroke-width: 1.8; }
.icon-btn, .icon-btn2, .link-btn {
  transition: background-color var(--polish-motion), color var(--polish-motion), box-shadow var(--polish-motion);
}
.icon-btn:hover:not(:disabled):not([aria-disabled=true]),
.icon-btn2:hover:not(:disabled):not([aria-disabled=true]),
.link-btn:hover:not(:disabled):not([aria-disabled=true]) { background: var(--polish-hover); color: var(--text); }
.link-btn.red { color: var(--red); }
.link-btn.red:hover:not(:disabled):not([aria-disabled=true]) { background: var(--red-bg); color: var(--red); }
:is(.icon-btn, .icon-btn2, .link-btn):is(:disabled, [aria-disabled=true]),
:is(.icon-btn, .icon-btn2, .link-btn):is(:disabled, [aria-disabled=true]):hover {
  background: transparent; color: var(--text-3); opacity: .5; box-shadow: none;
}
:is(.icon-btn, .icon-btn2, .link-btn).is-busy:is(:disabled, [aria-disabled=true]),
:is(.icon-btn, .icon-btn2, .link-btn).is-busy:is(:disabled, [aria-disabled=true]):hover {
  background: transparent; color: var(--brand); opacity: .82; cursor: progress;
}
.btn:disabled:has(.spin), .send.is-busy { opacity: .82; cursor: progress; }

/* Inputs keep native affordances; chip selects remain compact. */
input:where(:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=range]):not([type=file])), textarea, select, .dd-btn {
  border-color: var(--border-strong); background-color: var(--surface); color: var(--text);
  box-shadow: inset 0 1px 2px #17323b04;
  transition: border-color var(--polish-motion), box-shadow var(--polish-motion), background-color var(--polish-motion);
}
:is(input, textarea, select):hover:where(:not(:disabled):not(:focus):not([aria-invalid=true]):not([readonly]):not([type=checkbox]):not([type=radio]):not([type=color]):not([type=range])),
.dd-btn:hover:not(:disabled) { border-color: var(--text-3); }
:is(input, textarea, select):focus:where(:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=range])),
.dd-btn.open, .dd-btn:focus-visible { border-color: var(--brand); box-shadow: var(--focus); outline: none; }
input::placeholder, textarea::placeholder { color: var(--text-3); opacity: 1; }
:is(input, textarea, select)[aria-invalid=true] { border-color: var(--red); }
:is(input, textarea, select)[aria-invalid=true]:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 15%, transparent); }
:is(input, textarea, select):disabled, .dd-btn:disabled, .dd-btn:disabled:hover {
  border-color: var(--border); background-color: var(--sunk); color: var(--text-3); box-shadow: none;
}
input[readonly], textarea[readonly] { background-color: var(--surface-2); }
.field > span { color: var(--text); }
.field .hint { color: var(--text-2); }
.dd-chip .dd-btn { background: transparent; border-color: transparent; box-shadow: none; }
.dd-chip .dd-btn:hover:not(:disabled) { background: var(--polish-hover); }
.dd-menu { box-shadow: var(--polish-shadow-float); border-color: var(--border); }
.dd-opt:hover:not(.dis), .dd-opt.act:not(.dis) { background: var(--polish-hover); color: var(--text); }
.dd-opt.sel, .dd-opt.sel:hover:not(.dis), .dd-opt.sel.act { background: var(--brand-soft); color: var(--brand); }
.dd-opt.dis:hover { background: transparent; color: var(--text-3); }
.switch input { box-shadow: inset 0 0 0 1px #17323b12; }
.switch input:checked { background: var(--brand); }
.switch input:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }

/* Data surfaces: crisp rules, calm header, legible figures and semantic status. */
table { font-variant-numeric: tabular-nums; }
th { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }
td { border-color: var(--polish-rule); }
tbody tr:hover td { background: var(--polish-row); }
.kv tr:hover td { background: transparent; }
.pill { box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 12%, transparent); }
.pill, .tag { font-variant-numeric: tabular-nums; }
.tag { background: var(--surface-2); border-color: var(--border); }
.banner { box-shadow: none; }
.empty-icon { background: var(--surface-2); color: var(--text-3); box-shadow: inset 0 0 0 1px var(--border); }
.empty h3 { color: var(--text); }
.empty p { color: var(--text-2); }
code, kbd { border-color: var(--border); background: var(--sunk); }

/* Floating surfaces are the only strong elevation in the working UI. */
.modal-wrap { background: #0c202b66; backdrop-filter: none; }
.modal { border-color: var(--border); background: var(--surface); box-shadow: var(--polish-shadow-float); }
.modal h3 { color: var(--text); }
:where(.modal p) { color: var(--text-2); }
#toast { background: var(--text); color: var(--surface); border-color: transparent; box-shadow: var(--polish-shadow-float); }
@media (prefers-color-scheme: dark) {
  #toast { background: #edf3f5; color: #17323b; }
  #toast .i { color: #14633f; }
  #toast.err .i { color: #b02f36; }
  .modal-wrap { background: #0009; }
}
.ai-skeleton-card { border-color: var(--border); background: var(--surface); }
.ai-loading-copy strong { color: var(--text); }
.ai-loading-copy p { color: var(--text-2); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  :is(.btn, .icon-btn, .icon-btn2, .link-btn, .dd-btn):focus-visible { outline: 2px solid Highlight; }
  .pill { outline: 1px solid CanvasText; box-shadow: none; }
}
