/* ============================================================
   Hội chẩn — Apple-style Chat UI
   ============================================================ */

/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:            #f2f2f7;
  --surface:       #ffffff;
  --surface2:      #f9f9fb;
  --border:        #e2e2e7;
  --text:          #1d1d1f;
  --text-secondary:#6e6e73;
  --accent:        #007aff;   /* Apple blue */
  --accent-dark:   #0062cc;
  --bubble-mine:   #007aff;
  --bubble-other:  #ffffff;
  --bubble-mine-t: #ffffff;
  --bubble-other-t:#1d1d1f;
  --shadow:        0 2px 12px rgba(0,0,0,.08);
  --radius:        18px;
  --radius-sm:     12px;
  --glass-bg:      rgba(255,255,255,.38);
  --glass-stroke:  rgba(255,255,255,.6);
  --glass-shadow:  0 20px 50px rgba(31,38,135,.18), 0 2px 10px rgba(0,0,0,.06);
  --grid-line:     rgba(0,0,0,.06);
  --font:          -apple-system, BlinkMacSystemFont, "SF Pro Display",
                   "Segoe UI", system-ui, sans-serif;
  --mono:          "SF Mono", "Fira Code", monospace;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

/* ── Hidden util ── */
.hidden { display: none !important; }

/* ============================================================
   LAYOUT SHELL
   ============================================================ */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.screen.loginScreen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  /* subtle gradient backdrop */
  background:
    radial-gradient(ellipse 80% 60% at 30% 20%, rgba(0,122,255,.07) 0%, transparent 70%),
    radial-gradient(ellipse 60% 50% at 75% 80%, rgba(0,122,255,.05) 0%, transparent 70%),
    var(--bg);
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 28px;
  box-shadow: var(--shadow), 0 1px 0 var(--border) inset;
  padding: 48px 36px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* brand row */
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.homeBtnLogin {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background: var(--surface);
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s, transform .15s;
  box-shadow: 0 8px 18px rgba(0,0,0,.08);
}
.homeBtnLogin svg {
  width: 24px;
  height: 24px;
}
.homeBtnLogin:hover {
  color: var(--text);
  background: var(--surface2);
  border-color: #d7d7dd;
  transform: translateY(-1px);
}

.homeBtnLoginFloat {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 5;
}

.brandIcon {
  width: 58px;
  height: 58px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  border: 1px solid var(--border);
  background: var(--surface2);
  box-shadow: 0 8px 18px rgba(0,0,0,.08);
}
.brandIcon svg {
  width: 24px;
  height: 24px;
}

.title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.3px;
  color: var(--text);
}

@media (max-width: 768px) {
  .title {
    font-size: 18px;
  }
}

.subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Google button wrapper — center the rendered button */
.googleBtn {
  display: flex;
  justify-content: center;
  width: 100%;
}

.hint {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.5;
}

/* WS debug label */
.tiny {
  font-size: 10px;
  color: #aaa;
  text-align: center;
  word-break: break-all;
}
.mono {
  font-family: var(--mono);
  font-size: 9.5px;
  color: #999;
}

/* ============================================================
   CHAT SCREEN
   ============================================================ */
.screen.chatScreen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;            /* let flex children scroll */
  background:
    radial-gradient(ellipse 60% 50% at 20% 15%, rgba(255,255,255,.55) 0%, transparent 70%),
    radial-gradient(ellipse 50% 40% at 80% 85%, rgba(0,122,255,.12) 0%, transparent 70%),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    var(--bg);
  background-size: auto, auto, 26px 26px, 26px 26px, auto;
}

/* ── Liquid glass treatment ── */
.liquidGlass {
  position: relative;
  isolation: isolate;
  background: var(--glass-bg);
  border: 1px solid var(--glass-stroke);
  box-shadow: var(--glass-shadow);
  -webkit-backdrop-filter: blur(22px) saturate(1.35);
  backdrop-filter: blur(22px) saturate(1.35);
}
.liquidGlass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    linear-gradient(135deg, rgba(255,255,255,.6), rgba(255,255,255,0) 55%),
    radial-gradient(120% 80% at 10% 0%, rgba(255,255,255,.55) 0%, transparent 55%);
  opacity: .6;
  filter: url(#liquidGlass);
  pointer-events: none;
  mix-blend-mode: screen;
}
.liquidGlass > * {
  position: relative;
  z-index: 1;
}

.glassDefs {
  position: absolute;
  width: 0;
  height: 0;
}

/* ── Single chat shell ── */
.chatShell {
  flex: 1;
  min-height: 0;
  margin: 14px 16px;
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.cooldownToast {
  position: absolute;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text);
  background: rgba(255,255,255,.75);
  border: 1px solid rgba(255,255,255,.6);
  box-shadow: 0 8px 20px rgba(31,38,135,.12);
  z-index: 2;
}

/* ── Top Bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: transparent;
  flex-shrink: 0;
  /* safe-area for notch */
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid rgba(255,255,255,.35);
}

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

.homeBtn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background: var(--surface);
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s;
}
.homeBtn:hover {
  color: var(--text);
  background: var(--surface2);
  border-color: #d7d7dd;
}
.homeBtn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pill {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(0,122,255,.08);
  padding: 4px 12px;
  border-radius: 20px;
  letter-spacing: -.2px;
}

.me {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.ghostBtn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  transition: background .15s, color .15s;
  display: flex;
  align-items: center;
  gap: 5px;
}
.ghostBtn:hover {
  background: rgba(0,0,0,.05);
  color: var(--text);
}
.ghostBtn svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Messages Area ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
  background: transparent;
}

