/* Secretária Virtual — portal. Plain CSS, light + dark. */
:root {
    --bg: #f3f5f7;
    --surface: #ffffff;
    --surface-2: #f8fafb;
    --text: #1d2730;
    --muted: #5f6b77;
    --border: #dde3e9;
    --primary: #0b6e4f;
    --primary-hover: #095c42;
    --primary-soft: #e3f2ec;
    --bubble-in: #ffffff;
    --bubble-out: #dcf3e7;
    --chat-bg: #eef1ec;
    --danger: #b42318;
    --danger-soft: #fdecea;
    --warning: #8a5a00;
    --warning-soft: #fff4d6;
    --success-soft: #e3f2ec;
    --info-soft: #e7f0fb;
    --read: #1a73c8;
    --bar: #0b6e4f;
    --radius: 8px;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12171c;
        --surface: #1b2228;
        --surface-2: #20282f;
        --text: #e6eaee;
        --muted: #9aa6b2;
        --border: #2e3841;
        --primary: #3fb68b;
        --primary-hover: #57c79d;
        --primary-soft: #1d3a30;
        --bubble-in: #232c34;
        --bubble-out: #1f4536;
        --chat-bg: #161c21;
        --danger: #f08a80;
        --danger-soft: #3a2020;
        --warning: #f2c46b;
        --warning-soft: #3a3020;
        --success-soft: #1d3a30;
        --info-soft: #1e2d3d;
        --read: #6cb4ff;
        --bar: #3fb68b;
    }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--primary); }
h1 { font-size: 1.35rem; margin: 0 0 16px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }

/* ---------- shell ---------- */
.topbar {
    height: 52px;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 650; text-decoration: none; color: var(--text); }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.topbar-user form { margin: 0; }
