:root {
  --bg:#0a0d12;
  --surface:#10141a;
  --surface-2:#141920;
  --surface-3:#181e26;
  --text:#f4f6f8;
  --text-soft:#c8d0d9;
  --muted:#7f8a96;
  --muted-2:#58636f;
  --line:#20262f;
  --line-2:#2a323d;
  --accent:#7c6cf2;
  --accent-hover:#8a7af6;
  --positive:#4cc38a;
  --negative:#ef6c68;
}

*{box-sizing:border-box}

html{
  min-height:100%;
  background:var(--bg);
  color-scheme:dark;
}

body{
  min-height:100vh;
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:Inter,ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;
  -webkit-font-smoothing:antialiased;
}

button,textarea{font:inherit}
button{-webkit-tap-highlight-color:transparent}

.app-shell{
  width:min(100%,900px);
  min-height:100vh;
  margin:0 auto;
  padding:
    max(16px,env(safe-area-inset-top))
    max(16px,env(safe-area-inset-right))
    max(18px,env(safe-area-inset-bottom))
    max(16px,env(safe-area-inset-left));
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:14px;
}

.brand{
  display:flex;
  align-items:center;
  gap:10px;
}

.brand-mark{
  width:34px;
  height:34px;
  flex:0 0 34px;
  display:grid;
  place-items:center;
  border:1px solid var(--line-2);
  border-radius:10px;
  background:var(--surface);
  color:#d9d5ff;
}

.brand-mark svg{width:22px;height:22px}

.brand-name{
  color:var(--text);
  font-size:14px;
  font-weight:760;
  letter-spacing:-.02em;
}

.brand-sub{
  margin-top:1px;
  color:var(--muted);
  font-size:8.5px;
}

.top-actions{
  display:flex;
  align-items:center;
  gap:8px;
}

.icon-button{
  width:34px;
  height:34px;
  display:grid;
  place-items:center;
  padding:0;
  border:1px solid var(--line);
  border-radius:10px;
  background:var(--surface);
  color:#9aa5b1;
  cursor:pointer;
}

.icon-button svg{width:16px;height:16px}

.status-pill{
  display:inline-flex;
  align-items:center;
  gap:7px;
  min-height:34px;
  padding:0 10px;
  border:1px solid var(--line);
  border-radius:999px;
  background:var(--surface);
  color:#8d98a4;
  font-size:8.8px;
  font-weight:700;
  white-space:nowrap;
}

.status-dot{
  width:6px;
  height:6px;
  border-radius:50%;
  background:#5a646f;
}

.status-pill.ready .status-dot{background:var(--positive)}
.status-pill.error .status-dot{background:var(--negative)}

.conversation-layout{display:block}

.chat-card{
  overflow:hidden;
  border:1px solid var(--line);
  border-radius:18px;
  background:var(--surface);
}

.chat-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:13px 14px;
  border-bottom:1px solid var(--line);
  background:var(--surface);
}

.chat-title{
  color:var(--text-soft);
  font-size:11px;
  font-weight:740;
}

.chat-note{
  margin-top:2px;
  color:var(--muted-2);
  font-size:8px;
}

.text-button{
  min-height:30px;
  padding:0 10px;
  border:1px solid var(--line);
  border-radius:9px;
  background:transparent;
  color:#919ca8;
  font-size:8.7px;
  font-weight:700;
  cursor:pointer;
}

.text-button:hover{
  border-color:var(--line-2);
  color:var(--text-soft);
}

.chat{
  min-height:560px;
  max-height:67vh;
  overflow-y:auto;
  overscroll-behavior:contain;
  padding:22px 18px;
  background:#0d1117;
  scroll-behavior:smooth;
  scrollbar-width:thin;
  scrollbar-color:#29313b transparent;
}

.welcome-card{
  display:flex;
  gap:12px;
  width:min(100%,620px);
  margin:5px 0 18px;
}

.welcome-badge{
  width:30px;
  height:30px;
  flex:0 0 30px;
  display:grid;
  place-items:center;
  border:1px solid var(--line-2);
  border-radius:9px;
  background:var(--surface-2);
  color:#d9d5ff;
  font-size:10px;
  font-weight:800;
}

.welcome-body strong{
  color:var(--text-soft);
  font-size:11.5px;
  font-weight:720;
}

