﻿/*
  UI Modern Upgrade (Brand Green)
  Goals:
  1) Unified visual system
  2) Stronger interaction feedback
  3) Re-layered message/composer hierarchy
  4) Better maintainability via tokenized overrides
*/

:root {
  --brand: #038b60;
  --brand-deep: #046445;
  --brand-light: #1ea77e;
  --brand-pale: #dcf6ec;
  --brand-whisper: #eefaf4;

  --bg: #e6f4ee;
  --bg-mesh-1: rgba(3, 139, 96, 0.16);
  --bg-mesh-2: rgba(4, 100, 69, 0.12);

  --text: #0f2a22;
  --text-sub: #2f4e43;
  --text-light: #5c7a70;
  --border: #b9dfd0;
  --border-soft: #d8ede4;

  --focus-ring: 0 0 0 3px rgba(3, 139, 96, 0.28);

  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-soft: cubic-bezier(0.22, 1, 0.36, 1);

  --shadow-sm: 0 8px 24px rgba(9, 61, 47, 0.1);
  --shadow-md: 0 36px 90px -22px rgba(9, 61, 47, 0.24);
  --shadow-inset-light: inset 0 1px 0 rgba(255, 255, 255, 0.72);

  --radius-shell: 28px;
  --radius-bubble: 18px;

  --gradient-tech-soft: linear-gradient(130deg, rgba(255, 255, 255, 0.74), rgba(255, 255, 255, 0.48));
  --gradient-tech-brand: linear-gradient(145deg, #0aa26f 0%, #047451 58%, #035f43 100%);
}

body {
  background:
    radial-gradient(120% 90% at 8% -20%, var(--bg-mesh-1), transparent 58%),
    radial-gradient(90% 75% at 102% 110%, var(--bg-mesh-2), transparent 56%),
    linear-gradient(180deg, #edf7f3 0%, #e5f1eb 100%);
}

body::after {
  content: "";
  position: fixed;
  inset: -40% -20%;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(closest-side at 18% 32%, rgba(39, 177, 131, 0.13), transparent 68%),
    radial-gradient(closest-side at 86% 68%, rgba(8, 102, 72, 0.12), transparent 70%);
  filter: blur(46px);
  animation: mesh-drift 16s var(--ease-soft) infinite alternate;
}

@keyframes mesh-drift {
  from {
    transform: translate3d(-1.3%, -0.8%, 0) scale(1);
  }
  to {
    transform: translate3d(1.1%, 1%, 0) scale(1.03);
  }
}

.chat-app {
  width: min(980px, calc(100% - 32px));
  max-width: 980px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(245, 252, 249, 0.9));
  backdrop-filter: blur(8px);
  box-shadow:
    var(--shadow-md),
    0 0 0 1px rgba(3, 139, 96, 0.1),
    0 20px 44px rgba(6, 59, 44, 0.14),
    var(--shadow-inset-light);
}

.chat-header {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(160deg, #09895f 0%, #046749 56%, #03563c 100%);
  box-shadow:
    0 10px 30px rgba(4, 79, 56, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.chat-header::before,
.chat-header::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.chat-header::before {
  inset: auto -24% -56% -20%;
  height: 160%;
  background: radial-gradient(closest-side, rgba(155, 255, 224, 0.15), transparent 75%);
}

.chat-header::after {
  content: none;
}

.hd-title {
  letter-spacing: 0;
}

.hd-sub {
  opacity: 0.95;
}

.header-status {
  color: #b6ffe2;
}

.chat-app.is-streaming .header-status svg {
  animation: status-active 1.8s var(--ease-soft) infinite;
}

@keyframes status-active {
  0%,
  100% {
    transform: scale(1);
    filter: drop-shadow(0 0 0 rgba(182, 255, 226, 0));
  }
  50% {
    transform: scale(1.08);
    filter: drop-shadow(0 0 10px rgba(182, 255, 226, 0.54));
  }
}

.chat-log {
  padding: 24px 22px;
  gap: 20px;
  background:
    radial-gradient(circle at 14% 18%, rgba(3, 139, 96, 0.09), transparent 44%),
    radial-gradient(circle at 92% 80%, rgba(4, 100, 69, 0.07), transparent 42%),
    linear-gradient(180deg, #edf8f3 0%, #eaf6f1 100%);
}

.welcome-hint {
  border-left-width: 5px;
  background: var(--gradient-tech-soft);
  border-color: rgba(15, 143, 99, 0.22);
  border-left-color: var(--brand);
}

.msg {
  max-width: min(88%, 760px);
}

.msg-user .msg-body {
  overflow: visible;
  gap: 4px;
}

.bubble {
  border-radius: var(--radius-bubble);
  transition: box-shadow 0.28s var(--ease-soft), transform 0.28s var(--ease-soft), border-color 0.28s var(--ease-soft);
}

.bubble-bot {
  border: 1px solid rgba(10, 115, 82, 0.14);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 252, 249, 0.98));
  box-shadow:
    0 10px 26px rgba(8, 67, 50, 0.09),
    inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.msg-bot .bubble-bot:hover {
  box-shadow:
    0 14px 32px rgba(8, 67, 50, 0.13),
    inset 0 1px 0 rgba(255, 255, 255, 0.92);
}

.bubble-user {
  position: relative;
  width: auto;
  max-width: min(100%, 68ch);
  background:
    linear-gradient(155deg, #0ba572 0%, #067f58 56%, #056e4d 100%);
  box-shadow:
    0 10px 22px rgba(4, 110, 77, 0.24),
    0 2px 6px rgba(4, 83, 60, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.bubble-user::after {
  content: none;
}

.avatar-user,
.avatar-bot-mark {
  box-shadow: 0 10px 22px rgba(6, 91, 64, 0.24);
}

.msg-time {
  font-size: 11px;
  color: #58786d;
}

.msg-user .msg-time {
  opacity: 0.92;
  padding-right: 2px;
}

.answer-waiting {
  position: relative;
  color: #3f665a;
  font-style: normal;
}

.answer-waiting::after {
  content: "";
  display: block;
  height: 4px;
  margin-top: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(3, 139, 96, 0.18), rgba(3, 139, 96, 0.56), rgba(3, 139, 96, 0.16));
  background-size: 220% 100%;
  animation: waiting-flow 1.5s linear infinite;
}

@keyframes waiting-flow {
  from {
    background-position: 0% 50%;
  }
  to {
    background-position: 220% 50%;
  }
}

.reasoning-inner {
  border-left-width: 4px;
  border-color: rgba(3, 139, 96, 0.24);
  border-left-color: var(--brand);
  background: linear-gradient(180deg, rgba(238, 250, 244, 0.95), rgba(231, 246, 238, 0.92));
}

.reasoning-toggle {
  color: #16644a;
}

.reasoning-toggle:hover {
  background: rgba(16, 148, 104, 0.12);
}

.answer-wrap .copy-btn {
  border-color: rgba(8, 112, 80, 0.16);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 4px 10px rgba(8, 67, 50, 0.12);
}

.answer-wrap .copy-btn:hover {
  color: var(--brand);
  border-color: rgba(3, 139, 96, 0.4);
}

.chat-footer {
  position: relative;
  background: linear-gradient(180deg, rgba(250, 255, 253, 0.96), rgba(239, 249, 244, 0.94));
  border-top: 1px solid rgba(8, 112, 80, 0.13);
}

.chat-footer::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(159, 244, 214, 0.9), transparent);
}

.chat-footer-inner {
  border-radius: 20px;
  margin: 12px 14px 14px;
  padding: 12px;
  gap: 9px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(246, 253, 250, 0.9));
  border: 1px solid rgba(6, 106, 75, 0.14);
  box-shadow:
    0 14px 32px rgba(7, 73, 54, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.78);
  transition: box-shadow 0.25s var(--ease-soft), border-color 0.25s var(--ease-soft), transform 0.25s var(--ease-soft);
}

.chat-app.composer-ready .chat-footer-inner {
  border-color: rgba(6, 126, 88, 0.28);
  box-shadow:
    0 18px 36px rgba(7, 73, 54, 0.16),
    0 0 0 4px rgba(6, 126, 88, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.chat-footer textarea {
  border-radius: 14px;
  border-color: rgba(9, 124, 87, 0.22);
  background: linear-gradient(180deg, #f7fcfa, #f2faf6);
}

.chat-footer textarea:focus {
  border-color: rgba(3, 139, 96, 0.72);
  box-shadow: 0 0 0 4px rgba(3, 139, 96, 0.12);
}

.upload-btn,
.voice-btn,
.send-btn {
  transition:
    transform 0.16s var(--ease-soft),
    box-shadow 0.24s var(--ease-soft),
    border-color 0.24s var(--ease-soft),
    background 0.24s var(--ease-soft),
    color 0.24s var(--ease-soft),
    opacity 0.24s var(--ease-soft);
}

.upload-btn,
.voice-btn {
  border-color: rgba(9, 124, 87, 0.24);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(245, 252, 248, 0.96));
}

.upload-btn:hover,
.voice-btn:hover:not(:disabled) {
  border-color: rgba(3, 139, 96, 0.56);
  box-shadow: 0 10px 20px rgba(6, 95, 67, 0.16);
}

.send-btn {
  background: var(--gradient-tech-brand);
  box-shadow:
    0 12px 24px rgba(4, 110, 77, 0.36),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.send-btn.is-ready:not(:disabled) {
  box-shadow:
    0 14px 30px rgba(4, 110, 77, 0.4),
    0 0 0 4px rgba(3, 139, 96, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

.chat-app.is-streaming .send-btn {
  animation: send-working 1.2s var(--ease-soft) infinite;
}

@keyframes send-working {
  0%,
  100% {
    transform: translateY(0);
    filter: saturate(1);
  }
  50% {
    transform: translateY(-1px);
    filter: saturate(1.12);
  }
}

.img-thumb-wrap {
  border-color: rgba(9, 124, 87, 0.22);
  box-shadow: 0 8px 20px rgba(8, 67, 50, 0.12);
}

.img-thumb-edit,
.img-thumb-remove {
  backdrop-filter: blur(2px);
}

.lightbox {
  backdrop-filter: blur(8px);
  background: rgba(5, 33, 24, 0.74);
}

.img-editor-panel {
  border: 1px solid rgba(8, 112, 80, 0.2);
  box-shadow: 0 24px 60px rgba(4, 47, 34, 0.34);
}

.jump-latest-host .jump-latest-btn {
  border-color: rgba(9, 124, 87, 0.24);
  box-shadow: 0 10px 24px rgba(8, 67, 50, 0.16);
}

.jump-latest-host .jump-latest-btn:hover {
  border-color: rgba(3, 139, 96, 0.62);
}

/* Maintainable classes from JS (replace inline styles) */
.user-image-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.user-image-thumb {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 10px;
  border: 1.5px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  cursor: zoom-in;
  transition: transform 0.18s var(--ease-soft), opacity 0.18s var(--ease-soft);
}

.user-image-thumb:hover {
  opacity: 0.86;
  transform: translateY(-1px);
}

.unlock-btn {
  padding: 9px 16px;
  border: none;
  border-radius: 10px;
  background: var(--error-icon, #d92d20);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: filter 0.2s var(--ease-soft), transform 0.12s var(--ease-soft), opacity 0.2s var(--ease-soft);
}

.unlock-btn:hover {
  filter: brightness(1.04);
}

.unlock-btn:active {
  transform: scale(0.98);
}

.unlock-btn:disabled {
  opacity: 0.68;
  cursor: wait;
}

@media (max-width: 600px) {
  :root {
    --radius-bubble: 14px;
    --shadow-sm: 0 5px 14px rgba(9, 61, 47, 0.08);
  }

  body {
    background:
      linear-gradient(180deg, #ecf4f1 0%, #e8f0ec 100%);
  }

  body::before {
    opacity: 0.015;
  }

  .chat-app {
    width: 100%;
    border-radius: 0;
    border: none;
    box-shadow: none;
    background: #eef5f2;
  }

  body::after {
    animation: none;
    opacity: 0.35;
    filter: blur(60px);
  }

  .chat-header {
    padding: 8px 12px;
    gap: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.22);
    box-shadow:
      0 4px 14px rgba(4, 79, 56, 0.2),
      inset 0 1px 0 rgba(255, 255, 255, 0.16);
  }

  .chat-header::before {
    opacity: 0.5;
  }

  .hd-title-row {
    gap: 8px;
  }

  .chat-header .hd-title {
    font-size: 15px;
    line-height: 1.24;
  }

  .hd-title-icon svg {
    width: 18px;
    height: 18px;
  }

  .new-chat-btn {
    min-width: 38px;
    min-height: 38px;
    width: 38px;
    height: 38px;
    padding: 0;
    border-width: 1px;
    background: rgba(255, 255, 255, 0.08);
    box-shadow: none;
  }

  .new-chat-btn .btn-ico svg {
    width: 17px;
    height: 17px;
  }

  .chat-log {
    padding: 10px 8px;
    gap: 14px;
    background:
      linear-gradient(180deg, #edf5f2 0%, #e9f1ee 100%);
  }

  .msg {
    max-width: 100%;
    gap: 8px;
  }

  .welcome-hint {
    margin: 0 2px;
    padding: 12px 12px;
    border-left-width: 3px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.52;
  }

  .welcome-hint p {
    max-width: none;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .msg.msg-bot {
    align-self: flex-start;
    width: auto;
    max-width: min(96%, 760px);
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
  }

  .msg.msg-bot .avatar-bot-mark {
    width: 30px;
    height: 30px;
    box-shadow: 0 4px 10px rgba(6, 91, 64, 0.2);
  }

  .msg.msg-bot .avatar-bot-mark svg {
    width: 15px;
    height: 15px;
  }

  .msg.msg-bot .msg-body {
    width: auto;
    min-width: 0;
    max-width: calc(100vw - 70px);
  }

  .msg.msg-bot .bubble-bot {
    padding: 10px 12px;
    box-shadow:
      0 6px 14px rgba(8, 67, 50, 0.08),
      inset 0 1px 0 rgba(255, 255, 255, 0.9);
  }

  .msg.msg-user {
    max-width: 78%;
    gap: 6px;
  }

  .msg.msg-user .bubble-user {
    padding: 10px 13px;
    box-shadow:
      0 7px 16px rgba(4, 110, 77, 0.2),
      0 1px 3px rgba(4, 83, 60, 0.12),
      inset 0 1px 0 rgba(255, 255, 255, 0.08);
  }

  .msg.msg-user .msg-time,
  .msg.msg-bot .msg-time {
    font-size: 10.5px;
    opacity: 0.84;
  }

  .chat-footer {
    background: #eaf2ef;
    border-top: 1px solid rgba(10, 118, 84, 0.09);
  }

  .chat-footer-inner {
    margin: 0 8px 8px;
    border-radius: 19px;
    padding: 7px 8px;
    gap: 6px;
    border-color: rgba(7, 104, 74, 0.14);
    box-shadow:
      0 6px 14px rgba(7, 73, 54, 0.08),
      inset 0 1px 0 rgba(255, 255, 255, 0.78);
  }

  .chat-footer textarea {
    background: transparent;
    box-shadow: none;
    padding: 8px 6px;
  }

  .chat-footer textarea::placeholder {
    opacity: 0.86;
  }

  .chat-footer-inner .upload-btn,
  .chat-footer-inner .voice-btn,
  .chat-footer-inner .send-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    border-width: 1px;
    box-shadow: none;
  }

  .chat-footer-inner .upload-btn,
  .chat-footer-inner .voice-btn {
    border-color: rgba(9, 122, 86, 0.3);
    background: rgba(249, 253, 251, 0.92);
    color: #2f6454;
  }

  .chat-footer-inner .send-btn {
    background: linear-gradient(155deg, #13a876 0%, #0b8a61 56%, #087b56 100%);
    box-shadow: 0 4px 12px rgba(4, 110, 77, 0.2);
  }

  .chat-footer-inner .upload-btn svg,
  .chat-footer-inner .voice-btn svg,
  .chat-footer-inner .send-btn svg {
    width: 17px;
    height: 17px;
    stroke-width: 2;
  }

  .voice-btn.is-listening {
    animation: none;
    box-shadow: 0 0 0 2px rgba(3, 139, 96, 0.14);
    border-color: rgba(3, 139, 96, 0.58);
  }

  .chat-app.is-streaming .send-btn {
    animation: none;
    filter: saturate(1.06);
  }

  .answer-waiting::after {
    height: 3px;
    opacity: 0.75;
  }

  .user-image-thumb {
    width: 74px;
    height: 74px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body::after,
  .chat-header::after,
  .chat-app.is-streaming .send-btn,
  .chat-app.is-streaming .header-status svg,
  .answer-waiting::after {
    animation: none !important;
  }
}
