/* =====================================================================
   NCM JURÍDICO — Estilos
   ===================================================================== */
:root {
  --brand: #1F4E79;
  --brand-2: #2E6DA4;
  --brand-soft: #E8F0F8;
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --text: #18212F;
  --muted: #667085;
  --border: #E3E7ED;
  --danger: #C8321F;
  --danger-soft: #FDECEA;
  --warn: #B85C00;
  --warn-soft: #FFF3E0;
  --ok: #0A7F4F;
  --ok-soft: #E6F6EE;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --sidebar: 248px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); min-height: 100%; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
small, .muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Boot / spinner ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--brand-soft);
  border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-side { background: linear-gradient(150deg, #163A5C 0%, var(--brand) 55%, var(--brand-2) 100%);
  color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side .brand-big { font-size: 2.2rem; font-weight: 700; letter-spacing: .5px; }
.auth-side p { max-width: 420px; opacity: .9; line-height: 1.55; }
.auth-side ul { padding-left: 18px; opacity: .9; line-height: 1.9; }
.auth-main { display: grid; place-items: center; padding: 32px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); margin-bottom: 24px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: #12304D; color: #DCE6F2; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { padding: 20px 20px 12px; font-weight: 700; font-size: 1.1rem; color: #fff; letter-spacing: .3px; }
.sidebar .brand small { display: block; color: #8FA9C6; font-weight: 400; font-size: .75rem; margin-top: 2px; }
.office-switch { margin: 4px 14px 12px; }
.office-switch select { width: 100%; background: #1B4268; color: #fff; border: 1px solid #2A557F; }
.nav { list-style: none; margin: 0; padding: 4px 10px; flex: 1; }
.nav .group { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #7F9BBB; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: #DCE6F2; font-size: .92rem; }
.nav a:hover { background: #1B4268; text-decoration: none; }
.nav a.active { background: #fff; color: var(--brand); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar .user-box { border-top: 1px solid #224a72; padding: 14px 18px; font-size: .85rem; }
.sidebar .user-box a { color: #AFC6E0; }

.main { min-width: 0; }
.topbar { display: none; }
.content { padding: 28px 32px 60px; max-width: 1280px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.banner { padding: 10px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: .9rem; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #F7D2A6; }
.banner.danger { background: var(--danger-soft); color: var(--danger); border: 1px solid #F5C2BB; }
.banner.info { background: var(--brand-soft); color: var(--brand); border: 1px solid #C9DAEC; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 20px; border-bottom: 1px solid var(--border); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: .82rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: 4px; }
.stat.alert .value { color: var(--danger); }
.mt { margin-top: 16px; }
.mt-lg { margin-top: 24px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase;
  letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--border); background: #FAFBFC; white-space: nowrap; }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #F7FAFD; }
.tbl td.num, .tbl th.num { text-align: right; white-space: nowrap; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 11px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.list li:last-child { border-bottom: 0; }
.list .title { font-weight: 600; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: #EEF1F5; color: #475467; white-space: nowrap; }
.badge.blue { background: var(--brand-soft); color: var(--brand); }
.badge.green { background: var(--ok-soft); color: var(--ok); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.orange { background: var(--warn-soft); color: var(--warn); }

/* ---------- Forms ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 5px; color: #344054; }
input, select, textarea { width: 100%; font: inherit; padding: 9px 11px; border: 1px solid #CFD5DD; border-radius: 8px;
  background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #BBD3EC; border-color: var(--brand-2); }
textarea { min-height: 84px; resize: vertical; }
input[type=checkbox] { width: auto; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: .92rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.toolbar .grow { flex: 1; min-width: 200px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: .9rem;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; background: var(--brand); color: #fff; white-space: nowrap; }
.btn:hover { background: #18405F; text-decoration: none; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.secondary { background: #fff; color: var(--text); border-color: #CFD5DD; }
.btn.secondary:hover { background: #F5F7FA; }
.btn.danger { background: var(--danger); }
.btn.ghost { background: transparent; color: var(--brand-2); padding: 6px 10px; }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.sm { padding: 5px 10px; font-size: .8rem; }
.btn.block { width: 100%; }
.btn svg { width: 16px; height: 16px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; font: inherit; padding: 10px 14px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; font-weight: 600; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

dl.info { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px 20px; margin: 0; }
dl.info dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
dl.info dd { margin: 3px 0 0; font-weight: 500; word-break: break-word; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15,25,40,.45); display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; min-width: 0; max-width: 640px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 900px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-head h2 { min-width: 0; overflow-wrap: anywhere; margin: 0; }
.modal-body { padding: 20px; overflow-y: auto; overflow-x: hidden; min-width: 0; }
.modal-body .tbl-wrap, .modal-body table { max-width: 100%; }
.modal-body .toolbar { flex-wrap: wrap; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.x { background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--muted); line-height: 1; flex-shrink: 0; width: 40px; height: 40px; border-radius: 8px; }
.x:hover { background: var(--bg, #f1f4f8); }

/* ---------- Toast ---------- */
#toast-root { position: fixed; right: 18px; bottom: 18px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1D2939; color: #fff; padding: 11px 16px; border-radius: 8px; font-size: .9rem; box-shadow: var(--shadow); max-width: 380px; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- Agenda ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); }
.cal .dow { font-size: .75rem; font-weight: 600; color: var(--muted); padding: 8px; text-align: center; border-bottom: 1px solid var(--border); }
.cal .day { min-height: 92px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 6px; cursor: pointer; font-size: .8rem; }
.cal .day:nth-child(7n) { border-right: 0; }
.cal .day.out { background: #FAFBFC; color: #A0A8B5; }
.cal .day.today .n { background: var(--brand); color: #fff; border-radius: 50%; }
.cal .day.sel { background: var(--brand-soft); }
.cal .n { display: inline-grid; place-items: center; width: 24px; height: 24px; font-weight: 600; }
.cal .ev { display: block; margin-top: 3px; padding: 1px 5px; border-radius: 4px; background: var(--brand-soft); color: var(--brand);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .72rem; }
.cal .ev.audiencia { background: #FDEBD8; color: #9A4A00; }
.cal .ev.prazo { background: var(--danger-soft); color: var(--danger); }
.cal .ev.pagamento { background: #FCE8E6; color: #A1281B; }
.cal .ev.recebimento { background: #E3F4E8; color: #17663A; }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.kcol { background: #EEF1F5; border-radius: var(--radius); padding: 10px; min-height: 120px; }
.kcol h3 { padding: 4px 6px 10px; display: flex; justify-content: space-between; }
.kcard { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; font-size: .88rem; }
.kcard .row { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; align-items: center; }

/* ---------- Permissions matrix ---------- */
.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }

.bar { height: 8px; background: #EEF1F5; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand-2); }

.qr { background: #fff; padding: 10px; border: 1px solid var(--border); border-radius: 8px; display: inline-block; }
.qr img, .qr svg { width: 180px; height: 180px; display: block; }
code.secret { background: #F2F4F7; padding: 4px 8px; border-radius: 6px; word-break: break-all; }

/* ---------- Responsivo (celular) ---------- */
@media (max-width: 960px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-3 { grid-template-columns: 1fr; }
  dl.info { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 800px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 39; }
  .topbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 30; background: var(--brand); color: #fff;
    padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .topbar button { background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; padding: 2px 6px; }
  .topbar .t { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .content { padding: 18px 14px 80px; }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .kanban { grid-template-columns: 1fr; }
  .cal .day { min-height: 58px; padding: 3px; }
  .cal .ev { font-size: 0; height: 6px; padding: 0; margin-top: 2px; }
  .toolbar input, .toolbar select { min-width: 0; width: 100%; }
  .tbl .hide-sm { display: none; }
  .modal { max-height: 92vh; max-height: 92dvh; border-radius: 12px 12px 0 0; align-self: end; }
  .modal-head { position: sticky; top: 0; background: #fff; z-index: 1; }
  .modal-body { padding: 16px; }
  .modal-body table { display: block; overflow-x: auto; }
  .modal-back { padding: 0; }
}

/* Contador no menu */
.nbadge { margin-left: auto; background: #E8590C; color: #fff; font-size: .7rem; font-weight: 700; border-radius: 999px; padding: 1px 7px; }
.nav a.active .nbadge { background: #E8590C; color: #fff; }

/* Sino de avisos */
.bell { position: relative; background: none; border: 0; color: inherit; cursor: pointer; padding: 6px; border-radius: 8px; line-height: 0; }
.bell svg { width: 20px; height: 20px; }
.bell:hover { background: rgba(255,255,255,.12); }
.bell .bcount { position: absolute; top: 0; right: 0; background: #E8590C; color: #fff; font-size: .65rem; font-weight: 700; border-radius: 999px; padding: 1px 5px; line-height: 1.3; }
.sidebar .brand { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.nicon { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--brand-soft); color: var(--brand); flex-shrink: 0; }
.nicon svg { width: 17px; height: 17px; }
.nicon.red { background: var(--danger-soft); color: var(--danger); }

/* Calculadora de prazos */
.sugg { border: 1px solid #C9DAEC; background: #F5F9FD; border-radius: var(--radius); padding: 14px 16px; margin-top: 4px; }
.sugg-main { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.sugg .big { font-size: 1.7rem; font-weight: 700; color: var(--brand); line-height: 1.1; }
.sugg-steps { display: flex; gap: 18px; flex-wrap: wrap; }
.sugg-steps div { display: flex; flex-direction: column; font-size: .9rem; }
.sugg details { margin: 10px 0 6px; font-size: .88rem; }
.sugg summary { cursor: pointer; color: var(--brand-2); }
.sugg-list { margin: 6px 0 0; padding-left: 18px; line-height: 1.7; }
input.hl { outline: 2px solid #9CC3E8; background: #F5F9FD; }
.calc .field { margin-bottom: 10px; }
/* Filtros em botões */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { border: 1px solid #CFD5DD; background: #fff; border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .85rem; cursor: pointer; }
.chips button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.checks { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 4px 0 10px; }
.checks .check { font-weight: 400; margin-bottom: 0; }
.hchip { display: inline-flex; align-items: center; gap: 6px; background: var(--warn-soft); color: var(--warn); border: 1px solid #F7D2A6; border-radius: 999px; padding: 3px 10px; font-size: .82rem; font-weight: 600; }
.hchip.ok { background: var(--brand-soft); color: var(--brand); border-color: #C9DAEC; }
.office-logo { margin: 4px 14px 10px; background: #fff; border-radius: 10px; padding: 8px 10px; text-align: center; }
.office-logo img { max-width: 100%; max-height: 64px; object-fit: contain; display: inline-block; }
.auth-logo { background: #fff; border-radius: 12px; padding: 12px 16px; display: inline-block; margin-bottom: 18px; }
.auth-logo img { max-width: 260px; max-height: 110px; object-fit: contain; display: block; }
.logo-edit { display: grid; grid-template-columns: 240px 1fr; gap: 20px; align-items: center; }
.logo-prev { border: 1px dashed var(--line); border-radius: 10px; min-height: 110px; display: grid; place-items: center; padding: 10px; background: #fff; }
.logo-prev img { max-width: 100%; max-height: 110px; object-fit: contain; }
@media (max-width: 700px) { .logo-edit { grid-template-columns: 1fr; } }
.doc-page { background: #fff; color: #000; border: 1px solid var(--border, #dde3ea); border-radius: 6px; padding: 32px 40px; min-height: 320px; max-height: 60vh; overflow: auto;
  font-family: 'Times New Roman', serif; font-size: 12pt; line-height: 1.5; outline: none; }
.doc-page h2 { font-size: 14pt; }
.doc-page mark { background: #FFF3A3; }
