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

/* ── TOKENS ────────────────────────────────── */
:root {
  --bg:            #f5f4f1;
  --bg-sidebar:    #ffffff;
  --bg-agent:      #ffffff;
  --bg-user:       #1b1b2f;
  --bg-tool:       #f3f2ff;
  --bg-input:      #ffffff;
  --bg-surface:    #ffffff;

  --text:          #1b1b2f;
  --text-muted:    #888899;
  --text-light:    #b5b5c8;
  --text-inv:      #ffffff;

  --accent:        #6c63ff;
  --accent-dim:    rgba(108, 99, 255, 0.10);
  --accent-hover:  #5a52e0;
  --success:       #22c55e;
  --warning:       #f59e0b;
  --danger:        #ef4444;

  --border:        #e8e8f2;
  --border-strong: #d0d0e8;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.05);

  --sidebar-w: 272px;
  --header-h:  60px;
  --r:         14px;
  --r-sm:       8px;
  --r-lg:      20px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* ── BASE ──────────────────────────────────── */
html { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── LAYOUT ────────────────────────────────── */
.layout {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ── SIDEBAR ───────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand-icon {
  font-size: 26px;
  line-height: 1;
  color: var(--accent);
}

.brand-name {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}

.brand-tag {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-light);
  background: var(--bg);
  border-radius: 4px;
  padding: 2px 6px;
  margin-left: auto;
  border: 1px solid var(--border);
}

/* Section */
.sidebar-section {
  padding: 14px 14px 8px;
  border-bottom: 1px solid var(--border);
}

.sidebar-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-light);
  margin-bottom: 10px;
}

/* Status grid */
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.status-card {
  background: var(--bg);
  border-radius: var(--r-sm);
  padding: 10px 10px 8px;
  border: 1px solid var(--border);
  transition: border-color .15s;
}

.status-card:hover { border-color: var(--border-strong); }

.status-card-icon { font-size: 17px; margin-bottom: 4px; }

.status-card-value {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}

.status-card-label {
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.status-on     { color: var(--warning) !important; }
.status-off    { color: var(--text-light) !important; }
.status-active { color: var(--success) !important; }

/* Deadlines */
.deadline-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 0;
}

.deadline-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.deadline-dot.urgent { background: var(--danger); }
.deadline-dot.soon   { background: var(--warning); }
.deadline-dot.ok     { background: var(--success); }

.deadline-name  { flex: 1; font-size: 12.5px; color: var(--text); font-weight: 500; }
.deadline-days  { font-size: 11.5px; color: var(--text-muted); }

/* Expenses */
.expense-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.expense-cat    { font-size: 12.5px; color: var(--text); display: flex; align-items: center; gap: 7px; }
.expense-amount { font-size: 12.5px; font-weight: 700; color: var(--text); }
.expense-trend  { font-size: 10px; margin-left: 3px; font-weight: 600; }
.trend-up    { color: var(--danger); }
.trend-down  { color: var(--success); }
.trend-flat  { color: var(--text-muted); }

/* ── CHAT MAIN ─────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── HEADER ────────────────────────────────── */
.chat-header {
  order: 1;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  background: rgba(245,244,241,.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--r-sm);
  transition: background .15s, color .15s;
}

.sidebar-toggle:hover { background: var(--border); color: var(--text); }

.agent-identity {
  display: flex;
  align-items: center;
  gap: 11px;
  flex: 1;
}

/* Avatar — orb Google-style */
.agent-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.avatar-orb {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: conic-gradient(
    #6c63ff 0deg 90deg,
    #a78bfa 90deg 180deg,
    #f59e0b 180deg 270deg,
    #22c55e 270deg 360deg
  );
  display: block;
  box-shadow: 0 2px 8px rgba(108,99,255,.3);
  transition: transform .2s, box-shadow .2s;
}

.agent-avatar:is(.thinking, .listening) .avatar-orb {
  animation: orbSpin 2s linear infinite;
  box-shadow: 0 0 0 4px var(--accent-dim), 0 2px 12px rgba(108,99,255,.4);
}

