:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #6b7489;
  --line: #e3e7ef;
  --primary: #2f5fd0;
  --primary-soft: #e8eefc;
  --danger: #d64545;
  --danger-soft: #fdecec;
  --warn: #c98a00;
  --warn-soft: #fff6dd;
  --ok: #1f9d63;
  --ok-soft: #e4f6ed;
  --purple: #7a4fd6;
  --purple-soft: #f0eafd;
  --sidebar: #16213a;
  --sidebar-text: #c6cfe2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 2px 8px rgba(20, 30, 60, .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1420; --card: #171e2d; --text: #e6e9f0; --muted: #8e98ad; --line: #283149;
    --primary: #6b93ff; --primary-soft: #1d2a4a; --danger: #ff7272; --danger-soft: #3a1e24;
    --warn: #f0b93a; --warn-soft: #3a3019; --ok: #4fd18f; --ok-soft: #173326;
    --purple: #a988ff; --purple-soft: #2a2145; --sidebar: #0b0f19; --sidebar-text: #aab4c8;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1420; --card: #171e2d; --text: #e6e9f0; --muted: #8e98ad; --line: #283149;
  --primary: #6b93ff; --primary-soft: #1d2a4a; --danger: #ff7272; --danger-soft: #3a1e24;
  --warn: #f0b93a; --warn-soft: #3a3019; --ok: #4fd18f; --ok-soft: #173326;
  --purple: #a988ff; --purple-soft: #2a2145; --sidebar: #0b0f19; --sidebar-text: #aab4c8;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }
.hidden { display: none !important; }

