:root {
  --primary: #0a2f24;
  --primary-mid: #134033;
  --primary-deep: #062016;
  --heading: #062016;
  --gold: #c5a059;
  --gold-bright: #e0c07a;
  --bg: #f5f2ea;
  --bg-2: #ebe6db;
  --ink: #1a2a22;
  --muted: #5a6860;
  --card: #ffffff;
  --line: rgba(10, 47, 36, 0.12);
  --danger: #9b2c2c;
  --shadow: 0 12px 32px rgba(6, 32, 22, 0.1);
  --font: "Vazirmatn", system-ui, sans-serif;
  --fs: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --header-h: 58px;
  --tab-h: 64px;
  --ico: 44px;
  --ico-font: 1.25rem;
  --ico-radius: 14px;
  --login-grad: linear-gradient(180deg, #fbf8f3 0%, #f4efe7 55%, #eef5ef 100%);
  --desktop-bg: #e8e0d4;
  --girih: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='none' stroke='%23c5a059' stroke-width='1' opacity='.22'%3E%3Cpath d='M40 4 L76 40 L40 76 L4 40 Z'/%3E%3Cpath d='M40 16 L64 40 L40 64 L16 40 Z'/%3E%3C/g%3E%3C/svg%3E");
}

html[data-theme="dark"] {
  --primary: #2f7a4d;
  --primary-mid: #1a4a35;
  --primary-deep: #0b1812;
  --heading: #e8c878;
  --gold: #d4b56a;
  --gold-bright: #e8c878;
  --bg: #0b1410;
  --bg-2: #132019;
  --ink: #f0ebe4;
  --muted: #b7c0b8;
  --card: #15221b;
  --line: rgba(240, 235, 228, 0.12);
  --shadow: none;
  --login-grad: linear-gradient(180deg, #0b1410 0%, #132019 55%, #0f1c16 100%);
  --desktop-bg: #070d0a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: var(--font);
  font-size: max(18px, var(--fs));
  color: var(--ink);
  background: var(--bg);
  line-height: 1.7;
  overscroll-behavior: none;
}
button, textarea, select, input { font: inherit; color: inherit; }
*::-webkit-scrollbar { display: none; width: 0; height: 0; }
* { scrollbar-width: none; }

.splash {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-content: center; justify-items: center; gap: .55rem;
  background:
    var(--girih),
    radial-gradient(900px 420px at 85% -5%, rgba(197, 160, 89, .35), transparent 55%),
    radial-gradient(700px 380px at 0% 100%, rgba(255, 255, 255, .06), transparent 45%),
    linear-gradient(160deg, var(--primary-mid), var(--primary-deep));
  background-size: 80px 80px, auto, auto, auto;
  color: #fff;
  transition: opacity .35s ease, visibility .35s ease;
}
.splash.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-mark {
  width: 96px; height: 96px; border-radius: 26px;
  border: 0;
  background: transparent center / contain no-repeat;
  box-shadow: none;
  animation: pulse 1.6s ease-in-out infinite;
}
.splash strong { font-size: 1.45rem; }
.splash span { opacity: .84; font-size: .95rem; }
@keyframes pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.045)} }

.app-frame {
  height: 100%; max-width: 480px; margin: 0 auto;
  position: relative; display: flex; flex-direction: column;
  background: var(--bg); box-shadow: var(--shadow);
}

.screen {
  display: none !important;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding-top: var(--safe-t);
  padding-bottom: calc(var(--tab-h) + var(--safe-b));
}
.screen.active { display: flex !important; animation: in .22s ease; }
@keyframes in { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }

