:root {
  --ink: #17212b;
  --muted: #71808e;
  --line: #e5e9ee;
  --panel: #ffffff;
  --canvas: #f5f7f9;
  --blue: #2c68d8;
  --blue-soft: #eaf1ff;
  --orange: #c87918;
  --orange-soft: #fff4e4;
  --red: #c74b4b;
  --red-soft: #fff0f0;
  --green: #31835e;
  --green-soft: #e9f7ef;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-size: 14px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.app-shell { display: flex; min-height: 100vh; }

.sidebar { width: 224px; flex: 0 0 224px; background: #17232f; color: #c7d0d9; display: flex; flex-direction: column; padding: 26px 14px 18px; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 12px 32px; color: #fff; }
.brand-mark { width: 33px; height: 33px; display: grid; place-items: center; border-radius: 8px; background: #4077df; color: white; font-size: 22px; font-weight: 700; }
.brand strong { display: block; font-size: 16px; letter-spacing: .02em; }
.brand span { display: block; font-size: 11px; color: #8d9cab; margin-top: 3px; }
.nav-list { display: grid; gap: 5px; }
.nav-item { display: flex; align-items: center; gap: 11px; height: 42px; color: #aebbc7; padding: 0 12px; border-radius: 6px; text-decoration: none; transition: background .15s ease, color .15s ease; }
.nav-item:hover, .nav-item.active { background: #24384a; color: #fff; }
.nav-item.active { box-shadow: inset 3px 0 #5a8bea; }
.nav-icon { width: 17px; text-align: center; font-size: 18px; line-height: 1; }
.nav-badge { margin-left: auto; min-width: 21px; height: 20px; display: inline-grid; place-items: center; padding: 0 5px; border-radius: 10px; background: #ad513e; color: #fff; font-size: 11px; }
.sidebar-foot { margin-top: auto; border-top: 1px solid #2b3b49; padding: 17px 12px 0; }
.system-status { display: flex; gap: 7px; align-items: center; font-size: 12px; color: #d2dfda; }
.status-dot, .meta-dot { display: inline-block; width: 7px; height: 7px; border-radius: 100%; background: var(--green); }
.sidebar-foot small { display: block; margin-top: 8px; font-size: 11px; color: #748493; }

.main-content { max-width: 1420px; width: 100%; margin: 0 auto; padding: 38px 46px 30px; }
.config-notice { margin: -12px 0 22px; padding: 11px 14px; border: 1px solid #f0d4a9; border-radius: 6px; background: #fff8eb; color: #855519; line-height: 1.5; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 30px; }
.eyebrow { color: #7d8c9a; letter-spacing: .16em; font-size: 10px; font-weight: 700; margin: 0 0 8px; }
h1, h2, p { margin: 0; }
h1 { font-size: 29px; letter-spacing: -.03em; line-height: 1.15; }
.subtitle { color: var(--muted); margin-top: 9px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; padding-top: 12px; flex-wrap: wrap; justify-content: flex-end; }
.last-refresh { color: #85929e; font-size: 12px; }
.api-key-field { height: 34px; display: flex; align-items: center; gap: 7px; padding: 0 5px 0 9px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: #7d8b97; font-size: 11px; }
.api-key-field input { width: 105px; border: 0; outline: 0; background: transparent; font-size: 11px; color: var(--ink); }
.api-key-field button { border: 0; border-left: 1px solid var(--line); background: transparent; color: var(--blue); font-size: 11px; font-weight: 650; padding: 5px 6px 5px 9px; }
.connection-state { display: inline-flex; align-items: center; gap: 5px; color: #8a96a0; font-size: 11px; white-space: nowrap; }.connection-dot { width: 7px; height: 7px; border-radius: 100%; background: #aab4bc; }.connection-state.connected { color: var(--green); }.connection-state.connected .connection-dot { background: var(--green); }.connection-state.error { color: var(--red); }.connection-state.error .connection-dot { background: var(--red); }
.button { border: 1px solid transparent; border-radius: 5px; min-height: 34px; padding: 0 13px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; font-weight: 600; transition: all .15s ease; }
.button-primary { background: var(--blue); border-color: var(--blue); color: #fff; box-shadow: 0 2px 5px #2c68d822; }
.button-primary:hover { background: #2358bd; border-color: #2358bd; }
.button-quiet { color: #607181; background: #fff; border-color: var(--line); }
.button-quiet:hover { color: var(--blue); border-color: #b8ccef; background: #fbfcff; }
.button:disabled { opacity: .55; cursor: wait; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 31px; }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; min-height: 132px; padding: 19px 20px 16px; border-top: 3px solid #99b8f4; }
.stat-card.warning { border-top-color: #efb55e; }
.stat-card.danger { border-top-color: #e58a8a; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.stat-value { font-size: 31px; line-height: 1.2; font-weight: 700; letter-spacing: -.04em; margin-top: 7px; }
.stat-meta { margin-top: 12px; display: flex; gap: 7px; align-items: center; color: #83909b; font-size: 11px; }
.meta-dot.green { background: var(--green); }.meta-dot.orange { background: #df8a23; }.meta-dot.red { background: var(--red); }
.trend-up { color: var(--green); font-size: 14px; font-weight: 700; }

.toolbar-section { margin-bottom: 11px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 16px; }
.section-heading h2, .insight-panel h2 { font-size: 17px; letter-spacing: -.01em; }
.record-count { color: #8a96a0; font-size: 11px; margin-left: 11px; }
.sync-label { color: #8a96a0; font-size: 11px; }
.filters { display: flex; align-items: center; gap: 9px; }
.search-field { flex: 1; max-width: 530px; height: 37px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: #86939e; display: flex; align-items: center; padding: 0 11px; gap: 8px; }
.search-field input { border: 0; outline: 0; min-width: 0; width: 100%; color: var(--ink); background: transparent; }
.search-field input::placeholder { color: #a3adb7; }
.select-field { height: 37px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: #82909b; display: flex; align-items: center; gap: 8px; padding: 0 10px; }
.select-field select { color: var(--ink); border: 0; outline: 0; background: transparent; min-width: 90px; }

.table-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th { background: #fafbfc; color: #7c8996; font-size: 11px; font-weight: 700; text-align: left; white-space: nowrap; padding: 12px 17px; border-bottom: 1px solid var(--line); }
td { padding: 14px 17px; border-bottom: 1px solid #edf0f3; vertical-align: middle; color: #3c4a56; font-size: 12px; }
tbody tr:hover { background: #fbfcfe; }
.user-cell { display: flex; flex-direction: column; gap: 4px; min-width: 168px; }
.user-cell strong { color: #253541; font-size: 13px; font-weight: 650; }
.user-cell small, .token-cell small { color: #8b98a3; font-size: 11px; }
.token-cell { display: flex; flex-direction: column; gap: 4px; max-width: 235px; }
.token-cell code { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #5c6b79; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; }
.token-history { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #af6b2e !important; }
.number-cell { font-weight: 700; color: #334451; }
.number-cell.alert-number { color: var(--red); }
.province-tags { display: flex; gap: 4px; flex-wrap: wrap; max-width: 175px; }
.province-tag { color: #637583; background: #f1f4f6; border-radius: 3px; padding: 4px 6px; font-size: 10px; white-space: nowrap; }
.province-tag.more { color: var(--orange); background: var(--orange-soft); }
.last-seen { color: #687885; white-space: nowrap; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 12px; padding: 5px 8px; white-space: nowrap; font-size: 10px; font-weight: 700; }
.status-pill.alert { color: #a64141; background: var(--red-soft); }.status-pill.expired { color: #a5651b; background: var(--orange-soft); }.status-pill.normal { color: #347652; background: var(--green-soft); }
.status-pill::before { content: ''; width: 5px; height: 5px; border-radius: 100%; background: currentColor; }
.empty-state { min-height: 188px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 7px; color: #778590; }
.empty-state strong { color: #4b5a66; }.empty-state span { font-size: 12px; }.empty-icon { font-size: 29px; color: #9ba8b3; }
.table-footer { height: 48px; border-top: 1px solid #edf0f3; padding: 0 17px; display: flex; align-items: center; justify-content: space-between; color: #8a96a0; font-size: 11px; }

.insight-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 29px; }
.insight-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 19px 20px 14px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid #edf0f3; padding-bottom: 13px; }
.panel-heading p { margin-top: 5px; color: #8b97a1; font-size: 11px; }
.panel-icon { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 50%; font-weight: 700; font-size: 13px; }.panel-icon.orange { color: var(--orange); background: var(--orange-soft); }.panel-icon.blue { color: var(--blue); background: var(--blue-soft); }
.province-list { padding-top: 12px; display: grid; gap: 9px; }
.province-row { display: grid; grid-template-columns: 54px 1fr 42px; align-items: center; gap: 9px; font-size: 11px; color: #61717e; }
.province-row .bar-track { height: 6px; background: #edf1f4; border-radius: 3px; overflow: hidden; }.province-row .bar { display: block; height: 100%; background: #e0a355; border-radius: inherit; }.province-row em { color: #8b97a1; font-style: normal; text-align: right; }
.rule-list { padding-top: 8px; }.rule-row { display: flex; gap: 13px; padding: 10px 0; border-bottom: 1px solid #edf0f3; }.rule-row:last-child { border-bottom: 0; }.rule-number { color: #a7b2bc; font-family: ui-monospace, monospace; font-size: 11px; padding-top: 2px; }.rule-row strong { display: block; color: #4a5b67; font-size: 12px; }.rule-row small { display: block; color: #8b97a1; font-size: 11px; margin-top: 3px; line-height: 1.5; }
.page-footer { color: #a0aab2; font-size: 11px; text-align: center; padding: 27px 0 3px; }.page-footer span { margin: 0 7px; }

@media (max-width: 1000px) { .sidebar { width: 190px; flex-basis: 190px; }.main-content { padding: 30px 28px; }.stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .app-shell { display: block; }.sidebar { width: auto; padding: 12px 14px; display: block; }.brand { padding: 0 8px 12px; }.nav-list { display: flex; overflow-x: auto; }.nav-item { flex: 0 0 auto; height: 36px; }.sidebar-foot { display: none; }.main-content { padding: 25px 15px; }.topbar { display: block; }.topbar-actions { padding-top: 18px; justify-content: space-between; }.api-key-field { flex: 1 1 190px; }.api-key-field input { width: 100%; }.stats-grid { gap: 9px; }.stat-card { min-height: 116px; padding: 14px; }.stat-value { font-size: 25px; }.filters { flex-wrap: wrap; }.search-field { flex-basis: 100%; max-width: none; }.select-field { flex: 1; }.insight-grid { grid-template-columns: 1fr; }.section-heading { align-items: flex-start; gap: 8px; flex-direction: column; } }
@media (max-width: 420px) { .stats-grid { grid-template-columns: 1fr 1fr; }.stat-label { font-size: 11px; }.stat-meta { font-size: 10px; }.last-refresh { font-size: 10px; }.button-primary { padding: 0 9px; } }

.gateway-section { margin-top: 32px; }
.gateway-heading { align-items: center; margin-bottom: 15px; }
.gateway-heading p { margin-top: 5px; color: #8b97a1; font-size: 12px; }
.gateway-heading-actions { display: flex; align-items: center; gap: 12px; }
.gateway-form { display: grid; grid-template-columns: minmax(170px, .9fr) minmax(220px, 1.5fr) minmax(160px, 1fr) auto; align-items: start; gap: 12px; padding: 16px; background: #fff; border: 1px solid var(--line); border-radius: 7px 7px 0 0; }
.gateway-field { min-width: 0; display: flex; flex-direction: column; gap: 6px; color: #687885; font-size: 11px; font-weight: 650; }
.gateway-field > span { display: flex; align-items: center; gap: 7px; }
.gateway-field i { color: #a2adb6; font-style: normal; font-weight: 400; }
.gateway-field input, .gateway-field select { width: 100%; min-width: 0; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; outline: none; background: #fff; color: var(--ink); font-size: 12px; font-weight: 400; }
.gateway-field input:focus, .gateway-field select:focus { border-color: #8eace4; box-shadow: 0 0 0 2px #2c68d815; }
.gateway-field input::placeholder { color: #a4afb8; }
.gateway-field small { min-height: 14px; color: #909ca6; font-size: 10px; font-weight: 400; line-height: 1.4; }
.add-rule-button { height: 36px; margin-top: 19px; white-space: nowrap; }
.form-message { grid-column: 1 / -1; min-height: 15px; margin-top: -5px; color: var(--green); font-size: 11px; }
.form-message.error { color: var(--red); }
.gateway-table-panel { background: #fff; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 7px 7px; overflow: hidden; }
.gateway-table-wrap { overflow-x: auto; }
.gateway-table { width: 100%; min-width: 660px; }
.gateway-table th { padding-top: 10px; padding-bottom: 10px; }
.gateway-table td { padding-top: 11px; padding-bottom: 11px; }
.gateway-kind { color: #556674; font-size: 11px; font-weight: 650; white-space: nowrap; }
.gateway-value { display: block; max-width: 380px; overflow-wrap: anywhere; color: #334451; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; line-height: 1.5; }
.gateway-value.token-fingerprint { color: #8c6339; }
.gateway-remark, .gateway-created { color: #778590; font-size: 11px; }
.gateway-remove { height: 29px; min-height: 29px; padding: 0 9px; border: 1px solid #f0dada; border-radius: 4px; background: #fff; color: #af4d4d; font-size: 11px; white-space: nowrap; }
.gateway-remove:hover { border-color: #dfb0b0; background: #fff7f7; }
.gateway-empty { padding: 25px 16px; color: #8b97a1; font-size: 12px; text-align: center; }
.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; }
[hidden] { display: none !important; }
.mode-notice { padding: 12px 15px; margin-bottom: 20px; color: #276143; background: #eef8f2; border: 1px solid #d5e9dc; border-radius: 7px; line-height: 1.6; }
.geo-notice { margin: -10px 0 20px; }
.main-content { min-width: 0; flex: 1; }
.stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.lookup-panel, .history-panel, .event-panel { margin: 28px 0; padding: 22px; background: #fff; border: 1px solid var(--line); border-radius: 8px; scroll-margin-top: 20px; }
.lookup-panel { border-top: 3px solid #7da6ef; }
.section-heading p { color: var(--muted); font-size: 12px; margin-top: 7px; line-height: 1.6; }
.lookup-form { display: flex; gap: 10px; }
.lookup-form input { flex: 1; min-width: 0; border: 1px solid #cad5e0; border-radius: 5px; height: 40px; padding: 0 12px; font: inherit; }
.lookup-form input:focus { outline: 2px solid #dce8ff; border-color: #7da6ef; }
.helper-text { margin-top: 13px; color: var(--muted); font-size: 12px; line-height: 1.7; overflow-wrap: anywhere; }
.history-summary { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin: 20px 0 12px; }
.history-summary > div { padding: 15px; background: #f4f7fb; border-radius: 5px; }
.history-summary span { display: block; color: var(--muted); font-size: 11px; }
.history-summary strong { display: block; margin-top: 7px; font-size: 24px; }
.history-panel h3 { font-size: 14px; margin: 15px 0 0; }
.history-panel h3 span { color: var(--muted); font-weight: 400; }
.history-pulls-heading { margin-top: 20px; }
.event-filter { margin-bottom: 18px; }
.event-table { min-width: 940px; }
.event-table td { vertical-align: top; line-height: 1.6; }
.event-table th { padding-left: 12px; padding-right: 12px; }
.event-table td { padding-left: 12px; padding-right: 12px; }
.event-table code { font: 11px/1.6 ui-monospace, Consolas, monospace; }
.event-empty { text-align: center; padding: 32px !important; color: var(--muted); }
.error-text { color: #aa4141; }
.cell-sub { display: block; color: #82909b; font-size: 11px; font-weight: 400; margin-top: 4px; line-height: 1.6; }
.user-history-link { display: inline; padding: 0; border: 0; color: #2b60b2; font: inherit; font-weight: 650; text-align: left; background: none; cursor: pointer; overflow-wrap: anywhere; }
.user-history-link:hover { text-decoration: underline; }
.unknown-owner { color: #9a7743; font-size: 11px; }
.request-details { min-width: 170px; max-width: 330px; }
.request-details summary { color: #48678b; cursor: pointer; overflow-wrap: anywhere; font-size: 11px; }
.request-details:not([open]) summary { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.request-detail-body { margin-top: 8px; padding: 10px; background: #f4f7fa; border-radius: 5px; min-width: 240px; }
.request-detail-body p { color: var(--muted); font-size: 11px; }
.request-detail-body dl { margin: 8px 0 0; font-size: 11px; }
.request-detail-body dt { color: #52667e; font-weight: 650; margin-top: 7px; }
.request-detail-body dd { margin: 2px 0 0; color: #6b7887; overflow-wrap: anywhere; white-space: pre-wrap; }
.more-events { margin-top: 14px; }
@media (max-width: 1100px) { .topbar { display: block; }.topbar-actions { justify-content: flex-start; margin-top: 10px; }.history-summary { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px) { .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }.lookup-panel, .history-panel, .event-panel { padding: 16px 12px; }.lookup-form { flex-wrap: wrap; }.lookup-form input { flex-basis: 100%; }.lookup-form button { flex: 1; }.history-summary { grid-template-columns: repeat(2, 1fr); gap: 8px; }.mode-notice { font-size: 12px; }.nav-list { gap: 0; }.nav-item { padding: 0 9px; } }
@media (max-width: 900px) { .gateway-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); }.add-rule-button { margin-top: 0; min-height: 36px; }.form-message { grid-column: 1 / -1; margin-top: 0; } }
@media (max-width: 700px) { .gateway-section { margin-top: 26px; }.gateway-heading { align-items: flex-start; flex-direction: row; }.gateway-heading-actions { gap: 7px; }.gateway-form { grid-template-columns: 1fr; gap: 10px; padding: 13px; }.add-rule-button { width: 100%; }.form-message { margin-top: 0; }.gateway-table { min-width: 620px; } }
@media (max-width: 420px) { .gateway-heading { flex-direction: column; }.gateway-heading-actions { width: 100%; justify-content: space-between; } }

/* The sidebar switches pages; only the right pane scrolls vertically. */
html, body { height: 100%; overflow: hidden; }
.app-shell { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
.sidebar { height: 100%; min-height: 0; overflow-y: auto; flex-shrink: 0; }
.main-content { height: 100%; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior-y: contain; scrollbar-gutter: stable; }
.audit-page { min-width: 0; }
.audit-page > :first-child { margin-top: 0; }
.audit-page > :last-child { margin-bottom: 0; }
.audit-page .table-panel { width: 100%; }
.table-scroll { max-width: 100%; }
#pageTitle:focus { outline: none; }
.alert-provinces { display: flex; flex-wrap: wrap; gap: 5px; min-width: 190px; max-width: 330px; }
.email-alert-panel > .helper-text { margin: 0 0 15px; }
.email-alert-panel > .helper-text:last-child { margin: 15px 0 0; }
.nav-item:focus-visible { outline: 2px solid #8fb2ff; outline-offset: 2px; }
@media (max-width: 700px) {
  .app-shell { display: flex; flex-direction: column; }
  .sidebar { height: auto; max-height: 40dvh; flex: 0 0 auto; width: 100%; }
  .nav-list { scrollbar-width: thin; padding-bottom: 5px; }
  .main-content { width: 100%; max-width: none; flex: 1 1 0; height: auto; }
}