.welcome-body p{
  max-width:560px;
  margin:4px 0 0;
  color:var(--muted);
  font-size:9.4px;
  line-height:1.5;
}

.welcome-suggestions{
  display:flex;
  flex-wrap:wrap;
  gap:7px;
  margin-top:11px;
}

.welcome-suggestions button{
  min-height:29px;
  padding:0 10px;
  border:1px solid var(--line);
  border-radius:999px;
  background:var(--surface);
  color:#95a0ac;
  font-size:8.6px;
  font-weight:680;
  cursor:pointer;
}

.welcome-suggestions button:hover{
  border-color:var(--line-2);
  color:var(--text-soft);
}

.message-row{
  display:flex;
  width:100%;
  margin:0 0 14px;
}

.message-row.user{justify-content:flex-end}

.message{
  width:fit-content;
  max-width:min(74%,680px);
  padding:10px 12px;
  border:1px solid var(--line);
  border-radius:14px 14px 14px 5px;
  background:var(--surface-2);
  color:#d8dee6;
  font-size:11.2px;
  line-height:1.5;
  white-space:pre-wrap;
  overflow-wrap:anywhere;
}

.message-row.user .message{
  border-color:#4d438f;
  border-radius:14px 14px 5px 14px;
  background:#2a2450;
  color:#f4f1ff;
}

.message-row.system .message{
  max-width:100%;
  border-style:dashed;
  background:transparent;
  color:var(--muted);
  font-size:9.5px;
}

.typing{
  display:inline-flex;
  align-items:center;
  gap:4px;
  min-height:14px;
}

.typing i{
  width:5px;
  height:5px;
  border-radius:50%;
  background:#8c80e8;
  animation:typing 1s ease-in-out infinite;
}

.typing i:nth-child(2){animation-delay:.14s}
.typing i:nth-child(3){animation-delay:.28s}

@keyframes typing{
  0%,60%,100%{transform:translateY(0);opacity:.4}
  30%{transform:translateY(-2px);opacity:1}
}

.proposal{
  width:min(100%,620px);
  margin:4px 0 16px;
  overflow:hidden;
  border:1px solid var(--line);
  border-radius:14px;
  background:var(--surface);
}

.proposal-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding:13px 14px;
  border-bottom:1px solid var(--line);
  background:var(--surface);
}

.proposal-kicker{
  color:var(--muted-2);
  font-size:7.2px;
  font-weight:760;
  letter-spacing:.07em;
  text-transform:uppercase;
}

.proposal-desc{
  margin-top:3px;
  color:var(--text);
  font-size:12px;
  font-weight:730;
}

.proposal-value{
  font-size:16px;
  font-weight:780;
  white-space:nowrap;
}

.proposal-value.expense{color:var(--negative)}
.proposal-value.income{color:var(--positive)}

.proposal-grid{
  display:grid;
  grid-template-columns:repeat(3,minmax(0,1fr));
  gap:1px;
  background:var(--line);
  border-bottom:1px solid var(--line);
}

.proposal-field{
  min-width:0;
  padding:10px 11px;
  background:var(--surface);
}

.proposal-label{
  color:var(--muted-2);
  font-size:7px;
  font-weight:720;
  letter-spacing:.04em;
  text-transform:uppercase;
}