.app-header {
  min-height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px);
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
}
.app-header.marja-header,
.app-header.brand-green {
  background:
    var(--girih),
    linear-gradient(180deg, var(--primary-mid) 0%, var(--primary-deep) 100%);
  background-size: 72px 72px, auto;
  border-bottom: 0;
  color: #fff;
  padding-top: .75rem;
  padding-bottom: .75rem;
}
.app-header.marja-header .brand-head strong,
.app-header.brand-green .brand-head strong { color: var(--gold-bright); font-size: 1.12rem; }
.app-header.marja-header .brand-head .sub,
.app-header.brand-green .brand-head .sub { color: rgba(255,255,255,.78); }
.app-header.marja-header .icon-round,
.app-header.brand-green .icon-round {
  background: rgba(255,255,255,.1);
  border-color: rgba(197, 160, 89, .35);
  color: var(--gold-bright);
}
.brand-mark {
  width: var(--ico); height: var(--ico); border-radius: var(--ico-radius); flex: 0 0 auto;
  background: transparent center / contain no-repeat;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
}
.brand-row {
  display: flex; align-items: center; gap: .7rem; min-width: 0;
}
.brand-row .brand-head { text-align: right; }
.gold-divider {
  width: 88px; height: 2px; border-radius: 99px;
  margin: .2rem auto .55rem;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  position: relative;
}
.gold-divider::after {
  content: "";
  position: absolute; left: 50%; top: 50%;
  width: 8px; height: 8px;
  transform: translate(-50%, -50%) rotate(45deg);
  background: var(--gold);
  border-radius: 1px;
  box-shadow: 0 0 0 3px var(--card);
}
.brand-head { display: grid; gap: .05rem; }
.brand-head strong { font-size: 1.1rem; color: var(--heading); }
.brand-head .sub { color: var(--muted); font-size: .85rem; }
.spacer { width: var(--ico); height: var(--ico); flex: 0 0 auto; }

/* Shared icon sizing — header, footer tabs, chat, mode cards */
.icon-round,
.tab-ico,
.chat-send,
.mode-ico,
.marja-other-ico,
.fab,
.chat-avatar,
.brand-mark,
.expert-photo,
.profile-avatar,
.mode-arrow {
  width: var(--ico);
  height: var(--ico);
  font-size: var(--ico-font);
  line-height: 1;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  box-sizing: border-box;
}
.icon-round {
  border-radius: var(--ico-radius);
  border: 1px solid var(--line); background: var(--card);
  cursor: pointer;
}
.icon-round.back { transform: scaleX(-1); }

.home-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 1rem;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.home-scroll.mode-home {
  background:
    linear-gradient(180deg, var(--primary-deep) 0, var(--primary-deep) 10px, transparent 10px),
    var(--bg);
  /* Keep last actions clear of tabbar; FAB is hidden on home */
  padding-bottom: 1.25rem;
}
.home-sheet {
  background: var(--card);
  border-radius: 28px 28px 18px 18px;
  padding: 1.15rem 1rem 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  min-height: min(60vh, 480px);
  height: auto;
  flex: 0 0 auto; /* never shrink shorter than content — prevents card clipping grid */
  display: flex;
  flex-direction: column;
  gap: .75rem;
  overflow: visible;
}
.home-brand-foot {
  margin-top: auto;
  padding-top: 1.25rem;
  display: grid; place-items: center; gap: .35rem;
  opacity: .85;
}
.home-brand-foot .brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  box-shadow: none;
}
.home-brand-foot span {
  font-size: .78rem; color: var(--muted);
}

.field-label {
  display: block; margin-bottom: .4rem;
  color: var(--muted); font-size: .92rem; font-weight: 600;
}
.marja-block { margin-bottom: 1rem; }
.marja-row select {
  width: 100%; border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); padding: .8rem .9rem;
  box-shadow: var(--shadow);
}
.marja-chips {
  display: flex; gap: .45rem; overflow-x: auto;
  padding: .65rem 0 .1rem; margin-top: .2rem;
}
.marja-chip {
  flex: 0 0 auto; border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
  border-radius: 999px; padding: .45rem .85rem; cursor: pointer;
}
.marja-chip.active {
  background: var(--primary); color: #fff; border-color: transparent;
  box-shadow: 0 6px 16px rgba(26, 74, 42, .25);
}

.search-hero { margin-bottom: 1rem; }
.search-box {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: .85rem; box-shadow: var(--shadow);
}
.search-box textarea {
  width: 100%; border: 0; resize: vertical; min-height: 96px;
  background: transparent; outline: none; padding: .25rem;
}
.search-btn { width: 100%; margin-top: .55rem; }

.filters-row {
  display: grid; gap: .55rem; margin-bottom: .85rem;
}
.mini { display: grid; gap: .25rem; color: var(--muted); font-size: .85rem; }
.mini select {
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); padding: .55rem .7rem;
}
.font-row { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: .4rem .75rem; cursor: pointer;
}
.chip:hover { border-color: var(--gold); }

.status { min-height: 1.4rem; color: var(--muted); margin-bottom: .55rem; }
.results { display: grid; gap: .8rem; }
.result-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 1rem; box-shadow: var(--shadow);
}
.result-card .meta {
  display: flex; flex-wrap: wrap; gap: .4rem .75rem;
  color: var(--muted); font-size: .88rem; margin-bottom: .45rem;
}
.result-card .score { color: var(--primary); font-weight: 700; }
.result-card .gold { color: var(--gold); font-weight: 600; }
.result-card p { margin: 0 0 .8rem; }
.hidden { display: none !important; }

