/* ================================
   SAMPLE C — “Bright Hybrid” (Consolidated, Fixed)
   - Calmer blue accent (#5783db)
   - Wider desktop/Tesla scaling
   - Bright panels & high readability
   - Chat bubbles for .msgLLM / .msgClient
   - Composer = one gray rounded block (snippet-1 look)
   - Thumbnails row wraps, textarea full width, send/attach aligned
   - Scanline overlay disabled
   ================================ */

/* ---------- Theme Tokens ---------- */
:root{
  --bg:#f7f7f7;
  --panel:#ffffff;
  --surface:#ffffff;
  --chip-bg:#f5f5f5;
  --chip-bg-hover:#eeeeee;

  --fg:#2a2a2a;
  --muted:#6b7280;
  --accent:#5783db;
  --accent-strong:#3f6fc7;

  --ok:#10b981;
  --warn:#d97706;
  --danger:#dc2626;

  --radius:12px;
  --border:1px solid #e5e7eb;
  --soft-shadow:0 6px 18px rgba(0,0,0,0.08);
  --inner-shadow:inset 0 0 8px rgba(0,0,0,0.04);

  --cursor:#969696;
  --nav-h:44px;
  --nav-logo:32px;

  --bubble-gap:12px;
  --bubble-radius:16px;

  --bubble-llm-bg:#ffffff;
  --bubble-llm-fg:#111827;
  --bubble-llm-border:#e5e7eb;

  --bubble-client-bg:#747474;
  --bubble-client-fg:#ffffff;
  --bubble-client-border:transparent;
}

/* ---------- Global ---------- */
*{box-sizing:border-box}
html,body{
  height:100%; margin:0; background:var(--bg); color:var(--fg);
  font-family:Monaco, ui-monospace, monospace; font-size:14px; line-height:1.4;
  -webkit-font-smoothing:antialiased; -moz-osx-font-smoothing:grayscale;
}
@media (min-width:768px){html,body{font-size:15px}}
@media (min-width:1024px){html,body{font-size:16px}}

.app{position:fixed; inset:0; display:grid; place-items:center; padding:12px}
body::before,body::after{content:none!important}

/* ---------- Shell ---------- */
.shell{
  width:min(100%,980px); max-width:1160px; height:auto; max-height:90vh;   /* ← original feel */
  display:grid; grid-template-rows:auto 1fr auto; gap:10px; padding:8px;
  background:#fff; border:var(--border); border-radius:var(--radius);
  box-shadow:var(--soft-shadow); position:relative; overflow:hidden;
}
@media (max-width:640px){.shell{max-height:88vh}}

.nav{
  background:#fff; border-bottom:var(--border); height:var(--nav-h);
  display:flex; align-items:center; gap:16px; padding:6px 10px;
  font-size:13px; border-radius:calc(var(--radius) - 2px);
}
.nav a{color:var(--fg); text-decoration:none}
.nav a:hover,.nav a:visited,.nav a:active,.nav a:focus{color:var(--fg); text-decoration:none}
.icon-base{opacity:.4; transition:opacity .2s}
.icon{cursor:pointer; opacity:.7; transition:opacity .2s}
.icon.active{opacity:1}
.logo{max-height:var(--nav-logo); max-width:90%; object-fit:contain; width:auto; margin-right:2px; filter:none}

.content{
  background:var(--panel); border:var(--border); border-radius:var(--radius);
  padding:8px; overflow-y:auto; position:relative; transition:opacity .2s;
  box-shadow:var(--inner-shadow); min-height:100px;
}
.content.fade{opacity:0}

/* Opt-out “plain” content (no chrome) */
.content-plain{
  background: transparent; border: 0; border-radius: 0; box-shadow: none; padding: 5px 2px 5px 2px; overflow: auto;
}

/* ---------- Chat ---------- */
.msg{margin:var(--bubble-gap) 0; padding:0; background:transparent; border:none; font-size: 12px;}

/* LLM bubble */
.msg .msgLLM{
  background:var(--bubble-llm-bg); color:var(--bubble-llm-fg); padding:10px 12px; margin-bottom:6px;
}

/* Client bubble */
.msg .msgClient{
  background:var(--bubble-client-bg); color:var(--bubble-client-fg);
  border:1px solid var(--bubble-client-border);
  border-radius:var(--bubble-radius); padding:12px 14px;
  margin-left:48px; margin-right:10px;
  box-shadow:0 4px 14px rgba(0,0,0,0.12);
}

