/* ============================================================
   CloudIA — Lobster Cloud Playbook Assistant
   Design tokens per Lobster Brand Guidelines.
   Headlines: Montserrat (free; brand's Dax OT deliberately not used).
   Body: Roboto (brand body font). Both via Google Fonts.
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@600;700;800&family=Roboto:ital,wght@0,400;0,500;0,700;1,400&display=swap");

:root {
  /* Lobster greens */
  --green-50:  #e3f7ed;
  --green-100: #c4f3db;
  --green-200: #83ecb8;
  --green-300: #3cec94;
  --green-400: #0dd973;
  --green-500: #009d4e;  /* primary */
  --green-600: #117f4a;  /* hover */
  --green-700: #095435;
  --green-800: #00412d;  /* header */
  --green-900: #002e21;  /* titles */
  --green-950: #00140e;  /* body text */
  /* Greys */
  --grey-0:   #ffffff;
  --grey-50:  #f2f2f2;
  --grey-100: #e8e8e8;
  --grey-200: #cdced0;
  --grey-300: #b2b5bd;
  --grey-500: #747d9a;

  /* Semantic tokens */
  --bg:            #f6faf7;
  --surface:       #ffffff;
  --text:          var(--green-950);
  --text-muted:    var(--grey-500);
  --border:        #e2ece6;
  --accent:        var(--green-500);
  --accent-hover:  var(--green-600);
  --user-bubble:   var(--green-500);

  /* Scale */
  --radius-sm: 10px;
  --radius:    16px;
  --radius-lg: 24px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(0, 46, 33, .06);
  --shadow-md: 0 4px 16px rgba(0, 46, 33, .08);
  --shadow-lg: 0 12px 40px rgba(0, 46, 33, .16);
  --ring: 0 0 0 3px rgba(0, 157, 78, .25);

  --font-head: "Montserrat", system-ui, -apple-system, sans-serif;
  --font-body: "Roboto", system-ui, -apple-system, sans-serif;

  --header-h: 60px;
  --maxw: 760px;

  color-scheme: light;
}

/* ---- Dark theme tokens (explicit via [data-theme], or system default) ---- */
[data-theme="dark"] {
  --bg:           #0a1813;
  --surface:      #11241b;
  --text:         #e8f3ec;
  --text-muted:   #8fa89a;
  --border:       #1e3a2c;
  --accent:       var(--green-400);
  --accent-hover: var(--green-300);
  --user-bubble:  var(--green-600);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, .35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  --ring: 0 0 0 3px rgba(13, 217, 115, .3);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:           #0a1813;
    --surface:      #11241b;
    --text:         #e8f3ec;
    --text-muted:   #8fa89a;
    --border:       #1e3a2c;
    --accent:       var(--green-400);
    --accent-hover: var(--green-300);
    --user-bubble:  var(--green-600);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .35);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
    --ring: 0 0 0 3px rgba(13, 217, 115, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
#app { height: 100%; }

h1, h2, h3 { font-family: var(--font-head); font-weight: 700; letter-spacing: -0.015em; margin: 0; }

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

/* ---------------- Buttons ---------------- */
.btn-primary {
  font-family: var(--font-head); font-weight: 600; font-size: 1rem;
  background: var(--accent); color: #fff; border: 0;
  border-radius: var(--radius-pill); padding: .7rem 1.5rem; cursor: pointer;
  transition: background .15s ease, transform .05s ease;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-lg { padding: .85rem 2rem; font-size: 1.05rem; }

.btn-ghost {
  font-family: var(--font-body); font-size: .9rem; color: var(--green-100);
  background: transparent; border: 1px solid rgba(255,255,255,.25);
  border-radius: var(--radius-pill); padding: .4rem 1rem; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.btn-ghost:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.5); }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }

/* ---- Header controls: UI language toggle + theme toggle ---- */
.header-actions { display: flex; align-items: center; gap: .6rem; }
.controls { display: flex; align-items: center; gap: .5rem; }

