/* Karmadonov V40 — real viewport shell, independent chat scroll regions and reliable dark surfaces.
   Keep blur on compact chrome only; never blur the full scrolling message layer. */

:root {
  --km40-bg: #f2f2f6;
  --km40-panel: rgba(255,255,255,.78);
  --km40-panel-solid: #fff;
  --km40-border: rgba(65,65,80,.14);
  --km40-text: #17171c;
  --km40-muted: #777782;
  --km40-glass: blur(22px) saturate(1.45);
  --km40-motion: 180ms;
}
html.kmDarkTheme, body.kmDarkTheme, html[data-app-theme="dark"] {
  --km40-bg:#101014;
  --km40-panel:rgba(25,25,32,.78);
  --km40-panel-solid:#1d1d24;
  --km40-border:rgba(255,255,255,.13);
  --km40-text:#f4f4f7;
  --km40-muted:#aaaab5;
}

html, body { min-height:100%; overscroll-behavior-x:none; }
body.kmMessengerActive {
  height:100%;
  height:100dvh;
  min-height:0;
  overflow:hidden !important;
  overscroll-behavior:none;
}
body.kmMessengerActive #messengerView {
  position:fixed !important;
  inset:0 !important;
  z-index:10;
  display:flex !important;
  flex-direction:column !important;
  width:100%;
  height:100vh !important;
  height:100dvh !important;
  min-height:0 !important;
  max-height:100dvh;
  overflow:hidden !important;
  padding:0 !important;
  background:var(--km40-bg);
  isolation:isolate;
}


/* Shared chat-mode layout on desktop and mobile: the message viewport is the only scroller. */
#chatsPage.chatMode .pageHeading { display:none !important; }
#chatsPage.chatMode .sidebar { min-height:0; overflow-y:auto; -webkit-overflow-scrolling:touch; }
body.kmMessengerActive #messengerView > #chatsPage.chatMode {
  display:flex !important;
  flex:1 1 0 !important;
  flex-direction:column !important;
  height:auto !important;
  min-height:0 !important;
  max-height:none !important;
  overflow:hidden !important;
  padding:0 !important;
}
#chatsPage.chatMode .layout {
  display:grid;
  grid-template-columns:330px minmax(0,1fr);
  flex:1 1 0;
  width:100%;
  height:100%;
  min-height:0;
  overflow:hidden;
}
#chatsPage.chatMode .chat {
  display:flex;
  flex-direction:column;
  height:100%;
  min-height:0;
  overflow:hidden;
}
#chatsPage.chatMode .chatHeader { flex:0 0 auto; }
#chatsPage.chatMode #messages {
  flex:1 1 0;
  min-height:0;
  overflow-y:auto;
  overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;
}
#chatsPage.chatMode .composer { flex:0 0 auto; }

/* The account/title bar is outside all page scrollers, so it cannot drift away. */
body.kmMessengerActive #messengerView > .topbar {
  position:relative !important;
  inset:auto !important;
  top:auto !important;
  z-index:80 !important;
  flex:0 0 auto !important;
  min-height:calc(68px + env(safe-area-inset-top));
  padding-top:max(10px, env(safe-area-inset-top)) !important;
  padding-bottom:12px !important;
  background:var(--km40-panel) !important;
  border-bottom:1px solid var(--km40-border) !important;
  -webkit-backdrop-filter:var(--km40-glass);
  backdrop-filter:var(--km40-glass);
  box-shadow:0 1px 0 rgba(255,255,255,.42), 0 8px 26px rgba(20,20,35,.055);
}

body.kmMessengerActive #messengerView > .appPage:not(.hidden) {
  display:block !important;
  position:relative;
  flex:1 1 0 !important;
  width:100%;
  height:auto !important;
  min-height:0 !important;
  max-height:none !important;
  overflow-x:hidden !important;
  overflow-y:auto !important;
  padding:0 0 calc(100px + env(safe-area-inset-bottom)) !important;
  overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;
  scrollbar-width:thin;
  background:var(--km40-bg);
}

