:root {
  --bg: #F4F5F7; --surface: #FFFFFF; --surface-2: #F0F2F5; --text: #1B1F24; --muted: #5F6B7A;
  --border: #DDE1E6; --primary: #1565C0; --primary-text: #FFFFFF;
  --green: #1E9E4A; --orange: #E08A00; --red: #C62828;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #15181C; --surface: #1F2328; --surface-2: #2A2F36; --text: #E8EBEF; --muted: #9AA4B0;
          --border: #343A42; --primary: #4C8DDB; --shadow: none; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
a { color: var(--primary); }

/* topo */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: max(10px, env(safe-area-inset-top)) 16px 10px; background: var(--surface);
  border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-title { font-weight: 700; font-size: 16px; }
.status-text { font-size: 13px; font-weight: 600; }
.status-on { color: var(--green); } .status-warn { color: var(--orange); } .status-off { color: var(--red); }
.top-actions { display: flex; gap: 8px; flex-shrink: 0; }

.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px;
  padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; min-height: 38px; }
.btn:hover:not(:disabled) { filter: brightness(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: var(--red); background: transparent; }
.btn.toggle.on { background: var(--red); border-color: var(--red); color: #fff; }
.btn.toggle.off { background: var(--green); border-color: var(--green); color: #fff; }
.btn.fa { background: var(--primary); border-color: var(--primary); color: #fff; white-space: nowrap; }
.btn.further { background: var(--orange); border-color: var(--orange); color: #fff; white-space: nowrap; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; padding: 6px; }

.banner { margin: 12px 16px 0; padding: 10px 14px; border-radius: var(--radius); font-size: 14px;
  background: #FFF4E0; color: #6B4200; border: 1px solid #F3C77A; display: flex; gap: 10px;
  align-items: center; flex-wrap: wrap; justify-content: space-between; }
.banner.error { background: #FDECEC; color: #8B1C1C; border-color: #F2B8B8; }
@media (prefers-color-scheme: dark) {
  .banner { background: #3A2D12; color: #F6D28E; border-color: #6B5320; }
  .banner.error { background: #3B1A1A; color: #F4B4B4; border-color: #6E2C2C; }
}

.info { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px 16px; margin: 12px 16px;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.info > div { display: flex; flex-direction: column; min-width: 0; }
.info .wide { grid-column: 1 / -1; }
.info .k { font-size: 12px; color: var(--muted); }
.info .v { font-weight: 600; overflow-wrap: anywhere; }
.info select { font: inherit; padding: 2px 4px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); }

.tabs { display: flex; gap: 4px; margin: 0 16px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: 10px 12px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--primary); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--surface-2);
  font-size: 12px; text-align: center; }
main { padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); max-width: 1400px; }

.counters { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.counter { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; display: flex; align-items: baseline; gap: 10px; }
.counter span { font-size: 26px; font-weight: 700; }
.counter small { color: var(--muted); }

/* lista de chamados */
.list { display: flex; flex-direction: column; gap: 8px; }
.ticket { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; display: grid; gap: 4px 14px; align-items: center;
  grid-template-columns: 86px 130px 170px 110px minmax(0, 1fr) 150px 150px auto; box-shadow: var(--shadow); }
.ticket .kind { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 12px; text-align: center; }
.kind.Incident { background: #FDE7E7; color: #9B1C1C; } .kind.Request { background: #E3EEFC; color: #0D47A1; }
@media (prefers-color-scheme: dark) { .kind.Incident { background: #4A2020; color: #F7B3B3; }
  .kind.Request { background: #1D3350; color: #A9C9F5; } }
.ticket .num { font-weight: 700; }
.ticket .desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket .meta { color: var(--muted); font-size: 13px; }
.ticket .lbl { display: none; }
.empty { color: var(--muted); padding: 24px; text-align: center; background: var(--surface);
  border: 1px dashed var(--border); border-radius: var(--radius); }
.row-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; font-size: 14px; display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.row-item .t { color: var(--muted); font-size: 12px; min-width: 130px; }
.row-item .lvl-ERRO { color: var(--red); font-weight: 700; } .row-item .lvl-AVISO { color: var(--orange); font-weight: 700; }

/* configurações */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; }
.panel > summary { padding: 12px 14px; font-weight: 700; cursor: pointer; }
.panel-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.panel label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.panel label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
input, textarea, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; }
textarea { resize: vertical; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row input { flex: 1; min-width: 180px; }
.card-inner { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; display: flex;
  flex-direction: column; gap: 6px; }
details.sub { border-top: 1px solid var(--border); padding-top: 8px; }
details.sub > summary { cursor: pointer; font-size: 14px; margin-bottom: 8px; }
h4 { margin: 8px 0 0; font-size: 14px; }
.checklist { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checklist label.check { font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--surface-2); border-radius: 16px; padding: 4px 6px 4px 12px; display: flex; gap: 6px;
  align-items: center; font-size: 14px; }
.chip button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; }

/* modal e toast */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(720px, 94vw); max-height: 88vh;
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px;
  border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 14px 16px; overflow: auto; max-height: calc(88vh - 130px); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px;
  border-top: 1px solid var(--border); }
table.plan { width: 100%; border-collapse: collapse; margin: 6px 0 12px; font-size: 14px; }
table.plan th, table.plan td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.textbox { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; font-size: 14px; }
.err { color: var(--red); font-weight: 600; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: 90vw;
  box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.center-card { max-width: 420px; margin: 12vh auto; text-align: center; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
#unauthorized .center-card { text-align: left; }
#unauthorized .center-card > img { display: block; margin: 0 auto 10px; }
#unauthorized h1 { text-align: center; font-size: 20px; margin: 0 0 12px; }
#unauthorized form { display: flex; flex-direction: column; gap: 10px; margin: 10px 0 4px; }
#unauthorized label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
#unauthorized .btn { width: 100%; }
#unauthorized .link { background: none; border: 0; color: var(--primary); font: inherit; font-weight: 600;
  cursor: pointer; padding: 0; text-decoration: underline; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 1s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* celular */
@media (max-width: 860px) {
  .brand-title { font-size: 15px; white-space: nowrap; }
  .tabs { margin: 0 8px; }
  .tabs button { flex: 1 1 auto; padding: 10px 6px; font-size: 14px; }
  .info { grid-template-columns: 1fr 1fr; margin: 10px 12px; }
  main { padding-left: 12px; padding-right: 12px; }
  .top-actions #btn-check { display: none; }
  .ticket { grid-template-columns: auto 1fr auto; }
  .ticket .desc { grid-column: 1 / -1; white-space: normal; }
  .ticket .meta { grid-column: 1 / -1; }
  .ticket .fa-cell { grid-column: 1 / -1; }
  .ticket .fa-cell .btn { width: 100%; }
  .ticket .lbl { display: inline; color: var(--muted); }
}