.msg .msgTS{
  display:inline-block; margin-top:6px; font-size:10px; opacity:.85;
  color:rgba(255,255,255,0.9);
}
.msg .msgLLM .msgTS{color:#6b7280}
.msg a{color:var(--accent); text-decoration:underline}
.msg a:hover{color:var(--accent-strong)}

/* ---------- Overlay / Loader ---------- */
/* ===== Overlay: same footprint as the shell's inner area, scroll-safe ===== */
#session-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    background-color: rgba(255, 255, 255, 0.90); /* White with slight transparency */
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px; /* Padding on all sides to keep content from edges */
}
.overlay{
  position: absolute;
  /* match the shell’s content area: below the nav, full width/height inside shell */
  inset: var(--nav-h) 0 0 0;
  display: none;                       /* shown via .active */
  padding: 12px;                       /* small top/bottom padding as requested */
  background: rgba(255,255,255,0.90);
  box-shadow: var(--soft-shadow);
  backdrop-filter: saturate(120%) blur(2px);
  z-index: 5;

  /* IMPORTANT: let the overlay create its own scroll context */
  overflow: auto;                      /* scroll overlay if needed */
}
.overlay.active{
  display: flex;
  align-items: center;                /* full height, not vertically centered */
  justify-content: center;             /* keep panel centered horizontally */
}
/* Center the loader regardless of overlay flex alignment or content size */
.overlay .balls{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);   /* true center */
  z-index: 10;                         /* above blurred bg, below any modals */
  pointer-events: none;                /* clicks pass through while loading */
}
.balls{display:flex; gap:8px}
.ball{width:10px; height:10px; background:var(--accent); border-radius:50%;
  box-shadow:0 0 12px rgba(87,131,219,.35); animation:bounce .6s infinite alternate}
.ball:nth-child(2){animation-delay:.2s}
.ball:nth-child(3){animation-delay:.4s}
@keyframes bounce{from{transform:translateY(0)} to{transform:translateY(-8px)}}
.overlay.active .balls{display:none}

/* ---------- Media thumbs ---------- */
.photo-container{
  display:flex; flex-wrap:wrap; gap:8px; padding-top:6px; background:transparent; overflow:hidden;
}
.photo-container:not(:empty){padding-bottom:10px}

.media{
  height:90px; width:auto; max-width:220px;
  display:flex; justify-content:center; align-items:center;
  overflow:hidden; background:#f3f4f6;
  border-radius:8px; border:1px solid #e5e7eb; position:relative;
}
.media img{max-height:100%; width:auto; max-width:100%; object-fit:contain; transition:opacity .2s}
.media:hover img{opacity:.85}
.delete-btn{
  position:absolute; top:6px; right:6px; width:24px; height:24px;
  background:#fff; border:1px solid #d1d5db; border-radius:50%; padding:4px;
  display:flex; align-items:center; justify-content:center;
  opacity:0; transition:opacity .2s, transform .2s, box-shadow .2s;
  box-shadow:0 2px 6px rgba(0,0,0,.12); cursor:pointer;
}
.media:hover .delete-btn{opacity:1}
.delete-btn:hover{transform:scale(1.06); box-shadow:0 3px 10px rgba(0,0,0,.16)}
.delete-btn img{width:14px; height:14px}

/* Full-image overlay */
#imageOverlay{display:flex; position:fixed; inset:0; background:rgba(0,0,0,.7);
  justify-content:center; align-items:center; z-index:1000}
#showImage{display:flex; justify-content:center; align-items:center; width:100%; height:100%}
#showImage img{max-width:86%; max-height:86%; border-radius:10px; box-shadow:0 12px 30px rgba(0,0,0,.35)}