.btn {
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); padding: .75rem 1rem; cursor: pointer;
}
.btn.primary {
  background: linear-gradient(145deg, var(--primary-mid), var(--primary-deep));
  color: #fff; border: 0;
}
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.field { display: grid; gap: .35rem; margin-bottom: .85rem; }
.field span { color: var(--muted); font-size: .9rem; }
.field input, .field textarea, .field select {
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); padding: .75rem .85rem;
}
.scroll-pad { padding: 1rem; overflow: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet { padding: 0 1rem 1rem; }
.hint { color: var(--muted); font-size: .9rem; }
.card-panel, .expert-card, .list-card, .auth-form {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: .95rem 1rem; margin-bottom: .75rem;
  box-shadow: var(--shadow);
}
.list-end { text-align: center; color: var(--muted); padding: .8rem; font-size: .9rem; }
.history-section-title {
  margin: .35rem 0 .55rem;
  font-size: .95rem;
  color: var(--primary);
}
.history-badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: .15rem .55rem;
  margin-bottom: .35rem;
}
.history-badge.ai {
  background: rgba(26,74,42,.12);
  color: var(--primary);
}
.history-badge.expert {
  background: rgba(200,164,90,.22);
  color: #7a5a1a;
}
.consult-card .consult-preview {
  margin: .35rem 0 .55rem;
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.55;
}
.consult-card .btn { margin-top: .15rem; }

.tabbar {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + var(--safe-b));
  padding: .35rem .4rem calc(.35rem + var(--safe-b));
  display: grid; grid-template-columns: repeat(3, 1fr); gap: .2rem;
  background: color-mix(in srgb, var(--card) 94%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px); z-index: 20;
}
.tab {
  border: 0; background: transparent; color: var(--muted);
  display: grid; gap: .15rem; justify-items: center; align-content: center;
  padding: .35rem .2rem; border-radius: 14px; cursor: pointer; font-size: .78rem;
  transition: color .15s ease, background .15s ease;
}
.tab-ico {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: transparent;
  color: inherit;
  font-size: 0; /* hide any leftover glyph text */
}
.tab-ico svg {
  width: 22px;
  height: 22px;
  display: block;
}
.tab.active {
  color: var(--heading);
  background: rgba(197, 160, 89, .18);
  font-weight: 700;
}
.tab.active .tab-ico {
  color: var(--gold);
  background: rgba(197, 160, 89, .16);
}
html[data-theme="dark"] .tab.active {
  color: var(--gold-bright);
  background: rgba(197, 160, 89, .14);
}
html[data-theme="dark"] .tab.active .tab-ico {
  color: var(--gold-bright);
  background: rgba(197, 160, 89, .18);
}

.fab {
  position: absolute; left: 1rem;
  bottom: calc(var(--tab-h) + var(--safe-b) + .85rem);
  border: 0; border-radius: 50%;
  background: linear-gradient(145deg, var(--gold-bright), var(--gold));
  color: #062016;
  box-shadow: 0 12px 28px rgba(197, 160, 89, .45);
  z-index: 25; cursor: pointer;
}
.fab:active { transform: scale(.96); }
/* History list must clear the FAB */
#screenHistory .scroll-pad {
  padding-bottom: calc(var(--ico) + 1.75rem);
}

