/* =============== RESET & TOKENS =============== */
:root {
  --bg: #0b0c10;
  --panel: #111317;
  --panel-2: #171a21;
  --text: #e6e6e6;
  --muted: #a0a8b4;
  --primary: #5b8cff;
  --primary-600: #4577f5;
  --primary-700: #3766db;
  --success: #3ad29f;
  --danger: #ff6b6b;
  --warning: #ffb648;
  --border: #2a2f3a;

  --me: #2d5fff;
  --me-2: #234ccc;
  --them: #2b2f36;

  --radius: 12px;
  --radius-sm: 8px;

  --space-1: .25rem;
  --space-2: .5rem;
  --space-3: .75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  --shadow-1: 0 6px 20px rgba(0,0,0,.25);
  --shadow-2: 0 4px 12px rgba(0,0,0,.18);

  --font: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f8fb;
    --panel: #ffffff;
    --panel-2: #f1f3f7;
    --text: #1b1f27;
    --muted: #5a6272;
    --border: #dfe3eb;

    --them: #eef1f7;
    --me: #2563eb;
    --me-2: #1e49ad;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: linear-gradient(180deg, var(--bg), #0b0d12 35%);
  color: var(--text);
  line-height: 1.45;
}

/* Links & botões */
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .5rem;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: .6rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: .2s ease;
}
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary-700); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--primary-600); }
button.ghost, .btn.ghost { background: transparent; border-color: var(--border); }
button.danger { background: var(--danger); border-color: #e45b5b; color: #fff; }
button:disabled { opacity: .6; cursor: not-allowed; }

/* Inputs */
input, select, textarea {
  width: 100%;
  padding: .7rem .85rem;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius-sm);
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(91,140,255,.15);
}

/* Utils */
.container { width: min(1200px, 100%); margin-inline: auto; padding: var(--space-8) var(--space-4); }
.stack { display: grid; gap: var(--space-4); }
.row { display: flex; gap: var(--space-4); flex-wrap: wrap; align-items: center; }
.center { display: grid; place-items: center; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: var(--space-6);
}

/* Tipografia */
h1, h2, h3 { margin: 0 0 var(--space-4); line-height: 1.2; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.5vw, 2.2rem); }
h2 { font-size: clamp(1.3rem, 1.1rem + .7vw, 1.6rem); }
small, .muted { color: var(--muted); }

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

/* =============== LAYOUT DO APP =============== */
.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: 64px 1fr 64px;
  grid-template-areas:
    "sidebar header"
    "sidebar main"
    "sidebar composer";
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

@media (max-width: 880px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 64px auto 1fr 64px;
    grid-template-areas:
      "header"
      "sidebar"
      "main"
      "composer";
  }
}

/* Sidebar (lista de conversas) */
.sidebar {
  grid-area: sidebar;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: auto;
}
.sidebar .search {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}
.conv-list { list-style: none; padding: 0; margin: 0; }
.conv-item {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.conv-item:hover { background: var(--panel-2); }
.conv-item .meta { display: grid; gap: .25rem; flex: 1; min-width: 0; }
.conv-item .meta .title { font-weight: 600; display: flex; align-items: center; gap: .5rem; }
.conv-item .meta .last { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-grid; place-items: center;
  min-width: 20px; height: 20px; padding: 0 .4rem;
  background: var(--primary);
  color: #fff; border-radius: 999px;
  font-size: .75rem; font-weight: 700;
}

/* Header da conversa */
.header {
  grid-area: header;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-4);
  gap: var(--space-4);
}
.header .left, .header .right { display: flex; align-items: center; gap: var(--space-3); }

/* Área de mensagens */
.chat {
  grid-area: main;
  background: radial-gradient(1200px 800px at 70% -20%, rgba(91,140,255,.08), transparent 60%), var(--panel-2);
  overflow: auto;
  padding: var(--space-6) var(--space-4);
  display: grid; align-content: start; gap: var(--space-4);
}
.day-divider {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: var(--space-4);
  align-items: center; color: var(--muted);
}
.day-divider::before, .day-divider::after {
  content: ""; height: 1px; background: var(--border);
}
.message {
  display: grid; gap: .35rem; max-width: min(78%, 680px);
  padding: .6rem .8rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--them);
  position: relative;
}
.message.me {
  margin-left: auto;
  background: linear-gradient(180deg, var(--me), var(--me-2));
  color: #fff;
  border-color: transparent;
}
.message .meta { display: flex; align-items: center; gap: .5rem; }
.message .bubble { white-space: pre-wrap; word-wrap: break-word; }
.message .footer {
  display: flex; gap: .75rem; align-items: center; justify-content: flex-end;
  font-size: .8rem; color: var(--muted);
}
.message.me .footer { color: rgba(255,255,255,.9); opacity: .8; }
.msg-attachments { display: flex; gap: .5rem; flex-wrap: wrap; }
.attachment {
  background: rgba(0,0,0,.1); border: 1px dashed var(--border);
  padding: .4rem .6rem; border-radius: 8px; font-size: .9rem;
}
.reactions { display: flex; gap: .3rem; flex-wrap: wrap; }

/* Composer */
.composer {
  grid-area: composer;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: var(--space-3) var(--space-4);
  display: grid; grid-template-columns: auto 1fr auto; gap: var(--space-3);
}
.composer .tools { display: flex; gap: .25rem; }
.composer textarea {
  max-height: 30dvh; min-height: 44px; resize: vertical;
}

/* Avatares */
.avatar {
  width: 40px; height: 40px; border-radius: 999px;
  background: linear-gradient(180deg, #2e3340, #1e222b);
  border: 1px solid var(--border);
  display: grid; place-items: center; color: #fff; font-weight: 700;
}
.avatar.sm { width: 28px; height: 28px; font-size: .8rem; }

/* Chips/labels */
.chip {
  display: inline-flex; align-items: center; gap: .5rem;
  border: 1px solid var(--border); background: var(--panel);
  padding: .3rem .6rem; border-radius: 999px; color: var(--muted);
}

/* Tabelas simples (bloqueios) */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .7rem .6rem; border-bottom: 1px solid var(--border); text-align: left; }
.table th { color: var(--muted); font-weight: 600; }

/* Modais (estrutura pronta para quando usar JS) */
.modal {
  position: fixed; inset: 0; display: none; place-items: center;
  background: rgba(0,0,0,.55); padding: var(--space-4);
}
.modal .dialog {
  width: min(560px, 100%); background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-2); padding: var(--space-6);
}
.modal[open] { display: grid; }

/* Login/entrar */
.auth {
  min-height: 100dvh; display: grid; place-items: center;
  padding: var(--space-8);
}
.auth .card { width: min(420px, 100%); }
.footer-note { text-align: center; color: var(--muted); margin-top: var(--space-4); font-size: .9rem; }