.shell { display: grid; grid-template-columns: 210px 1fr; min-height: calc(100vh - 52px); }
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 12px 8px;
    display: flex; flex-direction: column; gap: 2px;
}
.sidebar a {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px; border-radius: 6px;
    color: var(--text); text-decoration: none;
}
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar-title { margin: 14px 12px 4px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.content { padding: 20px; min-width: 0; }
.content-flush { padding: 0; }
.content-flush > .alert { margin: 8px; }

@media (max-width: 760px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar {
        flex-direction: row; overflow-x: auto; white-space: nowrap;
        border-right: 0; border-bottom: 1px solid var(--border); padding: 6px;
    }
    .sidebar-title { display: none; }
    .content { padding: 14px 12px; }
}

/* ---------- basics ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.login-card { max-width: 380px; margin: 60px auto; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }

label { display: block; margin: 12px 0 4px; font-weight: 500; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 6px 14px 6px 0; font-weight: 400; }
input[type="email"], input[type="password"], input[type="text"], input[type="search"], input[type="number"], input[type="time"], textarea, select {
    width: 100%; padding: 8px 10px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); color: var(--text); font: inherit;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border: 1px solid transparent; border-radius: 6px;
    font: inherit; cursor: pointer; text-decoration: none; line-height: 1.2;
    background: var(--surface-2); color: var(--text); border-color: var(--border);
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 0.85rem; }
.btn-block { width: 100%; justify-content: center; margin-top: 18px; }
button.link { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; }
form.inline { display: inline; margin: 0; }

.alert { padding: 10px 12px; border-radius: 6px; margin: 0 0 12px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--primary); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-info { background: var(--info-soft); }

.badge { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 0.75rem; font-weight: 600; text-align: center; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.75rem; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.pill-bot { background: var(--info-soft); }
.pill-human { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.pill-closed { opacity: .8; }
.pill-ok { background: var(--success-soft); color: var(--primary); border-color: transparent; }
.pill-bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
details > summary { cursor: pointer; color: var(--primary); }
pre.code, pre.debug { overflow: auto; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); padding: 10px; border-radius: 6px; max-height: 320px; white-space: pre-wrap; word-break: break-word; }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { color: var(--muted); font-size: 0.85rem; }
.stat-value { font-size: 1.7rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat-note { color: var(--muted); font-size: 0.8rem; }

.bars { display: flex; align-items: flex-end; gap: 2px; height: 180px; padding: 8px 0 0; border-bottom: 1px solid var(--border); }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 4px; position: relative; }
.bar span { display: block; background: var(--bar); border-radius: 4px 4px 0 0; min-height: 0; }
.bar:hover span { filter: brightness(1.15); }
.bar:hover::after {
    content: attr(data-tip);
    position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%);
    background: var(--text); color: var(--surface); font-size: 0.75rem; padding: 3px 7px; border-radius: 4px; white-space: nowrap; z-index: 2;
}
.bar-labels { display: flex; gap: 2px; margin-top: 4px; }
.bar-labels span { flex: 1; text-align: center; font-size: 0.7rem; color: var(--muted); overflow: hidden; }

/* ---------- conversations (WhatsApp Web-like) ---------- */
.chat-layout { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 52px); }
.chat-sidebar { border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.chat-filters { padding: 10px; border-bottom: 1px solid var(--border); }
.chat-filters form { display: flex; gap: 6px; }
.filter-tabs { display: flex; gap: 4px; overflow-x: auto; margin-top: 8px; }
.filter-tabs a { padding: 3px 9px; border-radius: 999px; font-size: 0.8rem; text-decoration: none; color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.filter-tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.conversation-list { overflow-y: auto; flex: 1; }
.conversation-item { display: block; padding: 10px 12px; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text); }
.conversation-item:hover { background: var(--surface-2); }
.conversation-item.selected { background: var(--primary-soft); }
.conversation-item .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conversation-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item .preview { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item .pending { color: var(--warning); font-weight: 600; font-size: 0.75rem; }

.chat-main { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); }
.chat-empty { margin: auto; color: var(--muted); text-align: center; padding: 20px; }
#chat-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 14px; }
.chat-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.chat-head .who { flex: 1; min-width: 180px; }
.chat-head .who strong { display: block; }
.chat-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.window-warning { margin: 8px 0 0; }
#messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.day-sep { align-self: center; font-size: 0.75rem; color: var(--muted); background: var(--surface); padding: 2px 10px; border-radius: 999px; margin: 8px 0; }
.msg { max-width: min(560px, 80%); padding: 7px 10px 5px; border-radius: 8px; box-shadow: 0 1px 0 rgba(0,0,0,.06); word-wrap: break-word; }
.msg-in { align-self: flex-start; background: var(--bubble-in); }
.msg-out { align-self: flex-end; background: var(--bubble-out); }
.msg .meta { display: flex; justify-content: flex-end; gap: 6px; font-size: 0.7rem; color: var(--muted); margin-top: 2px; }
.msg .sender { font-size: 0.72rem; font-weight: 600; color: var(--primary); margin-bottom: 2px; }
.msg img { max-width: 100%; max-height: 320px; border-radius: 6px; display: block; }
.msg .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.msg .chips span { font-size: 0.75rem; border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; background: var(--surface); }
.tick-read { color: var(--read); }
.tick-failed { color: var(--danger); font-weight: 700; }
.composer { background: var(--surface); border-top: 1px solid var(--border); padding: 10px; }
.composer form { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.composer textarea { min-height: 44px; max-height: 160px; }
.composer-tools { display: flex; gap: 8px; margin-bottom: 6px; }
.composer-tools select { width: auto; max-width: 260px; }
.back-link { display: none; }

@media (max-width: 900px) {
    .chat-layout { grid-template-columns: 1fr; height: calc(100vh - 52px - 49px); }
    .chat-layout.has-chat .chat-sidebar { display: none; }
    .chat-layout:not(.has-chat) .chat-main { display: none; }
    .back-link { display: inline-block; margin-right: 6px; }
    .msg { max-width: 92%; }
}
