/* ==========================================================================
   Wise Technologies PWA — voice-first conversational chat
   Visual language matches https://wisetechnologies.my (wisetech-landing)
   Mobile-first; dark-mode aware; reduced-motion aware.
   ========================================================================== */

:root {
  --accent: #0e7490;
  --accent-2: #0d9488;
  --accent-3: #0891b2;
  --accent-soft: rgba(14,116,144,0.10);
  --accent-glow: rgba(13,148,136,0.14);
  --accent-deep: #0e7490;

  --bg: #faf9f7;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f4f1;
  --bubble-bot: #ffffff;
  --bubble-bot-border: #e2e0db;
  --bubble-user-bg: linear-gradient(135deg, #0e7490 0%, #0d9488 100%);
  --bubble-user-text: #ffffff;

  --text: #0f172a;
  --text-muted: #475569;
  --text-faded: #94a3b8;
  --border: #e2e0db;
  --border-strong: #cbd5e1;

  --shadow-xs: 0 1px 2px rgba(15,23,42,0.04);
  --shadow-sm: 0 2px 4px rgba(15,23,42,0.04), 0 1px 2px rgba(15,23,42,0.03);
  --shadow-md: 0 8px 24px rgba(15,23,42,0.06), 0 2px 6px rgba(15,23,42,0.04);
  --shadow-lg: 0 24px 56px rgba(14,116,144,0.14), 0 6px 16px rgba(15,23,42,0.06);
  --shadow-glow: 0 0 0 4px rgba(14,116,144,0.10);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-bubble: 18px;

  --danger: #dc2626;
  --danger-soft: rgba(220,38,38,0.12);

  --header-h: 64px;
  --composer-h: 92px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #2dd4bf;
    --accent-2: #14b8a6;
    --accent-3: #0d9488;
    --accent-deep: #134e4a;
    --accent-soft: rgba(45,212,191,0.10);
    --accent-glow: rgba(20,184,166,0.14);

    --bg: #0a0908;
    --bg-elevated: #1a1716;
    --surface: #1c1917;
    --surface-2: #292524;
    --bubble-bot: #1c1917;
    --bubble-bot-border: #2a2624;
    --bubble-user-bg: linear-gradient(135deg, #2dd4bf 0%, #14b8a6 100%);
    --bubble-user-text: #042f2e;

    --text: #f8fafc;
    --text-muted: #cbd5e1;
    --text-faded: #64748b;
    --border: #2a2624;
    --border-strong: #3f3a36;

    --shadow-xs: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 28px rgba(0,0,0,0.5), 0 2px 6px rgba(0,0,0,0.4);
    --shadow-lg: 0 24px 60px rgba(45,212,191,0.16), 0 6px 18px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 0 4px rgba(45,212,191,0.14);

    --danger: #f87171;
    --danger-soft: rgba(248,113,113,0.16);
  }
}

/* ----- Reset & base ----- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
@media (min-width: 768px) { html { font-size: 17px; } }

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  line-height: 1.55;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

::selection { background: var(--accent-soft); color: var(--accent); }

*:focus-visible {
  outline: 2px solid var(--accent) !important;
  outline-offset: 3px;
  border-radius: inherit;
}

button { font-family: inherit; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ----- Mesh background ----- */
.bg-mesh {
  position: fixed; inset: -10vh -10vw; z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 50% at 15% 20%, var(--accent-soft) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 85% 15%, var(--accent-glow) 0%, transparent 65%),
    radial-gradient(ellipse 70% 60% at 70% 90%, var(--accent-soft) 0%, transparent 70%);
  animation: mesh-drift 32s ease-in-out infinite alternate;
  opacity: 0.85;
}
@keyframes mesh-drift {
  0%   { transform: translate(0,0) scale(1); }
  50%  { transform: translate(-2%, 1%) scale(1.04); }
  100% { transform: translate(2%, -1%) scale(1.02); }
}
@media (prefers-reduced-motion: reduce) { .bg-mesh { animation: none; } }