.sheet-dialog {
  border: 0; border-radius: 20px; padding: 0;
  width: min(720px, calc(100% - 1.5rem));
  background: var(--card); color: var(--ink);
  box-shadow: var(--shadow);
}
.sheet-dialog::backdrop { background: rgba(18, 30, 22, .45); }
.sheet-dialog article { padding: 1rem 1.1rem 1.15rem; }
.sheet-dialog header { display: flex; justify-content: space-between; align-items: center; }
.sheet-dialog h3 { margin: 0; color: var(--primary); }
.dialog-body { white-space: pre-wrap; margin: .75rem 0 1rem; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

@media (min-width: 900px) {
  body {
    background:
      radial-gradient(900px 500px at 15% 0%, rgba(200,164,90,.18), transparent 55%),
      radial-gradient(700px 400px at 90% 10%, rgba(26,74,42,.12), transparent 50%),
      var(--desktop-bg);
    display: grid; place-items: center;
  }
  .app-frame {
    height: min(860px, 92vh); width: 420px; max-width: 420px;
    border-radius: 24px; overflow: hidden; border: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  body { font-size: max(18px, var(--fs)); }
}

/* —— Mode home / wizard —— */
.mode-home {
  display: flex;
  flex-direction: column;
  gap: .85rem;
  padding-top: .35rem;
  align-items: stretch;
}
.home-step {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  flex: 0 0 auto;
  min-height: 0;
}
.step-progress {
  display: flex; gap: .4rem; margin-bottom: .15rem;
}
.step-progress span {
  flex: 1; height: 4px; border-radius: 99px;
  background: var(--line);
}
.step-progress span.on { background: var(--primary); }
.step-progress span.done { background: color-mix(in srgb, var(--primary) 55%, var(--gold)); }
.step-title {
  margin: 0;
  font-size: 1.22rem;
  color: var(--heading);
  line-height: 1.45;
  text-align: center;
}
.step-back {
  align-self: flex-start;
  border: 0; background: transparent;
  color: var(--muted); padding: 0;
  font-size: .9rem; cursor: pointer;
}
.step-back:active { color: var(--primary); }
.marja-pick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
  flex: 0 0 auto;
}
.marja-pick-btn {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--line);
  background-color: var(--bg-2);
  background-image: none;
  color: var(--heading);
  border-radius: 12px;
  padding: .95rem .55rem;
  text-align: center;
  cursor: pointer;
  font-size: .86rem;
  line-height: 1.45;
  box-shadow: none;
  transition: transform .12s ease, border-color .12s ease, background-color .12s ease, color .12s ease;
  min-height: 3.4rem;
}
.marja-pick-btn:active { transform: scale(.98); }
.marja-pick-btn.active {
  background-color: var(--primary);
  color: #fff;
  border-color: transparent;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(6, 32, 22, 0.22);
}
/* Odd last item: full-width so the grid doesn’t leave a lone cell */
.marja-pick-btn:last-child:nth-child(odd) {
  grid-column: 1 / -1;
  max-width: 100%;
}
.marja-pick-btn.marja-pick-collapsed {
  display: none !important;
}
.marja-other {
  display: flex; align-items: center; gap: .75rem;
  width: 100%; text-align: right;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 16px;
  padding: .95rem 1rem;
  margin-top: .35rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  color: var(--ink);
  flex: 0 0 auto;
  position: relative;
  z-index: 1;
}
.marja-other-ico {
  border-radius: var(--ico-radius);
  background: rgba(26, 74, 42, 0.08);
  color: var(--primary);
}
.marja-other span:nth-child(2) { flex: 1; font-weight: 700; color: var(--heading); }
.mode-lead {
  margin: 0;
  color: var(--muted);
  font-size: .95rem;
  line-height: 1.6;
  text-align: center;
}
.mode-lead strong { color: var(--ink); }
.mode-card {
  display: flex; align-items: center; gap: .85rem;
  width: 100%; text-align: right;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 20px;
  padding: 1.1rem 1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease;
}
.mode-card:active { transform: scale(.985); }
.mode-card:hover { border-color: color-mix(in srgb, var(--primary) 35%, var(--line)); }
.mode-ico {
  border-radius: var(--ico-radius);
  background: linear-gradient(145deg, var(--primary-mid), var(--primary-deep));
  color: var(--gold-bright);
}
.mode-card-expert .mode-ico {
  background: linear-gradient(145deg, #8a6a2e, #5c4518);
  color: #fff;
}
.mode-body { flex: 1; display: grid; gap: .2rem; min-width: 0; }
.mode-body strong { font-size: 1.05rem; color: var(--heading); }
.mode-body span { color: var(--muted); font-size: .88rem; line-height: 1.45; }
.mode-arrow {
  color: var(--muted);
  transform: scaleX(-1);
}

/* —— Chat (aligned with store mock: deep green) —— */
.screen.chat-screen {
  padding-bottom: var(--safe-b);
  background: var(--chat-bg, #062016);
  --chat-bg: #062016;
  --chat-bubble-me: #1a5c3f;
  --chat-bubble-them: #121c17;
  --chat-ink: #f0ebe4;
  --chat-muted: #b7c0b8;
}
html[data-theme="light"] .screen.chat-screen {
  --chat-bg: #062016;
}
html[data-theme="dark"] .screen.chat-screen {
  --chat-bg: #04140f;
}

.chat-header {
  min-height: var(--header-h);
  display: flex; align-items: center; gap: .65rem;
  padding: .5rem .75rem;
  background:
    var(--girih),
    linear-gradient(180deg, var(--primary-mid), var(--primary-deep));
  background-size: 64px 64px, auto;
  color: #fff;
  border-bottom: 1px solid rgba(197, 160, 89, .18);
  z-index: 6;
}
.chat-header .icon-round {
  background: rgba(255,255,255,.1);
  border-color: rgba(197, 160, 89, .35);
  color: var(--gold-bright);
}
.chat-peer {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: .65rem;
}
.chat-peer strong { display: block; font-size: 1rem; line-height: 1.3; color: var(--gold-bright); }
.chat-status { display: block; font-size: .78rem; opacity: .82; line-height: 1.3; }
.chat-avatar {
  border-radius: 50%;
  background: rgba(10, 47, 36, .85) center / 72% no-repeat;
  border: 1px solid rgba(197, 160, 89, .45);
  color: transparent;
  overflow: hidden;
}
.chat-avatar.ai,
.chat-avatar.brand {
  background-color: #0a2f24;
  background-image: url("../icons/icon-192.png");
  background-size: cover;
  background-position: center;
}
.chat-avatar.expert { background: rgba(255,255,255,.14); color: #fff; }

.chat-toolbar {
  display: grid; grid-template-columns: 1fr 1fr; gap: .45rem;
  padding: .45rem .65rem;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  border-bottom: 1px solid var(--line);
}
.chat-tool {
  display: grid; gap: .15rem;
  font-size: .72rem; color: var(--muted);
}
.chat-tool select {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  padding: .4rem .55rem;
  font-size: .85rem;
}

.chat-thread {
  flex: 1; min-height: 0;
  overflow: auto;
  padding: .85rem .7rem 1rem;
  display: flex; flex-direction: column; gap: .55rem;
  -webkit-overflow-scrolling: touch;
  color: var(--chat-ink, var(--ink));
  background:
    var(--girih),
    radial-gradient(circle at 12% 8%, rgba(47,122,77,.14), transparent 40%),
    radial-gradient(circle at 88% 20%, rgba(197,160,89,.1), transparent 42%),
    var(--chat-bg, #062016);
  background-size: 96px 96px, auto, auto, auto;
}
html[data-theme="dark"] .chat-thread {
  background:
    var(--girih),
    radial-gradient(circle at 12% 8%, rgba(47,122,77,.12), transparent 40%),
    radial-gradient(circle at 88% 20%, rgba(197,160,89,.08), transparent 42%),
    var(--chat-bg);
  background-size: 96px 96px, auto, auto, auto;
}

.msg {
  max-width: 86%;
  display: flex; flex-direction: column; gap: .25rem;
  animation: bubble-in .18s ease;
}
.msg.them {
  flex-direction: row;
  align-items: flex-end;
  gap: .45rem;
  max-width: 92%;
}
.msg.them .msg-ava {
  width: 32px; height: 32px; border-radius: 50%; flex: 0 0 auto;
  background: #0a2f24 center / cover no-repeat;
  background-image: url("../icons/icon-192.png");
  border: 1px solid rgba(197,160,89,.4);
  margin-bottom: .15rem;
}
.msg.them .bubble { flex: 1; min-width: 0; }
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.msg.me { align-self: flex-end; }
.msg.them { align-self: flex-start; }
.msg.system { align-self: center; max-width: 92%; }

.bubble {
  position: relative;
  padding: .55rem .75rem .4rem;
  border-radius: 14px;
  box-shadow: 0 1px 1px rgba(0,0,0,.06);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
}
.msg.me .bubble {
  background: var(--chat-bubble-me, #1a5c3f);
  color: #eef6ef;
  border-bottom-left-radius: 4px;
}
.msg.them .bubble {
  background: var(--chat-bubble-them, #121c17);
  color: var(--chat-ink, #f0ebe4);
  border-bottom-right-radius: 4px;
  border: 1px solid rgba(197, 160, 90, 0.16);
}
html[data-theme="dark"] .msg.me .bubble {
  background: #1e4a30;
  color: #eef6ef;
}
.bubble-meta {
  border-top-color: rgba(200, 164, 90, 0.22) !important;
}
.bubble-meta .cite-label,
.msg.them .bubble-meta {
  color: var(--gold) !important;
}
.msg.system .bubble {
  background: color-mix(in srgb, var(--card) 70%, transparent);
  color: var(--muted);
  font-size: .82rem;
  text-align: center;
  border-radius: 999px;
  padding: .35rem .85rem;
  box-shadow: none;
}
.bubble-meta {
  display: flex; flex-wrap: wrap; gap: .25rem .55rem;
  font-size: .75rem; color: var(--muted); margin-top: .45rem;
  padding-top: .35rem; border-top: 1px solid var(--line);
}
.bubble-meta .cite-label {
  color: var(--primary); font-weight: 700; margin-inline-end: .15rem;
}
.bubble-time {
  align-self: flex-end;
  font-size: .68rem;
  color: color-mix(in srgb, var(--ink) 45%, transparent);
  margin-top: .15rem;
}
.msg.me .bubble-time { color: rgba(238, 246, 239, 0.55); }
html[data-theme="dark"] .msg.me .bubble-time { color: rgba(238,246,239,.55); }

.bubble-actions {
  display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .35rem;
}
.bubble-actions .btn {
  padding: .35rem .65rem; font-size: .78rem; border-radius: 10px;
}

.rate-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: .25rem;
  margin-top: .45rem;
}
.rate-row .rate-label {
  font-size: .75rem; color: var(--muted); margin-inline-end: .25rem;
}
.rate-star {
  border: 0; background: transparent; padding: .1rem .15rem;
  font-size: var(--ico-font); line-height: 1; cursor: pointer;
  color: color-mix(in srgb, var(--gold) 55%, var(--muted));
}
.rate-star.on, .rate-star:hover, .rate-star:focus-visible {
  color: var(--gold);
}
.rate-row.done .rate-star { cursor: default; }
.rate-thanks {
  font-size: .78rem; color: var(--primary); margin-top: .25rem;
}

.typing {
  display: inline-flex; gap: .28rem; align-items: center;
  padding: .7rem .9rem;
}
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: typing 1.1s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes typing {
  0%, 80%, 100% { opacity: .35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.chat-composer {
  display: flex; align-items: flex-end; gap: .45rem;
  padding: .45rem .55rem calc(.45rem + env(safe-area-inset-bottom, 0px));
  background: #04140f;
  border-top: 1px solid rgba(197, 160, 89, 0.16);
}
.chat-composer textarea {
  flex: 1; min-height: 44px; max-height: 120px;
  resize: none; border: 0;
  border-radius: 22px;
  background: #1a2820;
  color: #f0ebe4;
  padding: .7rem 1rem;
  outline: none;
  line-height: 1.45;
}
.chat-composer textarea::placeholder { color: rgba(240, 235, 228, 0.45); }
.chat-toolbar {
  background: #132019 !important;
  border-bottom-color: rgba(200, 164, 90, 0.14) !important;
  color: var(--chat-muted, #b7c0b8);
}
.chat-tool select {
  background: #1a2820 !important;
  color: #f0ebe4 !important;
  border-color: rgba(200, 164, 90, 0.18) !important;
}
.chat-send {
  border: 0; border-radius: 50%;
  background: linear-gradient(145deg, #1a5c3f, #0a2f24);
  color: #fff;
  cursor: pointer;
  transform: scaleX(-1);
  box-shadow: 0 6px 14px rgba(6,32,22,.35);
}
.chat-send:disabled { opacity: .45; cursor: default; box-shadow: none; }

.app-frame.chat-open .tabbar,
.app-frame.chat-open .fab { display: none !important; }

.expert-card {
  display: grid; gap: .45rem;
  cursor: pointer;
  transition: border-color .15s ease, transform .15s ease;
}
.expert-card:active { transform: scale(.985); }
.expert-card-head {
  display: flex; align-items: center; gap: .75rem;
}
.expert-photo {
  border-radius: 50%;
  background: linear-gradient(145deg, var(--primary), #123520);
  color: #fff;
  overflow: hidden;
  border: 1px solid var(--line);
}
.expert-photo img,
.chat-avatar-img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.expert-card-title { flex: 1; min-width: 0; display: grid; gap: .15rem; }
.expert-card-sub {
  display: flex; flex-wrap: wrap; gap: .25rem .65rem;
  color: var(--muted); font-size: .82rem;
}
.expert-card .meta-row {
  display: flex; flex-wrap: wrap; gap: .35rem .75rem;
  color: var(--muted); font-size: .85rem;
}
.expert-pending-banner {
  margin: 0 0 .85rem;
  padding: .85rem 1rem;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--primary) 28%, var(--line));
  background: color-mix(in srgb, var(--primary) 8%, var(--bg));
  display: grid;
  gap: .35rem;
}
.expert-pending-banner.hidden,
.expert-pending-banner[hidden] { display: none; }
.expert-pending-banner strong { font-size: .92rem; color: var(--primary); }
.expert-pending-banner p {
  margin: 0;
  font-size: .9rem;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.expert-pending-banner .hint { margin: 0; font-size: .8rem; }
.bubble-actions .btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}
.chat-avatar.has-photo {
  padding: 0; overflow: hidden; background: transparent;
}

/* Profile / wallet */
.profile-card {
  display: flex; align-items: center; gap: .9rem;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 1rem 1.05rem; margin-bottom: .75rem;
  box-shadow: var(--shadow);
}
.profile-avatar {
  border-radius: var(--ico-radius);
  background: linear-gradient(145deg, var(--primary), #123520);
  color: #fff;
  font-weight: 700;
}
.profile-meta { display: grid; gap: .15rem; min-width: 0; }
.profile-name {
  font-size: 1.15rem; line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.profile-email {
  color: var(--muted); font-size: .9rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.profile-role {
  justify-self: start;
  margin-top: .2rem;
  font-size: .75rem; font-weight: 700;
  color: var(--primary);
  background: rgba(26, 74, 42, .1);
  border-radius: 999px; padding: .12rem .55rem;
}
html[data-theme="dark"] .profile-role {
  background: rgba(47, 122, 77, .22);
}

.wallet-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 22px; padding: 1.1rem 1.05rem; margin-bottom: .75rem;
  box-shadow: var(--shadow);
}
.wallet-top {
  display: flex; align-items: center; gap: .85rem; margin-bottom: .85rem;
}
.wallet-ico {
  width: 52px; height: 52px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--primary-mid), var(--primary-deep));
  color: var(--gold-bright); font-size: 1.35rem;
  box-shadow: 0 6px 16px rgba(6,32,22,.18);
}
.wallet-label {
  margin: 0;
  color: var(--muted); font-size: .92rem; font-weight: 600;
}
.wallet-title {
  margin: 0 0 .15rem;
  font-size: 1.05rem; color: var(--heading); font-weight: 800;
}
.balance-hero {
  display: flex; align-items: baseline; gap: .45rem;
  margin-bottom: .35rem;
}
.balance-value {
  font-size: clamp(2.1rem, 9vw, 2.75rem);
  font-weight: 800; line-height: 1.1;
  color: var(--heading); letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.balance-unit {
  color: var(--muted); font-size: 1rem; font-weight: 600;
}
.wallet-estimate {
  margin: 0 0 1rem;
  color: var(--muted); font-size: .95rem;
}
.wallet-estimate strong { color: var(--ink); }
.wallet-history-btn {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; margin-top: .35rem;
  border: 0; border-radius: 14px;
  background: linear-gradient(145deg, var(--primary-mid), var(--primary-deep));
  color: #fff; padding: .75rem 1rem; cursor: pointer; font-weight: 700;
}
.wallet-history-btn span:last-child { opacity: .8; transform: scaleX(-1); }

.buy-section {
  border-top: 1px solid var(--line);
  padding-top: .9rem;
}
.buy-title {
  display: block; margin-bottom: .25rem;
  font-size: 1.02rem; color: var(--ink);
}
.buy-section .hint { margin: 0 0 .7rem; }

.token-packages {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem;
}
.token-pack {
  position: relative;
  display: grid; gap: .15rem; place-items: center;
  border: 1px solid var(--line); border-radius: 16px;
  background: var(--bg-2); padding: 1rem .4rem .85rem;
  cursor: pointer; transition: border-color .15s ease, transform .12s ease, background .15s ease;
  overflow: hidden;
  color: var(--ink);
}
.token-pack:active { transform: scale(.97); }
.token-pack.featured {
  background: var(--card);
  border-color: var(--gold);
  box-shadow: 0 8px 20px rgba(197, 160, 89, .22);
  padding-top: 1.35rem;
}
.token-pack.featured .pack-ribbon {
  position: absolute; top: 0; left: 0; right: 0;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  color: #062016;
  font-size: .68rem; font-weight: 800;
  padding: .2rem .35rem; text-align: center;
}
.token-pack:disabled { opacity: .55; cursor: default; }
.pack-amount { font-size: 1.25rem; font-weight: 800; line-height: 1.2; color: var(--heading); }
.pack-label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.pack-coin {
  width: 28px; height: 28px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--gold-bright), var(--gold) 55%, #8a6a2e);
  box-shadow: inset 0 -2px 4px rgba(0,0,0,.18);
  margin-bottom: .15rem;
}

.tx-card .buy-title { margin-bottom: .55rem; }
.tx-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: .15rem;
}
.tx-item {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .55rem 0;
  border-bottom: 1px solid var(--line);
}
.tx-item:last-child { border-bottom: 0; }
.tx-item strong { display: block; font-size: .95rem; font-weight: 700; }
.tx-date { display: block; color: var(--muted); font-size: .8rem; margin-top: .05rem; }
.tx-amount {
  flex: 0 0 auto; font-weight: 800; font-variant-numeric: tabular-nums;
}
.tx-amount.plus { color: var(--primary); }
.tx-amount.minus { color: var(--danger); }

.profile-actions {
  display: grid; gap: .55rem; margin-bottom: .75rem;
}

/* —— Theme-aware surfaces (login / sheets / headers) —— */
.login-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 1.5rem 1.25rem calc(1.5rem + var(--safe-b));
  overflow: auto;
  position: relative;
  background: var(--login-grad);
  color: var(--ink);
}
.login-wrap .login-hero h1 { color: var(--heading); }
.login-wrap .login-hero p,
.login-wrap .login-switch,
.login-wrap .hint { color: var(--muted); }
.login-theme {
  position: absolute;
  top: calc(.75rem + var(--safe-t));
  left: .85rem;
  z-index: 2;
}
.brand-head strong { color: var(--heading); }
.app-header:not(.marja-header):not(.brand-green) {
  background: color-mix(in srgb, var(--card) 92%, transparent);
  color: var(--ink);
}
.app-header:not(.marja-header):not(.brand-green) strong {
  color: var(--heading);
}
.history-badge.expert { color: var(--heading); }
html[data-theme="dark"] .history-badge.ai {
  background: rgba(47, 122, 77, .22);
  color: var(--gold-bright);
}
html[data-theme="dark"] .history-badge.expert {
  background: rgba(212, 181, 106, .2);
  color: var(--gold-bright);
}
.list-card p,
.card-panel p,
.installBox p,
#installBox p { color: var(--muted); }
.card-panel strong,
.list-card strong,
.buy-title { color: var(--heading); }
html[data-theme="dark"] .btn:not(.primary):not(.ghost) {
  background: var(--card);
  border-color: var(--line);
  color: var(--ink);
}
html[data-theme="dark"] .mode-card {
  background: var(--card);
}
html[data-theme="dark"] .home-sheet {
  background: var(--card);
  border-color: var(--line);
}
html[data-theme="dark"] .tabbar {
  background: color-mix(in srgb, var(--card) 94%, transparent);
  border-top-color: var(--line);
}
html[data-theme="dark"] .field input,
html[data-theme="dark"] .field textarea,
html[data-theme="dark"] .field select,
html[data-theme="dark"] .auth-form input,
html[data-theme="dark"] .auth-form textarea {
  background: var(--bg-2);
  border-color: var(--line);
  color: var(--ink);
}
html[data-theme="dark"] .auth-form {
  background: var(--card);
  border-color: var(--line);
}
html[data-theme="dark"] .sheet-dialog {
  background: var(--card);
  color: var(--ink);
}
html[data-theme="dark"] .sheet-dialog h3 { color: var(--heading); }
html[data-theme="dark"] .profile-card,
html[data-theme="dark"] .wallet-card,
html[data-theme="dark"] .list-card,
html[data-theme="dark"] .card-panel,
html[data-theme="dark"] .expert-card {
  background: var(--card);
  border-color: var(--line);
  color: var(--ink);
}
html[data-theme="dark"] .profile-email,
html[data-theme="dark"] .wallet-label,
html[data-theme="dark"] .balance-unit { color: var(--muted); }
html[data-theme="dark"] .gold-divider::after {
  box-shadow: 0 0 0 3px var(--card);
}

/* Android WebView shell — feel native, hide web-only chrome */
html.ask-native-android #installBox,
html.ask-native-android #btnInstall { display: none !important; }
html.ask-native-android .login-links,
html.ask-native-android .admin-link,
html.ask-native-android .cross-role-links { display: none !important; }
html.ask-native-android #splash { transition-duration: .15s; }
@media (min-width: 900px) {
  html.ask-native-android body { display: block; background: var(--bg); }
  html.ask-native-android .app-frame {
    height: 100%; width: 100%; max-width: none;
    border-radius: 0; border: 0; box-shadow: none;
  }
}

