:root {
  --brand: #1F4E23;
  --brand-2: #1A5C38;
  --brand-soft: #e7f0e8;
  --bg: #f4f5f2;
  --panel: #ffffff;
  --line: #e2e4de;
  --text: #1d211c;
  --muted: #6b7268;
  --alta: #b42318;
  --alta-soft: #fdecea;
  --media: #b54708;
  --media-soft: #fff4e5;
  --baixa: #5f6b5c;
  --baixa-soft: #eef0ec;
  --in: #ffffff;
  --out: #dcefdc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #6fbf7a; --brand-2: #5aae6a; --brand-soft: #1e2b20;
    --bg: #121411; --panel: #1b1e1a; --line: #2c312a; --text: #e6e9e3; --muted: #9aa396;
    --alta: #ff7b6e; --alta-soft: #3a1f1c; --media: #f0a35a; --media-soft: #3a2a17; --baixa: #a7b0a3; --baixa-soft: #262a24;
    --in: #232722; --out: #1f3622;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand-2); }
.hidden { display: none !important; }

/* Top bar */
.topbar {
  height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--brand); color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: #16301a; } }
.topbar .title { font-weight: 650; font-size: 15px; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; background: rgba(255,255,255,.15); white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #c9c9c9; }
.pill.ok .dot { background: #6ee07a; }
.pill.warn .dot { background: #ffc857; }
.pill.err .dot { background: #ff6b6b; }
.iconbtn { background: transparent; border: 0; color: inherit; padding: 6px 8px; border-radius: 8px; font-size: 13px; }
.iconbtn:hover { background: rgba(255,255,255,.12); }

/* Layout */
.layout { display: grid; grid-template-columns: 380px 1fr; height: calc(100% - 52px); }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 10px 10px 0; }
.tab { border: 0; background: transparent; padding: 7px 10px; border-radius: 8px; color: var(--muted); white-space: nowrap; font-size: 13px; }
.tab.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.tab .n { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--line); font-size: 11px; text-align: center; }
.tab.active .n { background: var(--brand); color: #fff; }
.filters { display: flex; gap: 8px; padding: 10px; border-bottom: 1px solid var(--line); }
.filters input, .filters select { flex: 1; min-width: 0; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.filters select { flex: 0 0 130px; }

.list { overflow-y: auto; flex: 1; }
.item { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 11px 14px; }
.item:hover { background: var(--bg); }
.item.active { background: var(--brand-soft); }
.item .row1 { display: flex; align-items: center; gap: 8px; }
.item .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.item .time.late { color: var(--alta); font-weight: 600; }
.item .row2 { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.item .preview { margin-top: 4px; color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--baixa-soft); color: var(--baixa); white-space: nowrap; }
.badge.alta { background: var(--alta-soft); color: var(--alta); font-weight: 600; }
.badge.media { background: var(--media-soft); color: var(--media); }
.badge.cat { background: var(--brand-soft); color: var(--brand); }
.badge.count { background: var(--brand); color: #fff; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* Detail */
.detail { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.dhead { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.dhead .who { flex: 1; min-width: 160px; }
.dhead .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.dhead .who b { font-size: 15px; }
.dhead .who small { display: block; color: var(--muted); }
.dhead select { padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 12px; border-radius: 8px; white-space: nowrap; }
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0d130e; } }
.btn.primary:disabled { opacity: .5; cursor: default; }
.btn.danger { color: var(--alta); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.back { display: none; }

.dbody { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.card p { margin: 0 0 8px; }
.card ul { margin: 0; padding-left: 18px; }
.urgent { background: var(--alta-soft); color: var(--alta); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-weight: 600; }
.warnbox { background: var(--media-soft); color: var(--media); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.meta { font-size: 12px; color: var(--muted); }

.thread { display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 78%; padding: 7px 10px; border-radius: 10px; background: var(--in); border: 1px solid var(--line); white-space: pre-wrap; word-wrap: break-word; }
.msg.out { align-self: flex-end; background: var(--out); border-color: transparent; }
.msg .t { display: block; font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg img { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; margin-bottom: 4px; }
.msg audio { width: 240px; max-width: 100%; display: block; }
.msg .tr { font-style: italic; color: var(--muted); margin-top: 4px; }
.msg .doc { display: inline-flex; gap: 6px; align-items: center; }
.daysep { align-self: center; font-size: 11px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 2px 10px; border-radius: 999px; margin: 6px 0; }

.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 16px 12px; }
.composer textarea { width: 100%; min-height: 96px; max-height: 40vh; resize: vertical; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.composer .bar { display: flex; gap: 8px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.composer .bar input { flex: 1; min-width: 160px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.composer .note { font-size: 12px; color: var(--muted); margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.composer .note.alert { color: var(--media); }

.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }
.qrbox { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; text-align: center; max-width: 420px; box-shadow: var(--shadow); color: var(--text); }
.qrbox img { width: 260px; height: 260px; background: #fff; padding: 8px; border-radius: 8px; }
.qrbox ol { text-align: left; color: var(--muted); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal .box { background: var(--panel); border-radius: 14px; width: min(680px, 100%); max-height: 90vh; overflow-y: auto; padding: 20px; }
.modal h3 { margin-top: 0; }
.modal label { display: block; font-weight: 600; margin: 14px 0 6px; }
.modal textarea { width: 100%; min-height: 120px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1d211c; color: #fff; padding: 9px 16px; border-radius: 8px; z-index: 20; max-width: calc(100% - 32px); }
.toast.err { background: var(--alta); }

/* ADVBOX */
.tasks { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
.tasks ul { margin: 0; padding-left: 18px; }
.taskform label { display: block; font-weight: 600; margin: 12px 0 6px; }
.taskform select, .taskform input[type=date], .taskform input[type=time], .taskform input[type=search], .taskform textarea,
#advbox-settings select, #advbox-settings input[type=search] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.taskform textarea { min-height: 130px; }
.taskform input[type=search] + select { margin-top: 6px; }
.taskform .row, #advbox-settings .row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.taskform .row input[type=search], #advbox-settings .row input[type=search] { flex: 1; }
.taskform .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
label.check { display: inline-flex !important; align-items: center; gap: 6px; font-weight: 400 !important; margin: 0 !important; }
#advbox-settings .results .row { border-bottom: 1px solid var(--line); padding: 6px 0; }
#advbox-settings .grow { flex: 1; }
@media (max-width: 560px) { .taskform .grid3 { grid-template-columns: 1fr; } }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--panel); padding: 28px; border-radius: 14px; width: min(360px, 100%); box-shadow: var(--shadow); border: 1px solid var(--line); }
.login h1 { font-size: 18px; margin: 0 0 4px; color: var(--brand); }
.login p { margin: 0 0 18px; color: var(--muted); }
.login input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); margin-bottom: 12px; }
.login button { width: 100%; padding: 10px; }
.login .err { color: var(--alta); min-height: 20px; font-size: 13px; }

/* Celular */
@media (max-width: 420px) {
  .topbar .title { display: none; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .layout.show-detail .sidebar { display: none; }
  .layout:not(.show-detail) .main { display: none; }
  .back { display: inline-block; }
  .msg { max-width: 90%; }
  html, body { overflow-x: hidden; }
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar .title { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
  .topbar .title small { display: none; }
  .iconbtn { padding: 6px 5px; }
  .filters select { flex-basis: 110px; }
  .dhead { padding: 8px 12px; gap: 6px; }
  .dhead .who { flex-basis: calc(100% - 90px); }
  .dhead .actions { gap: 6px; width: 100%; }
  .dhead .actions .btn, .dhead .actions select { padding: 5px 8px; font-size: 12px; }
  .composer .bar input { flex-basis: 100%; }
  .composer .bar .btn.primary { margin-left: auto; }
  .dbody { padding: 12px; }
  .composer { padding: 8px 12px 12px; }
}
