:root {
  --ink: #17201d;
  --ink-2: #27332f;
  --muted: #6d7773;
  --line: #dce2df;
  --line-dark: #cbd3cf;
  --paper: #ffffff;
  --canvas: #f3f5f3;
  --green: #167052;
  --green-dark: #0f573f;
  --green-soft: #e2f1e9;
  --lime: #c4e45a;
  --amber: #a96212;
  --amber-soft: #fff1dc;
  --red: #b83c43;
  --red-soft: #fae9e9;
  --shadow: 0 15px 38px rgba(23, 32, 29, .08);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body { min-height: 100vh; margin: 0; background: var(--canvas); color: var(--ink); font-size: 14px; letter-spacing: 0; }
body:has(dialog[open]) { overflow: hidden; }
button, input { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
.is-hidden { display: none !important; }
.eyebrow { color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: 1.2px; }

.site-header { border-bottom: 1px solid rgba(220, 226, 223, .85); background: rgba(255, 255, 255, .92); }
.header-inner { width: min(1280px, calc(100% - 48px)); height: 76px; margin: auto; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 42px; height: 42px; display: inline-grid; place-items: center; border-radius: 7px; background: var(--ink); color: var(--lime); }
.brand-mark svg { width: 23px; height: 23px; }
.brand-copy { display: grid; gap: 1px; }
.brand-copy strong { font-size: 17px; font-weight: 750; }
.brand-copy small { color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: 1.5px; }
.api-link { display: inline-flex; align-items: center; gap: 7px; color: var(--ink); font-size: 13px; font-weight: 700; text-decoration: none; }
.api-link svg { width: 15px; height: 15px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #31a471; box-shadow: 0 0 0 4px rgba(49, 164, 113, .12); }

.page-shell { width: min(1280px, calc(100% - 48px)); margin: 36px auto 64px; }
.query-band { position: relative; min-height: 250px; display: grid; grid-template-columns: minmax(250px, .75fr) minmax(440px, 1.25fr); align-items: center; gap: clamp(36px, 7vw, 100px); overflow: hidden; padding: 45px clamp(28px, 5vw, 68px); border-radius: 8px; background: var(--ink); color: white; box-shadow: 0 18px 46px rgba(23, 32, 29, .16); }
.query-band::after { content: ""; position: absolute; right: -44px; bottom: -110px; width: 390px; height: 390px; border: 1px solid rgba(196, 228, 90, .15); border-radius: 50%; box-shadow: 0 0 0 58px rgba(196, 228, 90, .035), 0 0 0 116px rgba(196, 228, 90, .025); pointer-events: none; }
.query-copy, .query-form, .form-message { position: relative; z-index: 1; }
.query-copy .eyebrow { color: var(--lime); }
.query-copy h1 { margin: 10px 0 9px; font-size: clamp(32px, 4.2vw, 54px); line-height: 1.08; font-weight: 670; }
.query-copy p { margin: 0; color: #b9c3bf; font-size: 15px; }
.query-form { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 12px; }
.key-field { display: grid; gap: 9px; min-width: 0; }
.key-field > span:first-child { color: #d5ddda; font-size: 12px; font-weight: 700; }
.key-input-wrap { min-width: 0; height: 58px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 11px; padding: 0 8px 0 17px; border: 1px solid #4b5853; border-radius: 6px; background: rgba(255, 255, 255, .07); transition: border-color .18s, background .18s, box-shadow .18s; }
.key-input-wrap:focus-within { border-color: var(--lime); background: rgba(255, 255, 255, .1); box-shadow: 0 0 0 3px rgba(196, 228, 90, .12); }
.key-input-wrap > svg { width: 18px; color: var(--lime); }
.key-input-wrap input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: white; font-size: 15px; }
.key-input-wrap input::placeholder { color: #86928d; }
.input-icon-button { width: 42px; height: 42px; display: inline-grid; place-items: center; border: 0; border-radius: 5px; background: transparent; color: #aeb9b5; cursor: pointer; }
.input-icon-button:hover { background: rgba(255, 255, 255, .08); color: white; }
.input-icon-button svg { width: 18px; }
.query-button { height: 58px; display: inline-flex; align-items: center; justify-content: center; gap: 28px; padding: 0 22px; border: 0; border-radius: 6px; background: var(--lime); color: var(--ink); font-weight: 800; cursor: pointer; transition: background .18s, transform .18s; white-space: nowrap; }
.query-button:hover { background: #d0ed70; transform: translateY(-1px); }
.query-button:disabled { cursor: wait; opacity: .72; transform: none; }
.query-button svg { width: 18px; }
.form-message { position: absolute; left: calc(50% + 20px); bottom: 19px; margin: 0; color: #ffb2b6; font-size: 12px; }

.welcome-state { min-height: 250px; display: flex; align-items: center; justify-content: center; gap: 28px; margin-top: 28px; border: 1px dashed var(--line-dark); border-radius: 8px; background: rgba(255, 255, 255, .48); color: var(--muted); }
.welcome-state > div:last-child { display: grid; gap: 6px; }
.welcome-state strong { color: var(--ink); font-size: 17px; }
.welcome-visual { width: 104px; height: 104px; position: relative; display: grid; place-items: center; }
.meter-ring { width: 74px; height: 74px; display: grid; place-items: center; border: 8px solid #e0e7e3; border-top-color: var(--green); border-radius: 50%; color: var(--green); transform: rotate(-25deg); }
.meter-ring svg { width: 25px; transform: rotate(25deg); }
.meter-line { position: absolute; right: -4px; bottom: 12px; width: 46px; height: 2px; background: var(--line-dark); transform: rotate(-35deg); }
.meter-dot { position: absolute; right: 2px; bottom: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--lime); border: 2px solid var(--ink); }

.loading-state { margin-top: 28px; padding: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); box-shadow: var(--shadow); }
.loading-head { display: flex; align-items: center; gap: 11px; }
.spinner { width: 19px; height: 19px; border: 2px solid #d9e1dd; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-top: 25px; }
.skeleton-grid i { height: 135px; border-radius: 7px; background: linear-gradient(90deg, #edf0ee 25%, #f7f8f7 50%, #edf0ee 75%); background-size: 220% 100%; animation: shimmer 1.25s infinite; }
@keyframes shimmer { to { background-position: -220% 0; } }

.results { margin-top: 38px; }
.result-heading, .logs-header { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.result-heading h2, .logs-header h2 { margin: 6px 0 0; font-size: 25px; line-height: 1.2; }
.query-meta { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 12px; }
.success-badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 4px; background: var(--green-soft); color: var(--green-dark); font-weight: 750; }
.success-badge svg { width: 15px; }

.quota-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-top: 20px; }
.quota-card { min-width: 0; min-height: 162px; display: flex; flex-direction: column; justify-content: space-between; padding: 21px; border: 1px solid var(--line); border-radius: 7px; background: var(--paper); box-shadow: 0 7px 22px rgba(23, 32, 29, .045); }
.quota-card.quota-total { background: var(--ink); color: white; border-color: var(--ink); }
.quota-card.quota-remaining { border-top: 3px solid var(--green); }
.card-label { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; font-weight: 750; }
.card-label svg { width: 19px; height: 19px; color: var(--green); }
.quota-total .card-label { color: #b7c1bd; }
.quota-total .card-label svg { color: var(--lime); }
.quota-card > strong { max-width: 100%; overflow: hidden; color: var(--ink); font-size: 29px; line-height: 1.15; font-weight: 690; text-overflow: ellipsis; white-space: nowrap; }
.quota-total > strong { color: white; }
.quota-card > strong.date-value { font-size: 21px; white-space: normal; }
.quota-card > small { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.quota-total > small { color: #aeb8b4; }

.usage-strip { display: grid; grid-template-columns: auto minmax(180px, 1fr) auto; align-items: center; gap: 24px; margin-top: 16px; padding: 19px 22px; border: 1px solid var(--line); border-radius: 7px; background: var(--paper); }
.usage-copy { min-width: 112px; display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.usage-copy span { color: var(--muted); font-size: 12px; font-weight: 700; }
.usage-copy strong { font-size: 18px; }
.progress-track { height: 9px; overflow: hidden; border-radius: 9px; background: #e3e9e6; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--green); transition: width .4s ease; }
.usage-meta { display: flex; align-items: center; gap: 16px; color: var(--muted); font-size: 11px; }
.usage-meta span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.usage-meta b { color: var(--ink); font-weight: 700; }
.legend-used, .legend-left { width: 8px; height: 8px; display: inline-block; border-radius: 50%; background: var(--green); }
.legend-left { background: #dce4e0; }

.logs-section { margin-top: 42px; }
.logs-actions { display: flex; align-items: center; gap: 10px; }
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 6px; background: #e9edeb; }
.segmented button { min-width: 52px; height: 31px; padding: 0 12px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer; }
.segmented button.active { background: var(--paper); color: var(--ink); box-shadow: 0 2px 8px rgba(23, 32, 29, .08); }
.icon-button, .page-button { width: 38px; height: 38px; display: inline-grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); cursor: pointer; }
.icon-button:hover, .page-button:hover:not(:disabled) { border-color: var(--green); color: var(--green); }
.icon-button svg, .page-button svg { width: 17px; height: 17px; }
.icon-button.is-spinning svg { animation: spin .7s linear infinite; }

.log-alert { margin-top: 18px; padding: 12px 14px; border: 1px solid #ebc78f; border-radius: 6px; background: var(--amber-soft); color: #7b4d13; font-size: 12px; }
.table-wrap { margin-top: 18px; overflow-x: auto; border: 1px solid var(--line); border-radius: 7px 7px 0 0; background: var(--paper); }
.logs-table { width: 100%; min-width: 1080px; border-collapse: collapse; table-layout: fixed; }
.logs-table th { height: 46px; padding: 0 14px; border-bottom: 1px solid var(--line); background: #f7f8f7; color: var(--muted); font-size: 11px; font-weight: 800; text-align: left; white-space: nowrap; }
.logs-table td { height: 59px; padding: 10px 14px; border-bottom: 1px solid #edf0ee; color: var(--ink-2); font-size: 12px; vertical-align: middle; }
.logs-table tr:last-child td { border-bottom: 0; }
.logs-table tbody tr:hover { background: #fafbfa; }
.logs-table th:nth-child(1) { width: 144px; }
.logs-table th:nth-child(2) { width: 126px; }
.logs-table th:nth-child(3) { width: 175px; }
.logs-table th:nth-child(4) { width: 76px; }
.logs-table th:nth-child(5) { width: 82px; }
.logs-table th:nth-child(6), .logs-table th:nth-child(7) { width: 104px; }
.logs-table th:nth-child(8) { width: 92px; }
.logs-table th:nth-child(9) { width: 112px; }
.cell-main { display: block; overflow: hidden; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.cell-sub { display: block; margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.model-name { font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; }
.type-pill { display: inline-flex; align-items: center; justify-content: center; min-width: 48px; height: 24px; padding: 0 8px; border-radius: 4px; background: #edf0ee; color: #57615d; font-size: 10px; font-weight: 800; }
.type-pill.consume { background: var(--green-soft); color: var(--green-dark); }
.type-pill.error { background: var(--red-soft); color: var(--red); }
.type-pill.topup, .type-pill.refund { background: var(--amber-soft); color: var(--amber); }
.cost-cell { color: var(--green-dark); font-weight: 750; }
.error-button { max-width: 90px; display: inline-flex; align-items: center; gap: 4px; padding: 0; overflow: hidden; border: 0; background: transparent; color: var(--red); font-size: 11px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.error-button svg { width: 13px; flex: 0 0 auto; }
.empty-logs { min-height: 230px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; margin-top: 18px; border: 1px solid var(--line); border-radius: 7px; background: var(--paper); color: var(--muted); }
.empty-logs > svg { width: 27px; color: var(--green); }
.empty-logs strong { color: var(--ink); }
.empty-logs span { font-size: 12px; }
.table-footer { min-height: 54px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 7px 7px; background: var(--paper); color: var(--muted); font-size: 11px; }
.pagination { display: flex; align-items: center; gap: 10px; }
.page-button { width: 31px; height: 31px; }
.page-button:disabled { cursor: not-allowed; opacity: .38; }
.page-button svg { width: 15px; }

.site-footer { width: min(1280px, calc(100% - 48px)); min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: auto; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.site-footer span:last-child { display: inline-flex; align-items: center; gap: 6px; }
.site-footer svg { width: 14px; }

.error-dialog { width: min(680px, calc(100% - 32px)); max-height: min(720px, calc(100vh - 32px)); padding: 0; border: 0; border-radius: 8px; background: var(--paper); color: var(--ink); box-shadow: 0 30px 80px rgba(23, 32, 29, .28); }
.error-dialog::backdrop { background: rgba(13, 20, 17, .55); backdrop-filter: blur(3px); }
.dialog-shell { padding: 24px; }
.dialog-shell header { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.dialog-shell h2 { margin: 5px 0 0; font-size: 21px; }
.dialog-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 20px; padding: 11px 13px; border-radius: 5px; background: #f2f4f3; color: var(--muted); font-size: 11px; }
.dialog-shell pre { max-height: 410px; overflow: auto; margin: 14px 0 0; padding: 16px; border: 1px solid #edd0d1; border-radius: 5px; background: #fff7f7; color: #772d31; font: 12px/1.65 "SFMono-Regular", Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 20; display: grid; gap: 9px; }
.toast { min-width: 260px; max-width: min(390px, calc(100vw - 32px)); display: flex; align-items: center; gap: 9px; padding: 13px 15px; border: 1px solid #c9ded3; border-radius: 6px; background: var(--paper); color: var(--green-dark); box-shadow: var(--shadow); font-size: 12px; }
.toast.error { border-color: #ebc6c8; color: var(--red); }
.toast svg { width: 17px; flex: 0 0 auto; }

@media (max-width: 980px) {
  .query-band { grid-template-columns: 1fr; gap: 28px; }
  .form-message { position: relative; left: auto; bottom: auto; grid-column: 1 / -1; margin: -16px 0 0; }
  .quota-grid { grid-template-columns: 1fr 1fr; }
  .usage-strip { grid-template-columns: auto 1fr; }
  .usage-meta { grid-column: 1 / -1; justify-content: flex-end; }
}

@media (max-width: 680px) {
  .header-inner, .page-shell, .site-footer { width: min(100% - 28px, 1280px); }
  .header-inner { height: 66px; }
  .brand-mark { width: 38px; height: 38px; }
  .page-shell { margin-top: 18px; margin-bottom: 40px; }
  .query-band { min-height: 0; padding: 30px 20px; }
  .query-copy h1 { font-size: 34px; }
  .query-form { grid-template-columns: 1fr; }
  .query-button { width: 100%; }
  .welcome-state { min-height: 210px; flex-direction: column; gap: 11px; padding: 28px 20px; text-align: center; }
  .welcome-visual { transform: scale(.85); }
  .skeleton-grid { grid-template-columns: 1fr 1fr; }
  .skeleton-grid i { height: 110px; }
  .result-heading { align-items: flex-start; flex-direction: column; }
  .query-meta { width: 100%; justify-content: space-between; }
  .quota-grid { grid-template-columns: 1fr; }
  .quota-card { min-height: 140px; }
  .usage-strip { grid-template-columns: 1fr; gap: 13px; }
  .usage-copy { width: 100%; }
  .usage-meta { grid-column: auto; justify-content: space-between; }
  .logs-header { align-items: flex-start; flex-direction: column; }
  .logs-actions { width: 100%; justify-content: space-between; }
  .site-footer { align-items: flex-start; flex-direction: column; justify-content: center; gap: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