/* Direct chats: only #messages scrolls. Header and composer are stable flex siblings. */
@media (max-width:800px) {
  body.kmMessengerActive #messengerView > #chatsPage.chatMode {
    display:flex !important;
    flex:1 1 0 !important;
    flex-direction:column !important;
    height:auto !important;
    min-height:0 !important;
    max-height:none !important;
    overflow:hidden !important;
    padding:0 !important;
  }
  #chatsPage.chatMode .pageHeading { display:none !important; }
  #chatsPage.chatMode .layout {
    display:flex !important;
    flex:1 1 0 !important;
    flex-direction:column !important;
    width:100%;
    height:100% !important;
    min-height:0 !important;
    overflow:hidden !important;
  }
  #chatsPage.chatMode .sidebar { display:none !important; }
  #chatsPage.chatMode .chat {
    display:flex !important;
    flex:1 1 0 !important;
    flex-direction:column !important;
    width:100%;
    height:100% !important;
    min-height:0 !important;
    overflow:hidden !important;
  }
  #chatsPage.chatMode .chatHeader {
    position:relative !important;
    inset:auto !important;
    top:auto !important;
    z-index:30 !important;
    flex:0 0 auto !important;
    min-height:68px;
    padding:9px 14px !important;
    background:var(--km40-panel) !important;
    border-bottom:1px solid var(--km40-border) !important;
    -webkit-backdrop-filter:var(--km40-glass);
    backdrop-filter:var(--km40-glass);
  }
  #chatsPage.chatMode #messages {
    position:relative !important;
    flex:1 1 0 !important;
    width:100%;
    height:auto !important;
    min-height:0 !important;
    max-height:none !important;
    overflow-x:hidden !important;
    overflow-y:auto !important;
    padding:14px 12px 18px !important;
    overscroll-behavior:contain;
    -webkit-overflow-scrolling:touch;
    scroll-behavior:auto !important;
  }
  #chatsPage.chatMode .composer {
    position:relative !important;
    inset:auto !important;
    left:auto !important;
    right:auto !important;
    bottom:auto !important;
    z-index:35 !important;
    display:flex !important;
    flex:0 0 auto !important;
    width:100% !important;
    margin:0 !important;
    padding:9px 10px calc(9px + env(safe-area-inset-bottom)) !important;
    background:var(--km40-panel) !important;
    border-top:1px solid var(--km40-border) !important;
    box-shadow:0 -8px 28px rgba(20,20,35,.06) !important;
    -webkit-backdrop-filter:var(--km40-glass);
    backdrop-filter:var(--km40-glass);
  }
}

/* KAI uses the same shell; the conversation scrolls between a fixed identity row and composer. */
body.kmMessengerActive #messengerView > #kaiPage:not(.hidden) {
  display:flex !important;
  flex:1 1 0 !important;
  flex-direction:column !important;
  height:auto !important;
  min-height:0 !important;
  max-height:none !important;
  overflow:hidden !important;
  padding:0 0 calc(91px + env(safe-area-inset-bottom)) !important;
}
#kaiPage .kaiPageInner {
  display:flex !important;
  flex:1 1 0 !important;
  flex-direction:column !important;
  width:100%;
  height:100% !important;
  min-height:0 !important;
  overflow:hidden !important;
  background:transparent !important;
}
#kaiPage .kaiHeader {
  position:relative !important;
  inset:auto !important;
  top:auto !important;
  z-index:30 !important;
  flex:0 0 72px !important;
  min-height:72px;
  background:var(--km40-panel) !important;
  border-bottom:1px solid var(--km40-border) !important;
  -webkit-backdrop-filter:var(--km40-glass);
  backdrop-filter:var(--km40-glass);
}
#kaiPage #kaiMessages {
  position:relative !important;
  flex:1 1 0 !important;
  width:100%;
  height:auto !important;
  min-height:0 !important;
  max-height:none !important;
  overflow-x:hidden !important;
  overflow-y:auto !important;
  padding:16px 14px 20px !important;
  overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;
  scroll-behavior:auto !important;
  contain:layout paint;
}
#kaiPage .kaiComposer {
  position:relative !important;
  inset:auto !important;
  bottom:auto !important;
  z-index:35 !important;
  display:flex !important;
  flex:0 0 auto !important;
  width:100%;
  margin:0;
  padding:9px 10px !important;
  background:var(--km40-panel) !important;
  border-top:1px solid var(--km40-border) !important;
  -webkit-backdrop-filter:var(--km40-glass);
  backdrop-filter:var(--km40-glass);
}

