/* ==========================================================================
   Customer portal
   ========================================================================== */

body {
  overflow-x: hidden;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.mt {
  margin-top: 16px;
}

.mt-sm {
  margin-top: 10px;
}

.p-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 2px 0 18px;
}

.p-title h2 {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.035em;
}

.p-title h2::before {
  content: '';
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: linear-gradient(140deg, var(--accent), var(--accent-3));
  box-shadow: 0 0 16px var(--accent-line);
}

.p-head {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--glass-bar);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  backdrop-filter: blur(20px) saturate(150%);
}

.p-head::after {
  content: '';
  position: absolute;
  inset: auto 0 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line-strong), transparent);
  opacity: 0.55;
}

.p-head .brand {
  gap: 10px;
}

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

.p-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--glass-soft);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  white-space: nowrap;
}

.p-user .btn {
  min-height: 24px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  font-size: 10.5px;
}

.p-main {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 22px 84px;
}

.p-connect {
  max-width: 440px;
  margin: 8vh auto 0;
}

.p-connect h1 {
  margin-bottom: 20px;
}

.p-connect .auth-brand {
  margin-bottom: 22px;
}

#connectMsg {
  min-height: 26px;
  margin-top: 12px;
}

/* ---------------------------------------------------------------- stats */
.stat .s {
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------- budget */
.budget-row + .budget-row {
  margin-top: 18px;
}

.budget-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  color: var(--fg-2);
  font-size: 11.5px;
  font-weight: 500;
}

.budget-label b {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 400;
}

.budget-foot {
  margin-top: 5px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
}

.budget-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
  padding-top: 13px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.budget-total b {
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.02em;
  text-transform: none;
  font-variant-numeric: tabular-nums;
}

.budget-alert {
  margin-top: 16px;
  padding-top: 13px;
  border-top: 1px solid var(--bad-line);
  color: var(--bad);
  font-size: 12px;
}

.usage-line {
  margin-top: 10px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

/* ----------------------------------------------------------------- chat */
.chat-card .card-head {
  flex-wrap: wrap;
}

.chat-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 0;
  padding: 0;
  overflow: hidden;
}

.conv-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.conv-side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 12px;
  border-right: 1px solid var(--line);
  min-width: 0;
}

.conv-search {
  width: 100%;
  min-height: 30px;
  font-size: 12px;
}

.conv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: 52vh;
}

.conv-row {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: var(--r-sm);
}

.conv-row.is-active {
  background: var(--accent-soft);
}

.conv-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 7px 8px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.conv-title {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
}

.conv-meta {
  color: var(--muted);
  font-size: 10px;
}

.conv-del {
  flex: none;
  width: 26px;
  height: 26px;
  color: var(--muted);
}

.conv-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 8px;
}

.cmd-menu {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface, var(--field));
  margin: 0 0 8px;
  max-height: 220px;
  overflow-y: auto;
}

.cmd-menu ul {
  list-style: none;
  margin: 0;
  padding: 4px;
}

.cmd-item {
  width: 100%;
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 7px 9px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
  border-radius: var(--r-sm);
}

.cmd-item:hover:not(:disabled),
.cmd-item:focus-visible {
  background: var(--accent-soft);
}

.cmd-item:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.cmd-item span {
  color: var(--muted);
}

.attach-box {
  margin: 0 0 8px;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  font-size: 11px;
  color: var(--muted);
}

@media (max-width: 760px) {
  .chat-layout {
    grid-template-columns: 1fr;
  }

  .conv-side {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .conv-list {
    max-height: 22vh;
  }
}

.chat-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-select {
  width: auto;
  min-width: 180px;
  min-height: 30px;
  padding: 5px 30px 5px 10px;
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 11px;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.switch .track {
  position: relative;
  width: 32px;
  height: 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--field);
  transition: background-color var(--t-2) var(--ease), border-color var(--t-2) var(--ease);
}

.switch .track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform var(--t-3) var(--ease-spring), background-color var(--t-2) var(--ease);
}

.switch input:checked + .track {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.switch input:checked + .track::after {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-line);
  transform: translateX(14px);
}

.switch input:focus-visible + .track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chat {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 360px;
  padding: 8px 4px 14px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scroll-behavior: smooth;
  isolation: isolate;
}

