:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --paper: #ffffff;
  --text: #202432;
  --muted: #73798b;
  --line: #e7e9f0;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eeedff;
  --danger: #b83d48;
  --danger-soft: #fff1f2;
  --ok: #287950;
  --ok-soft: #edf7f1;
  --sidebar-width: 224px;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button, input, select, textarea { color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
button, a, input, select, textarea { outline-offset: 3px; }
:focus-visible { outline: 3px solid #aaa5fb; }
input:focus, select:focus, textarea:focus { outline: none; }
button:disabled, .button[aria-disabled="true"] { cursor: not-allowed; opacity: .55; }
button, .button, input, select, textarea, .nav-item {
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
svg { display: block; flex-shrink: 0; }
h1, h2, p { margin-top: 0; }
form { margin: 0; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  padding: 10px 16px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); color: #fff; }

/* The sidebar remains the same across all administration pages. */
.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  z-index: 30;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  background: var(--paper);
  border-right: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 96px;
  padding: 0 24px;
  color: var(--text);
}
.brand:hover { color: var(--text); }
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
}
.brand-mark svg { width: 19px; height: 19px; }
svg.brand-mark { padding: 7px; }
.brand-name { font-size: 16px; font-weight: 650; letter-spacing: -.3px; white-space: nowrap; }
.nav-label { margin: 18px 28px 10px; color: #9297a5; font-size: 11px; font-weight: 600; letter-spacing: 1px; }
.side-nav { display: grid; gap: 6px; padding: 0 16px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 10px 13px;
  border-radius: 7px;
  color: #686e80;
  font-weight: 500;
}
.nav-item svg { width: 18px; height: 18px; color: #9297a6; }
.nav-item:hover { color: var(--text); background: #f5f6f9; }
.nav-item.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.nav-item.active svg { color: var(--accent); }
.sidebar-footer { margin-top: auto; padding: 20px 16px; }
.sidebar-footer form { padding-top: 14px; border-top: 1px solid var(--line); }
.logout-button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  padding: 9px 13px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}
.logout-button svg { width: 18px; height: 18px; }
.logout-button:hover { color: var(--text); background: #f5f6f9; }
.menu-backdrop, .mobile-header { display: none; }
.workspace {
  min-width: 0;
  margin-left: var(--sidebar-width);
  padding: 39px 36px 56px;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 30px;
}
.page-heading { min-width: 0; }
.page-heading h1 { margin: 0; overflow-wrap: anywhere; font-size: 28px; line-height: 1.4; font-weight: 650; letter-spacing: -.7px; }
.page-heading p { margin: 7px 0 0; color: var(--muted); line-height: 1.7; }
.page-header > .button { flex-shrink: 0; }
.breadcrumb { display: flex; align-items: center; gap: 7px; margin: 0 0 15px; color: var(--muted); font-size: 13px; }
.breadcrumb a { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb svg { width: 15px; height: 15px; }

/* Controls share one visual scale and one primary action color. */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.55;
  text-decoration: none;
  white-space: nowrap;
}
.button svg { width: 16px; height: 16px; }
.button:hover { border-color: #d1d4df; background: #f8f9fb; color: var(--text); }
.button.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.button.primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); color: #fff; }
.button.secondary { color: #555c70; background: var(--paper); }
.button.secondary:hover { background: #f6f7fa; }
.button.danger { color: var(--danger); border-color: #ecd4d7; }
.button.danger:hover { background: var(--danger-soft); border-color: #dfacb2; }
.text-button, .button.text-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 4px 0;
  border: 0;
  border-radius: 3px;
  color: var(--accent);
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.text-button:hover { color: var(--accent-hover); background: transparent; }
.text-button.danger { color: var(--danger); }
.text-button.danger:hover { color: #942b35; background: transparent; }
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 7px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}
.icon-button svg { width: 19px; height: 19px; }
.icon-button:hover { background: #f2f3f7; color: var(--text); }

/* All tables scroll within their panel, never with the entire page. */
.surface { min-width: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 9px; }
.section-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; min-height: 68px; padding: 19px 24px; border-bottom: 1px solid var(--line); }
.section-toolbar h2 { display: inline-flex; align-items: center; gap: 10px; margin: 0; font-size: 15px; font-weight: 600; }
.count { display: inline-flex; align-items: center; justify-content: center; min-width: 23px; min-height: 22px; padding: 1px 7px; border-radius: 5px; color: var(--muted); background: #f0f2f6; font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
.table-scroll { max-width: 100%; max-height: calc(100vh - 235px); overflow: auto; overscroll-behavior: contain; border-radius: 0 0 9px 9px; scrollbar-color: #cbd0dc transparent; scrollbar-width: thin; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; text-align: left; }
.data-table th, .data-table td { padding: 18px 24px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table th { position: sticky; z-index: 1; top: 0; padding-top: 13px; padding-bottom: 13px; color: var(--muted); background: #fafbfc; font-size: 12px; font-weight: 500; white-space: nowrap; }
.data-table td { font-size: 13px; line-height: 1.75; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: #fcfcff; }
.channel-table th:first-child { width: 36%; }
.channel-table th:last-child, .channel-table td:last-child { text-align: right; }
.channel-table .cell-keyword, .channel-table .channel-name { color: var(--text); font-size: 14px; font-weight: 550; }
.row-link { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.row-link svg { width: 14px; height: 14px; }
.keyword-table { min-width: 1140px; }
.keyword-table th, .keyword-table td { padding-right: 20px; padding-left: 20px; }
.keyword-table td { vertical-align: top; }
.cell-keyword { min-width: 190px; max-width: 260px; overflow-wrap: anywhere; font-weight: 500; }
.cell-category { min-width: 110px; max-width: 160px; overflow-wrap: anywhere; }
.cell-date { min-width: 120px; white-space: nowrap; color: #6d7485; font-variant-numeric: tabular-nums; }
.cell-volume { min-width: 155px; max-width: 210px; overflow-wrap: anywhere; }
.cell-competition { min-width: 100px; }
.cell-long { min-width: 230px; max-width: 360px; overflow-wrap: anywhere; white-space: normal; }
.keyword-table.rejected-table, .keyword-table.eliminated-table { min-width: 750px; }
.keyword-table.rejected-table .cell-long, .keyword-table.eliminated-table .cell-long { width: 42%; }
.api-table { min-width: 820px; table-layout: fixed; }
.api-table th:first-child { width: 104px; }
.api-table th:nth-child(2) { width: 96px; }
.api-table th:nth-child(3) { width: 150px; }
.api-table th:last-child { width: 260px; }
.api-table th, .api-table td { padding-right: 18px; padding-left: 18px; }
.api-table td { overflow-wrap: anywhere; }
.api-table .cell-date { white-space: normal; }
.key { color: #6a7081; font: 12px/1.8 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; white-space: normal; }
.key code { font: inherit; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 5px; color: var(--muted); background: #f1f2f5; font-size: 12px; line-height: 1.6; white-space: nowrap; }
.status::before { content: ""; width: 5px; height: 5px; flex-shrink: 0; border-radius: 50%; background: currentColor; }
.status.enabled { background: var(--ok-soft); color: var(--ok); }
.status.disabled { background: #f1f2f5; color: #7b8190; }
.api-actions { display: grid; gap: 5px; }
.actions-main, .actions-secondary { display: flex; flex-wrap: wrap; align-items: center; gap: 7px 14px; }
.actions-main .button { min-height: 32px; padding: 5px 10px; font-size: 12px; }
.actions-secondary .button, .actions-secondary .text-button { min-height: 27px; font-size: 12px; }
.actions-secondary form { display: inline-flex; }
.actions-secondary .text-button:not(.danger) { color: #757b8c; }
.actions-secondary .text-button:not(.danger):hover { color: var(--accent); }

.tabs { display: flex; align-items: center; gap: 26px; min-height: 64px; padding: 0 24px; border-bottom: 1px solid var(--line); }
.tab { position: relative; display: inline-flex; align-items: center; gap: 8px; align-self: stretch; padding: 19px 0; color: var(--muted); font-weight: 500; white-space: nowrap; }
.tab:hover { color: var(--accent); }
.tab.active { color: var(--accent); font-weight: 600; }
.tab.active::after { position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; background: var(--accent); content: ""; }
.tab-count { min-width: 20px; padding: 0 6px; border-radius: 4px; color: #818797; background: #f0f2f6; font-size: 11px; font-weight: 500; text-align: center; font-variant-numeric: tabular-nums; }
.tab.active .tab-count { color: var(--accent); background: var(--accent-soft); }
.keyword-paging { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--line); }
.paging-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; color: var(--muted); font-size: 12px; }
.paging-actions { display: flex; gap: 8px; margin-left: auto; }
.paging-actions .button { min-height: 34px; padding: 6px 12px; }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 350px; padding: 52px 24px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 18px; border-radius: 12px; color: #8b91a4; background: #f4f5f9; }
.empty-icon svg { width: 25px; height: 25px; }
.empty-state h2 { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.empty-state p { max-width: 370px; margin: 0 0 22px; color: var(--muted); font-size: 13px; line-height: 1.8; }
.empty-state p:last-child { margin-bottom: 0; }
.notice { margin: 0 0 22px; padding: 11px 15px; border: 1px solid #d6e9dd; border-radius: 6px; color: var(--ok); background: var(--ok-soft); font-size: 13px; }
.form-error { margin: 0 0 20px; padding: 11px 13px; border: 1px solid #f2d6da; border-radius: 6px; color: var(--danger); background: var(--danger-soft); font-size: 13px; }
.muted, .note { color: var(--muted); }

/* Channel and API creation happen in focused dialogs. */
dialog.modal, dialog.manual-dialog {
  width: min(440px, calc(100% - 32px));
  max-height: calc(100dvh - 48px);
  margin: auto;
  padding: 28px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--paper);
}
dialog::backdrop { background: rgb(23 28 44 / 35%); }
.dialog-heading, .modal-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 25px; }
.dialog-heading h2, .modal-header h2 { margin: 0; font-size: 20px; line-height: 1.4; font-weight: 600; letter-spacing: -.3px; }
.dialog-heading .icon-button, .modal-header .icon-button { flex-shrink: 0; margin: -5px -6px -5px 0; }
.field { display: grid; gap: 8px; margin-bottom: 20px; }
.field label { color: #424958; font-size: 13px; font-weight: 500; }
.field input, .field select, .login-form input {
  display: block;
  width: 100%;
  height: 44px;
  padding: 10px 12px;
  border: 1px solid #dfe2eb;
  border-radius: 6px;
  background: var(--paper);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
.field select { padding-right: 32px; }
input::placeholder, textarea::placeholder { color: #a2a7b4; opacity: 1; }
.field input:hover, .field select:hover, .login-form input:hover { border-color: #c7cbd8; }
.field input:focus, .field select:focus, .login-form input:focus { border-color: var(--accent); }
.field-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.dialog-actions, .modal-footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line); }
dialog.manual-dialog { width: min(650px, calc(100% - 32px)); }
.manual-dialog textarea { display: block; width: 100%; min-height: 280px; max-height: 50dvh; padding: 14px; resize: vertical; border: 1px solid var(--line); border-radius: 6px; background: #fafbfc; color: var(--text); font: 12px/1.8 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.manual-dialog textarea:focus { border-color: var(--accent); }
.manual-dialog > p, .modal-body > p { color: var(--muted); font-size: 13px; }
.no-js { margin: 16px 0; padding: 12px 15px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: var(--paper); }

/* A single, quiet entry point for the shared administration password. */
.login-shell { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh; padding: 36px 24px; }
.login-card { width: 100%; max-width: 414px; padding: 38px 36px 35px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 35px; color: var(--text); font-size: 15px; font-weight: 600; }
.login-brand .brand-mark { width: 30px; height: 30px; border-radius: 7px; }
.login-intro { margin-bottom: 28px; }
.login-intro h1 { margin: 0 0 8px; font-size: 25px; font-weight: 650; line-height: 1.45; letter-spacing: -.6px; }
.login-intro p { margin: 0; color: var(--muted); font-size: 13px; }
.login-form .field { margin-bottom: 21px; }
.login-form > .button, .login-form > button[type="submit"] { width: 100%; min-height: 44px; }
.login-footer { margin: 22px 0 0; color: #959aa7; font-size: 12px; text-align: center; }
.toast { position: fixed; z-index: 80; bottom: 30px; left: calc(50% + var(--sidebar-width) / 2); max-width: calc(100% - 40px); padding: 11px 19px; border: 1px solid #373d4d; border-radius: 7px; color: #fff; background: #2a3040; font-size: 13px; line-height: 1.6; text-align: center; opacity: 0; pointer-events: none; transform: translate(-50%, 8px); transition: opacity .15s ease, transform .15s ease; }
.toast.is-visible { opacity: 1; transform: translateX(-50%); }
.toast:empty { display: none; }

@media (min-width: 1500px) {
  .workspace { padding-right: 44px; padding-left: 44px; }
}

@media (min-width: 761px) and (max-width: 1090px) {
  .workspace { padding: 30px 24px 44px; }
  .api-table th, .api-table td { padding-right: 13px; padding-left: 13px; }
  .actions-main { gap: 6px; }
  .actions-main .button { font-size: 11px; padding: 5px 8px; }
  .data-table th, .data-table td { padding-right: 16px; padding-left: 16px; }
}

@media (max-width: 760px) {
  body.menu-open { overflow: hidden; }
  .sidebar { z-index: 50; width: var(--sidebar-width); visibility: hidden; transform: translateX(-100%); transition: transform .18s ease, visibility .18s ease; }
  .menu-open .sidebar { visibility: visible; transform: translateX(0); }
  .brand { min-height: 80px; }
  .nav-label { margin-top: 12px; }
  .menu-open .menu-backdrop { position: fixed; z-index: 40; inset: 0; display: block; width: 100%; height: 100%; padding: 0; border: 0; border-radius: 0; background: rgb(23 28 44 / 35%); }
  .mobile-header { display: flex; align-items: center; gap: 12px; height: 64px; margin: -24px -20px 26px; padding: 0 17px; border-bottom: 1px solid var(--line); background: var(--paper); }
  .mobile-brand { font-size: 15px; font-weight: 600; color: var(--text); }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 7px; border: 0; border-radius: 6px; color: #636a7c; background: transparent; }
  .menu-toggle svg { width: 21px; height: 21px; }
  .menu-toggle:hover { background: #f2f3f7; }
  .workspace { margin-left: 0; padding: 24px 20px 36px; }
  .page-header { align-items: flex-start; gap: 16px; margin-bottom: 24px; }
  .page-heading h1 { font-size: 24px; }
  .page-heading p { margin-top: 5px; font-size: 12px; }
  .page-header > .button { min-height: 36px; margin-top: 1px; padding: 8px 11px; font-size: 12px; }
  .page-header > .button svg { width: 14px; height: 14px; }
  .breadcrumb { margin-bottom: 12px; font-size: 12px; }
  .section-toolbar { min-height: 60px; padding: 16px; }
  .section-toolbar h2 { font-size: 14px; }
  .table-scroll { max-height: calc(100dvh - 240px); }
  .data-table th, .data-table td { padding-right: 16px; padding-left: 16px; }
  .data-table td { padding-top: 16px; padding-bottom: 16px; }
  .channel-table { min-width: 0; table-layout: fixed; }
  .channel-table th, .channel-table td { padding-right: 8px; padding-left: 8px; overflow-wrap: anywhere; white-space: normal; }
  .channel-table th:first-child { width: auto; }
  .channel-table th:nth-child(2), .channel-table th:nth-child(3) { width: 18%; text-align: center; }
  .channel-table td.numeric { text-align: center; font-variant-numeric: tabular-nums; }
  .channel-table th:last-child { width: 92px; }
  .channel-table .row-link { font-size: 12px; }
  .channel-table .row-link svg { display: none; }
  .tabs { max-width: 100%; min-height: 60px; gap: 18px; padding: 0 16px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; }
  .tab { flex-shrink: 0; gap: 6px; padding-top: 18px; padding-bottom: 18px; font-size: 13px; }
  .keyword-paging { padding: 14px 16px; }
  .empty-state { min-height: 310px; padding: 42px 22px; }
  .empty-state p { font-size: 12px; }
  .notice { margin-bottom: 18px; }
  .toast { bottom: 22px; left: 50%; }
  dialog.modal, dialog.manual-dialog { padding: 24px; max-height: calc(100dvh - 32px); }
  .dialog-heading, .modal-header { margin-bottom: 23px; }
  .dialog-heading h2, .modal-header h2 { font-size: 19px; }
  .manual-dialog textarea { min-height: 230px; }
}

@media (max-width: 390px) {
  .workspace { padding-right: 16px; padding-left: 16px; }
  .mobile-header { margin-right: -16px; margin-left: -16px; }
  .page-header { gap: 10px; }
  .page-heading h1 { font-size: 22px; }
  .login-shell { padding: 24px 16px; }
  .login-card { padding: 30px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