/* ----- Header ----- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.header-inner {
  max-width: 720px;
  margin: 0 auto;
  height: 100%;
  padding: 0 1rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem;
}
.brand-mark {
  display: inline-flex; align-items: center; gap: 0.6rem;
  font-weight: 600; letter-spacing: -0.01em;
  text-decoration: none; color: var(--text);
  min-height: 44px;
  padding: 4px 6px;
  border-radius: 8px;
}
.brand-mark svg { width: 1.6rem; height: 1.6rem; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-size: 0.98rem; font-weight: 600; }
.brand-name-accent {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.brand-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 1px;
}
.header-cta {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.5rem 0.85rem;
  min-height: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.85rem; font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.header-cta:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.header-cta-label { font-weight: 500; }

/* ----- Main / chat area ----- */
.app-main {
  position: relative; z-index: 1;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0;
}
.wau-watermark {
  position: fixed;
  bottom: calc(var(--composer-h) + 80px);
  left: 50%;
  transform: translateX(-50%);
  width: clamp(220px, 55vw, 420px);
  height: auto;
  opacity: 0.04;
  pointer-events: none;
  z-index: 0;
}
@media (prefers-color-scheme: dark) { .wau-watermark { opacity: 0.08; } }

/* ----- Status banner ----- */
.status-banner {
  margin: 0.75rem 1rem;
  padding: 0.65rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 0.5rem;
}
.status-banner.is-error {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}
.status-banner.is-info {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  background: var(--accent-soft);
  color: var(--accent);
}
.status-banner .dot {
  width: 8px; height: 8px; border-radius: 999px;
  background: currentColor;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
@media (prefers-reduced-motion: reduce) { .status-banner .dot { animation: none; } }

/* ----- Messages list ----- */
.messages {
  list-style: none;
  margin: 0;
  padding: 1rem 1rem calc(var(--composer-h) + 1rem);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  flex: 1 1 auto;
  overflow-y: auto;
  scroll-behavior: smooth;
  position: relative;
  z-index: 1;
}
@media (prefers-reduced-motion: reduce) { .messages { scroll-behavior: auto; } }

.msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: msg-in 0.3s cubic-bezier(0.4,0,0.2,1);
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) { .msg { animation: none; } }

.msg.bot { align-self: flex-start; }
.msg.user { align-self: flex-end; }

.bubble {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-bubble);
  font-size: 1rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.bot .bubble {
  background: var(--bubble-bot);
  color: var(--text);
  border: 1px solid var(--bubble-bot-border);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-xs);
}
.msg.user .bubble {
  background: var(--bubble-user-bg);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 6px;
  box-shadow: var(--shadow-sm);
}

.msg .audio-wrap {
  margin-top: 0.5rem;
}
.msg .audio-wrap audio {
  width: 100%;
  height: 36px;
  max-width: 280px;
  border-radius: 18px;
  outline: none;
}
.msg.bot .audio-wrap audio { background: var(--surface-2); }

.msg .voice-prefix {
  font-style: italic;
  opacity: 0.85;
  margin-right: 0.3rem;
}
.msg .voice-prefix::before {
  content: "🎙 ";
  font-style: normal;
}

.msg-time {
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--text-faded);
  padding: 0 6px;
}
.msg.user .msg-time { text-align: right; }

