.portal-main {
  padding-top: 36px;
  padding-bottom: 56px;
}

.auth-stage {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(260px, 320px);
  justify-content: center;
  align-items: center;
  gap: 28px;
  padding-top: 24px;
}

.auth-stage[hidden],
#login-screen[hidden],
#signup-screen[hidden] {
  display: none;
}

.auth-card {
  width: 100%;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-bottom: 18px;
}

.auth-tab {
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.auth-tab.active {
  background: var(--panel);
  color: var(--fg);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14);
}

.auth-card h1 {
  margin: 0 0 4px;
  font-size: 21px;
}

.auth-card .muted {
  margin: 0 0 16px;
  font-size: 13px;
}

.auth-switch {
  margin: 14px 0 0;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover {
  text-decoration: underline;
}

.auth-pet-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 20px 16px;
}

.pet-speech {
  margin: 0 0 6px;
  padding: 7px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12.5px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#auth-pet-canvas {
  width: 220px;
  height: 185px;
  cursor: pointer;
}

.pet-caption {
  margin: 6px 0 0;
  font-size: 11.5px;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field span {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

input, select {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%239aa3b2' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
}

.btn-group {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.form-msg {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--accent);
}

.form-msg.err {
  color: #ef4444;
}

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

.portal-head h1 {
  margin: 0 0 2px;
  font-size: 24px;
}

.portal-head p {
  margin: 0;
  font-size: 13.5px;
}

.plan-tag {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.portal-cols {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 18px;
  align-items: start;
}

.col-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.web-pet-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 10px 10px;
  margin-bottom: 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
}

#portal-pet-canvas {
  width: 210px;
  height: 175px;
  cursor: pointer;
}

.web-pet-name {
  margin-top: 2px;
  font-size: 14px;
  font-weight: 600;
}

.row-between {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.row-between h2 {
  margin: 0 0 2px;
}

#billing-btn,
#refresh-history {
  white-space: nowrap;
  flex-shrink: 0;
}

.row-between p {
  margin: 0;
  font-size: 13px;
}

.cancel-msg {
  margin-top: 4px !important;
  font-size: 12.5px !important;
  font-weight: 500;
  color: #f87171;
}

.web-billing-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
}

.web-bill-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.web-bill-btn.active {
  background: var(--accent);
  color: #fff;
}

.web-save-pill {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.web-bill-btn.active .web-save-pill {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.web-plan-save {
  font-size: 12px;
  font-weight: 500;
  color: #34d399;
}

.web-plans {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.web-plan-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
}

.web-plan-row.current {
  border-color: var(--accent);
}

.web-plan-meta {
  font-size: 12px;
  color: var(--muted);
}

.history-card {
  display: flex;
  flex-direction: column;
  min-height: 480px;
}

.history-split {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 12px;
  flex: 1;
  min-height: 400px;
}

.web-sessions {
  border-right: 1px solid var(--line);
  padding-right: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 480px;
  overflow-y: auto;
}

.sess-btn {
  text-align: left;
  padding: 7px 9px;
  border-radius: 7px;
  border: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sess-btn:hover { background: var(--surface); }
.sess-btn.active { background: var(--surface); font-weight: 600; }

.web-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 480px;
  overflow-y: auto;
}

.web-msg {
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.web-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  max-width: 86%;
}

.web-msg.assistant {
  align-self: flex-start;
  max-width: 86%;
}

.web-msg img {
  display: block;
  max-width: 100%;
  max-height: 140px;
  border-radius: 6px;
  margin-bottom: 6px;
}

.code-block {
  margin: 6px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: var(--panel);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 8px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.copy-btn {
  padding: 1px 7px;
  font-size: 11px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--fg);
  cursor: pointer;
}

.code-block pre {
  margin: 0;
  padding: 8px 10px;
  overflow-x: auto;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.inline-code {
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--surface);
}

/* Full-page Web Chat History */
.history-body {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.web-history-shell {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 280px 1fr;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.web-history-shell[hidden],
#guest-view[hidden],
#rename-form[hidden],
#rename-btn[hidden],
#delete-session-btn[hidden],
.modal-backdrop[hidden] {
  display: none;
}

.web-history-sidebar {
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.web-history-sidebar h2 {
  margin: 0;
  font-size: 15px;
}

.web-sessions-full {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 0;
}

.sess-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sess-btn.active .sess-title {
  font-weight: 600;
}

.sess-date {
  font-size: 11px;
  color: var(--muted);
}

.web-history-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--panel);
}

.web-history-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.web-history-title-wrap {
  min-width: 0;
  flex: 1 1 220px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.web-history-head h1 {
  margin: 0;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.web-history-head p {
  margin: 2px 0 0;
  font-size: 12px;
}

.rename-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.rename-form input {
  flex: 1 1 160px;
  min-width: 0;
}

.web-messages-full {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.web-messages-full .web-msg {
  max-width: min(86%, 640px);
}

.web-msg-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  opacity: 0.78;
  margin-bottom: 4px;
}

.web-msg-del {
  border: 0;
  background: transparent;
  color: inherit;
  opacity: 0;
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.web-msg:hover .web-msg-del,
.web-msg-del:focus-visible {
  opacity: 0.75;
}

.web-msg-del:hover {
  opacity: 1 !important;
}

.danger-btn {
  color: #ef4444;
  background: transparent;
  white-space: nowrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
}

.modal h2 {
  margin: 0 0 6px;
  font-size: 16px;
}

.modal p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.danger-fill {
  background: #dc2626;
  border-color: #dc2626;
  color: #ffffff;
}

@media (max-width: 860px) {
  .auth-stage {
    grid-template-columns: 1fr;
    max-width: 420px;
    margin: 0 auto;
  }

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

  .portal-head {
    flex-wrap: wrap;
  }

  .web-history-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    border-left: 0;
    border-right: 0;
  }

  .web-history-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px 16px;
  }

  .web-sessions-full {
    max-height: 160px;
  }

  .web-history-head {
    padding: 12px 16px;
  }

  .web-messages-full {
    padding: 16px;
  }

  .web-messages-full .web-msg {
    max-width: 92%;
  }
}

@media (max-width: 520px) {
  .portal-main {
    padding-top: 20px;
    padding-bottom: 36px;
  }

  .web-plan-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .web-plan-row .btn {
    width: 100%;
  }

  .row-between {
    flex-wrap: wrap;
  }
}

.quota-bar {
  margin: 0 0 12px;
  height: 6px;
  border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
}

.quota-bar[hidden],
#delete-modal[hidden] {
  display: none;
}

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

.quota-fill.warn {
  background: #f59e0b;
}

.quota-fill.full {
  background: #ef4444;
}

.usage-chart {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
  height: 92px;
  margin-bottom: 14px;
  padding: 12px 10px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
}

.usage-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  height: 100%;
}

.usage-val {
  font-size: 10.5px;
  color: var(--muted);
}

.usage-bar-wrap {
  width: 100%;
  max-width: 26px;
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--surface);
  border-radius: 5px;
  overflow: hidden;
}

.usage-bar {
  width: 100%;
  background: var(--accent);
  border-radius: 5px 5px 0 0;
  min-height: 2px;
}

.usage-day {
  font-size: 11px;
  color: var(--muted);
}