.proposal-data{
  margin-top:3px;
  overflow:hidden;
  color:#b8c1cb;
  font-size:9.4px;
  font-weight:680;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.proposal-actions{
  display:flex;
  justify-content:flex-end;
  gap:8px;
  padding:10px 11px;
  background:var(--surface);
}

.action-button{
  min-height:33px;
  padding:0 11px;
  border:1px solid var(--line);
  border-radius:9px;
  background:transparent;
  color:#98a3af;
  font-size:8.8px;
  font-weight:720;
  cursor:pointer;
}

.action-button:hover:not(:disabled){
  border-color:var(--line-2);
  color:var(--text-soft);
}

.action-button.primary{
  border-color:var(--accent);
  background:var(--accent);
  color:#fff;
}

.action-button.primary:hover:not(:disabled){
  border-color:var(--accent-hover);
  background:var(--accent-hover);
}

.action-button:disabled{
  opacity:.55;
  cursor:default;
}

.confirmed{
  width:100%;
  color:var(--positive);
  font-size:9.5px;
  font-weight:720;
  text-align:right;
}

.composer-wrap{
  padding:
    11px 12px
    max(12px,env(safe-area-inset-bottom));
  border-top:1px solid var(--line);
  background:var(--surface);
}

.composer{
  display:grid;
  grid-template-columns:38px minmax(0,1fr) 38px;
  gap:7px;
  align-items:end;
  padding:6px;
  border:1px solid var(--line-2);
  border-radius:14px;
  background:#0d1117;
}

.composer:focus-within{
  border-color:#4b465f;
}

.composer-action,
.send-button{
  width:38px;
  height:38px;
  display:grid;
  place-items:center;
  padding:0;
  border:0;
  border-radius:10px;
  cursor:pointer;
}

.composer-action{
  background:var(--surface-2);
  color:#929daa;
}

.composer-action.listening{
  background:#3a2024;
  color:var(--negative);
}

.send-button{
  background:var(--accent);
  color:#fff;
}

.composer-action svg,
.send-button svg{
  width:18px;
  height:18px;
}

.composer-action:disabled,
.send-button:disabled{
  opacity:.4;
  cursor:default;
}

textarea{
  width:100%;
  min-height:38px;
  max-height:112px;
  resize:none;
  overflow-y:auto;
  padding:9px 4px 6px;
  border:0;
  outline:0;
  background:transparent;
  color:var(--text);
  font-size:11.4px;
  line-height:1.45;
}

textarea::placeholder{color:var(--muted-2)}

.composer-foot{
  padding:6px 2px 0;
  color:var(--muted-2);
  font-size:7.5px;
}

.toast-stack{
  position:fixed;
  right:max(14px,env(safe-area-inset-right));
  bottom:max(14px,env(safe-area-inset-bottom));
  z-index:100;
  display:grid;
  gap:8px;
  pointer-events:none;
}

.toast{
  max-width:min(320px,calc(100vw - 28px));
  padding:9px 11px;
  border:1px solid var(--line-2);
  border-radius:10px;
  background:var(--surface-2);
  color:#b9c2cc;
  font-size:8.8px;
  font-weight:680;
}

.toast.success{color:var(--positive)}
.toast.error{color:var(--negative)}

@media(max-width:760px){
  .app-shell{
    width:100%;
    padding:
      max(12px,env(safe-area-inset-top))
      max(10px,env(safe-area-inset-right))
      max(10px,env(safe-area-inset-bottom))
      max(10px,env(safe-area-inset-left));
  }

  .topbar{margin-bottom:10px}
  .brand-sub{display:none}

  .status-pill{
    max-width:130px;
    overflow:hidden;
    text-overflow:ellipsis;
  }

  .chat{
    min-height:calc(100svh - 210px);
    max-height:none;
    padding:17px 10px 14px;
  }

  .message{max-width:88%}

  .proposal-grid{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }

  .composer-foot{
    display:none;
  }
}

@media(max-width:430px){
  .brand-mark{
    width:32px;
    height:32px;
    flex-basis:32px;
  }

  .status-pill{
    min-height:31px;
    padding:0 9px;
    font-size:8px;
  }

  .chat-head{
    padding:12px 11px;
  }

  .chat-note{display:none}

  .welcome-card{
    gap:10px;
  }

  .welcome-suggestions{
    display:grid;
    grid-template-columns:1fr;
  }
}

@media(prefers-reduced-motion:reduce){
  *,*::before,*::after{
    scroll-behavior:auto!important;
    animation-duration:.001ms!important;
    animation-iteration-count:1!important;
    transition-duration:.001ms!important;
  }
}


/* =========================================================
   MOBILE APP SHELL — v0.4
   - conversa com rolagem por toque
   - composer fixo na parte inferior
   - sem bounce da página inteira
========================================================= */

@media(max-width:760px){

  html,
  body{
    width:100%;
    height:100%;
    min-height:100%;
    overflow:hidden;
    overscroll-behavior:none;
  }

  body{
    position:fixed;
    inset:0;
  }

  .app-shell{
    width:100%;
    height:100dvh;
    min-height:0;
    display:flex;
    flex-direction:column;
    overflow:hidden;
    padding:
      max(10px,env(safe-area-inset-top))
      max(10px,env(safe-area-inset-right))
      max(8px,env(safe-area-inset-bottom))
      max(10px,env(safe-area-inset-left));
  }

  .topbar{
    flex:0 0 auto;
    margin-bottom:8px;
  }

  .conversation-layout{
    flex:1 1 auto;
    min-height:0;
    display:flex;
    overflow:hidden;
  }

  .chat-card{
    flex:1 1 auto;
    min-height:0;
    height:100%;
    display:flex;
    flex-direction:column;
    overflow:hidden;
  }

  .chat-head{
    flex:0 0 auto;
  }

  .chat{
    flex:1 1 auto;
    min-height:0;
    max-height:none;
    overflow-y:auto;
    overflow-x:hidden;
    -webkit-overflow-scrolling:touch;
    touch-action:pan-y;
    overscroll-behavior-y:contain;
    scroll-behavior:smooth;
    padding:16px 10px 14px;
  }

  .composer-wrap{
    position:sticky;
    bottom:0;
    z-index:8;
    flex:0 0 auto;
    padding:
      10px 10px
      max(10px,env(safe-area-inset-bottom));
    background:var(--surface);
    border-top:1px solid var(--line);
  }

  .composer{
    width:100%;
  }

  textarea{
    font-size:16px;
  }

}

@supports(height:100svh){
  @media(max-width:760px){
    .app-shell{
      height:100svh;
    }
  }
}

@supports(height:100dvh){
  @media(max-width:760px){
    .app-shell{
      height:100dvh;
    }
  }
}

/* =========================================================
   PERFIL POR DISPOSITIVO — v0.4.2
========================================================= */

.profile-button{
  min-height:34px;
  display:inline-flex;
  align-items:center;
  gap:7px;
  padding:0 10px;
  border:1px solid var(--line);
  border-radius:999px;
  background:var(--surface);
  color:#a8b2bd;
  font-size:8.8px;
  font-weight:700;
  cursor:pointer;
}

.profile-button:hover{
  border-color:var(--line-2);
  color:var(--text-soft);
}

.profile-dot{
  width:6px;
  height:6px;
  border-radius:50%;
  background:var(--accent);
}

.profile-modal[hidden]{
  display:none;
}

.profile-modal{
  position:fixed;
  inset:0;
  z-index:200;
  display:grid;
  place-items:center;
  padding:20px;
  background:rgba(4,6,9,.72);
  backdrop-filter:blur(10px);
}

.profile-dialog{
  width:min(100%,390px);
  padding:18px;
  border:1px solid var(--line-2);
  border-radius:16px;
  background:#11161d;
  box-shadow:0 24px 70px rgba(0,0,0,.42);
}

.profile-dialog-kicker{
  color:var(--muted-2);
  font-size:7.5px;
  font-weight:760;
  letter-spacing:.07em;
  text-transform:uppercase;
}

.profile-dialog-title{
  margin-top:5px;
  color:var(--text);
  font-size:18px;
  font-weight:760;
  letter-spacing:-.025em;
}

.profile-dialog-copy{
  margin-top:5px;
  color:var(--muted);
  font-size:9.3px;
  line-height:1.5;
}

.profile-options{
  display:grid;
  gap:8px;
  margin-top:15px;
}

.profile-option{
  display:flex;
  align-items:center;
  gap:11px;
  width:100%;
  padding:11px;
  border:1px solid var(--line);
  border-radius:12px;
  background:var(--surface);
  color:var(--text-soft);
  text-align:left;
  cursor:pointer;
}

.profile-option:hover{
  border-color:#3a4350;
  background:var(--surface-2);
}

.profile-avatar{
  width:34px;
  height:34px;
  flex:0 0 34px;
  display:grid;
  place-items:center;
  border-radius:10px;
  background:#25213f;
  color:#d8d2ff;
  font-size:9px;
  font-weight:800;
}

.profile-option strong{
  display:block;
  font-size:10.5px;
  font-weight:730;
}

.profile-option small{
  display:block;
  margin-top:2px;
  color:var(--muted-2);
  font-size:8px;
}

@media(max-width:430px){
  .top-actions{
    gap:6px;
  }

  .profile-button{
    max-width:90px;
    min-height:31px;
    padding:0 8px;
    overflow:hidden;
  }

  #profileName{
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
  }
}