.lang-toggle {
  display: inline-flex; border: 1px solid rgba(255,255,255,.25);
  border-radius: var(--radius-pill); overflow: hidden;
}
.lang-toggle button {
  font-family: var(--font-head); font-weight: 600; font-size: .72rem; letter-spacing: .03em;
  background: transparent; color: var(--green-100); border: 0;
  padding: .32rem .6rem; cursor: pointer; transition: background .15s ease, color .15s ease;
}
.lang-toggle button.active { background: #fff; color: var(--green-800); }
.lang-toggle button:not(.active):hover { background: rgba(255,255,255,.12); }

.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px;
  border-radius: var(--radius-pill); border: 1px solid rgba(255,255,255,.25);
  background: transparent; color: var(--green-100); cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.5); }

/* On the (light/dark) login screen the controls sit on the page background,
   not a dark header — give them on-surface colors there. */
.login-topbar {
  position: absolute; top: 1rem; right: 1rem;
  display: flex; gap: .5rem;
}
.login-topbar .lang-toggle { border-color: var(--border); }
.login-topbar .lang-toggle button { color: var(--text-muted); }
.login-topbar .lang-toggle button.active { background: var(--accent); color: #fff; }
.login-topbar .icon-btn { border-color: var(--border); color: var(--text-muted); }
.login-topbar .icon-btn:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* ---------------- Login ---------------- */
.login {
  position: relative;
  min-height: 100%;
  display: grid; place-items: center;
  padding: 2rem 1.5rem;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--green-100), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 2.5rem 2rem;
  text-align: center;
}
.login-logo { width: 144px; height: auto; object-fit: contain; margin-bottom: 1rem; }
.login-card h1 { font-size: 1.5rem; color: var(--text); }
.login-card p { color: var(--text-muted); line-height: 1.6; margin: .75rem 0 1.75rem; }

/* ---------------- Layout (sidebar + shell) ---------------- */
.layout { display: flex; height: 100%; }
.layout.embed { display: block; }

.sidebar {
  width: 280px; flex: none; height: 100%;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: .25rem; padding: .75rem;
}
.sidebar-head { display: flex; align-items: center; padding: .35rem .35rem .6rem; }
.sidebar-head .brand { display: flex; align-items: center; gap: .55rem; }
.sidebar-head .brand-mark {
  width: 48px; height: 48px; border-radius: 12px; background: var(--green-50);
  display: grid; place-items: center; flex: none;
}
.sidebar-head .brand-mark img { width: 40px; height: 40px; object-fit: contain; }
.sidebar-head .brand-name { font-family: var(--font-head); font-weight: 700; font-size: 1.05rem; color: var(--text); }

.btn-newchat {
  display: flex; align-items: center; justify-content: center; gap: .4rem;
  font-family: var(--font-head); font-weight: 600; font-size: .9rem;
  background: var(--accent); color: #fff; border: 0; border-radius: var(--radius-pill);
  padding: .6rem 1rem; cursor: pointer; transition: background .15s ease;
}
.btn-newchat:hover { background: var(--accent-hover); }