.agent-avatar.listening .avatar-orb {
  background: conic-gradient(#ef4444 0deg 120deg, #f59e0b 120deg 240deg, #ef4444 240deg 360deg);
  animation: orbSpin 1s linear infinite;
  box-shadow: 0 0 0 5px rgba(239,68,68,.15), 0 2px 12px rgba(239,68,68,.4);
}

@keyframes orbSpin {
  to { transform: rotate(360deg); }
}

/* "Hey" in accent in the agent name */
.agent-name {
  font-size: 15px;
  font-weight: 700;
  display: block;
  letter-spacing: -.2px;
}

.hey-word {
  color: var(--accent);
}

.agent-tagline { font-size: 12px; color: var(--text-muted); display: block; }

/* "Hey Casa" badge used in tagline */
.hey-badge {
  display: inline-block;
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 700;
  font-size: 10.5px;
  border-radius: 4px;
  padding: 1px 5px;
  letter-spacing: .03em;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-muted);
  padding: 7px;
  border-radius: var(--r-sm);
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { background: var(--border); color: var(--text); border-color: var(--border-strong); }

/* ── MESSAGES ──────────────────────────────── */
.messages-container {
  order: 2;
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 8px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

.messages {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Message row */
.msg {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  animation: msgIn .28s cubic-bezier(.34,1.5,.64,1) both;
}

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

.msg.user { flex-direction: row-reverse; }

/* Avatars */
.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.agent-av {
  background: none;
  box-shadow: none;
  padding: 2px;
}

.agent-av::after {
  content: '';
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(
    #6c63ff 0deg 90deg,
    #a78bfa 90deg 180deg,
    #f59e0b 180deg 270deg,
    #22c55e 270deg 360deg
  );
  box-shadow: 0 2px 6px rgba(108,99,255,.25);
}

.user-av {
  background: linear-gradient(135deg, #ff6b6b 0%, #ffd93d 30%, #4d96ff 65%, #c77dff 100%);
  border-radius: 9px;
  padding: 5px;
  box-shadow: 0 2px 6px rgba(108,99,255,.25);
}

.user-av svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Message body */
.msg-body {
  max-width: min(78%, 500px);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.msg.user .msg-body { align-items: flex-end; }

/* Bubble */
.msg-bubble {
  padding: 11px 15px;
  border-radius: var(--r);
  font-size: 14.5px;
  line-height: 1.62;
  word-break: break-word;
}

.msg.agent .msg-bubble {
  background: var(--bg-agent);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.msg.user .msg-bubble {
  background: var(--bg-user);
  color: var(--text-inv);
  border-bottom-right-radius: 4px;
}

.msg-time {
  font-size: 10.5px;
  color: var(--text-light);
  padding: 0 3px;
}

/* Tool card */
.tool-card {
  background: var(--bg-tool);
  border: 1px solid #dddaff;
  border-radius: var(--r-sm);
  padding: 9px 12px;
  font-size: 12px;
}

.tool-card-header {
  display: flex;
  align-items: center;
  gap: 7px;
}

.tool-card-icon { font-size: 13px; }

.tool-card-name {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--accent);
  font-weight: 600;
  flex: 1;
}

.tool-card-result {
  font-size: 11.5px;
  color: var(--success);
  font-weight: 600;
}

.tool-card-params {
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid #e0ddff;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tool-param { display: flex; gap: 6px; font-family: var(--mono); font-size: 11px; }
.param-key  { color: var(--text-muted); }
.param-value{ color: var(--text); font-weight: 500; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  animation: msgIn .25s ease both;
}

.typing-bubble {
  background: var(--bg-agent);
  border: 1px solid var(--border);
  border-radius: var(--r);
  border-bottom-left-radius: 4px;
  padding: 13px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
  box-shadow: var(--shadow-sm);
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-light);
  animation: typingPulse 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes typingPulse {
  0%,60%,100% { transform: scale(1);   opacity: .4; }
  30%          { transform: scale(1.4); opacity: 1;  }
}

/* Tool executing */
.tool-executing {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 10px 13px;
  background: var(--bg-agent);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  animation: msgIn .2s ease both;
}

.tool-executing code {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 12px;
  background: var(--accent-dim);
  padding: 1px 5px;
  border-radius: 4px;
}

.tool-executing-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }


/* ── INPUT ZONE ────────────────────────────── */
.input-zone {
  order: 3;
  padding: 12px 18px 18px;
  background: rgba(245,244,241,.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.suggestions-row {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  min-height: 30px;
}

.suggestion-chip {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  font-family: var(--font);
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.4;
}

.suggestion-chip:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  padding: 7px 7px 7px 15px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}

.input-bar.multiline {
  align-items: flex-start;
}

.input-bar.multiline .mic-btn,
.input-bar.multiline .send-btn {
  align-self: flex-end;
}

.input-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

#userInput {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text);
  resize: none;
  max-height: 160px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  background-clip: padding-box;
}

#userInput::-webkit-scrollbar { display: none; }

#userInput::placeholder { color: var(--text-light); }

/* ── MIC BUTTON ────────────────────────────── */
.mic-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: none;
  border: 1.5px solid var(--border);
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all .2s;
}

.mic-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.mic-btn.listening {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  animation: micPulse 1.2s infinite;
}

@keyframes micPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.5); }
  50%      { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

/* hide mic if Speech API unsupported */
.mic-btn.hidden { display: none; }

/* ── WELCOME HERO ───────────────────────────── */
.welcome-msg {
  text-align: center;
  padding: 40px 24px 32px;
  animation: msgIn .4s ease both;
}

.welcome-logo {
  height: 56px;
  width: auto;
  object-fit: contain;
  display: block;
  margin: 0 auto 20px;
  filter: drop-shadow(0 4px 12px rgba(108,99,255,.2));
}

.welcome-headline {
  font-size: 44px;
  font-weight: 900;
  letter-spacing: -1.5px;
  line-height: 1;
  margin-bottom: 28px;
}

.welcome-hey {
  background: linear-gradient(135deg, var(--accent) 0%, #a78bfa 50%, var(--warning) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-casa {
  color: var(--text);
}

.welcome-sub {
  font-size: 14.5px;
  color: var(--text-muted);
  max-width: 360px;
  margin: 0 auto 24px;
  line-height: 1.65;
}

.welcome-examples {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
  margin: 0 auto;
}

.welcome-example {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px 14px;
  font-size: 13.5px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  text-align: left;
}

.welcome-example:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-dim);
  transform: translateX(3px);
}

.welcome-example-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.welcome-example em {
  color: var(--accent);
  font-style: normal;
  font-weight: 600;
}

/* Listening overlay hint */
.listening-hint {
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--danger);
  font-weight: 600;
  animation: fadeIn .2s ease;
}

.listening-hint.active { display: flex; }
.listening-hint-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: micPulse .8s infinite;
}