/* ---------- Overlay Form ---------- */
body.overlay-open { overflow: hidden; }
.overlay.active .overlay-content{
  display: block;                      /* becomes visible only when overlay is active */
  width: min(95%, 920px);              /* nice readable width cap */
  margin: 0 auto;                      /* centered horizontally */

  /* “Card” chrome */
  background: #fff;
  border: var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--soft-shadow);

  /* KEY: never exceed overlay height; scroll inside the panel when content is long */
  height: auto;                 /* ensure intrinsic height for short content */
  max-height: calc(100% - 24px);/* overlay height minus overlay padding */
  overflow: auto;               /* scroll inside when content is tall */
}
.overlay-content{display:none}
.overlay-form{display:flex; flex-direction:column; gap:12px}
.overlay-header{display:flex; justify-content:space-between; align-items:center; font-weight:600; color:#1f2937}
#close-overlay{background:transparent; border:none; color:#4b5563; cursor:pointer; font-size:16px; padding:2px 6px}
#close-overlay:hover{color:#ef4444}
.overlay-form label{color:#4b5563}
.overlay-form input,.overlay-form textarea{
  background:#fff; border:1px solid #cbd5e1; color:#111827;
  padding:8px; border-radius:8px; width:100%; box-sizing:border-box;
}
.overlay-actions{display:flex; justify-content:flex-end}

/* ---------- Chips / Misc ---------- */
.setting-item{cursor:pointer; padding:8px; border-radius:8px; transition:background .15s}
.setting-item:hover{background:#f3f4f6}
.setting-item .value{font-weight:600; color:#111827}
.delete-icon:hover{color:#ef4444}
.voice-bubbles{display:flex; flex-wrap:wrap; gap:8px}
.voice-bubble{
  background:#fff; border:1px solid #d1d5db; color:#111827;
  padding:6px 12px; border-radius:999px; cursor:pointer;
  transition:background .15s, box-shadow .15s, border-color .15s;
}
.voice-bubble:hover{background:#eff6ff; border-color:#bfdbfe}
.voice-bubble.selected{
  background:var(--accent); color:#fff; border-color:var(--accent-strong);
  box-shadow:0 0 0 3px rgba(87,131,219,.2);
}

/* Fabric caption */
.no-images{text-align:center; color:#4b5563; padding:20px; font-size:14px}
.fabric-image{position:relative; width:100%; height:100%; display:flex; justify-content:center; align-items:center}
.fabric-image img{max-width:100%; max-height:100%; object-fit:contain; transition:opacity .3s}
.desc-overlay{
  position:absolute; left:0; right:0; bottom:0; background:rgba(255,255,255,.92);
  color:#111827; padding:6px 10px; font-size:12px; display:flex; align-items:center; justify-content:space-between;
  border-top:1px solid #e5e7eb;
}
#desc-text{flex:1; margin:0 36px}
.nav-btn{position:absolute; top:50%; transform:translateY(-50%); color:#1f2937; font-size:18px; padding:6px 10px; cursor:pointer; border-radius:8px; transition:background .15s, color .15s}
.nav-btn:hover{background:#e5e7eb; color:#111827}
#nav-prev{left:10px} #nav-next{right:10px}

/* Sliders */
.slider-labels{display:flex; justify-content:space-between; font-size:12px; color:#6b7280; margin-top:6px}
input[type="range"]{width:100%; background:#fff; border:1px solid #d1d5db; border-radius:8px; padding:2px; -webkit-appearance:none}
input[type="range"]::-webkit-slider-thumb{-webkit-appearance:none; width:14px; height:14px; background:var(--accent); border-radius:50%; box-shadow:0 0 0 3px rgba(87,131,219,.2); cursor:pointer}
input[type="range"]::-moz-range-thumb{width:14px; height:14px; background:var(--accent); border-radius:50%; box-shadow:0 0 0 3px rgba(87,131,219,.2); cursor:pointer}

/* ---------- Utilities ---------- */
.row{display:flex; align-items:center}
.wrap{flex-wrap:wrap}
.space-between{justify-content:space-between}
.gap-6{gap:6px} .gap-8{gap:8px} .gap-10{gap:10px} .gap-12{gap:12px}
.mt-6{margin-top:6px} .mt-8{margin-top:8px} .mt-10{margin-top:10px} .mt-12{margin-top:12px} .mt-14{margin-top:14px}
.hidden{display:none}
.small{font-size:13px; color:var(--muted)}

/* ---------- Cards / Tables / Buttons / Inputs ---------- */
.card{background:var(--surface); border:var(--border); border-radius:var(--radius); padding:12px; box-shadow:var(--inner-shadow)}
.table{width:100%; border-collapse:collapse}
.table th,.table td{padding:10px; border-bottom:1px solid #edf0f4; color:#1f2937; text-align:left}
.table thead th{color:#6b7280; font-weight:600; background:#fafafa}
.table tbody tr:hover{background:#f7fafc}
.btn{background:#fff; color:#1f2a44; border:1px solid #cdd6e3; padding:8px 12px; font-size:13px; cursor:pointer; border-radius:10px}
.btn:hover{background:#eff4ff; color:#243659; border-color:#b9c6db}
.btn:focus{outline:none; background:#e9eef7; font-weight:600; color:#1b63b2}
.btn-outline{background:#f9fafb; border:1px solid #d1d5db; color:#1f2937}
.btn-ghost{background:transparent; border:1px solid #e5e7eb; color:#6b7280}
.input{background:#fff; color:#111827; border:1px solid #cbd5e1; border-radius:8px; padding:8px; font-size:14px; outline:none}
.input:focus{box-shadow:0 0 0 3px rgba(87,131,219,.2); border-color:#9db3de}
.select{background:#fff; color:#111827; border:1px solid #cbd5e1; border-radius:8px; padding:8px 10px; cursor:pointer}
.select:hover{background:#f3f6fc}

/* Collapse caret (legacy compatibility) */
.wallet-collapse{cursor:pointer; user-select:none}
.wallet-caret{display:inline-block; transform:rotate(0); transition:transform .15s ease}
.wallet-caret.open{transform:rotate(180deg)}

/* Safety meter */
.safety{height:12px; border-radius:8px; background:#f1f5f9; overflow:hidden; margin-top:6px; border:1px solid #e5e7eb}
.safety > div{height:100%}
.safety .green{background:linear-gradient(90deg,var(--ok),#34d399)}
.safety .orange{background:linear-gradient(90deg,var(--warn),#fbbf24)}
.safety .red{background:linear-gradient(90deg,var(--danger),#fb7185)}

/* ---------- COMPOSER: snippet-1 look, fixed layout ---------- */
#tools.tools{
  background:#efefef; border:1px solid #efefef; border-radius:12px;
  padding:8px 10px 10px; box-shadow:none;

  display:flex; flex-direction:column; align-items:stretch;
  position: sticky; bottom: 0; z-index: 3;     /* keep visible above keyboards */
}

#tools .photo-container{ display:flex; flex-wrap:wrap; gap:8px; padding-top:0; width:100%; }

#tools .ta-wrap{ background:transparent; border:0; border-radius:12px; padding:0; width:100%; }
#tools textarea#ta{
  width:100%; box-sizing:border-box;
  background:#efefef; border:1px solid #efefef;
  color:#111827; padding:6px 8px;
  min-height:36px; max-height:160px; font-size:15px;
  outline:none; resize:none; caret-color:#969696;
}
#tools textarea#ta::placeholder{color:#9aa3af}

#tools .controls{
  display:flex; align-items:center; gap:10px; padding-top:8px; width:100%;
}

/* explicit ordering to keep Audio left of Attach, and parked to the right side */
#sendBtn{ order:1; margin-right:auto; }    /* pushes the other controls to right */
#draftStatus{ order:2; }
#lenStatus { order:3; }
#ttsToggle{ order:4; }                      /* Audio toggle sits right side, left of attach */
#clipBtn{ order:5; }                        /* Attach at far right */
#lenStatus {
    font-size: 10px;
}
#draftStatus {
    font-size: 1.5em;
    transition: opacity 1s ease;
    opacity: 0;
    margin-left: 6px;
}
#draftStatus.saving {
    color: green;
}
#draftStatus.saved {
    color: green;
}
#draftStatus.error {
    color: red;
}

/* =========================
   SEND
   ========================= */
#sendBtn.btn-icon{
  width:40px; height:40px; padding:0;
  border-radius:50%;
  border:1px solid #929292;
  background:#3b3b3b; color:#fff;
  display:inline-block; position:relative; cursor:pointer;
  font-size:0; line-height:0;
  box-shadow:0 6px 18px rgba(0,0,0,0.12);
  -webkit-tap-highlight-color: transparent;
}
#sendBtn.btn-icon::before{
  content:""; position:absolute; top:50%; left:50%;
  width:0; height:0;
  border-left:7px solid transparent; border-right:7px solid transparent;
  border-bottom:10px solid currentColor;
  transform:translate(-50%, -52%);
}
#sendBtn.btn-icon:hover{ background:#2a2a2a }
#sendBtn.btn-icon:focus{ outline:none; box-shadow:0 0 0 3px rgba(87,131,219,0.25); }

/* =========================
   ATTACH
   ========================= */
#clipBtn.btn-icon{
  width:40px; height:40px; padding:0;
  border-radius:10px; border:1px solid #d7dee9; background:#ffffff;
  display:flex; align-items:center; justify-content:center;
  position:relative; cursor:pointer; font-size:0; line-height:0;
  -webkit-tap-highlight-color: transparent;
}
#clipBtn.btn-icon::before{
  content:""; position:absolute; top:50%; left:50%; width:20px; height:20px;
  transform:translate(-50%, -50%);
  background:url("/assets/img/paperclip.png") no-repeat center / contain;
}
#clipBtn.btn-icon:hover{ background:#f5f7fb }

/* ---------- Mini Player (TTS) ---------- */
.mini-player{
  display:flex; align-items:center; gap:8px;
  padding:8px 10px; background:#222; color:#ddd;
  border-bottom:var(--border); border-radius:calc(var(--radius) - 2px);
  font-size:12px;
}
.mini-player.hidden{ display:none; }
.mini-player .mp-btn{
  border:1px solid #444; background:#333; color:#eee;
  border-radius:8px; padding:4px 8px; cursor:pointer; font-size:12px;
}
.mini-player .mp-btn:active{ transform:scale(0.98); }
.mini-player .mp-status{ opacity:.85; }
.mini-player .mp-preview{
  opacity:.75; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:52ch;
}
/* Only show mini-player when TTS is ON */
body.tts-on #miniPlayer{ display:flex; }

/* ---------- Audio Toggle Button (next to Attach) ---------- */
#ttsToggle.btn-icon{
  width:40px; height:40px; padding:0;
  border-radius:10px; border:1px solid #d7dee9; background:#ffffff;
  display:flex; align-items:center; justify-content:center;
  position:relative; cursor:pointer; font-size:0; line-height:0;
  -webkit-tap-highlight-color: transparent;
}
#ttsToggle.btn-icon::before{
  content:""; position:absolute; top:50%; left:50%;
  width:20px; height:20px; transform:translate(-50%, -50%);
  background-repeat:no-repeat; background-position:center; background-size:contain;
}
/* OFF (gray) */
#ttsToggle.audio.off{ border-color:#d7dee9; background:#fff; color:#9aa3af; }
#ttsToggle.audio.off::before{
  background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='%239aa3af'><path d='M12 14a3 3 0 0 0 3-3V6a3 3 0 0 0-6 0v5a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21H9v2h6v-2h-2v-3.08A7 7 0 0 0 19 11h-2z'/></svg>");
}
/* ON (green) */
#ttsToggle.audio.on{
  border-color:#b7e3c9; background:#ffffff; color:#10b981;
  box-shadow:0 0 0 3px rgba(16,185,129,.15);
}
#ttsToggle.audio.on::before{
  background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='%2310b981'><path d='M12 14a3 3 0 0 0 3-3V6a3 3 0 0 0-6 0v5a3 3 0 0 0 3 3zm-1 2.92A7 7 0 0 1 5 11h2a5 5 0 0 0 10 0h2a7 7 0 0 1-6 5.92V21h2v2H9v-2h2v-4.08z'/></svg>");
}
#ttsToggle.audio.on.speaking{ animation:pulseGlow 2s ease-in-out infinite; }

/* ---------- Compact / Keyboard Mode ---------- */
/* Collapse content ONLY in compact mode; default OFF/normal height when audio OFF */
body.tts-compact .content{
  max-height:140px; overflow:hidden;
  -webkit-mask-image:linear-gradient(#000 70%, transparent);
  mask-image:linear-gradient(#000 70%, transparent);
}

/* Use 100dvh sizing only when compact (to fight keyboards) */
@supports (height: 100dvh) {
  body.tts-compact .app { height: 100dvh; }
  body.tts-compact .shell{ max-height: calc(100dvh - 24px); }
}

/* iOS safe area */
@supports (padding: max(0px)) {
  #tools.tools{ padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}

/* Pulse animation for speaking */
@keyframes pulseGlow {
  0% { box-shadow: 0 0 2px rgba(16,185,129, .45); transform: scale(1); }
  50% { box-shadow: 0 0 8px rgba(16,185,129, .95); transform: scale(1.06); }
  100% { box-shadow: 0 0 2px rgba(16,185,129, .45); transform: scale(1); }
}

/* Displaying the backend clients state (busy,away,etc) */
.client-state {
    display: inline-flex;
    align-items: center;
    gap: 8px;  /* Space between label and circle */
    font-size: 14px;  /* Adjust as needed */
    color: #333;  /* Default text color */
}

.state-label {
    font-weight: bold;
}

.state-circle {
    width: 12px;  /* Circle size */
    height: 12px;
    border-radius: 50%;  /* Make it circular */
    animation: pulse 1s ease-in-out infinite;  /* Apply pulse animation */
}

@keyframes pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
    100% {
        opacity: 1;
    }
}