/* ==========================================================================
   Round Portal — public user area (/portal)
   Reuses design tokens from styles.css
   ========================================================================== */

.portal-body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 620px at 12% -10%, rgba(91, 140, 255, 0.16), transparent 62%),
    radial-gradient(1000px 560px at 92% 0%, rgba(34, 211, 238, 0.11), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.portal-body code,
.portal-body pre {
  font-family: var(--mono);
}

/* ---------------------------------------------------------------- signed out */

.portal-auth {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 48px 20px;
  overflow: hidden;
}

.portal-auth-bg {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(520px 520px at 20% 30%, rgba(91, 140, 255, 0.22), transparent 65%),
    radial-gradient(460px 460px at 80% 70%, rgba(124, 92, 255, 0.18), transparent 65%);
  filter: blur(10px);
  pointer-events: none;
}

.portal-auth-card {
  position: relative;
  width: min(560px, 100%);
  padding: 40px;
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(16, 24, 42, 0.94), rgba(8, 13, 24, 0.97));
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}

.portal-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.portal-brand strong {
  display: block;
  font-size: 17px;
  letter-spacing: 0.02em;
}

.portal-brand span:not(.brand-mark) {
  display: block;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.portal-brand.compact {
  margin: 0;
}

.portal-auth-card h1 {
  margin: 0 0 14px;
  font-size: clamp(26px, 4vw, 34px);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.portal-lead {
  margin: 0 0 26px;
  color: var(--text-muted);
  font-size: 14.5px;
  line-height: 1.65;
}

.portal-lead strong {
  color: var(--accent);
}

.portal-oauth {
  display: grid;
  gap: 12px;
  margin-bottom: 26px;
}

.oauth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.oauth-btn:hover {
  border-color: rgba(91, 140, 255, 0.6);
  background: rgba(91, 140, 255, 0.12);
  transform: translateY(-1px);
}

.oauth-btn svg {
  width: 19px;
  height: 19px;
  flex: none;
}

.portal-muted {
  margin: 0;
  padding: 14px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.55;
}

.portal-perks {
  display: grid;
  gap: 10px;
  margin: 0 0 26px;
  padding: 0;
  list-style: none;
}

.portal-perks li {
  display: flex;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13.5px;
}

.portal-perks li span {
  color: var(--ok);
  font-weight: 700;
}

.portal-admin-link {
  display: inline-block;
  color: var(--text-dim);
  font-size: 12.5px;
  text-decoration: none;
}

.portal-admin-link:hover {
  color: var(--primary);
}

/* --------------------------------------------------------------- signed in */

.portal-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.portal-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: rgba(6, 10, 19, 0.82);
  backdrop-filter: blur(16px);
}

.portal-topbar-inner {
  display: flex;
  align-items: center;
  gap: 28px;
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 12px 24px;
}

.portal-nav {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(6, 11, 20, 0.6);
}

.portal-nav-item {
  padding: 8px 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}

.portal-nav-item:hover {
  color: var(--text);
}

.portal-nav-item.active {
  background: rgba(91, 140, 255, 0.16);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(91, 140, 255, 0.32);
}

.portal-user {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  min-width: 0;
}

.portal-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  object-fit: cover;
}

.portal-user-meta {
  display: grid;
  min-width: 0;
}

.portal-user-meta strong {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.portal-user-meta span {
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.portal-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: min(1240px, 100%);
  margin: 18px auto 0;
  padding: 18px 22px;
  border: 1px solid rgba(52, 211, 153, 0.35);
  border-radius: 16px;
  background: linear-gradient(120deg, rgba(52, 211, 153, 0.14), rgba(34, 211, 238, 0.08));
}

.portal-banner strong {
  font-size: 14px;
}

.portal-banner p {
  margin: 4px 0 10px;
  color: var(--text-muted);
  font-size: 12.5px;
}

.portal-banner code {
  display: inline-block;
  max-width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: rgba(3, 7, 17, 0.7);
  color: var(--accent);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.portal-banner-actions {
  display: flex;
  gap: 8px;
  flex: none;
}

.portal-main {
  flex: 1;
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 28px 24px 56px;
}

.portal-view {
  display: none;
  gap: 20px;
}

.portal-view.active {
  display: grid;
}

.portal-view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}

.portal-view-head h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 28px);
  letter-spacing: -0.02em;
}

