:root {
  color-scheme: light;
  /* Paleta Pantone (couro/terracota) fornecida pelo cliente */
  --surface-1: #fdfbf7;
  --page-plane: #f9f7f4;
  --text-primary: #1e1609;
  --text-secondary: #51403b;
  --muted: #8c7e73;
  --gridline: #ede9e4;
  --baseline: #c2b7a5;
  --border: rgba(30,22,9,0.12);

  --brand: #51403b;       /* marrom couro (era navy) */
  --brand-2: #1e1609;      /* marrom quase preto (era navy escuro) */
  --accent: #8c7e73;       /* taupe quente (era dourado) */

  --series-blue: #51403b;  /* cor de link/interação (era azul) */
  --series-orange: #eb6834;
  --series-aqua: #1baf7a;
  --series-yellow: #eda100;
  --series-magenta: #e87ba4;
  --series-green: #008300;
  --series-violet: #35322f; /* usado na tag "Pós" (era violeta) */
  --series-red: #e34948;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  --radius: 10px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
  font-size: 14px;
}

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--brand-2);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.brand { padding: 4px 6px 22px; }
.brand-logo { display: block; width: 100%; max-width: 188px; height: auto; }
.brand-oab { font-size: 11.5px; font-weight: 600; color: #c2b7a5; letter-spacing: .03em; margin-top: 7px; }
.brand-sub { font-size: 11px; color: #a89a8c; letter-spacing: .04em; text-transform: uppercase; margin-top: 4px; }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.nav a {
  color: #c2b7a5;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav a.active { background: var(--accent); color: var(--text-primary); }

.sidebar-footer { margin-top: auto; padding: 14px 12px 0; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar-footer .user-name { font-size: 12.5px; font-weight: 600; color: #c2b7a5; margin-bottom: 4px; }
.sidebar-footer .btn-logout {
  background: none; border: none; padding: 0; color: #a89a8c; font-size: 12px;
  cursor: pointer; text-decoration: underline;
}
.sidebar-footer .btn-logout:hover { color: #fff; }

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--gridline);
}
#page-title { font-size: 18px; font-weight: 600; }
.topbar-actions { display: flex; gap: 10px; }

.view { padding: 24px 28px 60px; overflow-y: auto; }

/* Botões */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--gridline); }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-2); }
.btn-danger { color: var(--critical); border-color: var(--critical); background: transparent; }
.btn-danger:hover { background: #fdeceb; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Cards / stat tiles */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--gridline);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}
.stat-tile .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-tile .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat-tile .value.accent-blue { color: var(--series-blue); }
.stat-tile .value.accent-good { color: var(--good); }
.stat-tile .value.accent-gold { color: var(--accent); }
.stat-tile .value.accent-critical { color: var(--critical); }

.card {
  background: var(--surface-1);
  border: 1px solid var(--gridline);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}
.card h3 { margin: 0 0 14px; font-size: 15px; }

/* Tabela */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; padding: 10px 12px; border-bottom: 1px solid var(--gridline); }
td { padding: 10px 12px; border-bottom: 1px solid var(--gridline); vertical-align: middle; }
tr:hover td { background: #f6f2ec; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; }
.badge-blue { background: #efe6db; color: var(--series-blue); }
.badge-good { background: #e6f7e6; color: var(--good); }
.badge-gold { background: #efe9e2; color: #51403b; }
.badge-serious { background: #fdece3; color: var(--serious); }
.badge-critical { background: #fdeceb; color: var(--critical); }
.badge-muted { background: var(--gridline); color: var(--text-secondary); }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid.cols-1 { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.span-2 { grid-column: span 2; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
input, select, textarea {
  font-family: inherit;
  font-size: 13.5px;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--baseline);
  background: #fff;
  color: var(--text-primary);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--series-blue); outline-offset: 1px; border-color: var(--series-blue); }
textarea { resize: vertical; min-height: 70px; }

.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(11,11,11,0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px; overflow-y: auto; z-index: 50;
}
.modal {
  background: var(--surface-1); border-radius: var(--radius-lg);
  width: 100%; max-width: 640px; padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal h2 { margin: 0 0 4px; font-size: 17px; }
.modal .modal-sub { color: var(--muted); font-size: 12.5px; margin-bottom: 18px; }
.modal-close { position: absolute; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--brand-2); color: #fff; padding: 10px 18px;
  border-radius: 8px; font-size: 13px; z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.toast.error { background: var(--critical); }
.toast.hidden { display: none; }

/* Agenda */
.agenda-list { display: flex; flex-direction: column; gap: 8px; }
.agenda-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px; border: 1px solid var(--gridline); border-radius: 10px;
  background: var(--surface-1);
}
.agenda-item .when { width: 130px; flex-shrink: 0; font-weight: 700; color: var(--brand); font-size: 13px; }
.agenda-item .info { flex: 1; min-width: 0; }
.agenda-item .info .title { font-weight: 600; }
.agenda-item .info .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* Filtro / busca */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.toolbar input[type="search"] { flex: 1; max-width: 320px; }
.toolbar select { width: auto; }

/* Calendário (Agenda) */
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.cal-header h3 { margin: 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-weekdays { margin-bottom: 6px; text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.cal-cell { min-height: 86px; border: 1px solid var(--gridline); border-radius: 8px; padding: 6px; background: var(--page-plane); font-size: 11.5px; }
.cal-cell.cal-empty { background: transparent; border-color: transparent; }
.cal-cell.cal-today { border-color: var(--brand); background: #efe9e2; }
.cal-day-num { font-weight: 700; margin-bottom: 4px; color: var(--text-secondary); }
.cal-event {
  background: var(--brand); color: #fff; border-radius: 5px; padding: 2px 5px; margin-bottom: 3px;
  font-size: 10.5px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-more { color: var(--muted); font-size: 10px; }

/* Upload de arquivos */
.dropzone {
  border: 1.5px dashed var(--baseline); border-radius: 10px;
  padding: 18px; text-align: center; color: var(--muted); font-size: 12.5px;
  cursor: pointer; background: #f6f2ec;
}
.dropzone:hover { border-color: var(--series-blue); color: var(--series-blue); }
.file-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.file-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border: 1px solid var(--gridline); border-radius: 8px; font-size: 12.5px; }
.file-row a { color: var(--series-blue); text-decoration: none; }

.tag-imediato { color: var(--good); }
.tag-pos { color: var(--series-violet); }

.section-note {
  background: #efe9e2; border: 1px solid #dad3c9; color: #51403b;
  padding: 12px 14px; border-radius: 10px; font-size: 12.5px; margin-bottom: 18px;
}

/* View toggle (Lista / Kanban) */
.view-toggle { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.toggle-btn { border: none; background: var(--surface-1); padding: 8px 14px; font-size: 12.5px; font-weight: 600; cursor: pointer; color: var(--text-secondary); }
.toggle-btn + .toggle-btn { border-left: 1px solid var(--border); }
.toggle-btn.active { background: var(--brand); color: #fff; }
.toggle-btn:not(.active):hover { background: var(--gridline); }

/* Kanban */
.kanban-board { display: flex; gap: 14px; align-items: flex-start; overflow-x: auto; padding-bottom: 10px; }
.kanban-col {
  flex: 0 0 270px; background: var(--page-plane); border: 1px solid var(--gridline);
  border-radius: var(--radius-lg); display: flex; flex-direction: column; max-height: calc(100vh - 200px);
}
.kanban-col-header {
  display: flex; justify-content: space-between; align-items: center; padding: 12px 14px;
  font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--text-secondary); border-bottom: 1px solid var(--gridline);
}
.kanban-count { background: var(--gridline); color: var(--text-secondary); border-radius: 99px; padding: 1px 8px; font-size: 11px; }
.kanban-col-body { padding: 10px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; min-height: 70px; transition: background .15s; }
.kanban-col-body.drag-over { background: #efe6db; }
.kanban-card {
  background: var(--surface-1); border: 1px solid var(--gridline); border-radius: 10px;
  padding: 12px; cursor: grab; box-shadow: 0 1px 2px rgba(11,11,11,0.04);
}
.kanban-card.dragging { opacity: .4; }
.kanban-card-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.kanban-card-client { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.kanban-card-row { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; margin-bottom: 6px; }
.kanban-card-local { color: var(--muted); font-size: 11.5px; margin-bottom: 8px; }
.kanban-card-actions { display: flex; justify-content: flex-end; }
.kanban-empty { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 6px; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* Configurações — colunas do Kanban */
.config-hint { color: var(--text-secondary); font-size: 13px; margin-top: -6px; margin-bottom: 16px; }
.config-subtitle { margin: 22px 0 10px; font-size: 13px; }
.status-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.status-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--gridline); border-radius: 8px; background: var(--page-plane);
}
.status-row input[type="color"] { width: 34px; height: 34px; padding: 2px; flex-shrink: 0; cursor: pointer; }
.status-row .status-label { flex: 1; min-width: 0; }
.status-row-actions { display: flex; gap: 4px; flex-shrink: 0; }
.new-status-form { display: flex; gap: 10px; align-items: center; padding-top: 4px; }
.new-status-form input[type="color"] { width: 38px; height: 38px; padding: 2px; flex-shrink: 0; cursor: pointer; }
.new-status-form input[type="text"] { flex: 1; }
.extra-fields-form { display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--text-primary); }
.checkbox-row input { width: auto; }
input[type="checkbox"] { accent-color: var(--brand); }

/* Página cheia de detalhe do registro/caso */
.case-detail-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; font-size: 13.5px;
}
.case-detail-client { color: var(--text-secondary); }
.case-detail-client a { color: var(--series-blue); text-decoration: none; font-weight: 600; }
.case-detail-client a:hover { text-decoration: underline; }

/* Login / criar conta / esqueci minha senha */
.auth-screen {
  min-height: 100vh; width: 100%; display: flex; align-items: center; justify-content: center;
  background: var(--page-plane); padding: 20px;
}
.auth-card {
  background: var(--brand-2); color: #fff; border-radius: var(--radius-lg);
  padding: 36px 32px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.auth-logo { display: block; width: 100%; max-width: 200px; height: auto; margin: 0 auto 22px; }
.auth-card h2 { margin: 0 0 4px; font-size: 18px; text-align: center; color: #fff; }
.auth-card .modal-sub { color: #a89a8c; text-align: center; margin-bottom: 22px; font-size: 12.5px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .field label { color: #c2b7a5; }
.auth-card .btn-primary { background: var(--accent); border-color: var(--accent); color: var(--text-primary); }
.auth-card .btn-primary:hover { filter: brightness(1.1); }
.auth-error { color: #ff9a8d; font-size: 12.5px; margin-top: 12px; min-height: 16px; text-align: center; }
.auth-success { color: #a3d9a3; font-size: 12.5px; margin-top: 12px; text-align: center; }
.auth-links { text-align: center; margin-top: 18px; font-size: 12.5px; }
.auth-links a { color: #c2b7a5; cursor: pointer; text-decoration: underline; }
.auth-links a:hover { color: #fff; }
.auth-demo-link {
  word-break: break-all; font-size: 11.5px; color: #c2b7a5; margin-top: 12px;
  text-align: center; background: rgba(255,255,255,0.06); padding: 10px; border-radius: 8px;
}
.auth-demo-link a { color: #fff; }

/* IA (chat com agentes) */
.ia-layout { display: flex; gap: 16px; align-items: flex-start; }
.ia-sidebar {
  flex: 0 0 220px; display: flex; flex-direction: column; gap: 6px;
  background: var(--surface-1); border: 1px solid var(--gridline); border-radius: var(--radius-lg); padding: 10px;
}
.ia-agent-item {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.ia-agent-item:hover { background: var(--gridline); }
.ia-agent-item.active { background: var(--brand); color: #fff; }
.ia-agent-item.active .btn { background: rgba(255,255,255,0.15); color: #fff; border-color: transparent; }
.ia-chat {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  background: var(--surface-1); border: 1px solid var(--gridline); border-radius: var(--radius-lg);
  padding: 16px; height: calc(100vh - 200px);
}
.ia-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 10px; }
.ia-bubble { max-width: 78%; padding: 10px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; }
.ia-bubble-user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.ia-bubble-assistant { align-self: flex-start; background: var(--page-plane); border: 1px solid var(--gridline); border-bottom-left-radius: 4px; }
.ia-context-row { display: flex; gap: 8px; margin: 10px 0; }
.ia-context-row select { max-width: 240px; }
.ia-input-row { display: flex; gap: 10px; align-items: flex-end; }
.ia-input-row textarea { flex: 1; min-height: 52px; max-height: 140px; resize: vertical; }

/* ---------- E-mail ---------- */
.email-layout { display: flex; gap: 16px; align-items: flex-start; }
.email-sidebar-wrap {
  flex: 0 0 200px; overflow: hidden;
  transition: flex-basis .2s ease, opacity .15s ease;
}
.email-sidebar-wrap.collapsed { flex-basis: 0; opacity: 0; }
.email-sidebar {
  width: 200px; display: flex; flex-direction: column; gap: 10px;
  background: var(--surface-1); border: 1px solid var(--gridline); border-radius: var(--radius-lg); padding: 10px;
  height: calc(100vh - 200px); overflow-y: auto;
}
.email-sidebar-toggle {
  flex: 0 0 auto; align-self: flex-start; margin-top: 4px;
  width: 22px; height: 40px; border-radius: 6px; border: 1px solid var(--gridline);
  background: var(--surface-1); color: var(--text-secondary); cursor: pointer; font-size: 14px; line-height: 1; padding: 0;
}
.email-sidebar-toggle:hover { background: var(--gridline); color: var(--text-primary); }
.email-account-switch { width: 100%; }
.email-account-single { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); padding: 4px 2px 8px; border-bottom: 1px solid var(--gridline); word-break: break-all; }
.email-folder-list { display: flex; flex-direction: column; gap: 2px; }
.email-folder-item { padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.email-folder-item:hover { background: rgba(0,0,0,0.04); }
.email-folder-item.active { background: var(--brand); color: #fff; }
.email-list {
  flex: 0 0 330px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto;
  background: var(--surface-1); border: 1px solid var(--gridline); border-radius: var(--radius-lg); padding: 10px;
  height: calc(100vh - 200px);
}
.email-list-item { padding: 10px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.email-list-item:hover { background: rgba(0,0,0,0.03); }
.email-list-item.active { background: #efe9e2; border-color: var(--brand); }
.email-list-item.unread .email-list-item-from,
.email-list-item.unread .email-list-item-subject { font-weight: 700; color: var(--text-primary); }
.email-list-item-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.email-list-item-from { font-weight: 600; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 190px; }
.email-list-item-date { flex-shrink: 0; }
.email-list-item-subject { font-size: 13px; margin-top: 3px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-list-item-actions { margin-top: 6px; display: flex; justify-content: flex-end; }
.email-reader {
  flex: 1; min-width: 0; overflow-y: auto;
  background: var(--surface-1); border: 1px solid var(--gridline); border-radius: var(--radius-lg); padding: 18px;
  height: calc(100vh - 200px);
}
.email-reader-header h3 { margin: 0 0 10px; font-size: 16px; }
.email-reader-meta { font-size: 12.5px; color: var(--text-secondary); line-height: 1.7; }
.email-reader-body { margin-top: 16px; border-top: 1px solid var(--gridline); padding-top: 16px; }
.email-reader-body pre { white-space: pre-wrap; font-family: inherit; font-size: 13.5px; line-height: 1.6; }
.email-body-frame { width: 100%; border: none; min-height: 100px; }
.email-attachments { margin-top: 16px; border-top: 1px solid var(--gridline); padding-top: 12px; font-size: 12.5px; }
.email-attachment-chip { display: inline-block; background: var(--page-plane); border: 1px solid var(--gridline); border-radius: 99px; padding: 3px 10px; margin: 4px 4px 0 0; font-size: 12px; }