.sidebar-label {
  font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-muted); padding: .85rem .5rem .35rem;
}
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv-empty { color: var(--text-muted); font-size: .85rem; padding: .35rem .5rem; }
.conv-item {
  display: flex; align-items: center; border-radius: var(--radius-sm);
  transition: background .12s ease;
}
.conv-item:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.conv-item.active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.conv-open {
  flex: 1; text-align: left; background: none; border: 0; cursor: pointer;
  font-family: var(--font-body); font-size: .88rem; color: var(--text);
  padding: .55rem .6rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-del {
  flex: none; background: none; border: 0; cursor: pointer; color: var(--text-muted);
  padding: .35rem .5rem; opacity: 0; transition: opacity .12s ease, color .12s ease;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: var(--alert); }

.menu-toggle { display: none; }
.brand-mobile { display: none; }
.backdrop { display: none; }

/* ---------------- App shell ---------------- */
.app-shell {
  flex: 1; min-width: 0;
  display: grid;
  grid-template-rows: var(--header-h) 1fr auto;
  height: 100%;
}
.app-shell.embed { grid-template-rows: 1fr auto; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem; background: var(--green-800); color: #fff;
}
.brand { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.brand-mark {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 12px;
  background: #fff; box-shadow: var(--shadow-sm); flex: none;
}
.brand-mark img { width: 38px; height: 38px; object-fit: contain; }
.brand-name {
  font-family: var(--font-head); font-weight: 600; font-size: 1.05rem;
  color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------------- Thread ---------------- */
.thread { overflow-y: auto; scroll-behavior: smooth; }

/* Empty state */
.empty-state {
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: .5rem; padding: 2rem 1.5rem;
}
.empty-logo { width: 168px; height: auto; object-fit: contain; margin-bottom: .5rem; }
.empty-state h2 { font-size: 1.75rem; color: var(--text); }
.empty-state p { color: var(--text-muted); margin: 0 0 1.5rem; }
.suggestions {
  display: grid; gap: .6rem; width: 100%; max-width: 560px;
  grid-template-columns: repeat(2, 1fr);
}
.chip {
  font-family: var(--font-body); font-size: .9rem; text-align: left;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem 1rem; cursor: pointer; line-height: 1.4;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, transform .05s ease, box-shadow .15s ease;
}
.chip:hover { border-color: var(--green-300); box-shadow: var(--shadow-md); transform: translateY(-1px); }
@media (max-width: 540px) { .suggestions { grid-template-columns: 1fr; } }

/* Messages */
.messages {
  max-width: var(--maxw); margin: 0 auto; width: 100%;
  padding: 1.5rem 1rem 0.5rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 84%; padding: .8rem 1.05rem; border-radius: var(--radius);
  line-height: 1.6; font-size: .98rem; word-wrap: break-word;
  animation: rise .18s ease both;
}
.msg.bot .bubble {
  background: var(--surface); border: 1px solid var(--border);
  border-bottom-left-radius: 4px; box-shadow: var(--shadow-sm); color: var(--text);
}
.msg.user .bubble {
  background: var(--user-bubble); color: #fff; border-bottom-right-radius: 4px;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Typing indicator */
.is-thinking { padding: 1rem 1.05rem; }
.typing { display: inline-flex; gap: 5px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--green-300);
  animation: blink 1.2s infinite ease-in-out both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

/* Rich markdown answer content */
.answer { font-size: .98rem; line-height: 1.65; }
.answer > *:first-child { margin-top: 0; }
.answer > *:last-child { margin-bottom: 0; }
.answer p { margin: 0 0 .7rem; }
.answer h1, .answer h2, .answer h3, .answer h4 {
  font-family: var(--font-head); color: var(--text);
  line-height: 1.3; margin: 1.1rem 0 .5rem;
}
.answer h1 { font-size: 1.3rem; }
.answer h2 { font-size: 1.15rem; }
.answer h3 { font-size: 1.02rem; }
.answer h4 { font-size: .95rem; }
.answer ul, .answer ol { margin: .4rem 0 .8rem; padding-left: 1.3rem; }
.answer li { margin: .25rem 0; }
.answer li::marker { color: var(--green-500); }
.answer a { color: var(--green-600); text-decoration: none; font-weight: 500; }
.answer a:hover { text-decoration: underline; }
.answer strong { color: var(--text); font-weight: 700; }
.answer code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .88em;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
  padding: .1rem .35rem; border-radius: 6px;
}
.answer pre {
  background: var(--green-900); color: #e7f6ee; border-radius: var(--radius-sm);
  padding: .85rem 1rem; overflow-x: auto; margin: .6rem 0 .9rem; font-size: .85rem; line-height: 1.5;
}
.answer pre code { background: none; color: inherit; padding: 0; }
.answer blockquote {
  margin: .7rem 0; padding: .5rem .9rem; border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text);
}
.answer blockquote p { margin: 0; }
.answer hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }

/* Tables */
.answer table {
  width: 100%; border-collapse: collapse; margin: .6rem 0 1rem;
  font-size: .9rem; display: block; overflow-x: auto;
}
.answer thead { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.answer th, .answer td {
  border: 1px solid var(--border); padding: .5rem .7rem; text-align: left; vertical-align: top;
}
.answer th { font-family: var(--font-head); font-weight: 600; color: var(--text); white-space: nowrap; }
.answer tbody tr:nth-child(even) { background: color-mix(in srgb, var(--text) 4%, transparent); }

/* Sources + badge */
.sources { margin-top: .75rem; padding-top: .6rem; border-top: 1px solid var(--border); font-size: .82rem; }
.sources-title { font-weight: 700; color: var(--accent); }
.sources ul { margin: .35rem 0 0; padding-left: 1.1rem; display: grid; gap: .2rem; }
.sources a { color: var(--green-600); text-decoration: none; }
.sources a:hover { text-decoration: underline; }
.model-badge {
  margin-top: .6rem; display: inline-block; font-size: .68rem; font-weight: 500;
  color: var(--text-muted); background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-radius: var(--radius-pill); padding: .15rem .55rem; letter-spacing: .02em;
}

/* Feedback */
.feedback { margin-top: .65rem; display: flex; gap: .4rem; align-items: center; }
.feedback .fb {
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .2rem .5rem; cursor: pointer; font-size: .95rem; line-height: 1;
  transition: background .15s ease, border-color .15s ease;
}
.feedback .fb:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); border-color: var(--accent); }
.feedback .fb-thanks { font-size: .8rem; color: var(--green-600); }

