:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: rgba(0, 0, 0, 0.08);
  --track: rgba(0, 0, 0, 0.06);
  --accent: #0071e3;
  --gemini: #0a84ff;
  --brand: #8b5cf6;
  --claude: #ea580c;
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #1a1d24;
    --text: #f5f5f7;
    --muted: #9ca3af;
    --border: rgba(255, 255, 255, 0.1);
    --track: rgba(255, 255, 255, 0.1);
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

main { max-width: 1080px; margin: 0 auto; padding: 24px 18px 64px; }

/* Desktop: whole page at 135% (viewport-based breakpoints stay valid: 1200 / 1.35 ≈ 889px of layout). */
@media (min-width: 1200px) {
  html { zoom: 1.35; }
}
h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.every { font-weight: 700; }
.brand-accent { color: var(--brand); font-weight: 700; }
.subtitle, .panel-sub { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

.login {
  max-width: 380px;
  margin: 12vh auto 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-icon { width: 44px; height: 44px; margin: 0 auto 12px; color: var(--brand); }
.login-description { font-size: 14px; color: var(--muted); margin: 8px 0 20px; }
.login input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.primary-button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.primary-button.small { padding: 8px 14px; font-size: 13px; }
.primary-button:hover { opacity: 0.92; }

.ghost-btn, .icon-btn {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
}
.icon-btn { width: 38px; height: 38px; padding: 8px; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn svg { width: 18px; height: 18px; }
.ghost-btn.small { padding: 6px 10px; font-size: 12px; }

.notice {
  background: rgba(234, 88, 12, 0.12);
  border: 1px solid rgba(234, 88, 12, 0.35);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 14px;
  margin-bottom: 18px;
}
.notice.error { background: rgba(220, 38, 38, 0.12); border-color: rgba(220, 38, 38, 0.35); }

.limits-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 820px) {
  .limits-grid { grid-template-columns: 1fr; }
}

.limit-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
}
.card-body { display: flex; justify-content: space-between; align-items: center; margin: 16px 0; }
.metric .num { font-size: 38px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.metric small { font-size: 20px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.metric .caption { font-size: 13px; color: var(--muted); margin-top: 4px; }
.sub-metric { font-size: 12px; margin-top: 6px; font-weight: 600; }
.pool-gemini .sub-metric { color: var(--gemini); }
.pool-claude .sub-metric { color: var(--claude); }

.ring { width: 88px; height: 88px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring .bg { stroke: var(--border); }
.ring .fg { stroke-linecap: round; transition: stroke-dashoffset 0.35s ease; }
.fg-gemini { stroke: var(--gemini); }
.fg-claude { stroke: var(--claude); }

.limit-delimiter {
  height: 2px;
  flex: none;
  border-radius: 0;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 10px;
  display: flex;
}
.delim-fill {
  display: flex;
  height: 100%;
  overflow: hidden;
}
.delim-seg {
  display: block;
  height: 100%;
  flex: none;
}

.card-foot {
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
}
.card-foot b { color: var(--text); font-weight: 600; }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}
.panel details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.segmented {
  display: inline-flex;
  background: var(--bg);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.segmented button.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.devices-panel { padding: 32px 32px 26px; }
.devices-panel .panel-head { align-items: flex-start; gap: 16px; margin-bottom: 0; }
.devices-panel h2 { font-size: 26px; letter-spacing: -0.03em; }
.devices-panel .panel-sub { margin-top: 6px; font-size: 15px; }
.device-table { margin-top: 26px; }
.row {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(130px, 1.1fr) minmax(260px, 1.8fr);
  gap: 24px;
  align-items: center;
}
.row.th {
  padding: 0 0 12px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.01em;
  border-bottom: 1px solid var(--border);
}
.row.tr { padding: 22px 0; border-bottom: 1px solid var(--border); }
.row.tr:last-child { border-bottom: 0; }
.row.revoked { opacity: 0.72; }
.device-table .empty { text-align: center; color: var(--muted); padding: 24px; }

.dev-cell { display: flex; align-items: center; gap: 18px; min-width: 0; overflow-wrap: anywhere; }
.avatar {
  width: 72px;
  height: 72px;
  flex: none;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: #fff;
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, #5ac8fa, #0a84ff);
  background: linear-gradient(160deg, color-mix(in srgb, var(--avatar-color, #0a84ff), white 28%), var(--avatar-color, #0a84ff));
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16), 0 1px 3px rgba(0, 0, 0, 0.12);
}
.avatar::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 55%);
  pointer-events: none;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar svg { width: 36px; height: 36px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.15)); }
.dev-name { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.dev-meta { margin-top: 4px; font-size: 13px; color: var(--muted); }
.dev-edit { margin-top: 8px; }
.dev-edit:hover { background: var(--bg); }
.tok { min-width: 0; text-align: center; }
.tok-main { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.token-unit { color: var(--muted); font-size: 0.83em; }
.tok-sub { margin-top: 5px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.dev-limits { display: grid; gap: 12px; min-width: 0; }
.dev-limits-label { display: none; }
.quota-heading { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 2px 8px; font-size: 13px; }
.quota-heading > :first-child { font-weight: 600; }
.quota-value { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.quota-bar { height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; margin-top: 5px; }
.bar-fill { display: block; width: 0; height: 100%; border-radius: inherit; }
.quota-window[data-pool="gemini"] .bar-fill { background: linear-gradient(90deg, #5ac8fa, var(--gemini)); }
.quota-window[data-pool="claude"] .bar-fill { background: linear-gradient(90deg, #ec9a72, var(--claude)); }
.quota-window.blocked .bar-fill { background: var(--danger); }
.quota-window:is(.closed, .blocked) .quota-value { color: var(--danger); }
.quota-window.closed .quota-bar { background: rgba(220, 38, 38, 0.07); box-shadow: inset 0 0 0 1px rgba(220, 38, 38, 0.28); }

@media (max-width: 780px) {
  .devices-panel { padding: 24px 20px 20px; }
  .row { grid-template-columns: minmax(0, 1fr) minmax(0, 34%); gap: 16px 20px; }
  .row.th > :last-child { position: absolute; clip-path: inset(50%); }
  .dev-limits { grid-column: 1 / -1; }
  .dev-limits-label { display: block; color: var(--muted); font-size: 12px; }
}

@media (max-width: 420px) {
  .devices-panel .segmented { max-width: 100%; flex-wrap: wrap; }
  .devices-panel .segmented button { padding-inline: 6px; }
  .row { grid-template-columns: minmax(0, 1fr); }
  .row.th { position: absolute; clip-path: inset(50%); }
  .device-table { margin-top: 8px; }
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-top: 14px;
}
.stacked-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  margin-top: 14px;
  max-width: 460px;
}
.stacked-form > button { align-self: flex-start; }
.inline-form label, .stacked-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.inline-form label.checkbox-label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; padding: 8px 4px; }
.inline-form input[type="text"],
.inline-form input[type="number"],
.inline-form input[type="password"],
.stacked-form input[type="text"],
.stacked-form input[type="number"],
.modal input[type="text"],
.modal input[type="number"],
.modal select {
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

.pool-inputs-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
}
.pool-inputs-grid label { width: 100%; }
.pool-inputs-grid input { width: 100%; }

.groups-list, .keys-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.group-row, .key-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg);
  font-size: 13px;
}
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; }
.key-result {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(22, 163, 74, 0.12);
  border: 1px solid rgba(22, 163, 74, 0.35);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
}

.error-message { color: var(--danger); font-size: 13px; margin: 6px 0 0; }
.feedback { color: var(--ok); font-size: 13px; margin: 8px 0 0; }

.modal {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px;
  background: var(--card);
  color: var(--text);
  width: min(460px, 92vw);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.45); }
.modal form { display: flex; flex-direction: column; gap: 12px; }
.modal h3 { margin: 0 0 4px; font-size: 18px; }
.modal label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.avatar-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