/* Cups: theme selectors explicitly support both saved theme markers (html and body). */
html[data-app-theme="dark"] #cupsPage,
html.kmDarkTheme #cupsPage,
body.kmDarkTheme #cupsPage {
  background:#101014 !important;
  color:#f4f4f7 !important;
}
html[data-app-theme="dark"] #cupsPage .cupsPageInner,
html.kmDarkTheme #cupsPage .cupsPageInner,
body.kmDarkTheme #cupsPage .cupsPageInner {
  background:transparent !important;
  color:#f4f4f7 !important;
}
html[data-app-theme="dark"] #cupsPage .coffeeBalanceCard,
html[data-app-theme="dark"] #cupsPage .premiumHeroCard,
html[data-app-theme="dark"] #cupsPage .premiumPlansCard,
html[data-app-theme="dark"] #cupsPage .premiumFeaturesCard,
html[data-app-theme="dark"] #cupsPage .coffeeGiftCard,
html[data-app-theme="dark"] #cupsPage .premiumGiftsCard,
html[data-app-theme="dark"] #cupsPage .coffeeHistoryCard,
html.kmDarkTheme #cupsPage .coffeeBalanceCard,
html.kmDarkTheme #cupsPage .premiumHeroCard,
html.kmDarkTheme #cupsPage .premiumPlansCard,
html.kmDarkTheme #cupsPage .premiumFeaturesCard,
html.kmDarkTheme #cupsPage .coffeeGiftCard,
html.kmDarkTheme #cupsPage .premiumGiftsCard,
html.kmDarkTheme #cupsPage .coffeeHistoryCard,
body.kmDarkTheme #cupsPage .coffeeBalanceCard,
body.kmDarkTheme #cupsPage .premiumHeroCard,
body.kmDarkTheme #cupsPage .premiumPlansCard,
body.kmDarkTheme #cupsPage .premiumFeaturesCard,
body.kmDarkTheme #cupsPage .coffeeGiftCard,
body.kmDarkTheme #cupsPage .premiumGiftsCard,
body.kmDarkTheme #cupsPage .coffeeHistoryCard {
  background:rgba(29,29,36,.88) !important;
  color:#f4f4f7 !important;
  border:1px solid rgba(255,255,255,.12) !important;
  box-shadow:0 10px 28px rgba(0,0,0,.18) !important;
}
html[data-app-theme="dark"] #cupsPage .coffeeBalanceCard,
html.kmDarkTheme #cupsPage .coffeeBalanceCard,
body.kmDarkTheme #cupsPage .coffeeBalanceCard {
  background:linear-gradient(135deg,rgba(40,40,49,.92),rgba(25,25,32,.92)) !important;
}
html[data-app-theme="dark"] #cupsPage .premiumHeroCard,
html.kmDarkTheme #cupsPage .premiumHeroCard,
body.kmDarkTheme #cupsPage .premiumHeroCard {
  background:linear-gradient(135deg,#17171d,#101014) !important;
}
html[data-app-theme="dark"] #cupsPage .premiumPlan,
html[data-app-theme="dark"] #cupsPage .premiumGift,
html.kmDarkTheme #cupsPage .premiumPlan,
html.kmDarkTheme #cupsPage .premiumGift,
body.kmDarkTheme #cupsPage .premiumPlan,
body.kmDarkTheme #cupsPage .premiumGift {
  background:#25252e !important;
  color:#f4f4f7 !important;
  border-color:rgba(255,255,255,.13) !important;
  box-shadow:none !important;
}
html[data-app-theme="dark"] #cupsPage .premiumPlan.featured,
html.kmDarkTheme #cupsPage .premiumPlan.featured,
body.kmDarkTheme #cupsPage .premiumPlan.featured {
  background:#111116 !important;
  color:#fff !important;
  border-color:rgba(255,255,255,.19) !important;
}
html[data-app-theme="dark"] #cupsPage .premiumPlan h3,
html[data-app-theme="dark"] #cupsPage .premiumPlanPrice,
html[data-app-theme="dark"] #cupsPage .premiumGiftName,
html[data-app-theme="dark"] #cupsPage .premiumGiftPrice,
html[data-app-theme="dark"] #cupsPage .coffeeGiftCard h2,
html[data-app-theme="dark"] #cupsPage .coffeeHistoryCard h2,
html[data-app-theme="dark"] #cupsPage .premiumSectionHeader h2,
html[data-app-theme="dark"] #cupsPage .premiumFeaturesCard h2,
html.kmDarkTheme #cupsPage .premiumPlan h3,
html.kmDarkTheme #cupsPage .premiumPlanPrice,
html.kmDarkTheme #cupsPage .premiumGiftName,
html.kmDarkTheme #cupsPage .premiumGiftPrice,
html.kmDarkTheme #cupsPage .coffeeGiftCard h2,
html.kmDarkTheme #cupsPage .coffeeHistoryCard h2,
html.kmDarkTheme #cupsPage .premiumSectionHeader h2,
html.kmDarkTheme #cupsPage .premiumFeaturesCard h2,
body.kmDarkTheme #cupsPage .premiumPlan h3,
body.kmDarkTheme #cupsPage .premiumPlanPrice,
body.kmDarkTheme #cupsPage .premiumGiftName,
body.kmDarkTheme #cupsPage .premiumGiftPrice,
body.kmDarkTheme #cupsPage .coffeeGiftCard h2,
body.kmDarkTheme #cupsPage .coffeeHistoryCard h2,
body.kmDarkTheme #cupsPage .premiumSectionHeader h2,
body.kmDarkTheme #cupsPage .premiumFeaturesCard h2 {
  color:#f4f4f7 !important;
}
html[data-app-theme="dark"] #cupsPage .premiumPlanNote,
html[data-app-theme="dark"] #cupsPage .premiumGiftNote,
html[data-app-theme="dark"] #cupsPage .premiumSectionHeader p,
html[data-app-theme="dark"] #cupsPage .coffeeGiftCard p,
html[data-app-theme="dark"] #cupsPage .coffeeHistoryItem small,
html[data-app-theme="dark"] #cupsPage .coffeeUnit,
html[data-app-theme="dark"] #cupsPage .coffeeBalanceCard .muted,
html.kmDarkTheme #cupsPage .premiumPlanNote,
html.kmDarkTheme #cupsPage .premiumGiftNote,
html.kmDarkTheme #cupsPage .premiumSectionHeader p,
html.kmDarkTheme #cupsPage .coffeeGiftCard p,
html.kmDarkTheme #cupsPage .coffeeHistoryItem small,
html.kmDarkTheme #cupsPage .coffeeUnit,
html.kmDarkTheme #cupsPage .coffeeBalanceCard .muted,
body.kmDarkTheme #cupsPage .premiumPlanNote,
body.kmDarkTheme #cupsPage .premiumGiftNote,
body.kmDarkTheme #cupsPage .premiumSectionHeader p,
body.kmDarkTheme #cupsPage .coffeeGiftCard p,
body.kmDarkTheme #cupsPage .coffeeHistoryItem small,
body.kmDarkTheme #cupsPage .coffeeUnit,
body.kmDarkTheme #cupsPage .coffeeBalanceCard .muted {
  color:#aaaab5 !important;
}
html[data-app-theme="dark"] #cupsPage select,
html[data-app-theme="dark"] #cupsPage input,
html.kmDarkTheme #cupsPage select,
html.kmDarkTheme #cupsPage input,
body.kmDarkTheme #cupsPage select,
body.kmDarkTheme #cupsPage input {
  background:#25252e !important;
  color:#f4f4f7 !important;
  border-color:rgba(255,255,255,.15) !important;
  color-scheme:dark;
}
html[data-app-theme="dark"] #cupsPage select option,
html.kmDarkTheme #cupsPage select option,
body.kmDarkTheme #cupsPage select option { background:#25252e !important; color:#f4f4f7 !important; }
html[data-app-theme="dark"] #cupsPage .coffeeMessage,
html.kmDarkTheme #cupsPage .coffeeMessage,
body.kmDarkTheme #cupsPage .coffeeMessage { background:#292932 !important; color:#f4f4f7 !important; border-color:rgba(255,255,255,.12) !important; }
html[data-app-theme="dark"] #cupsPage .coffeeMessage.error,
html.kmDarkTheme #cupsPage .coffeeMessage.error,
body.kmDarkTheme #cupsPage .coffeeMessage.error { background:#351d23 !important; color:#ffb8c0 !important; }
html[data-app-theme="dark"] #cupsPage .coffeeHistoryItem,
html.kmDarkTheme #cupsPage .coffeeHistoryItem,
body.kmDarkTheme #cupsPage .coffeeHistoryItem { border-color:rgba(255,255,255,.10) !important; }
html[data-app-theme="dark"] #cupsPage .coffeeHistoryIcon,
html.kmDarkTheme #cupsPage .coffeeHistoryIcon,
body.kmDarkTheme #cupsPage .coffeeHistoryIcon { background:#303039 !important; color:#f4f4f7 !important; }
html[data-app-theme="dark"] #cupsPage .coffeeHistoryAmount.in,
html.kmDarkTheme #cupsPage .coffeeHistoryAmount.in,
body.kmDarkTheme #cupsPage .coffeeHistoryAmount.in { color:#f4f4f7 !important; }
html[data-app-theme="dark"] #cupsPage .coffeeHistoryAmount.out,
html.kmDarkTheme #cupsPage .coffeeHistoryAmount.out,
body.kmDarkTheme #cupsPage .coffeeHistoryAmount.out { color:#aaaab5 !important; }
html[data-app-theme="dark"] #cupsPage .coffeeCupBig,
html.kmDarkTheme #cupsPage .coffeeCupBig,
body.kmDarkTheme #cupsPage .coffeeCupBig { background:#303039 !important; color:#f4f4f7 !important; filter:none !important; }
html[data-app-theme="dark"] #cupsPage .premiumPlanIcon,
html.kmDarkTheme #cupsPage .premiumPlanIcon,
body.kmDarkTheme #cupsPage .premiumPlanIcon { background:#eeeef2 !important; color:#111 !important; }