/* ---------------- Composer ---------------- */
.composer {
  padding: .85rem 1rem calc(3.5rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.composer-inner {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: flex-end; gap: .5rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: .4rem .4rem .4rem .75rem;
  box-shadow: var(--shadow-sm); transition: border-color .15s ease, box-shadow .15s ease;
}
.composer-inner:focus-within { border-color: var(--green-400); box-shadow: var(--ring); }

.lang-select { display: flex; align-items: center; align-self: stretch; }
.lang-select select {
  appearance: none; -webkit-appearance: none;
  font-family: var(--font-body); font-size: .8rem; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent); border: 0; border-radius: var(--radius-pill);
  padding: .35rem 1.6rem .35rem .7rem; cursor: pointer; align-self: center;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%23009d4e' d='M0 0l5 6 5-6z'/></svg>");
  background-repeat: no-repeat; background-position: right .6rem center;
}

.composer-input {
  flex: 1; resize: none; border: 0; outline: none; background: transparent;
  font-family: var(--font-body); font-size: 1rem; line-height: 1.5; color: var(--text);
  padding: .55rem .25rem; max-height: 160px; min-height: 24px;
}
.composer-input::placeholder { color: var(--grey-300); }

.btn-send {
  flex: none; width: 42px; height: 42px; border: 0; border-radius: 50%;
  background: var(--accent); color: #fff; cursor: pointer; display: grid; place-items: center;
  transition: background .15s ease, transform .05s ease;
}
.btn-send:hover { background: var(--accent-hover); }
.btn-send:active { transform: scale(.94); }

/* Embed tweaks */
.embed .messages, .embed .composer-inner { max-width: 100%; }
.embed .composer { padding: .6rem .6rem .8rem; }

/* ---------------- Responsive: sidebar becomes an overlay ---------------- */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 50;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: grid; }
  .brand-mobile { display: flex; align-items: center; gap: .55rem; }
  .app-header { gap: .5rem; }
  .app-header .brand-mobile .brand-name { font-size: 1rem; }
  .backdrop:not([hidden]) {
    display: block; position: fixed; inset: 0; z-index: 40;
    background: rgba(0, 20, 14, .45);
  }
  /* On mobile the header brand lives in .brand-mobile; hide the desktop one. */
  .header-actions .btn-ghost { padding: .4rem .7rem; }
}
/* The mobile menu button + brand only make sense with a sidebar present. */
@media (min-width: 861px) {
  .menu-toggle { display: none; }
  .brand-mobile { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto; }
}