@keyframes fadeIn { from { opacity:0 } to { opacity:1 } }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--accent);
  border: none;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s, opacity .15s;
  opacity: .45;
}

.send-btn:not(:disabled) { opacity: 1; }
.send-btn:not(:disabled):hover  { background: var(--accent-hover); transform: scale(1.06); }
.send-btn:not(:disabled):active { transform: scale(.94); }
.send-btn:disabled { cursor: not-allowed; }

.input-hint {
  font-size: 10.5px;
  color: var(--text-light);
  text-align: center;
  margin-top: 7px;
}

.input-hint kbd {
  background: var(--border);
  border-radius: 3px;
  padding: 1px 4px;
  font-family: var(--mono);
  font-size: 9.5px;
  border: 1px solid var(--border-strong);
}

/* ── LOGO USAGES ───────────────────────────── */
.brand-logo {
  height: 46px;
  width: auto;
  object-fit: contain;
  display: block;
  margin: -10px 0 -6px -8px;
}

.avatar-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.welcome-logo {
  height: 64px;
  width: auto;
  object-fit: contain;
  display: block;
  margin: 0 auto 16px;
}

/* ── SIDEBAR ?? PLACEHOLDERS ────────────────── */
.val-ask {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1.5px dashed var(--accent);
  border-radius: 6px;
  padding: 1px 7px;
  cursor: pointer;
  letter-spacing: .06em;
  transition: background .15s, color .15s, transform .1s;
  user-select: none;
  line-height: 1.6;
}

.val-ask:hover {
  background: var(--accent);
  color: #fff;
  border-style: solid;
  transform: scale(1.1);
}

.val-ask:active { transform: scale(.95); }

.deadline-days { min-width: 36px; text-align: right; display: flex; justify-content: flex-end; align-items: center; }
.expense-amount { display: flex; align-items: center; gap: 4px; }

/* ── SIDEBAR OVERLAY (mobile) ──────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(2px);
  z-index: 99;
}

.sidebar-overlay.active { display: block; }

/* ── PWA INSTALL BANNER ────────────────────── */
.pwa-banner {
  display: none;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  padding: 10px 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}

.pwa-banner.hidden,
.pwa-banner-dismissed .pwa-banner {
  display: none;
}

.pwa-banner-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}

.pwa-banner-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.pwa-banner-body strong {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.pwa-banner-body span {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.pwa-install-btn {
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 7px 16px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  transition: opacity .15s, transform .1s;
  box-shadow: 0 2px 8px rgba(108,99,255,.3);
}

.pwa-install-btn:hover  { opacity: .9; }
.pwa-install-btn:active { transform: scale(.95); }

.pwa-dismiss-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  flex-shrink: 0;
  transition: color .15s;
}

.pwa-dismiss-btn:hover { color: var(--text-muted); }

/* ── RESPONSIVE ────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 100;
    transform: translateX(-100%);
    box-shadow: var(--shadow-md);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-toggle { display: flex; }

  .messages { padding: 0 12px; }
  .input-zone { padding: 10px 12px 16px; }

  .pwa-banner {
    display: flex;
  }

  .suggestions-row { display: none; }
}

@media (display-mode: standalone) {
  .pwa-banner {
    display: none;
  }
}

@media (max-width: 420px) {
  .msg-body { max-width: 88%; }
  .welcome-title { font-size: 20px; }
}
