/* Jarvis - painel pessoal. CSS puro, sem dependências nem fontes externas. */

:root {
  --off-white: #F6F5F1;
  --surface: #FFFFFF;
  --surface-2: #FBFAF7;
  --forest: #1E3A2F;
  --forest-700: #27493A;
  --forest-500: #35584A;
  --green: #2F6F4F;
  --green-soft: #E7EFE9;
  --green-line: #CBDCD1;
  --ink: #1A1F1C;
  --ink-2: #44504A;
  --muted: #6B7873;
  --line: #E3E1D9;
  --danger: #8C2F23;
  --danger-soft: #FBEDEA;
  --warn: #8A6412;
  --warn-soft: #FBF4E3;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(26, 31, 28, .05), 0 8px 24px rgba(26, 31, 28, .06);
  --tap: 44px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--off-white);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overflow-wrap: anywhere;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--green); }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

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

.icon {
  width: 20px; height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.nav-ico { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }

/* ---------- Boot ---------- */
.boot {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--off-white);
  z-index: 50;
}
.boot-card { display: flex; flex-direction: column; align-items: center; gap: 14px; color: var(--muted); }
.spinner {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--green-line);
  border-top-color: var(--green);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--forest); color: #F8FAF8; }
.btn-primary:hover:not([disabled]) { background: var(--forest-700); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover:not([disabled]) { background: var(--surface); border-color: var(--green-line); }
.btn-icon { min-width: var(--tap); padding: 0 10px; background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-icon:hover:not([disabled]) { background: rgba(30, 58, 47, .07); }
.btn-primary.btn-icon { background: var(--forest); color: #F8FAF8; }
.btn-block { width: 100%; }
.btn-sm { min-height: var(--tap); padding: 0 13px; font-size: .92rem; }

/* ---------- Campos ---------- */
.input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
textarea.input { min-height: 96px; resize: vertical; }
.input:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; border-color: var(--green); }
label { font-size: .86rem; font-weight: 600; color: var(--ink-2); }
.hint { font-size: .82rem; color: var(--muted); }

.alert {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  border: 1px solid #F0D7D1;
  color: var(--danger);
  font-size: .9rem;
}
.alert.ok { background: var(--green-soft); border-color: var(--green-line); color: var(--green); }

/* ---------- Login ---------- */
.login-view {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 26px 22px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-sub { font-size: .88rem; color: var(--muted); }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex: 0 0 auto;
  border-radius: 11px;
  background: var(--forest);
  color: #F8FAF8;
  font-weight: 600; font-size: 1.05rem;
}
#login-form { display: grid; gap: 7px; }
#login-form .btn { margin-top: 12px; }
.powered { margin-top: 20px; text-align: center; font-size: .8rem; }
.powered a { color: var(--muted); text-decoration: none; }
.powered a:hover { color: var(--green); text-decoration: underline; }

/* ---------- Estrutura do app ---------- */
.app {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100dvh;
}
.sidebar { display: none; }

.main {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
}

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--off-white);
  position: sticky; top: 0; z-index: 5;
}
.topbar-title { flex: 1 1 auto; min-width: 0; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 2px; flex: 0 0 auto; }

.screens { flex: 1 1 auto; min-height: 0; display: flex; }
.screen { flex: 1 1 auto; min-width: 0; min-height: 0; overflow: auto; }
.screen[hidden] { display: none; }

.stack { display: grid; gap: 14px; padding: 14px 12px 20px; max-width: 920px; }

.app-foot { padding: 10px 12px; border-top: 1px solid var(--line); text-align: center; font-size: .78rem; }
.app-foot a { color: var(--muted); text-decoration: none; }
.app-foot a:hover { color: var(--green); text-decoration: underline; }

.tabbar {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 56px;
  border: 0; background: transparent;
  color: var(--muted);
  font: inherit; font-size: .72rem; font-weight: 500;
  cursor: pointer;
}
.tab[aria-current="page"] { color: var(--forest); }
.tab[aria-current="page"] .icon { stroke-width: 2; }
.tab:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }

.only-mobile { display: inline-flex; }

/* ---------- Listas e cartões ---------- */
.list { display: grid; gap: 8px; align-content: start; }

.card {
  display: block; width: 100%; text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
  min-height: var(--tap);
}
button.card { cursor: pointer; }
button.card:hover { border-color: var(--green-line); background: var(--surface-2); }
button.card:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.card[aria-current="true"] { border-color: var(--green); background: var(--green-soft); }
.card-title { font-weight: 600; font-size: .96rem; }
.card-meta { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: .8rem; color: var(--muted); }
.card-row { display: flex; align-items: flex-start; gap: 10px; }
.card-row > div { min-width: 0; flex: 1 1 auto; }
/* O seletor .card-row > div acima também pega as ações, por isso esta regra
   precisa da mesma força para o botão não encolher e quebrar letra por letra. */
