:root {
  --bg: #F7F5F0;
  --surface: #FFFFFF;
  --border: #E6E1D6;
  --ink: #1C2026;
  --ink-secondary: #6B7280;
  --ink-muted: #9CA3AF;
  --brand: #B8860B;
  --brand-tint-bg: #FDF3DC;
  --brand-tint-text: #7A5206;
  --good-bg: #E6F4EA;
  --good-text: #146C14;
  --good-delta: #006C10;
  --warning-bg: #FEF3D6;
  --warning-text: #7A5206;
  --critical: #DC3C3D;
  --cat-cliente: #f47230;
  --cat-tarefa: #257de0;
  --cat-fiscal: #00b894;
  --cat-automatico: #9CA3AF;
  --sidebar-bg: #1C2026;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--ink);
}

a { color: var(--brand-tint-text); text-decoration: none; }
a:hover { color: var(--brand); }

.layout { display: flex; width: 100%; min-height: 100vh; }

/* Sidebar */
.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  flex: 0 0 clamp(138px, 16vw, 186px); min-width: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px 8px; gap: 12px;
  transition: flex-basis .2s ease, min-width .2s ease, padding .2s ease;
}
.brand-row { display: flex; align-items: center; gap: 12px; padding: 0 6px; margin-bottom: 8px; }
.brand-badge {
  width: 36px; height: 36px; border-radius: 999px; background: var(--brand);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  color: #fff; font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 14px;
}
.brand-text { min-width: 0; flex: 1; }
.brand-name { font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 15px; color: #fff; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11px; color: var(--ink-muted); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-toggle {
  position: static; margin: 0 0 12px 10px;
  width: 26px; height: 26px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--ink-secondary); cursor: pointer; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(28,32,38,0.12);
  transition: background .15s ease, color .15s ease, border-color .15s ease, transform .15s ease;
}
.sidebar-toggle:hover { background: var(--brand-tint-bg); color: var(--brand); border-color: var(--brand); transform: scale(1.06); }
.sidebar-toggle svg { transition: transform .2s ease; }

nav.main-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 500; color: var(--ink-muted);
  transition: background .15s ease, color .15s ease;
}
.nav-link:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-link.active { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link svg { flex-shrink: 0; }
.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }


.sidebar > div:first-child { overflow-y: auto; min-height: 0; }
.sidebar-bottom { flex: none; margin-top: auto; border-top: 1px solid #393e44; padding-top: 10px; display: flex; flex-direction: column; gap: 12px; }
.user-footer {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px; border-radius: 10px;
  background: rgba(255,255,255,0.04);
}
.user-avatar {
  width: 30px; height: 30px; border-radius: 999px; flex-shrink: 0;
  background: rgba(255,255,255,0.09); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; font-family: 'Space Grotesk', sans-serif;
}
.user-info { min-width: 0; flex: 1; }
.user-name { font-size: 12.5px; font-weight: 600; color: #fff; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 10.5px; color: var(--ink-muted); line-height: 1.3; white-space: nowrap; overflow: hidden; }
.logout-btn {
  background: none; border: none; color: var(--ink-muted); cursor: pointer; flex-shrink: 0;
  padding: 7px; border-radius: 7px; display: flex; align-items: center; justify-content: center;
  transition: background .15s ease, color .15s ease;
}
.logout-btn:hover { background: rgba(220,60,61,0.16); color: #ff8a8b; }

/* Sidebar collapsed state */
.layout.sidebar-collapsed .sidebar { flex-basis: 60px; padding-inline: 6px; }
.layout.sidebar-collapsed .brand-row { justify-content: center; }
.layout.sidebar-collapsed .brand-text,
.layout.sidebar-collapsed .nav-label,
.layout.sidebar-collapsed .user-info { display: none; }
.layout.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }
.layout.sidebar-collapsed .nav-link { justify-content: center; }
.layout.sidebar-collapsed .sidebar-toggle { display: flex; margin: 0 auto 12px; }
.layout.sidebar-collapsed .user-footer { justify-content: center; padding: 10px 6px; }

/* Content */
.content { container-type: inline-size; flex: 999 1 640px; min-width: 0; display: flex; flex-direction: column; }

header.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 2.5%; background: var(--surface); border-bottom: 1px solid var(--border);
  flex-wrap: wrap; gap: 12px;
}
.page-title { font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.topbar-date { font-size: 13px; color: var(--ink-secondary); }
.email-pill {
  display: flex; align-items: center; gap: 8px; background: #F3F1EB;
  border-radius: 999px; padding: 7px 16px; font-size: 12px; color: #4B5563; font-weight: 500;
}

main { width: 95%; box-sizing: border-box; margin: 0 auto; padding: 24px 0 40px; display: flex; flex-direction: column; gap: 18px; }

/* Paginas (Visao geral / Clientes / ...) alternadas via JS, sem recarregar */
.page { display: none; flex-direction: column; gap: 18px; }
.page.active { display: flex; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 2px 7px rgba(38,35,27,.045);
  transition: box-shadow .15s ease, border-color .15s ease;
}
.card:hover { box-shadow: 0 4px 14px rgba(28,32,38,0.07); border-color: #DCD7C9; }
h2.card-title { font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 16px; color: var(--ink); margin: 0 0 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.stat-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "label icon" "value icon" "detail detail";
  align-items: start;
  gap: 6px 12px;
  padding: clamp(16px, 1.3vw, 24px);
}
.stat-label { grid-area: label; font-size: 13px; font-weight: 600; color: #525b65; }
.stat-icon { grid-area: icon; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 12px; }
.stat-icon svg { width: 18px; height: 18px; }
.stat-value { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-card .stat-value { grid-area: value; font-size: clamp(32px, 2.2vw, 44px); letter-spacing: -.045em; line-height: 1.12; }
.stat-delta { grid-area: detail; margin-top: 5px; padding-top: 10px; border-top: 1px solid #efede8; font-size: 12px; font-weight: 500; }

.two-col { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.card-pad { padding: 22px 24px; }
.card-pad-sm { padding: 20px 22px; }

.row-between { display: flex; align-items: center; justify-content: space-between; }

/* Chart bars */
.bar-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-label { flex: 0 0 96px; font-size: 12.5px; color: #374151; }
.bar-track { flex: 1; background: #F0EDE4; border-radius: 4px; height: 14px; position: relative; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 0 4px 4px 0; transition: width .4s ease; }
.bar-value { flex: 0 0 30px; text-align: right; font-size: 12.5px; font-weight: 600; }

/* Lists */
.list-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-top: 1px solid #F0EDE4; gap: 12px; }
.avatar { width: 32px; height: 32px; border-radius: 999px; background: #EEF0F2; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 12px; font-weight: 600; color: #4B5563; }
.list-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.list-name { font-size: 13px; font-weight: 600; }
.list-sub { font-size: 12px; color: var(--ink-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 999px; flex-shrink: 0; }
.pill-neutral { color: #4B5563; background: #EEF0F2; }
.pill-warning { color: var(--warning-text); background: var(--warning-bg); }
.pill-good { color: var(--good-text); background: var(--good-bg); }

.task-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-top: 1px solid #F0EDE4; gap: 12px; }
.task-main { display: flex; align-items: center; gap: 12px; min-width: 0; font-size: 13px; cursor: pointer; overflow-wrap: anywhere; }
.task-main input { width: 17px; height: 17px; accent-color: var(--brand); flex-shrink: 0; }
.task-badge { flex-shrink: 0; display: inline-flex; gap: 5px; align-items: center; color: #805507; background: #fcf3de; border-radius: 7px; padding: 4px 8px; font-size: 12px; }
.operational-title, .files-heading, .nc-open { display: flex; align-items: center; gap: 9px; }
.operational-title svg { color: #a4770a; }
.fiscal-amount { display: grid; gap: 4px; border-radius: 10px; background: #eff4ed; padding: 15px; font-size: 13px; }
.fiscal-amount strong { font-size: 29px; letter-spacing: -.04em; }
.fiscal-amount small, .folder-detail, #task-feedback { color: var(--ink-secondary); }
.folder-detail { overflow-wrap: anywhere; margin-top: 6px; }
.files-heading { font-size: 14px; margin: 0 0 3px; }
.nc-open { justify-content: center; border: 1px solid #b3b9bc; border-radius: 8px; padding: 10px; color: var(--ink); font-weight: 600; font-size: 13px; }
.nc-open:hover { background: #f7f7f4; }

.dot { width: 8px; height: 8px; border-radius: 999px; flex-shrink: 0; }

.integration-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; }
.integration-main { display: flex; align-items: center; gap: 9px; min-width: 0; }
.status-ok { display: flex; align-items: center; gap: 5px; flex-shrink: 0; font-size: 11px; color: var(--ink-secondary); }

.notif-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 0; }
.notif-main { display: flex; align-items: center; gap: 8px; min-width: 0; }

.legend-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: 12px; color: #374151; }

.nc-path-box {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px;
  border-top: 1px solid var(--border); margin-top: 14px; padding-top: 13px;
}
#nc-files { list-style: none; padding: 5px 12px; margin: 0; background: #f5f5f3; border-radius: 8px; }
.nc-path-box strong { font-size: 12px; }
#nc-files li { font-size: 12px; padding-block: 6px; overflow-wrap: anywhere; }
#nc-files li + li { border-top: 1px solid var(--border); }
#nc-files small { display: block; margin-top: 3px; color: #59616b; }
.integrations-page .card { width: min(100%, 640px); }
.integrations-page .integration-row { padding: 14px 0; }
.field-heading { display: flex; align-items: center; justify-content: space-between; }
.copy-btn { background: transparent; color: #626c78; border: 0; border-radius: 6px; cursor: pointer; padding: 5px; display: grid; place-items: center; }
.copy-btn:hover, .copy-btn:focus-visible { color: #73500a; background: var(--brand-tint-bg); }
#copy-feedback { font-size: 12px; color: var(--ink-secondary); }
#copy-feedback:empty { display: none; }
.email-pill.is-new svg { border-radius: 4px; color: #2465ab; stroke: currentColor; animation: mail-ring 2.6s ease-out infinite; }
@keyframes mail-ring { from { box-shadow: 0 0 0 1px rgba(42,120,215,.45); } to { box-shadow: 0 0 0 7px rgba(42,120,215,0); } }
@media (prefers-reduced-motion: reduce) { .email-pill.is-new svg { animation: none; outline: 2px solid #8eb9ec; outline-offset: 2px; } }
@media (max-width: 600px) { .sidebar { flex-basis: 138px; } }


button.btn {
  width: 100%; box-sizing: border-box; padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: #F9F8F5; color: var(--ink); font-size: 13px;
  font-weight: 500; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
}
button.btn:hover { background: #F0EDE4; }

.skeleton { color: var(--ink-muted); font-style: italic; font-size: 12px; }

/* Pagina Clientes */
.clients-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.search-input {
  flex: 0 1 280px; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 13px; font-family: inherit; background: #F9F8F5; color: var(--ink);
}
.search-input:focus { outline: 2px solid var(--brand); outline-offset: 1px; background: #fff; }

table.clients-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.clients-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-secondary); font-weight: 600; padding: 11px 12px; background: #f7f6f2; border-bottom: 1px solid var(--border);
}
table.clients-table td { padding: 13px 12px; border-bottom: 1px solid #F0EDE4; vertical-align: middle; }
table.clients-table tr:last-child td { border-bottom: none; }
.client-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.client-email { font-size: 12px; color: var(--ink-secondary); overflow-wrap: anywhere; }

table.clients-table tbody tr.client-row { cursor: pointer; transition: background .12s ease; }
table.clients-table tbody tr.client-row:hover { background: #FAF8F2; }

.client-phone { font-variant-numeric: tabular-nums; }
.clients-table td { overflow-wrap: anywhere; }
.list-main > div:last-child { min-width: 0; }
@container (max-width: 1050px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: minmax(0, 1fr); }
}
@container (max-width: 520px) {
  .stat-grid { grid-template-columns: minmax(0, 1fr); }
  .search-input { min-width: 0; flex: 1 1 100%; }
}
@container (max-width: 850px) {
  table.clients-table thead { display: none; }
  table.clients-table, table.clients-table tbody, table.clients-table tr, table.clients-table td { display: block; width: 100%; }
  table.clients-table tr { padding: 12px 0; border-bottom: 1px solid #F0EDE4; }
  table.clients-table td { border-bottom: none; padding: 4px 0; }
  td[data-label]::before { content: attr(data-label) " · "; font-size: 12px; font-weight: 600; color: #59616b; }
}

/* Modal de detalhes/edição de cliente */
body.modal-open { overflow: hidden; }
.client-drawer {
  position: fixed; inset: 0 0 0 auto; margin: 0; width: min(460px, 100%);
  max-width: 100%; height: 100%; max-height: 100%; padding: 0; border: 0;
  background: var(--surface); color: var(--ink); box-shadow: -12px 0 44px #2123291c;
}
.client-drawer[open] { display: flex; flex-direction: column; animation: drawer-enter .25s cubic-bezier(.18,.7,.25,1); }
.client-drawer::backdrop { background: #1e22283d; }
@keyframes drawer-enter { from { transform: translateX(100%); } to { transform: translateX(0); } }
@media (prefers-reduced-motion: reduce) { .client-drawer[open] { animation: none; } }
.client-drawer [hidden] { display: none; }
.client-open { border: 0; padding: 0; text-align: left; background: transparent; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.client-open:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
.drawer-identity { display: flex; align-items: center; gap: 12px; min-width: 0; overflow-wrap: anywhere; }
.drawer-identity .avatar { width: 42px; height: 42px; background: var(--brand-tint-bg); color: var(--brand-tint-text); }
#drawer-mode { color: var(--ink-secondary); font-size: 12px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 16px; font-weight: 600; }
.modal-close {
  background: none; border: none; cursor: pointer; font-size: 20px; line-height: 1;
  color: var(--ink-muted); padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: #F0EDE4; color: var(--ink); }
.modal-body { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.modal-field label {
  font-size: 11px; font-weight: 600; color: var(--ink-secondary);
  text-transform: uppercase; letter-spacing: .03em;
}
.modal-field input[type="text"] {
  padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 13.5px; font-family: inherit; color: var(--ink); background: #F9F8F5;
}
.modal-field input[type="text"]:focus { outline: 2px solid var(--brand); outline-offset: 1px; background: #fff; }
.modal-readonly { font-size: 13.5px; color: var(--ink); padding: 8px 0 2px; overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.5; }
.modal-field input[type="text"]:read-only { padding: 4px 0; border-color: transparent; background: transparent; }
.modal-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-error {
  font-size: 12.5px; color: var(--critical); background: #FBE6E6;
  border-radius: 8px; padding: 9px 12px;
}
.modal-footer { display: flex; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }
.modal-footer .btn { width: auto; flex: 1; }
button.btn.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.btn.btn-primary:hover { background: #9C6B08; }
button.btn.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

/* Caixa de confirmação padrão do sistema (substitui o window.confirm nativo) */
.confirm-dialog {
  position: fixed; inset: 0; margin: auto; width: min(380px, calc(100% - 48px));
  max-height: calc(100% - 48px); padding: 0; border: 0; border-radius: 14px;
  background: var(--surface); color: var(--ink); box-shadow: 0 14px 44px #2123293d;
}
.confirm-dialog[open] { display: flex; flex-direction: column; animation: confirm-enter .18s ease-out; }
.confirm-dialog::backdrop { background: #1e22283d; }
@keyframes confirm-enter { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@media (prefers-reduced-motion: reduce) { .confirm-dialog[open] { animation: none; } }
.confirm-body { padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.confirm-body h3 { margin: 0; font-family: 'Space Grotesk', sans-serif; font-size: 16px; font-weight: 600; }
.confirm-body p { margin: 0; font-size: 13.5px; color: var(--ink-secondary); line-height: 1.5; }

/* Toast discreto com opção de "Desfazer" (ex.: ao concluir uma tarefa) */
.undo-toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(8px);
  display: flex; align-items: center; gap: 6px; background: #1C2026; color: #fff;
  padding: 12px 10px 12px 18px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 10px 30px #00000038; z-index: 999;
  opacity: 0; transition: opacity .22s ease, transform .22s ease; pointer-events: none;
}
.undo-toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.undo-toast .undo-action {
  border: 0; background: transparent; color: #E8B100; font: inherit; font-weight: 700;
  cursor: pointer; padding: 6px 10px; border-radius: 6px; white-space: nowrap;
}
.undo-toast .undo-action:hover { background: #ffffff1a; }
.undo-toast .undo-action:disabled { opacity: .6; cursor: wait; }
@media (prefers-reduced-motion: reduce) { .undo-toast { transition: none; } }


#sla-card { --sla-text: var(--ink-secondary); --sla-tint: #f0f2f3; }
#sla-card.has-overdue { --sla-text: #b52832; --sla-tint: #fbe6e6; }
#sla-card .stat-icon { color: var(--sla-text); background: var(--sla-tint); }
#stat-sla-delta { color: var(--sla-text); }

.stat-card.has-overdue .stat-icon { color: #b52832; background: #fbe6e6; }
.stat-card.has-overdue .stat-delta { color: #b52832; }
.task-badge.is-overdue { color: #b52832; background: #fbe6e6; }
#nc-last-read { color: var(--ink-secondary); font-size: 12px; }
#nc-retry { align-self: flex-start; border: 1px solid var(--border); background: var(--surface); color: var(--ink); padding: 6px 12px; border-radius: 7px; font: inherit; font-size: 12px; cursor: pointer; }
#nc-retry:disabled { cursor: wait; opacity: .65; }

.tasks-link { display: block; width: fit-content; margin-top: 10px; font-size: 12px; }
