:root {
  --primary: #0F766E;
  --primary-dark: #0B5E57;
  --on-primary: #FFFFFF;
  --canvas: #F5F7F8;
  --surface: #FFFFFF;
  --surface-alt: #EEF2F3;
  --hairline: #D8E0E2;
  --ink: #172126;
  --muted: #627078;
  --success: #197044;
  --warning: #A25D00;
  --danger: #B42318;
  --sidebar: #182A30;
  --sidebar-ink: #DCE7E8;
  --sidebar-muted: #A9BBBE;
  --shadow: 0 3px 10px rgb(23 33 38 / 8%);
  font-family: Inter, "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }
input, select, textarea {
  width: 100%; min-height: 40px; border: 1px solid var(--hairline); border-radius: 6px;
  color: var(--ink); background: var(--surface); padding: 8px 10px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid rgb(15 118 110 / 24%); outline-offset: 1px; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: #334047; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 28px; line-height: 1.2; margin-bottom: 0; font-weight: 650; letter-spacing: 0; }
h2 { font-size: 18px; margin-bottom: 0; letter-spacing: 0; }
h3 { font-size: 14px; margin-bottom: 0; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(100%, 396px); border: 1px solid var(--hairline); background: var(--surface); border-radius: 8px; padding: 32px; box-shadow: var(--shadow); }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 6px; background: var(--primary); color: var(--on-primary); font-weight: 750; letter-spacing: 0; overflow: hidden; }
.brand-mark.small { width: 28px; height: 28px; font-size: 11px; }
.brand-mark.has-logo { padding: 2px; background: var(--surface); border: 1px solid var(--hairline); }
.brand-mark img { display: block; width: 100%; height: 100%; object-fit: contain; }
.eyebrow { margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0; }
.login-panel .eyebrow { margin-top: 20px; }
.login-copy { color: var(--muted); margin: 8px 0 24px; }
.stack { display: grid; gap: 16px; }
.form-error { color: var(--danger); margin-bottom: 0; font-size: 13px; }
.setup-hint { margin: 20px 0 0; color: var(--warning); font-size: 13px; line-height: 1.55; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar { background: var(--sidebar); color: var(--sidebar-ink); display: flex; flex-direction: column; min-height: 100vh; position: sticky; top: 0; height: 100vh; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; height: 68px; padding: 0 18px; border-bottom: 1px solid rgb(220 231 232 / 15%); font-weight: 700; }
#sidebar-brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-list { display: grid; gap: 2px; padding: 14px 10px; }
.nav-item { border: 0; min-height: 38px; text-align: left; color: var(--sidebar-muted); background: transparent; border-radius: 4px; padding: 8px 10px; font-size: 14px; }
.nav-item:hover { color: var(--sidebar-ink); background: rgb(255 255 255 / 8%); }
.nav-item.active { color: var(--on-primary); background: var(--primary); }
.sidebar-footer { margin-top: auto; border-top: 1px solid rgb(220 231 232 / 15%); padding: 14px 18px; }
.user-summary { font-size: 13px; line-height: 1.45; color: var(--sidebar-ink); margin-bottom: 8px; }
.user-summary span { display: block; color: var(--sidebar-muted); font-size: 12px; }

.workspace { min-width: 0; }
.topbar { min-height: 84px; display: flex; align-items: center; gap: 16px; justify-content: space-between; padding: 18px 32px; background: var(--surface); border-bottom: 1px solid var(--hairline); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar .eyebrow { margin-bottom: 4px; }
.page-content { padding: 24px 32px 40px; max-width: 1560px; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.page-intro { color: var(--muted); margin: 7px 0 0; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.toolbar select { width: auto; min-width: 180px; }
.toolbar-search { width: min(250px, 100%); }

.button { border: 1px solid transparent; border-radius: 6px; min-height: 38px; padding: 8px 13px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.button.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.button.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.button.secondary { background: var(--surface); color: var(--ink); border-color: var(--hairline); }
.button.text { background: transparent; color: inherit; border-color: transparent; padding-left: 0; }
.button.icon { display: none; background: var(--surface); color: var(--ink); border-color: var(--hairline); }
.button.danger { color: var(--danger); background: var(--surface); border-color: #F1C0BC; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(145px, 1fr)); gap: 12px; margin-bottom: 20px; }
.metric { background: var(--surface); border: 1px solid var(--hairline); border-radius: 6px; padding: 16px; min-height: 100px; }
.metric-label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.metric-value { font-size: 28px; font-weight: 650; line-height: 1; }
.section { margin-top: 24px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--hairline); background: var(--surface); border-radius: 6px; }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--hairline); padding: 11px 12px; text-align: left; font-size: 13px; vertical-align: top; }
th { background: var(--surface-alt); color: #3C4C53; font-size: 12px; font-weight: 700; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #FBFCFC; }
.empty { padding: 28px 16px; color: var(--muted); text-align: center; background: var(--surface); border: 1px dashed var(--hairline); border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.truncate { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { display: inline-flex; align-items: center; min-height: 22px; border-radius: 4px; padding: 2px 7px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.status.pending, .status.running, .status.waiting_browser, .status.review { background: #FFF3D8; color: var(--warning); }
.status.completed, .status.published, .status.active { background: #E4F5EA; color: var(--success); }
.status.failed, .status.revoked, .status.archived { background: #FCE8E7; color: var(--danger); }
.status.internal { background: #E8EEF0; color: #43545C; }
.status.api { background: #E8F1FD; color: #175DAA; }
.status.browser { background: #F5ECFA; color: #704090; }
.status.manual { background: #EDF0F1; color: #536269; }
.status.demo { background: #FCE8E7; color: var(--danger); }
.status.verified { background: #E4F5EA; color: var(--success); }
.readiness-summary { display: flex; flex-wrap: wrap; gap: 12px; margin: -6px 0 16px; font-size: 13px; }
.readiness-summary span { font-weight: 650; }
.ready { color: var(--success); }
.not-ready { color: var(--danger); }
.readiness-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.readiness-grid > div { display: grid; gap: 5px; padding: 12px; border: 1px solid var(--hairline); border-radius: 6px; background: var(--surface); }
.readiness-grid span, .readiness-grid small { color: var(--muted); font-size: 12px; }
.readiness-grid strong { font-size: 14px; }
.inline-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.link-button { color: var(--primary); background: transparent; border: 0; padding: 0; font-weight: 650; font-size: 13px; }
.link-button.danger { color: var(--danger); }
.list-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0 0; color: var(--muted); font-size: 13px; }
.scope-summary { min-width: 220px; line-height: 1.65; }
.scope-summary-all { color: var(--success); font-weight: 650; }
.danger-text { color: var(--danger); }

.modal { width: min(680px, calc(100vw - 28px)); max-height: min(760px, calc(100vh - 28px)); border: 1px solid var(--hairline); border-radius: 8px; padding: 0; color: var(--ink); box-shadow: 0 18px 60px rgb(0 0 0 / 22%); }
.modal::backdrop { background: rgb(23 33 38 / 45%); }
.modal form { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; max-height: inherit; }
.modal-header, .modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; }
.modal-header { border-bottom: 1px solid var(--hairline); }
.modal-header .button.icon { display: block; }
.modal-body { display: grid; gap: 14px; padding: 20px; overflow: auto; }
.modal-footer { border-top: 1px solid var(--hairline); justify-content: flex-end; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; }
.check-row input { width: 16px; min-height: 16px; }
.check-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 10px; border: 1px solid var(--hairline); border-radius: 6px; }
.platform-choice { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.platform-choice label { flex: 0 0 auto; min-width: max-content; white-space: nowrap; }
.platform-choice .small { flex: 0 0 auto; white-space: nowrap; }
.check-list label { display: flex; align-items: center; gap: 7px; font-weight: 500; min-width: 0; }
.check-list input { width: 16px; min-height: 16px; }
.check-list select { flex: 0 0 auto; width: 96px; min-width: 0; height: 30px; padding: 3px 6px; font-size: 12px; }
.lookup-field, .lookup-add { display: grid; gap: 6px; position: relative; }
.lookup-selected { min-height: 23px; display: flex; align-items: center; }
.lookup-results { display: grid; gap: 4px; max-height: 208px; overflow: auto; padding: 6px; border: 1px solid var(--hairline); border-radius: 6px; background: var(--surface-alt); }
.lookup-results p { margin: 6px; }
.lookup-result { width: 100%; min-height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 9px; color: var(--ink); background: var(--surface); border: 1px solid var(--hairline); border-radius: 4px; text-align: left; font-size: 13px; }
.lookup-result:hover { border-color: var(--primary); background: #F7FBFA; }
.lookup-result span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lookup-result small { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.scope-editor, .access-manager { display: grid; gap: 16px; }
.scope-editor > .small, .access-manager > .small { margin: 0; }
.scope-block { display: grid; gap: 12px; padding-top: 2px; }
.scope-block + .scope-block { padding-top: 16px; border-top: 1px solid var(--hairline); }
.scope-block h3 { margin-bottom: 5px; }
.scope-block p { margin-bottom: 0; }
.scope-chip-list { display: flex; flex-wrap: wrap; gap: 7px; min-height: 24px; }
.scope-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 28px; padding: 3px 6px 3px 8px; border: 1px solid var(--hairline); border-radius: 4px; color: #314149; background: var(--surface-alt); font-size: 12px; font-weight: 600; overflow-wrap: anywhere; }
.chip-remove { min-width: 22px; min-height: 22px; padding: 0 4px; border: 0; border-radius: 3px; color: var(--danger); background: transparent; font-size: 11px; font-weight: 650; }
.chip-remove:hover { background: #FCE8E7; }
.access-list-tools { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.compact-table { border-radius: 4px; }
.compact-table th, .compact-table td { padding: 8px 10px; }
.key-token { overflow-wrap: anywhere; padding: 10px; background: var(--surface-alt); border: 1px solid var(--hairline); border-radius: 4px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.branding-layout { display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(280px, .92fr); align-items: start; gap: 20px; }
.branding-panel { display: grid; gap: 16px; padding: 20px; background: var(--surface); border: 1px solid var(--hairline); border-radius: 6px; }
.branding-panel h3 { margin-bottom: 6px; }
.branding-panel p { margin-bottom: 0; }
.branding-logo-preview { width: 144px; height: 144px; font-size: 32px; }
.branding-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.project-danger-action { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; border-top: 1px solid var(--hairline); }
.project-danger-action .small { margin: 0; }
.delete-confirmation { display: grid; gap: 14px; }
.danger-copy { color: var(--danger); font-weight: 650; margin: 0; }
.deletion-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; padding: 12px; list-style: none; background: var(--surface-alt); border: 1px solid var(--hairline); border-radius: 6px; }
.deletion-summary li { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.deletion-summary strong { color: var(--danger); }
.toast { position: fixed; z-index: 10; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px)); padding: 12px 14px; border-radius: 6px; color: white; background: #24333A; box-shadow: var(--shadow); font-size: 13px; }
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; position: fixed; z-index: 5; width: 220px; box-shadow: 12px 0 30px rgb(0 0 0 / 20%); }
  .sidebar.open { display: flex; }
  .button.icon { display: block; }
  .topbar { padding: 16px 20px; }
  .page-content { padding: 20px; }
}
@media (max-width: 640px) {
  .topbar { align-items: flex-start; min-height: 74px; }
  .topbar h1 { font-size: 23px; }
  .topbar-actions { display: none; }
  .page-header { display: grid; }
  .toolbar select, .toolbar .button { width: 100%; }
  .toolbar .toolbar-search { width: 100%; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .check-list, .deletion-summary, .branding-layout, .readiness-grid { grid-template-columns: 1fr; }
  .project-danger-action { align-items: flex-start; flex-direction: column; }
  .list-footer { align-items: flex-start; flex-direction: column; }
  .access-list-tools { grid-template-columns: 1fr; }
  table { min-width: 650px; }
  .login-panel { padding: 24px; }
}