/* Calm, restrained motion: short transitions on controls; no animated scroll surfaces. */
#messengerView .topbar,
#messengerView .chatHeader,
#messengerView .kaiHeader,
#messengerView .composer,
#messengerView .kaiComposer,
#messengerView .bottomNav {
  transition:background-color var(--km40-motion) ease,border-color var(--km40-motion) ease,box-shadow var(--km40-motion) ease;
}
#messengerView .navItem,
#messengerView .chatCallBtn,
#messengerView .topIconButton,
#messengerView .topAvatarButton,
#messengerView .premiumFeaturesToggle,
#messengerView .reactionBtn {
  transition:background-color var(--km40-motion) ease,color var(--km40-motion) ease,border-color var(--km40-motion) ease,transform var(--km40-motion) ease;
}
#messages,#kaiMessages { scroll-behavior:auto !important; }
@media (prefers-reduced-motion:reduce) {
  #messengerView .topbar,#messengerView .chatHeader,#messengerView .kaiHeader,#messengerView .composer,#messengerView .kaiComposer,#messengerView .bottomNav,
  #messengerView .navItem,#messengerView .chatCallBtn,#messengerView .topIconButton,#messengerView .topAvatarButton,#messengerView .premiumFeaturesToggle,#messengerView .reactionBtn { transition:none !important; }
}
@media (prefers-reduced-transparency:reduce) {
  #messengerView .topbar,#messengerView .chatHeader,#messengerView .kaiHeader,#messengerView .composer,#messengerView .kaiComposer,#messengerView .bottomNav { -webkit-backdrop-filter:none !important; backdrop-filter:none !important; }
  html.kmDarkTheme #messengerView .topbar,html.kmDarkTheme #messengerView .chatHeader,html.kmDarkTheme #messengerView .kaiHeader,html.kmDarkTheme #messengerView .composer,html.kmDarkTheme #messengerView .kaiComposer,html.kmDarkTheme #messengerView .bottomNav { background:rgba(25,25,32,.97) !important; }
}

html[data-app-theme="dark"] #cupsPage .premiumHeroIcon,
html.kmDarkTheme #cupsPage .premiumHeroIcon,
body.kmDarkTheme #cupsPage .premiumHeroIcon,
html[data-app-theme="dark"] #cupsPage .premiumPlanBadge,
html.kmDarkTheme #cupsPage .premiumPlanBadge,
body.kmDarkTheme #cupsPage .premiumPlanBadge {
  background:#e9e9ee !important;
  color:#111116 !important;
}
