/* vls-dashboard — thème clair sobre, sans framework. Contrastes AA. */
:root {
  --bg: #f5f6f8; --surface: #ffffff; --text: #1d2330; --muted: #5d6675; --line: #dfe3ea;
  --brand: #1f6f5c; --brand-ink: #ffffff; --link: #1a5fb4;
  --grey: #5d6675; --blue: #1a5fb4; --green: #1e7a3c; --red: #b42318; --dark-green: #14532d;
  --grey-bg: #eceef2; --blue-bg: #e3edfb; --green-bg: #e3f4e8; --red-bg: #fde8e6; --dark-green-bg: #d6efdc;
  --radius: 8px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--link); }
h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: .6rem 0 .3rem; }
.muted { color: var(--muted); }
.small, small { font-size: .85rem; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pad { padding: .8rem; }
.error-text { color: var(--red); font-size: .85rem; }
code { background: var(--grey-bg); padding: 0 .3rem; border-radius: 4px; }

/* ---------- layout */
body { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
body.login-page { display: block; }
.sidebar { background: #16302a; color: #e8f0ed; padding: 1rem .6rem; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: .15rem; }
.sidebar a { color: #e8f0ed; text-decoration: none; padding: .55rem .7rem; border-radius: 6px; display: flex;
  justify-content: space-between; align-items: center; }
.sidebar a:hover, .sidebar a:focus-visible { background: rgba(255, 255, 255, .08); }
.sidebar a.active { background: var(--brand); }
.brand-full { font-weight: 700; padding: .3rem .7rem 1rem; line-height: 1.2; }
.brand-full small { font-weight: 400; opacity: .8; }
.logout { margin-top: auto; padding: .5rem .7rem; }
.link { background: none; border: 0; color: inherit; cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }
.topbar { display: none; }
.content { padding: 1.2rem 1.5rem 3rem; min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card.bad { border-color: var(--red); }

/* ---------- controls */
.btn { display: inline-block; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 6px; padding: .45rem .8rem; cursor: pointer; font: inherit; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.small { padding: .25rem .55rem; font-size: .85rem; }
input, select, textarea { font: inherit; padding: .4rem .5rem; border: 1px solid #b9c0cc; border-radius: 6px; background: #fff; color: var(--text); }
:focus-visible { outline: 3px solid #7aa7e8; outline-offset: 1px; }
label { display: inline-flex; flex-direction: column; gap: .2rem; font-size: .85rem; color: var(--muted); }
label.chk, label.chip { flex-direction: row; align-items: center; gap: .3rem; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: .25rem .7rem; background: var(--surface); color: var(--text); cursor: pointer; }
.chip input { margin: 0; }
.period { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.custom-dates { display: inline-flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.filters { margin-bottom: 1rem; }
.filter-row { display: flex; flex-wrap: wrap; gap: .7rem; align-items: flex-end; }
.filter-row .grow { flex: 1 1 260px; }
.filter-row .grow input { width: 100%; }

/* ---------- banners, badges */
.banner { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.banner.danger, .alert { background: var(--red-bg); color: var(--red); border: 1px solid #f3b8b1; border-radius: 6px; padding: .5rem .8rem; }
.badge { display: inline-block; padding: .1rem .45rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--grey-bg); color: var(--grey); white-space: nowrap; }
.st-sent { background: var(--grey-bg); color: var(--grey); }
.st-delivered { background: var(--blue-bg); color: var(--blue); }
.st-read { background: var(--green-bg); color: var(--green); }
.st-failed { background: var(--red-bg); color: var(--red); }
.st-recovered { background: var(--dark-green-bg); color: var(--dark-green); }
.step { background: #efe9fb; color: #5b2fb3; }
.count { display: inline-block; min-width: 1.4rem; padding: 0 .35rem; border-radius: 999px; background: #d92d20;
  color: #fff; font-size: .75rem; text-align: center; font-weight: 700; }

/* ---------- KPI & charts */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; display: flex; flex-direction: column; gap: .2rem; }
.kpi .label { color: var(--muted); font-size: .82rem; }
.kpi strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); }
.kpi.bad strong { color: var(--red); }
.kpi.good strong { color: var(--dark-green); }
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.chart-wide { grid-column: 1 / -1; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: .8rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem .8rem; margin: 0; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.log { padding-left: 1rem; font-size: .85rem; max-height: 320px; overflow: auto; }

/* ---------- tables */
.table-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.data { border-collapse: collapse; width: 100%; font-size: .9rem; }
.data th, .data td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
.data th { background: #f0f2f5; font-weight: 600; white-space: nowrap; }
.data th a { color: inherit; text-decoration: none; }
.data tr:last-child td { border-bottom: 0; }
.data .empty { text-align: center; color: var(--muted); padding: 2rem; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: flex-start; }
.actions form { margin: 0; }
.reveal { border: 0; background: none; padding: 0; color: inherit; font: inherit; cursor: pointer; border-bottom: 1px dotted var(--muted); }
.pager { display: flex; gap: 1rem; justify-content: center; align-items: center; margin: 1rem 0; }
.tabs { display: flex; gap: .3rem; margin-bottom: .8rem; }
.tabs a { padding: .4rem .9rem; border-radius: 6px; text-decoration: none; color: var(--text); border: 1px solid var(--line); background: var(--surface); }
.tabs a.active { background: var(--brand); color: #fff; border-color: var(--brand); }
ul.plain { list-style: none; padding: 0; margin: .3rem 0; display: flex; flex-direction: column; gap: .3rem; }

/* ---------- login */
main.login { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: .8rem; }
.login-card input { width: 100%; }

/* ---------- Team Inbox */
main.inbox { padding: 0; min-width: 0; height: 100vh; }
.inbox-grid { display: grid; grid-template-columns: 320px 1fr; height: 100vh; }
.conv-pane { border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.conv-tabs { display: flex; border-bottom: 1px solid var(--line); }
.conv-tabs a { flex: 1; text-align: center; padding: .6rem .2rem; font-size: .85rem; text-decoration: none; color: var(--muted); }
.conv-tabs a.active { color: var(--brand); border-bottom: 2px solid var(--brand); font-weight: 600; }
.relance-filter { padding: .5rem .8rem; border-bottom: 1px solid var(--line); flex-direction: row; align-items: center; }
#conv-list { overflow-y: auto; flex: 1; outline: none; }
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv { display: flex; flex-direction: column; gap: .15rem; padding: .65rem .8rem; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--text); }
.conv:hover, .conv.kbd { background: #f2f5f9; }
.conv.active { background: #e6f2ee; box-shadow: inset 3px 0 0 var(--brand); }
.conv.unread .name { font-weight: 800; }
.conv-top { display: flex; justify-content: space-between; gap: .5rem; }
.conv-snippet { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-badges { display: flex; gap: .25rem; flex-wrap: wrap; }
.thread-pane { min-width: 0; min-height: 0; display: flex; }
.empty-thread { margin: auto; padding: 2rem; }
.thread { display: grid; grid-template-columns: 1fr 300px; width: 100%; min-height: 0; }
.thread-main { display: flex; flex-direction: column; min-height: 0; height: 100vh; }
.thread-head { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; padding: .6rem .9rem; border-bottom: 1px solid var(--line); background: var(--surface); }
.thread-head .who { display: flex; flex-direction: column; flex: 1; min-width: 140px; }
.back-btn { display: none; border: 0; background: none; font-size: 1.3rem; cursor: pointer; }
.conv-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.conv-actions form { margin: 0; }
.labels-menu { position: relative; }
.labels-menu summary { list-style: none; }
.labels-menu form { position: absolute; right: 0; z-index: 5; background: var(--surface); border: 1px solid var(--line);
  border-radius: 6px; padding: .6rem; display: flex; flex-direction: column; gap: .3rem; min-width: 180px; box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .5rem; background: #eef1f4; }
.older { align-self: center; }
.msg { display: flex; flex-direction: column; max-width: 75%; }
.msg-in { align-self: flex-start; }
.msg-out { align-self: flex-end; align-items: flex-end; }
.msg-activity { align-self: center; max-width: 90%; }
.activity { font-size: .8rem; color: var(--muted); background: #e2e6eb; padding: .2rem .6rem; border-radius: 999px; }
.bubble { padding: .5rem .7rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); }
.msg-out .bubble { background: #dff3ea; border-color: #c4e5d6; }
.msg.private .bubble { background: #fff6dc; border-color: #f0dc9e; }
.note-label { font-size: .75rem; font-weight: 700; color: #8a6100; display: block; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-meta { font-size: .75rem; color: var(--muted); margin-top: .15rem; display: flex; gap: .3rem; }
.tick.read { color: #1a73e8; font-weight: 700; }
.tick.failed { color: var(--red); font-weight: 700; }
.att-img { max-width: 240px; max-height: 240px; border-radius: 6px; display: block; margin-top: .3rem; }
.composer { border-top: 1px solid var(--line); background: var(--surface); padding: .6rem .9rem; display: flex; flex-direction: column; gap: .5rem; }
.window { margin: 0; font-size: .82rem; }
.window.ok { color: var(--green); }
.window.closed { color: #8a4b00; }
.reply-form textarea { width: 100%; resize: vertical; }
.reply-tools { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: flex-end; margin-top: .3rem; }
.template-form { display: flex; flex-direction: column; gap: .4rem; }
.template-form fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .3rem; }
.tpl-body { background: var(--grey-bg); padding: .5rem; border-radius: 6px; white-space: pre-wrap; margin: 0; color: var(--text); }
.msg-error { color: var(--red); font-size: .85rem; }
.contact-panel { border-left: 1px solid var(--line); background: var(--surface); padding: 1rem; overflow-y: auto; height: 100vh; }
.contact-panel .ctx { margin: .6rem 0; padding: .6rem; }

/* ---------- mobile */
@media (max-width: 900px) {
  body { display: block; }
  .topbar { display: flex; align-items: center; gap: .6rem; padding: .5rem 1rem; background: #16302a; color: #fff; position: sticky; top: 0; z-index: 20; }
  .menu-btn { background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }
  .sidebar { display: none; position: fixed; z-index: 30; top: 44px; left: 0; width: 240px; height: calc(100vh - 44px); }
  .sidebar.open { display: flex; }
  .brand-full { display: none; }
  .content { padding: 1rem; }
  .charts { grid-template-columns: 1fr; }
  main.inbox, .inbox-grid, .thread-main, .contact-panel { height: calc(100vh - 44px); }
  .inbox-grid { grid-template-columns: 1fr; }
  .inbox-grid.has-conv .conv-pane { display: none; }
  .inbox-grid:not(.has-conv) .thread-pane { display: none; }
  .thread { grid-template-columns: 1fr; }
  .contact-panel { display: none; }
  .back-btn { display: inline-block; }
  .msg { max-width: 90%; }
}
