:root {
  --bg: #f3f5f8; --surface: #ffffff; --surface-2: #f8fafc; --text: #0f1b2d; --muted: #5d6b7e;
  --border: #e2e7ee; --primary: #1e3a5f; --primary-2: #2c5282; --accent: #2f80ed; --accent-soft: #e8f1fd;
  --ok: #15803d; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fdf3e2; --danger: #c53030; --danger-soft: #fdeaea;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 2px 8px rgba(15, 27, 45, .04);
  --shadow-lg: 0 10px 40px rgba(15, 27, 45, .18);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #171e28; --surface-2: #1c2531; --text: #e6ebf2; --muted: #93a1b4;
    --border: #2a3442; --primary: #8fb4e6; --primary-2: #a9c6ee; --accent: #5aa0f5; --accent-soft: #1b2b42;
    --ok: #4ade80; --ok-soft: #13291c; --warn: #f0b252; --warn-soft: #2e2413; --danger: #f87171; --danger-soft: #331a1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 10px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased; min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* botões e campos */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; line-height: 1.2;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); border-color: #c9d2de; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #0f141b; } }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 4px 8px; font-size: 12.5px; border-radius: 6px; }
.btn svg { width: 15px; height: 15px; flex: none; }
.input, select.input {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 8px 10px;
  outline: none; transition: border-color .12s, box-shadow .12s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.lbl { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); margin: 0 0 4px; }
.field { margin-bottom: 14px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; margin-bottom: 8px; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 10% -10%, rgba(47,128,237,.12), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 32px 28px; box-shadow: var(--shadow-lg); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: #1e3a5f; display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 18px; height: 18px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.login-card h1 { font-size: 20px; margin: 26px 0 4px; }
.login-card .btn.primary { width: 100%; justify-content: center; padding: 10px; margin-top: 6px; }

/* layout */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 10px 24px; }
.topbar .spacer { flex: 1; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); min-width: 0; overflow: hidden; }
.crumbs a { color: var(--muted); white-space: nowrap; }
.crumbs a:hover { color: var(--text); }
.crumbs b { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.usermenu { position: relative; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 600; cursor: pointer; border: none; }
.dropdown { position: absolute; right: 0; top: 40px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-lg); min-width: 220px; padding: 6px; z-index: 30; }
.dropdown .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; font-size: 13px; }
.dropdown button { display: block; width: 100%; text-align: left; border: none; background: none; padding: 8px 10px;
  border-radius: 6px; cursor: pointer; }
.dropdown button:hover { background: var(--surface-2); }
.page { max-width: 1240px; margin: 0 auto; padding: 28px 24px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* seleção de empresa */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.emp-card { padding: 16px 18px; cursor: pointer; transition: border-color .12s, transform .12s; display: flex; flex-direction: column; gap: 10px; }
.emp-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.emp-card h3 { font-size: 15px; line-height: 1.3; }
.emp-card .cnpj { font-size: 12.5px; color: var(--muted); }
.emp-card .counts { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; padding: 2px 8px;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.pill.blue { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.pill.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.pill.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.pill.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

.tipo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; max-width: 820px; }
.tipo-card { padding: 26px; cursor: pointer; transition: border-color .12s, transform .12s; }
.tipo-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.tipo-card .ico { width: 44px; height: 44px; border-radius: 10px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; margin-bottom: 16px; }
.tipo-card .ico svg { width: 22px; height: 22px; }
.tipo-card h2 { font-size: 20px; }
.tipo-card p { color: var(--muted); margin: 6px 0 16px; }
.tipo-card.off { opacity: .55; cursor: not-allowed; }

/* kanban */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .input { width: auto; }
.toolbar .search { flex: 1; min-width: 220px; position: relative; }
.toolbar .search .input { width: 100%; padding-left: 32px; }
.toolbar .search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; color: var(--muted); }
.syncbar { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); }
.board { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.col { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; display: flex; flex-direction: column;
  max-height: calc(100vh - 230px); min-height: 300px; }
.col.drop { border-color: var(--accent); background: var(--accent-soft); }
.col-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.col-head h2 { font-size: 14px; }
.col-head .dot { width: 8px; height: 8px; border-radius: 50%; }
.col-head .count { font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 0 8px; }
.col-head .acts { margin-left: auto; display: flex; gap: 6px; }
.col-body { overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.col-foot { padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); text-align: center; }
.nota { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; cursor: grab;
  box-shadow: var(--shadow); transition: border-color .12s; position: relative; }
.nota:hover { border-color: #b9c6d6; }
.nota.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.nota.dragging { opacity: .45; }
.nota.cancelada .nome { text-decoration: line-through; color: var(--muted); }
.nota-top { display: flex; align-items: flex-start; gap: 8px; }
.nota-top input { margin: 2px 0 0; accent-color: var(--primary); cursor: pointer; }
.nota .nome { font-weight: 600; font-size: 13.5px; line-height: 1.3; flex: 1; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.nota .valor { font-weight: 600; font-size: 13.5px; white-space: nowrap; }
.nota .meta { font-size: 12px; color: var(--muted); margin: 4px 0 0 24px; display: flex; gap: 10px; flex-wrap: wrap; }
.nota .tags { margin: 6px 0 0 24px; display: flex; gap: 5px; flex-wrap: wrap; }
.nota .acoes { display: flex; gap: 4px; margin: 8px 0 0 24px; flex-wrap: wrap; }
.nota .proc { font-size: 11.5px; color: var(--muted); margin: 6px 0 0 24px; }
.spin { width: 15px; height: 15px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* filtros e totais */
.filtros { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px 14px; padding: 14px 16px; margin: -4px 0 14px; }
.filtros .fld.w2 { grid-column: span 2; }
.filtros .lbl { margin-bottom: 3px; }
.totais { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 22px; margin: 0 0 14px; font-size: 12.5px; color: var(--muted); }
.totais div span { display: block; font-size: 11.5px; }
.totais div b { color: var(--text); font-size: 15px; font-weight: 600; }
.totais .exp { margin-left: auto; display: flex; gap: 6px; }
@media (max-width: 1000px) { .filtros { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .filtros { grid-template-columns: 1fr 1fr; } .filtros .fld.w2 { grid-column: 1 / -1; } .totais .exp { margin-left: 0; } }

/* tabela admin */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs button { border: none; background: none; padding: 10px 14px; cursor: pointer; font-weight: 500; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--primary); }
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 10px 14px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl td.r, .tbl th.r { text-align: right; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(10, 18, 30, .5); display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; animation: fade .12s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border); }
.modal.wide { max-width: 960px; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; }
.modal-head .x { margin-left: auto; }
.modal-body { padding: 20px 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.secao { margin-bottom: 18px; }
.secao h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 18px; }
.kv div span { display: block; font-size: 11.5px; color: var(--muted); }
.kv div b { font-weight: 500; word-break: break-word; }
.kv .full { grid-column: 1 / -1; }
.aviso { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; font-size: 13px; }
.chave { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); word-break: break-all; }
.emp-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-lg);
  font-size: 13.5px; max-width: 380px; animation: fade .15s; }
.toast.erro { background: var(--danger); color: #fff; }

@media (max-width: 860px) {
  .board { grid-template-columns: 1fr; }
  .col { max-height: none; }
  .topbar { padding: 10px 16px; }
  .page { padding: 20px 16px 40px; }
  .row2 { grid-template-columns: 1fr; }
}