/* hide scrollbar on desktop for cleaner look */
.messages::-webkit-scrollbar          { width: 6px; }
.messages::-webkit-scrollbar-track    { background: transparent; }
.messages::-webkit-scrollbar-thumb    { background: var(--border); border-radius: 3px; }

/* ── Message Row ── */
.row {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  animation: msgIn .22s cubic-bezier(.34,1.56,.64,1) both;
}
.rowMine  { align-self: flex-end; align-items: flex-end; }
.rowOther { align-self: flex-start; align-items: flex-start; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px) scale(.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1);   }
}

/* meta row: name + time */
.meta {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  padding: 0 4px;
  font-size: 11.5px;
  color: var(--text-secondary);
  letter-spacing: .1px;
}
.meta .who {
  font-weight: 600;
  color: var(--text);
}
.delBtn {
  font-family: var(--font);
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255,138,0,.35);
  background: rgba(255,138,0,.12);
  color: #c86a00;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.delBtn:hover {
  background: rgba(255,138,0,.2);
  border-color: rgba(255,138,0,.6);
  color: #a75700;
}

.heartWrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid rgba(255,59,48,.25);
  box-shadow: 0 6px 14px rgba(0,0,0,.1);
  margin-top: -10px;
  z-index: 2;
}
.rowMine .heartWrap {
  align-self: flex-end;
}
.rowOther .heartWrap {
  align-self: flex-start;
}
.heartBtn {
  font-family: var(--font);
  font-size: 12px;
  padding: 0;
  border: none;
  background: #ffffff;
  color: #ff3b30;
  cursor: pointer;
}
.heartBtn:disabled {
  opacity: .55;
  cursor: not-allowed;
}
.heartCount {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 12px;
}
.meta .time {
  font-weight: 500;
  color: var(--text-secondary);
  background: rgba(0,0,0,.05);
  padding: 2px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.rowMine .meta {
  justify-content: flex-end;
}
.rowMine .meta .time {
  background: rgba(0,122,255,.12);
  color: var(--accent-dark);
}

/* ── Bubbles ── */
.bubble {
  padding: 9px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
  position: relative;
  background: rgba(255,255,255,.35);
  border: 1px solid rgba(255,255,255,.5);
  box-shadow: 0 6px 18px rgba(31,38,135,.18);
  -webkit-backdrop-filter: blur(20px) saturate(1.55);
  backdrop-filter: blur(20px) saturate(1.55);
  position: relative;
}
.bubble::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    linear-gradient(135deg, rgba(255,255,255,.6), rgba(255,255,255,0) 55%),
    radial-gradient(120% 80% at 10% 0%, rgba(255,255,255,.55) 0%, transparent 55%);
  opacity: .55;
  filter: url(#liquidGlass);
  pointer-events: none;
  mix-blend-mode: screen;
}
.bubble > * {
  position: relative;
  z-index: 1;
}

/* mine — Apple blue */
.bubble.mine {
  background: rgba(0,122,255,.35);
  color: #0f2a4d;
  border-bottom-right-radius: 4px;
}

/* other — white card */
.bubble.other {
  background: rgba(255,255,255,.5);
  color: var(--bubble-other-t);
  border-bottom-left-radius: 4px;
}

/* file bubble */
.fileWrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 180px;
}
.fileImg {
  max-width: 260px;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: block;
}
.fileInfo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.fileName {
  font-weight: 600;
  font-size: 13px;
  color: inherit;
  word-break: break-all;
}
.fileMeta {
  font-size: 11.5px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.fileLink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: inherit;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(0,0,0,.06);
}
.bubble.mine .fileLink {
  background: rgba(255,255,255,.18);
}

/* ── Composer / Input Footer ── */
.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: transparent;
  flex-shrink: 0;
  border-top: 1px solid rgba(255,255,255,.35);
}

.fileInput {
  display: none;
}

.fileBtn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background .15s, color .15s, border-color .15s;
}
.fileBtn:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: #d7d7dd;
}
.fileBtn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.input {
  flex: 1;
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  background: rgba(255,255,255,.65);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 22px;
  padding: 10px 18px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  /* prevent zoom on iOS */
  font-size: max(16px, 15px);
}
.input::placeholder {
  color: #aaa;
}
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,122,255,.15);
}

.sendBtn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(145deg, #34aaff, #007aff);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,122,255,.3);
  transition: transform .15s, box-shadow .15s;
}
.sendBtn:active {
  transform: scale(.9);
  box-shadow: 0 1px 4px rgba(0,122,255,.25);
}
.sendBtn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #fff;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  /* nudge arrow visually to center */
  transform: translateX(1px);
}

/* ============================================================
   RESPONSIVE — mobile
   ============================================================ */
@media (max-width: 480px) {
  .card {
    padding: 40px 24px 28px;
    border-radius: 24px;
  }
  .messages {
    padding: 12px 12px;
  }
  .row { max-width: 82%; }
  .topbar { padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top,0px)); }
  .composer { padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom,0px)); }
  .chatShell { margin: 10px 10px; border-radius: 20px; }
  .ghostBtnText { display: none; }
  .ghostBtn { padding: 6px; gap: 0; }
}

/* Full-screen login on very small screens */
@media (max-width: 360px) {
  .screen.loginScreen { padding: 16px; }
  .card { padding: 36px 18px 24px; }
}