.card-row > .card-actions { display: flex; gap: 6px; flex: 0 0 auto; min-width: auto; }
.card-actions .btn { white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: .74rem; font-weight: 600; color: var(--ink-2);
  white-space: nowrap;
}
.badge.is-done { background: var(--green-soft); border-color: var(--green-line); color: var(--green); }
.badge.is-run { background: #E9EFF7; border-color: #CCDCEE; color: #2A4F7A; }
.badge.is-wait { background: var(--warn-soft); border-color: #EDDFBC; color: var(--warn); }
.badge.is-fail { background: var(--danger-soft); border-color: #F0D7D1; color: var(--danger); }

.empty, .loading, .error-box {
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
  font-size: .9rem;
  text-align: center;
}
.error-box { border-style: solid; background: var(--danger-soft); border-color: #F0D7D1; color: var(--danger); }
.error-box .btn { margin-top: 10px; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; }

.block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.block .list .card { background: var(--surface-2); }

.form-grid { display: grid; gap: 7px; }
.form-grid .btn { margin-top: 8px; justify-self: start; }

/* ---------- Conversas ---------- */
.conv-layout { display: flex; min-width: 0; min-height: 0; height: 100%; }
.conv-list-pane, .conv-thread-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; flex: 1 1 auto; }
.conv-layout[data-pane="list"] .conv-thread-pane { display: none; }
.conv-layout[data-pane="thread"] .conv-list-pane { display: none; }

.pane-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 10px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.pane-head .btn { grid-column: 1 / -1; }
.field-inline { font-size: .82rem; }

.agent-card {
  margin: 12px 12px 0;
  padding: 11px 13px;
  border: 1px solid var(--green-line);
  border-radius: var(--radius);
  background: var(--green-soft);
  font-size: .86rem;
  color: var(--forest);
}
.agent-card .agent-name { font-weight: 600; }
.agent-card .agent-title { color: var(--ink-2); }

#conv-list { padding: 12px; overflow: auto; flex: 1 1 auto; min-height: 0; }

.thread-head {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.thread-head .th-title { font-weight: 600; }
.thread-head .th-sub { font-size: .8rem; color: var(--muted); }

.thread-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 14px 12px; display: grid; gap: 10px; align-content: start; }

.msg { max-width: min(680px, 94%); padding: 11px 13px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); }
.msg.is-user { justify-self: end; background: var(--forest); border-color: var(--forest); color: #F3F7F3; }
.msg.is-agent { justify-self: start; }
.msg-text { white-space: pre-wrap; font-size: .95rem; }
.msg-foot { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: .74rem; color: var(--muted); }
.msg.is-user .msg-foot { color: rgba(243, 247, 243, .78); }
.msg.is-user .badge { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .26); color: #F3F7F3; }

.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.composer-input {
  flex: 1 1 auto; min-width: 0;
  min-height: var(--tap); max-height: 160px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  resize: none;
  overflow: auto;
}
.composer-input:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; border-color: var(--green); }
.composer-alert { margin: 0 12px 10px; }

/* ---------- Segundo cérebro ---------- */
.status-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.status-grid { display: grid; gap: 10px 18px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-top: 4px; }
.status-item .k { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.status-item .v { font-size: .94rem; font-weight: 600; }
.status-item .v.path { font-family: var(--mono); font-size: .8rem; font-weight: 500; }

.search-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: center; margin-bottom: 12px; }
.search-ico { color: var(--muted); }
.search-row .btn { grid-column: 1 / -1; }

.note-path { font-family: var(--mono); font-size: .78rem; color: var(--muted); overflow-wrap: anywhere; }
.note-state:empty { display: none; }
.note-body {
  margin: 0;
  max-height: 60vh;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: .82rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.note-body:empty { display: none; }

/* ---------- Diálogos ---------- */
.dlg {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: auto;
}
.dlg-wide { width: min(760px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(26, 31, 28, .42); }
.dlg-form { display: grid; gap: 7px; padding: 16px 18px 18px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.dlg-actions .btn { flex: 1 1 auto; }

/* ---------- Tablet e desktop ---------- */
/* Entre 700px e 959px a lista ocupa a tela inteira e cabe tudo numa linha.
   Acima disso ela vira a coluna estreita, então o botão volta para a linha de baixo. */
@media (min-width: 700px) and (max-width: 959px) {
  .pane-head { grid-template-columns: auto minmax(0, 1fr) auto; }
  .pane-head .btn { grid-column: auto; }
}

@media (min-width: 700px) {
  .search-row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .search-row .btn { grid-column: auto; }
  .stack { padding: 18px 18px 24px; }
  .dlg-actions .btn { flex: 0 0 auto; }
}

@media (min-width: 960px) {
  .app { grid-template-columns: 248px minmax(0, 1fr); grid-template-rows: 100dvh; }
  .sidebar {
    display: flex; flex-direction: column; gap: 14px;
    padding: 16px 12px;
    border-right: 1px solid var(--line);
    background: var(--surface);
    min-width: 0;
    overflow: auto;
  }
  .side-brand { display: flex; align-items: center; gap: 10px; padding: 0 4px 4px; }
  .side-brand-name { font-weight: 600; font-size: 1.05rem; }
  .side-nav { display: grid; gap: 4px; }
  .nav-item {
    display: flex; align-items: center; gap: 10px;
    min-height: var(--tap);
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-2);
    font: inherit; font-weight: 500; font-size: .94rem;
    cursor: pointer;
    text-align: left;
  }
  .nav-item:hover { background: var(--surface-2); border-color: var(--line); }
  .nav-item:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
  .nav-item[aria-current="page"] { background: var(--green-soft); border-color: var(--green-line); color: var(--forest); font-weight: 600; }
  .side-foot { margin-top: auto; display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
  .side-user { display: flex; align-items: center; gap: 8px; padding: 0 4px; font-size: .82rem; color: var(--muted); }
  .side-email { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar { display: none; }
  .only-mobile { display: none !important; }

  .conv-layout { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); }
  .conv-layout[data-pane="list"] .conv-thread-pane,
  .conv-layout[data-pane="thread"] .conv-list-pane { display: flex; }
  .conv-list-pane { border-right: 1px solid var(--line); background: var(--surface); }
  .conv-thread-pane { background: var(--off-white); }
}

/* ---------- Última palavra: o atributo hidden sempre esconde ----------
   Vem no fim de propósito: várias regras acima definem display (flex, grid,
   inline-flex) e venceriam o hidden por ordem de declaração. */
[hidden] { display: none !important; }
