:root {
  --bg: #f8f9fa;
  --surface: #fff;
  --ink: #252729;
  --muted: #777c82;
  --line: #e7e9ec;
  --soft: #f2f3f5;
  --green: #367260;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  font-size: 14px;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { border: 0; background: none; color: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
button:disabled { opacity: .5; cursor: wait; }
button, a, input { outline-offset: 4px; }
:focus-visible { outline: 2px solid #858b93; }
input {
  width: 100%; padding: 12px 14px; color: var(--ink); background: var(--surface);
  border: 1px solid #dfe2e6; border-radius: 8px; min-height: 44px;
}
input::placeholder { color: #9b9fa5; }
input:focus { border-color: #858b93; outline: 0; box-shadow: 0 0 0 3px #25272908; }
input[type=checkbox] { width: 16px; min-height: 16px; accent-color: var(--ink); }
label { display: block; font-weight: 500; }
label input { margin-top: 10px; }
small { font-size: 12px; color: var(--muted); }
p { margin: 0; line-height: 1.7; color: var(--muted); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.4px; }
h1 { font-size: 26px; }
h2 { font-size: 16px; }
h3 { font-size: 16px; }
.hidden { display: none !important; }
.icon-definitions { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.primary, .outline, .danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 40px; padding: 9px 15px; border-radius: 8px; font-weight: 500; white-space: nowrap;
}
.primary { background: var(--ink); color: white; border: 1px solid var(--ink); }
.primary:hover { background: #404347; }
.outline { background: var(--surface); border: 1px solid #e0e3e7; }
.outline:hover { background: #f8f9fa; border-color: #c8cdd2; }
.danger { color: #a64d4d; border: 1px solid #eedfdf; }
.danger:hover { background: #fbf5f5; }
.brand-icon {
  height: 32px; width: 32px; flex-shrink: 0; border-radius: 9px; background: var(--ink); color: white;
  display: grid; place-items: center; font-size: 19px; font-weight: 600;
}
.login { min-height: 100svh; display: grid; place-items: center; padding: 30px; }
.login-card { width: min(100%, 352px); padding: 12px 0; text-align: center; }
.login-card .brand-icon { height: 42px; width: 42px; font-size: 24px; margin: 0 auto 18px; }
.login-card h1 { font-size: 26px; margin-bottom: 38px; }
.login-card label { text-align: left; font-size: 13px; }
.login-card .primary { width: 100%; margin-top: 20px; min-height: 44px; }
.workspace { display: flex; min-height: 100svh; }
aside {
  width: 212px; position: fixed; inset: 0 auto 0 0; z-index: 2;
  display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line);
  padding: 34px 18px 24px;
}
.brand { display: inline-flex; align-items: center; gap: 11px; padding: 0 12px; font-size: 20px; font-weight: 600; letter-spacing: -.5px; }
aside nav { display: grid; gap: 6px; margin-top: 48px; }
.nav { width: 100%; display: flex; gap: 12px; align-items: center; min-height: 44px; padding: 11px 14px; text-align: left; border-radius: 8px; color: var(--muted); }
.nav:hover { color: var(--ink); background: #fafafa; }
.nav.active { color: var(--ink); background: var(--soft); font-weight: 550; }
.nav[data-page=ipa] { margin-top: 22px; }
.nav[data-page=settings] { margin-top: 22px; }
.logout { display: flex; align-items: center; gap: 12px; color: var(--muted); margin-top: auto; padding: 12px 14px; text-align: left; font-size: 13px; }
.logout:hover { color: var(--ink); }
main { width: calc(100% - 212px); margin-left: 212px; padding: 64px 44px 80px; min-width: 0; }
.content-shell { max-width: 1040px; margin-inline: auto; }
header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 36px; min-height: 42px; }
.header-actions { display: flex; gap: 14px; align-items: center; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; background: var(--soft); border-radius: 5px; color: var(--muted); font-size: 12px; font-weight: 400; line-height: 1.4; white-space: nowrap; }
.badge.good { color: var(--green); background: #f0f5f2; }
.badge.good::before { content: ""; width: 4px; height: 4px; background: currentColor; border-radius: 50%; }
.badge.warning { color: #8c6c2f; background: #f8f4eb; }
.badge.error { color: #985252; background: #fbf0f0; }
.stats { display: grid; grid-template-columns: repeat(4,1fr); padding: 26px 0; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; }
.stats article { padding: 2px 28px; min-width: 0; }
.stats article + article { border-left: 1px solid var(--line); }
.stats article > span { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.stats strong { display: block; margin-top: 18px; font-size: 32px; font-weight: 500; line-height: 1; font-variant-numeric: tabular-nums; }
.pending-count { font-size: 11px; color: var(--ink); white-space: nowrap; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 34px 0 18px; }
.module-card { display: flex; align-items: center; gap: 18px; padding: 26px 28px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.module-icon { width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 11px; display: grid; place-items: center; }
.module-icon .icon { width: 21px; height: 21px; }
.module-info { flex: 1; min-width: 0; }
.module-info h3 { margin-bottom: 8px; }
#system-status .badge { padding: 0; background: none; font-size: 12px; }
.panel, .profile-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.panel { padding: 28px; }
.table-wrap { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
th { padding: 18px 22px; font-weight: 400; font-size: 12px; color: var(--muted); background: #fcfcfc; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child { border-radius: 12px 0 0 0; }
th:last-child { border-radius: 0 12px 0 0; }
td { padding: 22px; border-bottom: 1px solid var(--line); line-height: 1.7; }
tr:last-child td { border: 0; }
td small { display: block; margin-top: 3px; }
td .outline { font-size: 12px; padding: 7px 10px; min-height: 34px; }
td:last-child button + button { margin-left: 6px; }
td .primary { font-size: 12px; padding: 7px 10px; min-height: 34px; }
.empty { padding: 72px 24px; text-align: center; color: var(--muted); }
.tabs { display: flex; gap: 30px; border-bottom: 1px solid var(--line); }
.tab { padding: 0 0 16px; color: var(--muted); font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab .pending-count { margin-left: 7px; }
.access-policy { margin: 24px 0; color: var(--muted); font-size: 13px; }
.access-policy summary { cursor: pointer; }
.access-policy p { margin-top: 12px; }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 500; }
.profile-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 20px; }
.profile-card { padding: 26px; }
.profile-title { display: flex; align-items: center; gap: 13px; }
.region { width: 42px; height: 42px; flex-shrink: 0; display: grid; place-items: center; background: var(--soft); color: #5d6268; border-radius: 9px; font-size: 12px; font-weight: 550; }
.profile-title .badge { margin-left: auto; }
.profile-details { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin: 20px 0 26px; }
.profile-details p { font-size: 13px; overflow-wrap: anywhere; }
.profile-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.profile-actions button { font-size: 12px; padding: 8px 12px; min-height: 36px; }
#open-model-import { font-size: 13px; }
.settings { max-width: 560px; padding: 32px; margin: 52px auto 0; }
.settings h2 { font-size: 18px; margin-bottom: 32px; }
.settings-field { margin: 26px 0; }
.settings-field > input { margin-top: 10px; }
.field-heading { position: relative; display: flex; align-items: center; gap: 6px; min-height: 24px; }
.field-heading label { font-size: 13px; }
.field-heading .badge { font-size: 11px; padding: 3px 7px; margin-left: 4px; }
.field-help { display: inline-flex; }
.help-trigger { display: grid; place-items: center; width: 24px; height: 24px; padding: 0; color: var(--muted); cursor: help; border-radius: 50%; }
.help-trigger > span { display: grid; place-items: center; width: 16px; height: 16px; border: 1px solid #c6cbd0; border-radius: 50%; font-size: 11px; line-height: 1; }
.help-trigger:hover, .help-trigger:focus-visible { color: var(--ink); }
.help-tooltip { display: none; position: absolute; z-index: 5; bottom: calc(100% + 8px); left: 0; width: min(340px,100%); padding: 16px 18px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: 0 8px 28px #25272914; font-size: 13px; line-height: 1.8; font-weight: 400; }
.help-tooltip::before { content: ""; position: absolute; left: 0; right: 0; bottom: -10px; height: 10px; }
.field-help.open .help-tooltip { display: block; }
.field-help.below .help-tooltip { bottom: auto; top: calc(100% + 8px); }
.field-help.below .help-tooltip::before { bottom: auto; top: -10px; }
.help-tooltip > span { display: block; }
.help-tooltip > span + span { margin-top: 10px; }
.help-tooltip code { font-size: 12px; }
.tooltip-note { color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; margin-top: 34px; }
dialog { width: min(560px,calc(100vw - 32px)); padding: 28px; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 20px 80px #12182020; color: var(--ink); }
dialog::backdrop { background: #20232655; backdrop-filter: blur(2px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 24px; }
.dialog-head h2 { font-size: 18px; }
.icon-button { padding: 0 3px; color: var(--muted); font-size: 25px; }
#dialog-content label { margin: 20px 0; }
#dialog-content h3 { margin: 24px 0 16px; font-size: 14px; }
.permission { display: flex; align-items: center; gap: 10px; font-weight: 400; }
.permission input { margin: 0; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; padding: 18px; border-radius: 8px; background: var(--bg); font-size: 12px; line-height: 1.8; max-height: 340px; overflow: auto; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 28px; }
.wizard-status-actions { justify-content: flex-start; align-items: center; flex-wrap: wrap; }
.wizard-steps { display: flex; list-style: none; padding: 0; margin: 4px 0 28px; counter-reset: step; }
.wizard-steps li { flex: 1; display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.wizard-steps li::before { counter-increment: step; content: counter(step); display: grid; place-items: center; width: 23px; height: 23px; border-radius: 50%; background: var(--soft); font-size: 11px; }
.wizard-steps li.active { color: var(--ink); font-weight: 500; }
.wizard-steps li.active::before { color: white; background: var(--ink); }
.wizard-steps li.complete::before { content: "✓"; color: var(--green); background: #f0f5f2; }
.wizard-loading { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 48px 0; }
.wizard-loading::before { content: ""; width: 17px; height: 17px; border: 2px solid var(--line); border-top-color: var(--muted); border-radius: 50%; }
.wizard-help { font-size: 12px; color: var(--muted); line-height: 1.8; }
.wizard-help summary { cursor: pointer; width: fit-content; }
.wizard-help p { margin-top: 10px; }
.wizard-success { padding: 10px 0 4px; text-align: center; }
.success-mark { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: #f0f5f2; color: var(--green); font-size: 23px; margin: 0 auto 20px; }
#dialog-content .wizard-success h3 { margin: 0 0 8px; font-size: 18px; }
.wizard-success .actions { justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 28px; }
.wizard-success .actions button { min-height: 40px; margin: 0; }
.wizard-success .actions .primary { min-width: 120px; }
.wizard-success > .primary { margin-top: 28px; min-width: 120px; }
.text-button { min-height: 40px; padding: 9px 12px; color: var(--muted); border-radius: 8px; }
.text-button:hover { color: var(--ink); background: var(--soft); }
.model-import > .primary { width: 100%; }
.model-location { margin: 18px 0 22px; padding: 15px 16px; background: var(--bg); border-radius: 8px; }
.model-location span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.model-location code { display: block; font-size: 12px; line-height: 1.7; overflow-wrap: anywhere; }
.model-guide { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 20px; }
.model-guide summary { cursor: pointer; font-size: 13px; font-weight: 500; }
.model-guide-fields { display: grid; grid-template-columns: 120px minmax(0,1fr); gap: 16px; }
#dialog-content .model-guide-fields label { margin-bottom: 14px; font-size: 13px; }
.model-guide p { font-size: 12px; }
.command-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 22px; font-size: 12px; color: var(--muted); }
.copy-command { padding: 3px 0 3px 12px; color: var(--ink); font-size: 12px; white-space: nowrap; }
.model-guide pre { margin: 8px 0 0; padding: 14px 16px; }
.model-guide .model-location { margin-bottom: 0; }
.toast {
  position: fixed; inset: 20px 22px auto auto; margin: 0; width: min(420px,calc(100vw - 44px));
  padding: 14px 17px; background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--green); border-radius: 8px; box-shadow: 0 8px 28px #25272918;
  font-size: 13px; line-height: 1.6; opacity: 0; visibility: hidden; transform: translateY(-8px); overflow: hidden;
  transition: opacity .18s, transform .18s, visibility .18s, display .18s allow-discrete, overlay .18s allow-discrete;
}
.toast:popover-open { opacity: 1; visibility: visible; transform: translateY(0); }
@starting-style { .toast:popover-open { opacity: 0; transform: translateY(-8px); } }
.toast.error { border-left-color: #b97878; color: #985252; }
.toast-progress { position: absolute; bottom: 0; left: 0; height: 2px; width: 100%; background: var(--green); opacity: .6; transform-origin: left; animation: toast-countdown 5s linear forwards; }
.toast.error .toast-progress { background: #b97878; }
@keyframes toast-countdown { to { transform: scaleX(0); } }
@media (min-width:1600px) { main { padding-top: 80px; } }
@media (max-width:1100px) {
  aside { width: 188px; padding-inline: 14px; }
  main { width: calc(100% - 188px); margin-left: 188px; padding: 46px 30px 64px; }
  .stats article { padding-inline: 20px; }
  .stats article > span { flex-wrap: wrap; gap: 4px; }
  .profile-grid { grid-template-columns: 1fr; }
}
@media (max-width:700px) {
  .workspace { flex-direction: column; }
  aside { position: static; width: 100%; padding: 20px 20px 0; border-right: 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; }
  .brand-row { grid-column: 1; }
  .brand { font-size: 19px; padding: 0; gap: 10px; }
  .brand-icon { width: 30px; height: 30px; font-size: 18px; }
  aside nav { grid-column: 1 / -1; grid-row: 2; display: grid; grid-template-columns: repeat(4,1fr); gap: 0; margin-top: 24px; }
  .nav { flex-direction: column; justify-content: center; gap: 8px; padding: 12px 2px 14px; font-size: 11px; min-height: 64px; border-radius: 0; border-bottom: 2px solid transparent; }
  .nav.active { background: none; border-bottom-color: var(--ink); }
  .nav[data-page=ipa], .nav[data-page=settings] { margin-top: 0; }
  .logout { grid-column: 2; grid-row: 1; padding: 6px; margin: 0; }
  .logout span { display: none; }
  main { width: 100%; margin: 0; padding: 32px 20px 56px; }
  header { margin-bottom: 28px; gap: 12px; }
  h1 { font-size: 23px; }
  .header-actions { gap: 9px; }
  #refresh { padding: 8px 10px; min-height: 36px; }
  #refresh span { display: none; }
  .badge { font-size: 11px; }
  .stats { grid-template-columns: repeat(2,1fr); padding: 0; }
  .stats article { padding: 22px; }
  .stats article + article { border-left: 0; }
  .stats article:nth-child(even) { border-left: 1px solid var(--line); }
  .stats article:nth-child(n+3) { border-top: 1px solid var(--line); }
  .stats article > span { font-size: 12px; }
  .stats strong { font-size: 30px; margin-top: 16px; }
  .section-heading { margin-top: 28px; }
  .module-card { padding: 22px 18px; gap: 13px; }
  .module-icon { width: 40px; height: 40px; }
  .module-info h3 { font-size: 14px; }
  .module-card button { padding: 8px 10px; min-height: 36px; font-size: 12px; }
  .module-card button .icon { display: none; }
  .profile-card { padding: 22px; }
  .profile-title { gap: 11px; }
  .settings { margin-top: 0; padding: 24px; }
  .settings input { font-size: 14px; }
  .settings .form-actions .primary { width: 100%; }
  #open-model-import { font-size: 12px; padding: 8px 10px; }
  th, td { padding: 16px; }
  dialog { padding: 24px; }
  .model-guide-fields { grid-template-columns: 1fr; gap: 0; }
  .wizard-steps li { font-size: 11px; gap: 5px; }
  .wizard-steps li::before { width: 20px; height: 20px; }
  #dialog-content .model-guide-fields label { margin-bottom: 0; }
  .toast { top: 12px; right: 12px; width: calc(100vw - 24px); }
}
@media (prefers-reduced-motion:no-preference) {
  button { transition: background-color .15s, border-color .15s, color .15s, transform .15s; }
  .primary:active, .outline:active, .danger:active { transform: scale(.98); }
  dialog[open] { animation: dialog-in .22s ease-out both; }
  dialog[open]::backdrop { animation: fade-in .2s ease-out both; }
  dialog.closing { animation: dialog-out .16s ease-in both; }
  dialog.closing::backdrop { animation: fade-in .16s ease-in reverse both; }
  .page:not(.hidden), .wizard-stage > *, .help-tooltip { animation: fade-up .2s ease-out both; }
  .wizard-loading::before { animation: spin .8s linear infinite; }
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes dialog-out { to { opacity: 0; transform: translateY(6px) scale(.99); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion:reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .toast-progress { display: none; }
}