/* Typing indicator */
.msg.typing .bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1rem 1.1rem;
}
.typing-dot {
  width: 7px; height: 7px;
  border-radius: 999px;
  background: var(--text-muted);
  opacity: 0.4;
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%           { transform: translateY(-5px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .typing-dot { animation: none; opacity: 0.7; } }

/* ----- Composer ----- */
.composer {
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  padding: 0.75rem 0.85rem max(0.85rem, env(safe-area-inset-bottom));
}
.composer-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 720px;
  margin: 0 auto;
}

.mic-btn {
  flex-shrink: 0;
  width: 60px; height: 60px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #ffffff;
  border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: transform 0.18s, box-shadow 0.18s, filter 0.18s;
  position: relative;
}
@media (prefers-color-scheme: dark) { .mic-btn { color: #042f2e; } }

.mic-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.mic-btn:active { transform: scale(0.96); }
.mic-btn .mic-icon svg {
  width: 26px; height: 26px;
}
.mic-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* recording state */
.mic-btn.is-recording {
  background: var(--danger);
  color: #ffffff;
  animation: rec-pulse 1.6s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(220,38,38,0.55), var(--shadow-lg); }
  70%  { box-shadow: 0 0 0 14px rgba(220,38,38,0), var(--shadow-lg); }
  100% { box-shadow: 0 0 0 0 rgba(220,38,38,0), var(--shadow-lg); }
}
@media (prefers-reduced-motion: reduce) { .mic-btn.is-recording { animation: none; } }

.mic-btn.is-recording .mic-icon { display: none; }
.mic-btn.is-recording .mic-recording-time {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: 0.02em;
}
.mic-recording-time { display: none; }
.mic-btn.is-recording .mic-recording-time { display: inline; }

/* processing state */
.mic-btn.is-processing {
  background: var(--surface-2);
  color: var(--text-muted);
  animation: none;
}
.mic-btn.is-processing .mic-icon { display: none; }
.mic-btn.is-processing::after {
  content: '';
  width: 22px; height: 22px;
  border: 2.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 999px;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .mic-btn.is-processing::after { animation: none; opacity: 0.6; } }

/* error state */
.mic-btn.is-error {
  background: var(--surface);
  color: var(--danger);
  border: 2px solid var(--danger);
  box-shadow: 0 0 0 4px var(--danger-soft);
}

.text-input-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
}
.text-input {
  width: 100%;
  min-height: 48px;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.text-input::placeholder { color: var(--text-faded); }
.text-input:focus { border-color: var(--accent); box-shadow: var(--shadow-glow); }
.text-input:disabled { background: var(--surface-2); cursor: not-allowed; opacity: 0.6; }

.send-btn {
  flex-shrink: 0;
  width: 48px; height: 48px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  border: 1.5px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, color 0.15s, background 0.15s;
}
.send-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.send-btn svg { width: 20px; height: 20px; }

.composer-hint {
  margin: 0.5rem auto 0;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-faded);
  max-width: 720px;
  min-height: 1em;
}
.composer-hint.is-error { color: var(--danger); }

/* ----- Footer ----- */
.app-footer {
  text-align: center;
  padding: 0.5rem 1rem 1.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  position: relative;
  z-index: 1;
}
.footer-wa {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-weight: 500; font-size: 0.88rem;
  text-decoration: none;
  margin-bottom: 0.85rem;
  min-height: 40px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.footer-wa:hover { border-color: #25d366; color: #25d366; background: rgba(37,211,102,0.06); }
.footer-privacy {
  margin: 0.35rem 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.5;
}
.footer-privacy strong { color: var(--text); font-weight: 600; letter-spacing: 0.01em; }
.footer-signature {
  margin: 1rem 0 0;
  font-style: italic;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 500;
}

/* ----- Language modal ----- */
.lang-modal,
.mic-denied-modal {
  position: fixed; inset: 0;
  z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
@media (min-width: 540px) {
  .lang-modal,
  .mic-denied-modal { align-items: center; padding: 1rem; }
}
.lang-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15,23,42,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.lang-modal-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 1.75rem 1.25rem max(1.5rem, env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.35s cubic-bezier(0.4,0,0.2,1);
  border: 1px solid var(--border);
}
@media (min-width: 540px) {
  .lang-modal-card {
    border-radius: var(--radius-xl);
    padding: 2rem 1.75rem;
  }
}
@keyframes modal-in {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .lang-modal-card { animation: none; } }

.lang-title {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
  margin: 0 0 0.25rem;
  color: var(--text);
  display: flex; flex-direction: column; gap: 0.35rem;
}
.lang-title-multi {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0;
  line-height: 1.55;
}
.lang-sub {
  margin: 0 0 1.25rem;
  font-size: 0.92rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.lang-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
  margin-bottom: 1rem;
}
@media (min-width: 380px) {
  .lang-options { grid-template-columns: 1fr 1fr; }
  .lang-options .lang-btn:first-child { grid-column: 1 / -1; }
}
.lang-btn {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.85rem 1rem;
  min-height: 52px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 0.98rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, background 0.15s, box-shadow 0.15s;
  text-align: left;
}
.lang-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.lang-btn:active { transform: scale(0.98); }
.lang-btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #ffffff;
  justify-content: center;
  border: none;
  margin-top: 0.5rem;
}
@media (prefers-color-scheme: dark) { .lang-btn-primary { color: #042f2e; } }
.lang-btn-primary:hover { filter: brightness(1.05); border: none; background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%); }

.lang-flag {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  border-radius: 999px;
  background: var(--surface-2);
  flex-shrink: 0;
}
.lang-name { flex: 1; }
.lang-foot {
  margin: 0.85rem 0 0;
  font-size: 0.78rem;
  color: var(--text-faded);
  text-align: center;
}

/* ----- Touch target floor ----- */
button, a, input { min-height: 24px; }
@media (pointer: coarse) {
  .lang-btn, .header-cta, .footer-wa, .send-btn { min-height: 44px; }
}

/* ----- Audio element styling (light tweak) ----- */
audio::-webkit-media-controls-panel {
  background: var(--surface-2);
}
