:root {
  /* Identidade Prysmo: navy + cyan sobre claro, tipografia Roboto */
  --paper:    #eef2f7;
  --surface:  #ffffff;
  --surface-2:#eef2f7;
  --navy:     #1F2B4A;
  --ink:      #1F2B4A;
  --muted:    #69748b;
  --line:     #e1e7f0;
  --accent:   #0F9FBC;
  --accent-d: #0B7E96;
  --accent-soft: #def1f6;
  --blue:     #0B82E6;
  --blue-soft:#e2eefd;
  --red:      #b3392a;
  --red-soft: #fbe7e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31,43,74,.05), 0 10px 28px -14px rgba(31,43,74,.22);
  font-size: 15.5px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: "Roboto", system-ui, sans-serif;
  line-height: 1.55; -webkit-font-smoothing: antialiased;
  background-image: radial-gradient(1100px 520px at 88% -10%, #e3eef5 0%, transparent 60%);
}
h1, h2, h3 { font-family: "Roboto", sans-serif; font-weight: 700; letter-spacing: -.01em; color: var(--navy); margin: 0; }
.muted { color: var(--muted); }
.logo { height: 28px; display: block; }
code { background: var(--surface-2); padding: .1rem .35rem; border-radius: 5px; font-size: .85em; }

/* ---------- inputs / botões ---------- */
input, select, textarea, button { font: inherit; color: var(--ink); }
input, textarea { width: 100%; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: .65rem .8rem; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
button { cursor: pointer; border: 1px solid transparent; border-radius: 999px;
  padding: .6rem 1.3rem; font-weight: 500; transition: filter .15s, background .15s, border-color .15s; }
.btn-primary { background: linear-gradient(135deg, #1f6fd0, var(--blue)); color: #fff;
  box-shadow: 0 8px 18px -9px var(--blue); font-weight: 500; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-block { width: 100%; }

/* ---------- login ---------- */
.login-bg { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--surface); padding: 2.6rem 2.4rem; border-radius: 18px;
  width: 374px; border: 1px solid var(--line); box-shadow: var(--shadow); text-align: center; }
.login-brand { margin-bottom: 1.4rem; }
.login-brand .logo { height: 34px; margin: 0 auto; }
.login-card h1 { margin: .4rem 0 .1rem; font-size: 1.7rem; }
.login-card .muted { margin-top: 0; }
.login-card label { display: block; margin: 1.05rem 0 .25rem; font-size: .8rem;
  color: var(--muted); font-weight: 600; text-align: left; }
.btn-primary.btn-block { margin-top: 1.4rem; }
.alert { background: var(--red-soft); color: #9a3320; padding: .6rem .8rem; border-radius: 10px;
  border: 1px solid #f0c9bf; font-size: .9rem; margin-top: 1rem; text-align: left; }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 1.2rem; padding: .7rem 1.4rem;
  background: rgba(255,255,255,.9); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-title { color: var(--muted); font-weight: 600; font-size: .9rem;
  border-left: 1px solid var(--line); padding-left: 1.2rem; }
.user { margin-left: auto; display: flex; align-items: center; gap: .9rem; }
.user-name { color: var(--navy); font-weight: 600; font-size: .9rem; }
.logout { color: var(--muted); text-decoration: none; font-size: .85rem; }
.logout:hover { color: var(--accent); }
.tab { background: transparent; color: var(--muted); border: 1px solid var(--line);
  padding: .4rem .9rem; border-radius: 999px; font-weight: 500; font-size: .85rem; }
.tab:hover { color: var(--navy); border-color: var(--accent); }

/* ---------- shell (sidebar + chat) ---------- */
.chat-body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.chat-shell { flex: 1; display: grid; grid-template-columns: 280px 1fr; min-height: 0; }

.sidebar { border-right: 1px solid var(--line); background: rgba(255,255,255,.6);
  padding: 1rem; display: flex; flex-direction: column; gap: .8rem; min-height: 0; }
.conv-list { overflow-y: auto; display: flex; flex-direction: column; gap: .35rem; }
.conv-row { display: flex; align-items: center; gap: .15rem; }
.conv-item { flex: 1; min-width: 0; text-align: left; background: transparent; border: 1px solid transparent;
  border-radius: 10px; padding: .55rem .7rem; color: var(--ink); font-size: .88rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 400; }
.conv-item:hover { background: var(--surface); border-color: var(--line); }
.conv-item.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-d); font-weight: 600; }
.conv-del { flex: 0 0 auto; opacity: 0; background: transparent; border: none;
  padding: .3rem .4rem; border-radius: 8px; color: var(--muted); font-size: .85rem; line-height: 1; }
.conv-row:hover .conv-del { opacity: .8; }
.conv-del:hover { opacity: 1 !important; color: var(--red); background: var(--red-soft); }

/* ---------- área do chat ---------- */
.chat-main { display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 1.6rem clamp(1rem, 8vw, 6rem); display: flex; flex-direction: column; gap: 1rem; }
.empty-hint { color: var(--muted); text-align: center; margin: auto; font-style: italic; }
.msg { max-width: 760px; width: fit-content; padding: .8rem 1.1rem; border-radius: var(--radius);
  box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, #1f6fd0, var(--blue)); color: #fff; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); }
.msg.system-note { align-self: center; background: var(--surface-2); color: var(--muted);
  font-size: .82rem; font-style: italic; border-radius: 999px; box-shadow: none; }

.composer { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem;
  padding: .9rem clamp(1rem, 8vw, 6rem) .4rem;
  border-top: 1px solid var(--line); background: rgba(255,255,255,.7); }

/* chips de anexos staged (acima da linha de input) */
.attachments { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .2rem; }
.attachments[hidden] { display: none; }
.chip { display: inline-flex; align-items: center; gap: .4rem; max-width: 260px;
  background: var(--accent-soft); border: 1px solid var(--accent); color: var(--accent-d);
  border-radius: 999px; padding: .3rem .7rem; font-size: .82rem; }
.chip .spinner { margin: 0; }
.chip-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-error { background: var(--red-soft); border-color: #f0c9bf; color: #9a3320; }
.chip-x { background: transparent; border: none; color: inherit; padding: 0 0 0 .1rem;
  font-size: 1.05rem; line-height: 1; cursor: pointer; }
/* chips já dentro da bolha do usuário enviada */
.msg-atts { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .5rem; }
.chip-in-msg { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.35); color: #fff; }
.composer textarea { resize: none; max-height: 160px; border-radius: 14px; }
.attach { flex: 0 0 auto; display: grid; place-items: center; width: 42px; height: 42px;
  border: 1px solid var(--line); border-radius: 50%; cursor: pointer; font-size: 1.4rem;
  color: var(--accent-d); background: var(--surface); }
.attach:hover { border-color: var(--accent); }
.composer .btn-primary { flex: 0 0 auto; height: 42px; }
.status { min-height: 1.3em; padding: 0 clamp(1rem, 8vw, 6rem) .6rem; font-size: .82rem; color: var(--muted); }

.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: .4rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modal de keys ---------- */
.modal { position: fixed; inset: 0; background: rgba(31,43,74,.45); display: grid; place-items: center; z-index: 20; }
/* `.modal[hidden]` (classe+atributo) tem especificidade maior que `.modal`,
   então o atributo `hidden` volta a esconder de fato o modal. */
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); border-radius: 18px; padding: 1.6rem; width: min(560px, 92vw);
  box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .3rem; }
.modal-x { background: transparent; color: var(--muted); font-size: 1.5rem; padding: 0 .4rem; }
.key-create { display: flex; gap: .5rem; margin: 1rem 0; }
.key-create input { flex: 1; }
.key-create .btn-primary { flex: 0 0 auto; }
.key-reveal { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 10px;
  padding: .7rem .9rem; font-family: monospace; font-size: .82rem; word-break: break-all; margin-bottom: 1rem; }
.key-list { display: flex; flex-direction: column; gap: .5rem; max-height: 320px; overflow-y: auto; }
.key-row { display: flex; align-items: center; gap: .6rem; border: 1px solid var(--line);
  border-radius: 10px; padding: .55rem .8rem; font-size: .85rem; }
.key-row .kp { font-family: monospace; color: var(--navy); }
.key-row .kmeta { color: var(--muted); font-size: .78rem; }
.key-row .revoke { margin-left: auto; color: var(--red); background: var(--red-soft);
  border: 1px solid #f0c9bf; border-radius: 999px; padding: .2rem .7rem; font-size: .78rem; font-weight: 600; }
.key-row.revoked { opacity: .5; }

@media (max-width: 720px) {
  .chat-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