.chat::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(var(--line) 1px, transparent 1px);
  background-size: 22px 22px;
  opacity: 0.4;
  -webkit-mask-image: radial-gradient(90% 80% at 50% 45%, #000 10%, transparent 76%);
  mask-image: radial-gradient(90% 80% at 50% 45%, #000 10%, transparent 76%);
  pointer-events: none;
}

.chat-empty {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  overflow: hidden;
  color: var(--muted);
  animation: fade-up 600ms var(--ease-out) both;
}

.chat-empty::before {
  content: '';
  position: absolute;
  width: 260px;
  height: 260px;
  border: 1px dashed var(--line-strong);
  border-radius: 50%;
  opacity: 0.55;
  animation: orbit 48s linear infinite;
}

.chat-empty::after {
  content: '';
  position: absolute;
  width: 150px;
  height: 150px;
  border: 1px solid var(--line);
  border-radius: 50%;
  opacity: 0.6;
}

.chat-empty .brand-mark {
  position: relative;
  z-index: 1;
  width: 46px;
  height: 46px;
  border-radius: 15px;
  opacity: 0.92;
}

.chat-empty .brand-mark svg {
  width: 24px;
  height: 24px;
}

.chat-word {
  position: relative;
  z-index: 1;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  opacity: 0.8;
}

@keyframes orbit {
  to {
    transform: rotate(360deg);
  }
}

.msg {
  align-self: flex-start;
  max-width: 86%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  border-bottom-left-radius: 5px;
  background: var(--glass-strong);
  color: var(--fg-2);
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  animation: msg-in 320ms var(--ease-out) both;
}

.msg.user {
  align-self: flex-end;
  border-color: transparent;
  border-radius: 14px;
  border-bottom-right-radius: 5px;
  background: linear-gradient(180deg, var(--btn-a), var(--btn-b));
  color: var(--btn-fg);
  box-shadow: 0 12px 28px -18px var(--accent-line);
}

.msg.err {
  border-color: var(--bad-line);
  background: var(--bad-soft);
  color: var(--bad);
}

.msg.tool {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono, monospace);
}

.msg.streaming::after {
  content: '▍';
  margin-left: 2px;
  color: var(--accent);
  animation: blink 1s steps(2) infinite;
}

.msg.typing {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 38px;
  padding: 12px 16px;
}

.msg.typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing 1.1s var(--ease) infinite;
}

.msg.typing span:nth-child(2) {
  animation-delay: 140ms;
}

.msg.typing span:nth-child(3) {
  animation-delay: 280ms;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 10px;
  padding: 6px 6px 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--field);
  transition: border-color var(--t-2) var(--ease), box-shadow var(--t-2) var(--ease);
}

.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.composer textarea {
  flex: 1;
  min-height: 38px;
  max-height: 156px;
  padding: 9px 0;
  overflow-y: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 13.5px;
  resize: none;
}

.composer textarea:focus {
  background: transparent;
  box-shadow: none;
}

.composer .btn {
  flex: 0 0 auto;
  width: 40px;
  height: 38px;
  padding: 0;
  border-radius: var(--r-sm);
}

.composer .btn svg {
  width: 16px;
  height: 16px;
}

/* -------------------------------------------------------------- keyframes */
@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

@keyframes typing {
  0%,
  60%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* --------------------------------------------------------------- mobile */
@media (max-width: 760px) {
  .p-head {
    height: 56px;
    padding: 0 14px;
  }

  .p-main {
    padding: 20px 14px 64px;
  }

  .p-connect {
    margin-top: 4vh;
  }

  .chat {
    height: 54vh;
  }

  .chat-select {
    min-width: 130px;
  }

  .p-user span {
    display: none;
  }
}

@media (max-width: 520px) {
  .p-head .brand-sub {
    display: none;
  }

  .msg {
    max-width: 92%;
  }
}

/* ------------------------------------------------- readable portal type scale */
.login-lead {
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.7;
}

.p-connect h1 { font-size: 30px; }
#connectMsg { font-size: 14px; }
.p-user { font-size: 12px; }
.p-user .btn { font-size: 12px; }
.stat .s { font-size: 11.5px; }
.budget-label { font-size: 13px; }
.budget-label b,
.budget-foot { font-size: 11.5px; }
.usage-line { font-size: 12px; }

.conv-search,
.conv-title { font-size: 13.5px; }
.conv-meta,
.conv-empty { font-size: 12px; }
.cmd-item { font-size: 13.5px; }
.attach-chip { font-size: 12px; }
.chat-select { font-size: 12.5px; }
.switch { font-size: 12px; }

.msg { font-size: 15.5px; line-height: 1.75; }
.msg.tool { font-size: 13px; }
.composer textarea { font-size: 15px; }

/* Forms are read and typed in, so they follow the same readable scale. */
.field > span,
.field > label {
  font-size: 12.5px;
}

.field input,
.field select,
.field textarea {
  font-size: 15px;
}
