/* ============================================================
   Баланс — Chat UI
   Mobile-first, Unbounded font, #084734 brand palette
   ============================================================ */

/* ── CSS Custom Properties ─────────────────────────────────── */

:root {
  --c-bg:        #F7FAF4;   /* фон приложения */
  --c-surface:   #FFFFFF;   /* поверхности (шапка, кнопки) */
  --c-text:      #1A1A1A;   /* основной текст */
  --c-muted:     #888888;   /* вспомогательный текст */
  --c-accent:    #CEF17B;   /* Lime Glow — акцент */
  --c-brand:     #084734;   /* Emerald Pine — брендовый */
  --c-green-tea: #CDEDB3;   /* Green Tea — сообщения пользователя */

  --header-h:    56px;
  --panel-pad:   12px;
  --input-h:     44px;
  --radius-pill: 22px;
  --radius-bubble: 16px;

  --shadow-header: 0 1px 4px rgba(0, 0, 0, .06);
  --shadow-panel:  0 -1px 4px rgba(0, 0, 0, .06);
  --shadow-bubble: 0 1px 2px rgba(0, 0, 0, .05);

  --font: 'Unbounded', system-ui, -apple-system, sans-serif;
}

/* ── Reset ─────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  height: 100%;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  /* Desktop: center the chat column */
  display: flex;
  justify-content: center;
  align-items: stretch;
}

/* ── App shell ─────────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  /* dvh accounts for browser address bar on mobile */
  height: 100vh;   /* fallback for older browsers */
  height: 100dvh;  /* overrides — dynamic viewport excludes address bar */
  overflow: hidden;
  background: var(--c-bg);
}

/* Desktop: fixed-width column with subtle shadow */
@media (min-width: 520px) {
  .app {
    max-width: 480px;
    box-shadow: 0 0 40px rgba(0, 0, 0, .08);
  }
}

/* ── Chat header ────────────────────────────────────────────── */

.chat-header {
  flex-shrink: 0;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--c-surface);
  box-shadow: var(--shadow-header);
  display: flex;
  align-items: center;
  z-index: 10;
}

.chat-header__brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-header__name {
  font-size: 18px;
  font-weight: 700;
  color: var(--c-brand);
  letter-spacing: -.3px;
  line-height: 1.2;
}

.chat-header__sub {
  font-size: 12px;
  font-weight: 400;
  color: var(--c-muted);
  line-height: 1.2;
}

/* ── Messages area ──────────────────────────────────────────── */

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* Smooth momentum scrolling on iOS */
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* ── Message base ───────────────────────────────────────────── */

.msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: msgSlideUp .3s ease-out both;
}

/* ── Bot message (left) ─────────────────────────────────────── */

.msg--bot {
  align-self: flex-start;
  max-width: 85%;
}

@media (min-width: 520px) {
  .msg--bot { max-width: 75%; }
}

.msg__avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--c-brand);
  color: var(--c-accent);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Stick to bottom of bubble */
  align-self: flex-end;
  margin-bottom: 0;
}

.msg__content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0; /* allow text to wrap */
}

.msg--bot .msg__bubble {
  background: var(--c-surface);
  color: var(--c-text);
  border-radius: var(--radius-bubble) var(--radius-bubble) var(--radius-bubble) 4px;
  box-shadow: var(--shadow-bubble);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── User message (right) ───────────────────────────────────── */

.msg--user {
  align-self: flex-end;
  max-width: 75%;
  flex-direction: row-reverse; /* bubble on right, no avatar */
  padding-right: 12px;
}

.msg--user .msg__bubble {
  background: var(--c-green-tea);
  color: var(--c-brand);
  border-radius: var(--radius-bubble) var(--radius-bubble) 4px var(--radius-bubble);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  min-width: 0;
  overflow: hidden;
}

/* Hint text below bot bubble */
.msg__hint {
  font-size: 11px;
  color: var(--c-muted);
  padding: 0 2px;
  line-height: 1.4;
}

/* ── Typing indicator ───────────────────────────────────────── */

.msg__bubble--typing {
  padding: 12px 16px;
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 14px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c-muted);
  opacity: .45;
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }

/* ── Progress bar (inside bot bubble) ──────────────────────── */

.progress {
  margin-top: 10px;
}

.progress__bar {
  height: 5px;
  border-radius: 99px;
  background: var(--c-green-tea);
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  border-radius: 99px;
  background: var(--c-brand);
  transition: width .6s ease-out;
  /* Pulse at 0% to show activity */
  animation: progressPulse 1.8s ease-in-out infinite;
}

/* Once progress > 0 we override the animation via inline width */
.progress__fill[style] {
  animation: none;
}

.progress__label {
  margin-top: 6px;
  font-size: 11px;
  color: var(--c-muted);
  line-height: 1.4;
}

/* ── File badge (inside bubble, after upload) ───────────────── */

.file-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: color-mix(in srgb, var(--c-green-tea) 50%, white);
  border: 1px solid var(--c-green-tea);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--c-brand);
  margin-top: 4px;
  max-width: 100%;
  overflow: hidden;
}

.file-badge__icon {
  font-size: 10px;
  font-weight: 700;
  background: var(--c-brand);
  color: var(--c-accent);
  padding: 1px 4px;
  border-radius: 3px;
  flex-shrink: 0;
}

