:root {
  --brand: #4338ca;
  --brand-dark: #312e81;
  --brand-soft: #eef2ff;
  --accent: #f59e0b;
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--brand-dark); color: #c7d2fe; padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; }
.logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 0 8px 18px; }
.logo-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; }
.logo small { display: block; font-weight: 400; color: #a5b4fc; font-size: 12px; }
.side a.nav { color: #c7d2fe; padding: 9px 12px; border-radius: 8px; display: flex; justify-content: space-between; }
.side a.nav:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.side a.nav.active { background: var(--brand); color: #fff; }
.side .spacer { flex: 1; }
.side .who { border-top: 1px solid rgba(255,255,255,.12); padding: 14px 8px 0; font-size: 13px; }
.side .who b { color: #fff; display: block; }
.side .who button { margin-top: 8px; }
.main { padding: 24px 28px 48px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

/* Componentes */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.btn { border: 1px solid var(--line); background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #3730a3; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.25); color: #e0e7ff; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
label { display: block; font-weight: 500; font-size: 13px; margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--brand); }
textarea { min-height: 120px; resize: vertical; }
.field { margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 8px 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Indicadores */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); cursor: pointer; border-top: 3px solid var(--c, var(--brand)); }
.stat:hover { border-color: var(--c, var(--brand)); }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }

/* Filtros e tabela */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 12px; }
.filters .q { grid-column: span 2; }
.unit-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.unit-row input { flex: 1; }
.unit-row.off input { color: var(--muted); text-decoration: line-through; }
.tag { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: #fef3c7; color: #92400e; margin-left: 6px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #fafafa; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--brand-soft); }
td .sub { color: var(--muted); font-size: 12px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.s-aberto { background: #dbeafe; color: #1e40af; }
.s-em_andamento { background: #ede9fe; color: #5b21b6; }
.s-aguardando_cliente { background: #fef3c7; color: #92400e; }
.s-resolvido { background: #d1fae5; color: #065f46; }
.s-fechado { background: #e5e7eb; color: #374151; }
.p-baixa { background: #f3f4f6; color: #4b5563; }
.p-media { background: #e0f2fe; color: #075985; }
.p-alta { background: #ffedd5; color: #9a3412; }
.p-urgente { background: #fee2e2; color: #991b1b; }
.role { background: var(--brand-soft); color: var(--brand); }

/* Detalhe do chamado */
.ticket-layout { display: grid; grid-template-columns: 1fr 300px; gap: 18px; align-items: start; }
.timeline { display: flex; flex-direction: column; gap: 12px; }
.msg { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.msg.staff { border-left: 3px solid var(--brand); }
.msg.client { border-left: 3px solid var(--accent); }
.msg.nota { background: #fffbeb; border: 1px dashed #f59e0b; }
.msg .meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; margin-bottom: 6px; flex-wrap: wrap; }
.msg .meta b { color: var(--text); font-size: 13px; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; }
.event { color: var(--muted); font-size: 13px; padding: 2px 4px 2px 16px; position: relative; }
.event::before { content: ""; position: absolute; left: 4px; top: 10px; width: 6px; height: 6px; border-radius: 50%; background: #9ca3af; }
.side-panel .field select { margin-top: 2px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.reply-box { margin-top: 16px; }
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; font: inherit; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, var(--brand-dark), var(--brand)); }
.login { width: 100%; max-width: 380px; }
.login .logo { color: var(--text); padding: 0 0 18px; }
.login .logo small { color: var(--muted); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; }

.toast { position: fixed; bottom: 20px; right: 20px; background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 60; }

/* Celular */
.menu-btn { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 2px; }
  .logo { padding: 0; margin-right: auto; }
  .side .spacer, .side .who { display: none; }
  .side a.nav { padding: 6px 10px; font-size: 13px; }
  .main { padding: 16px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .q { grid-column: 1 / -1; }
  .ticket-layout, .grid2 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
code { font: 12.5px ui-monospace, SFMono-Regular, Consolas, monospace; background: #f3f4f6; padding: 1px 5px; border-radius: 4px; }
pre { font: 12.5px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; background: #111827; color: #e5e7eb; padding: 12px 14px; border-radius: 8px; overflow-x: auto; white-space: pre; }
.doc td { vertical-align: top; }
/* Relatórios */
:root { --s1: #2a78d6; --s2: #eb6834; }
.rep-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 16px; }
.hbar { display: grid; grid-template-columns: 130px 1fr 36px; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.hbar .hl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .ht { height: 12px; background: #f3f4f6; border-radius: 0 4px 4px 0; }
.hbar .hf { display: block; height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .hn { text-align: right; font-weight: 600; }
.legend { display: flex; gap: 16px; font-size: 13px; margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.daychart { display: flex; align-items: stretch; gap: 2px; height: 180px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.day { flex: 1; display: flex; flex-direction: column; min-width: 0; cursor: default; }
.day:hover { background: var(--brand-soft); }
.day .bars { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.day .bars span { width: 40%; max-width: 14px; border-radius: 4px 4px 0 0; min-height: 0; }
.day .b1 { background: var(--s1); }
.day .b2 { background: var(--s2); }
.day .dl { height: 0; overflow: visible; font-size: 11px; color: var(--muted); white-space: nowrap; transform: translateY(6px); }
.daychart + .muted { margin-top: 22px; }
.tip { position: fixed; background: #111827; color: #fff; font-size: 12px; padding: 5px 9px; border-radius: 6px; pointer-events: none; z-index: 70; }