/* ── Layout ── */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; letter-spacing: -.01em; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--sidebar-text); opacity: .8; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500; margin-bottom: 2px;
}
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav a.ativo { background: rgba(255,255,255,.12); color: #fff; }
.nav .badge { margin-left: auto; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar .rodape { margin-top: auto; font-size: 12px; padding: 10px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar .rodape a { color: var(--sidebar-text); }
.main { flex: 1; min-width: 0; padding: 24px 28px 60px; }
.topo { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.topo .acoes { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 20; flex-direction: row;
    align-items: center; padding: 8px 10px; overflow-x: auto; }
  .brand { padding: 0 10px 0 4px; font-size: 14px; white-space: nowrap; }
  .brand small, .sidebar .rodape { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { white-space: nowrap; padding: 7px 9px; margin: 0; }
  .nav a span.rotulo { display: none; }
  .main { padding: 16px 16px 60px; }
}

/* ── Componentes ── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
@media (max-width: 860px) { .g2, .g3 { grid-template-columns: 1fr; } }

.kpi { cursor: pointer; transition: border-color .15s; }
.kpi:hover { border-color: var(--primary); }
.kpi .valor { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.kpi .rotulo { color: var(--muted); font-size: 12.5px; }
.kpi.danger .valor { color: var(--danger); }
.kpi.warn .valor { color: var(--warn); }
.kpi.purple .valor { color: var(--purple); }
.kpi.ok .valor { color: var(--ok); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn.prim { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.prim:hover { filter: brightness(1.08); }
.btn.perigo { color: var(--danger); }
.btn.peq { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600;
  background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.purple { background: var(--purple-soft); color: var(--purple); }
.badge.cinza { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.bolinha { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
label { display: block; font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.campo { margin-bottom: 12px; }
.form-grid { display: grid; gap: 0 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .inteiro { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.filtros { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filtros input, .filtros select { width: auto; min-width: 150px; }
.filtros input[type=search] { min-width: 240px; flex: 1; max-width: 420px; }

.tabela-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.clicavel { cursor: pointer; }
tr.clicavel:hover td { background: var(--primary-soft); }

.abas { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.abas button { background: none; border: none; font: inherit; padding: 9px 12px; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.abas button.ativo { color: var(--primary); border-bottom-color: var(--primary); }

.lista-item { padding: 11px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.lista-item:last-child { border-bottom: none; }
.lista-item .corpo { flex: 1; min-width: 0; }
.vazio { color: var(--muted); padding: 24px; text-align: center; }

.leitura { margin: 8px 0 4px; padding: 8px 10px; border-radius: 8px; background: var(--primary-soft); }
.intimacao .texto { white-space: pre-wrap; font-size: 13px; max-height: 110px; overflow: hidden; position: relative; color: var(--text); margin: 8px 0; }
.intimacao .texto.aberto { max-height: none; }
.intimacao .texto:not(.aberto)::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 40px;
  background: linear-gradient(transparent, var(--card)); }
.intimacao { margin-bottom: 12px; }
.linha-acoes { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Kanban */
.kanban { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 12px; overflow-x: auto; }
.coluna { background: var(--bg); border: 1px dashed var(--line); border-radius: var(--radius); padding: 10px; min-height: 300px; }
.coluna.sobre { border-color: var(--primary); background: var(--primary-soft); }
.coluna h3 { display: flex; justify-content: space-between; }
.tcard { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); }
.tcard .titulo { font-weight: 550; margin-bottom: 4px; }

/* Agenda */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal .cab { padding: 6px; font-size: 12px; color: var(--muted); font-weight: 600; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: center; }
.cal .dia { min-height: 108px; padding: 4px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); cursor: pointer; background: var(--card); }
.cal .dia.fora { background: var(--bg); color: var(--muted); }
.cal .dia.hoje .num { background: var(--primary); color: #fff; border-radius: 99px; padding: 0 6px; }
.cal .dia.feriado { background: var(--warn-soft); }
.cal .num { font-size: 12px; font-weight: 600; display: inline-block; margin-bottom: 3px; }
.cal .item { font-size: 11.5px; padding: 1px 5px; border-radius: 4px; margin-bottom: 2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border-left: 3px solid var(--primary); background: var(--primary-soft); }
.cal .item.prazo { border-left-color: var(--danger); background: var(--danger-soft); }
.cal .item.fer { border-left-color: var(--warn); background: transparent; color: var(--warn); }
@media (max-width: 700px) { .cal .dia { min-height: 64px; } .cal .item { font-size: 10px; } }

/* Modal */
.fundo { position: fixed; inset: 0; background: rgba(10, 15, 30, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--card); border-radius: 12px; width: 100%; max-width: 620px; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal .rodape-modal { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 200; box-shadow: 0 4px 20px rgba(0,0,0,.2); max-width: 380px; }
.toast.erro { background: var(--danger); color: #fff; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login h1 { margin-bottom: 4px; }

.detalhe-cab { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 18px; }
.detalhe-cab .k { font-size: 11.5px; color: var(--muted); }
.detalhe-cab .v { font-weight: 500; word-break: break-word; }
.paginacao { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

/* Minhas notas */
.notas-card { padding: 6px 16px; }
.nota { display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.nota:last-child { border-bottom: none; }
.nota.nova { align-items: center; }
.nota.nova input[name=texto] { border: none; padding: 4px 0; font-size: 15px; background: transparent; }
.nota.nova input[name=texto]:focus { outline: none; }
.nota-check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--muted); background: transparent; flex-shrink: 0;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 13px; padding: 0; margin-top: 1px; }
.nota-check.vazio { border-style: dashed; cursor: default; opacity: .5; }
.nota-check:hover { border-color: var(--warn); }
.nota.feita .nota-check { background: var(--warn); border-color: var(--warn); }
.nota-sep.titulo { padding: 14px 0 2px; border-top: none; }
.nota-check.fixa { border-radius: 6px; }
.nota-corpo { flex: 1; min-width: 0; }
.nota-texto { font-size: 15px; white-space: pre-wrap; word-break: break-word; cursor: text; border-radius: 4px; }
.nota-texto[contenteditable=true] { outline: 2px solid var(--primary-soft); padding: 2px 4px; }
.nota.feita .nota-texto { color: var(--muted); text-decoration: line-through; }
.nota-info { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.nota-info:empty { display: none; }
.nota-acoes { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.nota:hover .nota-acoes, .nota:focus-within .nota-acoes { opacity: 1; }
@media (hover: none) { .nota-acoes { opacity: 1; } }
.nota.arrastando { opacity: .4; }
.nota[draggable=true] { cursor: grab; }
.nota-sep { display: flex; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
