:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --sidebar: #1f2937;
  --sidebar-text: #d1d5db;
  --sidebar-active: #374151;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  --comment: #fef9c3;
  --radius: 8px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 8px; }
h1:focus { outline: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: var(--sidebar-w, 232px); flex-shrink: 0; position: relative; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; overflow-y: auto; }
.sidebar .brand { padding: 16px; font-weight: 600; color: #fff; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.sidebar .compose { margin: 0 12px 12px; }
.sidebar nav { display: flex; flex-direction: column; padding: 0 8px; }
.sidebar nav a { color: var(--sidebar-text); padding: 7px 10px; border-radius: 6px; display: flex; justify-content: space-between; align-items: center; text-decoration: none; }
.sidebar nav a:hover { background: var(--sidebar-active); }
.sidebar nav a.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.sidebar nav .count { font-size: 12px; background: #4b5563; color: #fff; border-radius: 10px; padding: 0 7px; }
.sidebar .section { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #9ca3af; padding: 16px 18px 6px; }
.sidebar .tag-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.sidebar .me { margin-top: auto; padding: 12px; border-top: 1px solid #374151; display: flex; flex-direction: column; gap: 8px; }
.sidebar .me .name { color: #fff; font-weight: 600; }
.sidebar .me select { width: 100%; }
.sidebar .me .links { display: flex; justify-content: space-between; font-size: 12px; }
.sidebar .me .links a { color: var(--sidebar-text); }
.main { flex: 1; display: flex; min-width: 0; }
.page { flex: 1; overflow-y: auto; padding: 24px 32px; }
.page.narrow { max-width: 1100px; }

/* ---------- Controls ---------- */
.btn { border: 1px solid var(--border); background: #fff; color: var(--text); padding: 6px 12px; border-radius: 6px; cursor: pointer; font: inherit; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.sidebar .btn.primary { width: 100%; justify-content: center; }
input, select, textarea { font: inherit; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus, .editor:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { width: 100%; resize: vertical; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-weight: normal; margin: 0 12px 0 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.grow { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.alert { padding: 10px 12px; border-radius: 6px; margin-bottom: 12px; }
.alert.error { background: #fee2e2; color: #991b1b; }
.alert.ok { background: #d1fae5; color: #065f46; }
.alert.info { background: var(--accent-soft); color: #1e3a8a; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: #f3f4f6; color: #374151; white-space: nowrap; }
.badge.tag { color: #fff; }
.badge.status-Open { background: #dbeafe; color: #1e40af; }
.badge.status-Waiting { background: #fef3c7; color: #92400e; }
.badge.status-Resolved { background: #d1fae5; color: #065f46; }
.badge.snoozed { background: #ede9fe; color: #5b21b6; }
table.grid { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.grid th { background: #f9fafb; font-size: 12px; color: var(--muted); font-weight: 600; }
table.grid tr:last-child td { border-bottom: none; }
table.grid tr.inactive td { color: var(--muted); }

/* ---------- Inbox ---------- */
.list-pane { width: 380px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list-header { padding: 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.list-header .title { font-weight: 600; font-size: 15px; }
.list-header input[type=search] { width: 100%; }
.bulk { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; }
.conv-list { overflow-y: auto; flex: 1; }
.conv-item { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; text-decoration: none; color: inherit; }
.conv-item:hover { background: #f9fafb; text-decoration: none; }
.conv-item.selected { background: var(--accent-soft); }
.conv-item.unread .who, .conv-item.unread .subject { font-weight: 700; }
.conv-item .body { flex: 1; min-width: 0; }
.conv-item .line { display: flex; justify-content: space-between; gap: 8px; }
.conv-item .who { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .when { font-size: 12px; color: var(--muted); white-space: nowrap; }
.conv-item .subject { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv-item .preview { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv-item .meta { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; align-items: center; }
.conv-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-top: 6px; flex-shrink: 0; visibility: hidden; }
.conv-item.unread .dot { visibility: visible; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.detail-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.detail-header { background: var(--panel); border-bottom: 1px solid var(--border); padding: 12px 20px; }
.detail-header h1 { font-size: 18px; margin: 0 0 6px; }
.detail-header .contact { color: var(--muted); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.toolbar select { max-width: 200px; }
.presence { font-size: 12px; color: var(--warn); margin-top: 6px; }
.timeline { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.msg { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.msg.outbound { border-left: 3px solid var(--accent); }
.msg .msg-head { padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 8px; cursor: pointer; }
.msg .msg-head .from { font-weight: 600; }
.msg .msg-head .to { font-size: 12px; color: var(--muted); }
.msg .msg-body { padding: 4px 14px 12px; }
.msg iframe { width: 100%; border: none; min-height: 24px; display: block; }
.msg .attachments { padding: 0 14px 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.msg.collapsed .msg-body, .msg.collapsed .attachments { display: none; }
.msg .collapsed-preview { padding: 0 14px 10px; color: var(--muted); font-size: 12px; }
.comment { background: var(--comment); border: 1px solid #fde68a; border-radius: var(--radius); padding: 8px 12px; align-self: flex-end; max-width: 80%; }
.comment .who { font-weight: 600; font-size: 12px; }
.comment .text { white-space: pre-wrap; }
.activity { font-size: 12px; color: var(--muted); text-align: center; }
.draft-box { background: #fff7ed; border: 1px dashed #fdba74; border-radius: var(--radius); padding: 8px 12px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.composer { background: var(--panel); border-top: 1px solid var(--border); padding: 12px 20px; }
.composer .tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.composer .tabs .btn.active { background: var(--accent-soft); border-color: var(--accent); }
.composer .fields { display: grid; grid-template-columns: 44px 1fr; gap: 4px 8px; align-items: center; margin-bottom: 6px; }
.composer .fields span { color: var(--muted); font-size: 12px; text-align: right; }
.composer .fields input { width: 100%; }
.editor-toolbar { display: flex; gap: 2px; border: 1px solid var(--border); border-bottom: none; border-radius: 6px 6px 0 0; padding: 4px; background: #f9fafb; flex-wrap: wrap; }
.editor-toolbar button { border: none; background: transparent; padding: 3px 8px; border-radius: 4px; cursor: pointer; font: inherit; }
.editor-toolbar button:hover { background: #e5e7eb; }
.editor { min-height: 120px; max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 0 0 6px 6px; padding: 8px 10px; background: #fff; }
.editor:empty::before { content: attr(data-placeholder); color: var(--muted); }
.composer textarea.comment-input { min-height: 70px; background: var(--comment); }
.composer .actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; bottom: 110%; left: 0; z-index: 20; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.12); width: 320px; max-height: 320px; overflow-y: auto; padding: 6px; }
.dropdown-menu.down { bottom: auto; top: 110%; }
.dropdown-menu input { width: 100%; margin-bottom: 6px; }
.dropdown-menu .item { padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.dropdown-menu .item:hover { background: #f3f4f6; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.chip-x { cursor: pointer; opacity: .8; margin-left: 2px; }

/* ---------- Rules ---------- */
.rule-block { border: 1px solid var(--border); border-radius: var(--radius); background: #fff; padding: 12px 16px; margin-bottom: 12px; }
.rule-block > .heading { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 8px; }
.cond-group { border-left: 3px solid var(--accent-soft); padding-left: 12px; margin: 6px 0; }
.cond-row, .action-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.action-row { border: 1px solid var(--border); border-radius: 6px; padding: 8px; align-items: flex-start; flex-direction: column; }
.action-row .row { width: 100%; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 4px 12px; }
.trace { font-family: Consolas, monospace; font-size: 12px; white-space: pre-wrap; background: #f9fafb; border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
.tabs-line { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs-line a { padding: 8px 12px; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; }
.tabs-line a.active { border-color: var(--accent); color: var(--text); font-weight: 600; }

/* ---------- Login ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 32px; width: 420px; max-width: 92vw; }
.login-card form { margin: 6px 0; }
.login-card button.user { width: 100%; text-align: left; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; font: inherit; }
.login-card button.user:hover { background: #f3f4f6; }
.login-card button.user small { color: var(--muted); display: block; }
.login-card .new-user { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }

#blazor-error-ui { background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2); display: none; left: 0; padding: .6rem 1.25rem .7rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }
.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; }
.blazor-error-boundary::after { content: "Ocorreu um erro."; }

@media (max-width: 900px) {
  .sidebar { width: 64px; }
  .sidebar .label, .sidebar .section, .sidebar .count, .sidebar .me .links { display: none; }
  .list-pane { width: 100%; }
  .main.has-detail .list-pane { display: none; }
}

/* ---------- Prazos (SLA) ---------- */
.badge.sla-ok { background: #f3f4f6; color: #374151; }
.badge.sla-warn { background: #fef3c7; color: #92400e; font-weight: 600; }
.badge.sla-late { background: #fee2e2; color: #991b1b; font-weight: 600; }
.sla-line { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; }

/* ---------- Relatórios ---------- */
:root {
  --series-1: #2a78d6;   /* azul: recebidas */
  --series-2: #eb6834;   /* laranja: respostas enviadas */
  --chart-grid: #e8e8e4;
  --chart-axis: #6b7280;
}
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 24px; font-weight: 600; margin-top: 2px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.report-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .report-grid { grid-template-columns: 1fr; } }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text); }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
svg.chart { width: 100%; height: auto; display: block; margin-top: 8px; }
svg.chart .grid-line { stroke: var(--chart-grid); stroke-width: 1; }
svg.chart .axis-label { fill: var(--chart-axis); font-size: 11px; }
svg.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .series-1 { stroke: var(--series-1); }
svg.chart .series-2 { stroke: var(--series-2); }
svg.chart .dot { stroke: #fff; stroke-width: 2; opacity: 0; }
svg.chart .dot-1 { fill: var(--series-1); }
svg.chart .dot-2 { fill: var(--series-2); }
svg.chart .hit { fill: transparent; }
svg.chart .hover-col:hover .dot { opacity: 1; }
svg.chart .hover-col:hover .hit { fill: rgba(17, 24, 39, .04); }
svg.chart rect:hover { stroke: #111827; stroke-width: 1; }

/* ---------- IA ---------- */
.ai-card { background: #f5f3ff; border: 1px solid #ddd6fe; border-radius: var(--radius); padding: 10px 14px; }
.ai-card .ai-text { white-space: pre-wrap; margin: 6px 0; }
.translate-line { margin-top: 8px; }

/* ---------- WhatsApp ---------- */
.wa-icon { font-size: 10px; margin-right: 4px; vertical-align: middle; }
.msg.wa { max-width: 75%; }
.msg.wa.inbound-wa { align-self: flex-start; background: #fff; }
.msg.wa.outbound { align-self: flex-end; background: #dcf8c6; border-left: none; border-color: #c5e8b0; }
.msg.wa .wa-body { padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.wa .wa-meta { padding: 0 12px 6px; font-size: 11px; color: var(--muted); text-align: right; }
.wa-ticks.read { color: #2563eb; }
.wa-window { font-size: 12px; margin-top: 6px; }
.wa-window.closed { color: var(--danger); }
.wa-template { border: 1px solid var(--border); border-radius: 6px; padding: 10px; background: #f9fafb; }
.wa-template .preview { white-space: pre-wrap; background: #dcf8c6; border-radius: 8px; padding: 8px 10px; margin-top: 8px; }

.readonly-banner { margin: 0 12px 12px; padding: 6px 10px; border-radius: 6px; background: #fef3c7; color: #92400e; font-size: 12px; }

/* Árvore de pastas do Outlook */
.sidebar .folder-section { cursor: pointer; user-select: none; }
.sidebar .folder-tree .folder-row { display: flex; align-items: center; }
.sidebar .folder-tree .folder-row a { flex: 1; min-width: 0; padding: 4px 8px; font-size: 13px; }
.sidebar .folder-tree .folder-row a .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-resizer { position: absolute; top: 0; right: 0; width: 8px; height: 100%; cursor: col-resize; z-index: 5; }
.sidebar-toggle { margin-left: auto; background: none; border: 0; color: #9ca3af; cursor: pointer; font-size: 16px; padding: 2px 6px; border-radius: 4px; }
.sidebar-toggle:hover { color: #fff; background: var(--sidebar-active); }
html.sidebar-collapsed .sidebar { width: 64px !important; }
html.sidebar-collapsed .sidebar .label, html.sidebar-collapsed .sidebar .section, html.sidebar-collapsed .sidebar .count,
html.sidebar-collapsed .sidebar .folder-n, html.sidebar-collapsed .sidebar .folder-tree, html.sidebar-collapsed .sidebar .folder-toggle,
html.sidebar-collapsed .sidebar .me .links, html.sidebar-collapsed .sidebar .me select, html.sidebar-collapsed .sidebar .readonly-banner { display: none; }
html.sidebar-collapsed .sidebar .brand { justify-content: center; padding: 16px 0; }
html.sidebar-collapsed .sidebar-toggle { margin-left: 0; }
html.sidebar-collapsed .sidebar-resizer { display: none; }
.sidebar-resizer:hover { background: rgba(96,165,250,.35); }
.sidebar .folder-toggle { width: 16px; flex: none; background: none; border: 0; color: #9ca3af; cursor: pointer; padding: 0; font-size: 11px; }
.sidebar .folder-n { font-size: 11px; color: #9ca3af; margin-left: 6px; flex: none; }

/* Análise da caixa */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.grid-2 > .card { min-width: 0; }
.bar { background: var(--border); border-radius: 4px; height: 8px; overflow: hidden; }
.bar > div { background: #2563eb; height: 100%; border-radius: 4px; }
.suggestion { border-left: 4px solid #9ca3af; }
.suggestion p { margin: 6px 0 0; }
.suggestion .row { gap: 8px; }
.suggestion.sev-high { border-left-color: #dc2626; }
.suggestion.sev-medium { border-left-color: #d97706; }
.suggestion.sev-low { border-left-color: #2563eb; }
.suggestion.sev-info { border-left-color: #16a34a; }

/* Pedidos (Controlo de Back Office) */
.pedido-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.pedido-chip { font-weight: 700; padding: 1px 8px; border-radius: 6px; text-decoration: none; color: #fff; background: #2563eb; }
.pedido-chip.flow-Reservas { background: #7c3aed; }
.pedido-join { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; max-height: 260px; overflow: auto; }
.pedido-candidate { text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; cursor: pointer; }
.pedido-candidate:hover { border-color: #2563eb; }

/* Logs */
.log-json { max-width: 380px; word-break: break-all; font-family: ui-monospace, Consolas, monospace; font-size: 11px; }

/* Atribuições e avisos */
.alerts-card { border-left: 4px solid #dc2626; }
.alert-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--border); }
.kpi-btn { text-align: left; cursor: pointer; font: inherit; }
.kpi-btn.active { outline: 2px solid #2563eb; }
.badge.state-Pendente { background: #fef3c7; color: #92400e; }
.badge.state-EmCurso { background: #dbeafe; color: #1e40af; }
.badge.state-SemResposta { background: #fee2e2; color: #991b1b; }
.badge.state-Concluido { background: #dcfce7; color: #166534; }
.badge.kind-Atribuição, .badge.kind-Passagem { background: #dbeafe; color: #1e40af; }
.badge.kind-Resposta { background: #fef3c7; color: #92400e; }
.badge.kind-Prazo, .badge.kind-Escalada { background: #fee2e2; color: #991b1b; }
tr.clickable, table.clickable tr { cursor: pointer; }

/* Passagens */
.card.transfer.pending { border-left: 4px solid #d97706; }

/* Assinatura */
.sig-toolbar { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.sig-editor { min-height: 120px; border: 1px solid var(--border); border-radius: 6px; padding: 10px; background: #fff; color: #111; }
.sig-editor img { max-height: 80px; }