.file-badge__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  max-width: 100%;
}

/* ── Bottom panel ───────────────────────────────────────────── */

.bottom-panel {
  flex-shrink: 0;
  padding: var(--panel-pad) 12px;
  background: var(--c-surface);
  box-shadow: var(--shadow-panel);
  /* Safe area inset for iPhone home bar */
  padding-bottom: max(var(--panel-pad), env(safe-area-inset-bottom));
}

/* ── Choice buttons ─────────────────────────────────────────── */

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-choice {
  height: var(--input-h);
  padding: 0 18px;
  border: 1.5px solid var(--c-brand);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--c-brand);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, transform .1s;
  /* Prevent text from being too small on very narrow screens */
  flex: 1 1 auto;
  min-width: 120px;
  text-align: center;
}

.btn-choice:hover {
  background: var(--c-green-tea);
}

.btn-choice:active,
.btn-choice.is-pressed {
  background: var(--c-accent);
  color: var(--c-brand);
  transform: scale(.97);
}

.btn-choice.is-used,
.btn-choice:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

/* ── Number / text input row ─────────────────────────────────── */

.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.text-input {
  flex: 1;
  height: var(--input-h);
  padding: 0 16px;
  border: 1.5px solid var(--c-green-tea);
  border-radius: var(--radius-pill);
  background: var(--c-bg);
  font-family: var(--font);
  font-size: 14px;
  color: var(--c-text);
  outline: none;
  transition: border-color .15s;
  -webkit-appearance: none;
}

.text-input::placeholder {
  color: var(--c-muted);
}

.text-input:focus {
  border-color: var(--c-brand);
}

/* Remove number spinners */
.text-input[type="number"]::-webkit-inner-spin-button,
.text-input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.btn-send {
  flex-shrink: 0;
  width: var(--input-h);
  height: var(--input-h);
  border: none;
  border-radius: 50%;
  background: var(--c-brand);
  color: var(--c-accent);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .15s, transform .1s;
  line-height: 1;
}

.btn-send:hover  { opacity: .85; }
.btn-send:active { transform: scale(.93); }

/* ── File upload area ────────────────────────────────────────── */

.upload-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-upload {
  height: var(--input-h);
  padding: 0 20px;
  border: 1.5px dashed var(--c-brand);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--c-brand);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-upload:hover { background: color-mix(in srgb, var(--c-green-tea) 40%, white); }

.file-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--c-text);
  padding: 0 4px;
}

.file-item__check {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--c-green-tea);
  color: var(--c-brand);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-item__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.btn-submit-files {
  height: var(--input-h);
  padding: 0 24px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--c-brand);
  color: var(--c-accent);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  align-self: stretch;
}

.btn-submit-files:hover  { opacity: .88; }
.btn-submit-files:active { transform: scale(.97); }

/* ── Animations ──────────────────────────────────────────────── */

@keyframes msgSlideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: .4;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

@keyframes progressPulse {
  0%, 100% { opacity: .5; }
  50%       { opacity: 1; }
}

/* ── Loan form ───────────────────────────────────────────────── */

/* Скролл-контейнер для карточек кредитов */
.loan-form-body {
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Фиксированный футер формы: + Добавить + Готово */
.loan-form-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--c-green-tea);
  flex-shrink: 0;
}

.loan-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.loan-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--c-bg);
  border: 1.5px solid var(--c-green-tea);
  border-radius: 14px;
  padding: 12px 12px 10px;
}

.loan-remove-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--c-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.loan-remove-btn:hover { color: var(--c-text); }

.loan-type-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.loan-type-btn {
  height: 30px;
  padding: 0 12px;
  border: 1.5px solid var(--c-green-tea);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--c-brand);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
}
.loan-type-btn:hover { background: var(--c-green-tea); }
.loan-type-btn.is-selected {
  background: var(--c-brand);
  border-color: var(--c-brand);
  color: var(--c-accent);
}

.loan-field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.loan-field-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 0 2px;
}

.loan-field-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Все инпуты в форме кредита — единый размер */
.loan-field-row .text-input,
.loan-card > .text-input {
  flex: 1;
  width: 100%;
  height: 44px;
  font-size: 13px;
  padding: 0 14px;
  border: 1px solid #ddd;
  border-radius: 12px;
}
.loan-field-row .text-input:focus,
.loan-card > .text-input:focus {
  border-color: var(--c-brand);
}

.btn-unknown {
  flex-shrink: 0;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #ddd;
  border-radius: 12px;
  background: transparent;
  color: var(--c-muted);
  font-family: var(--font);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, color .12s, border-color .12s;
}
.btn-unknown:hover { background: var(--c-green-tea); color: var(--c-brand); border-color: var(--c-brand); }
.btn-unknown.is-active {
  background: var(--c-green-tea);
  border-color: var(--c-brand);
  color: var(--c-brand);
  font-weight: 600;
}

/* ── Scrollbar (WebKit) ──────────────────────────────────────── */

.messages::-webkit-scrollbar {
  width: 4px;
}
.messages::-webkit-scrollbar-track {
  background: transparent;
}
.messages::-webkit-scrollbar-thumb {
  background: var(--c-green-tea);
  border-radius: 99px;
}