.portal-view-head p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 13.5px;
}

.portal-card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: var(--shadow);
}

.portal-card h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.portal-card p {
  margin: 5px 0 0;
  color: var(--text-muted);
  font-size: 12.5px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.portal-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.portal-stat-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.portal-card.stat {
  display: grid;
  gap: 6px;
  position: relative;
  overflow: hidden;
}

.portal-card.stat::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 2px;
  background: var(--gradient);
  opacity: 0.55;
}

.stat-label {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.portal-card.stat strong {
  font-size: clamp(22px, 3vw, 29px);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.stat-hint {
  color: var(--text-muted);
  font-size: 12px;
}

.portal-two-col {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 14px;
}

.portal-badge {
  padding: 5px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: rgba(91, 140, 255, 0.12);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.portal-badge.ok {
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(52, 211, 153, 0.12);
  color: var(--ok);
}

.portal-badge.warn {
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.12);
  color: var(--warn);
}

.portal-badge.danger {
  border-color: rgba(251, 113, 133, 0.4);
  background: rgba(251, 113, 133, 0.12);
  color: var(--danger);
}

.quota-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  overflow: hidden;
}

.quota-fill {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: var(--gradient);
  transition: width 0.4s ease;
}

.quota-fill.warn {
  background: linear-gradient(135deg, #fbbf24, #f97316);
}

.quota-fill.danger {
  background: linear-gradient(135deg, #fb7185, #ef4444);
}

.quota-legend {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 12px;
}

/* ------------------------------------------------------------------ charts */

.usage-bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 160px;
  padding-top: 8px;
}

.usage-bar {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  height: 100%;
  min-width: 0;
}

.usage-bar-track {
  display: flex;
  align-items: flex-end;
  width: 100%;
  flex: 1;
  border-radius: 7px;
  background: rgba(148, 163, 184, 0.09);
  overflow: hidden;
}

.usage-bar-fill {
  width: 100%;
  min-height: 3px;
  border-radius: 7px 7px 0 0;
  background: linear-gradient(180deg, #22d3ee, #5b8cff);
  transition: height 0.4s ease;
}

.usage-bar-label {
  color: var(--text-dim);
  font-size: 10px;
  white-space: nowrap;
}

.usage-bar-value {
  color: var(--text-muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.portal-empty {
  margin: 14px 0 0;
  color: var(--text-dim);
  font-size: 12.5px;
  text-align: center;
}

/* ------------------------------------------------------------------- table */

.table-card {
  padding: 0;
  overflow: hidden;
}

.portal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.portal-table th {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(6, 11, 20, 0.5);
  color: var(--text-dim);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.portal-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.07);
  color: var(--text-muted);
  vertical-align: middle;
}

.portal-table tbody tr:last-child td {
  border-bottom: 0;
}

.portal-table tbody tr:hover {
  background: rgba(91, 140, 255, 0.05);
}

.portal-table td strong {
  color: var(--text);
  font-weight: 600;
}

.portal-table .row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* ----------------------------------------------------------------- buttons */

.portal-primary-btn,
.portal-ghost-btn,
.portal-danger-btn,
.code-copy {
  padding: 9px 15px;
  border-radius: 9px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.portal-primary-btn {
  border: 1px solid rgba(91, 140, 255, 0.5);
  background: linear-gradient(135deg, #5b8cff, #7c5cff);
  color: #fff;
}

.portal-primary-btn:hover {
  filter: brightness(1.08);
}

.portal-ghost-btn {
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
}

.portal-ghost-btn:hover {
  border-color: rgba(91, 140, 255, 0.5);
  color: var(--text);
}

.portal-danger-btn {
  border: 1px solid rgba(251, 113, 133, 0.4);
  background: rgba(251, 113, 133, 0.1);
  color: var(--danger);
}

.portal-danger-btn:hover {
  background: rgba(251, 113, 133, 0.2);
}

.portal-primary-btn:disabled,
.portal-ghost-btn:disabled,
.portal-danger-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.portal-select {
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
}

/* ---------------------------------------------------------------- endpoint */

.endpoint-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.endpoint-list > div {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}

.endpoint-list dt {
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.endpoint-list dd {
  margin: 0;
  min-width: 0;
}

.endpoint-list code {
  display: inline-block;
  max-width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(3, 7, 17, 0.65);
  color: var(--accent);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.model-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.model-chip {
  padding: 6px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: rgba(91, 140, 255, 0.08);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11.5px;
}

/* -------------------------------------------------------------------- code */

.code-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.code-tab {
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.code-tab.active {
  border-color: rgba(91, 140, 255, 0.5);
  background: rgba(91, 140, 255, 0.14);
  color: var(--text);
}

.code-block-wrap {
  position: relative;
}

.code-copy {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 6px 11px;
  border: 1px solid var(--border-strong);
  background: rgba(11, 18, 32, 0.92);
  color: var(--text-muted);
  font-size: 11px;
}

.code-copy:hover {
  color: var(--text);
  border-color: rgba(91, 140, 255, 0.5);
}

.code-block {
  margin: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(3, 7, 17, 0.75);
  color: #cbd5f5;
  font-size: 12px;
  line-height: 1.65;
  overflow-x: auto;
  white-space: pre;
}

/* ------------------------------------------------------------------- misc */

.portal-alert {
  padding: 12px 15px;
  border: 1px solid rgba(251, 113, 133, 0.4);
  border-radius: 10px;
  background: rgba(251, 113, 133, 0.1);
  color: #ffc2cb;
  font-size: 13px;
  line-height: 1.5;
}

.recent-logs {
  display: grid;
  gap: 8px;
}

.recent-log {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(6, 11, 20, 0.45);
  font-size: 12px;
}

.recent-log .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
  background: var(--ok);
}

.recent-log .dot.error {
  background: var(--danger);
}

.recent-log .dot.rate {
  background: var(--warn);
}

.recent-log .model {
  flex: 1;
  min-width: 0;
  color: var(--text);
  font-family: var(--mono);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-log .meta {
  color: var(--text-dim);
  font-size: 11px;
  white-space: nowrap;
}

.portal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 18px 24px 28px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11.5px;
}

.portal-toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 44px));
  padding: 12px 16px;
  border: 1px solid rgba(52, 211, 153, 0.4);
  border-radius: 11px;
  background: rgba(8, 20, 18, 0.96);
  color: var(--text);
  font-size: 12.5px;
  box-shadow: var(--shadow);
}

.portal-toast.error {
  border-color: rgba(251, 113, 133, 0.45);
  background: rgba(26, 10, 15, 0.96);
}

/* --------------------------------------------------------------- responsive */

@media (max-width: 980px) {
  .portal-topbar-inner {
    flex-wrap: wrap;
    gap: 12px;
  }

  .portal-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
  }

  .portal-nav-item {
    flex: 1;
    white-space: nowrap;
  }

  .portal-user-meta {
    display: none;
  }

  .portal-stat-grid,
  .portal-stat-grid.three {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .portal-two-col {
    grid-template-columns: 1fr;
  }

  .portal-banner {
    flex-direction: column;
    align-items: flex-start;
  }

  .portal-table {
    min-width: 720px;
  }

  .table-card {
    overflow-x: auto;
  }
}

@media (max-width: 560px) {
  .portal-auth-card {
    padding: 28px 22px;
  }

  .portal-main {
    padding: 20px 16px 44px;
  }

  .portal-stat-grid,
  .portal-stat-grid.three {
    grid-template-columns: 1fr;
  }

  .endpoint-list > div {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .portal-topbar-inner,
  .portal-footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .portal-footer {
    flex-direction: column;
    align-items: flex-start;
  }
}
