:root {
  --navy: #0b1f33;
  --navy-2: #12304d;
  --cyan: #19c3e6;
  --cyan-d: #0f97b5;
  --bg: #f3f6f9;
  --card: #ffffff;
  --text: #13212f;
  --muted: #5d6f80;
  --line: #dde5ec;
  --ok: #1a9e5c;
  --warn: #d98a00;
  --danger: #cf3b3b;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
a { color: var(--cyan-d); }
button, input, select, textarea { font: inherit; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #cfe3f2; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 20px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand b { display: block; color: #fff; font-size: 18px; letter-spacing: .5px; }
.brand span { color: var(--cyan); font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; }
.nav { padding: 10px 8px; flex: 1; }
.nav h6 { margin: 14px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: #7f9ab0; font-weight: 600; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border-radius: 8px; color: #d7e7f3; text-decoration: none; font-size: 14px; }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active { background: var(--cyan); color: var(--navy); font-weight: 600; }
.badge { background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.badge.cyan { background: var(--cyan); color: var(--navy); }
.userbox { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.userbox b { color: #fff; display: block; }
.userbox button { margin-top: 8px; }
.main { padding: 24px 28px 60px; min-width: 0; }
.topline { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topline h1 { margin: 0; font-size: 22px; }
.menu-btn { display: none; }

/* ---------- Componentes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }
.row > .shrink { flex: 0 0 auto; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #c7d3de; border-radius: 8px; background: #fff; color: var(--text);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--cyan); border-color: transparent; }
.btn { border: 0; border-radius: 8px; padding: 10px 16px; cursor: pointer; background: #e4ebf1; color: var(--text); font-weight: 600; white-space: nowrap; }
.btn:hover { filter: brightness(.96); }
.btn.primary { background: var(--cyan); color: var(--navy); }
.btn.dark { background: var(--navy); color: #fff; }
.btn.danger { background: #fde8e8; color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.big { padding: 14px 22px; font-size: 17px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.25); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: #e7eef4; color: var(--muted); }
.pill.ok { background: #dcf5e7; color: var(--ok); }
.pill.warn { background: #fff1d6; color: #9a6200; }
.pill.danger { background: #fde8e8; color: var(--danger); }
.pill.cyan { background: #d6f5fc; color: #0a6f86; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat b { display: block; font-size: 30px; }
.stat span { color: var(--muted); font-size: 13px; }
.empty { padding: 26px; text-align: center; color: var(--muted); }
.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 6px 14px; }
.checks label { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--text); margin: 0; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: #fff; }
.list-item.called { background: #f6f9fb; }
.list-item .name { font-weight: 700; font-size: 16px; }
.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.alert.warn { background: #fff4dc; color: #7a4f00; }
.alert.danger { background: #fde8e8; color: #8c1f1f; }
.alert.info { background: #e3f6fb; color: #0a5a6d; }
.secret { font-family: Consolas, monospace; font-size: 17px; background: #eef3f7; padding: 10px; border-radius: 8px; word-break: break-all; }
.bar-chart { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 200px 1fr 60px; gap: 10px; align-items: center; font-size: 13px; }
.bar { height: 16px; background: var(--cyan); border-radius: 4px; min-width: 2px; }
.cols-chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.cols-chart div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: 11px; color: var(--muted); }
.cols-chart i { display: block; width: 100%; background: var(--cyan); border-radius: 4px 4px 0 0; min-height: 2px; }
.chat { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }
.chat-list a { display: flex; justify-content: space-between; padding: 10px 12px; border-radius: 8px; text-decoration: none; color: var(--text); }
.chat-list a.active { background: #e3f6fb; font-weight: 700; }
.chat-group { margin: 10px 4px 4px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; font-size: 11px; }
.chat-list { max-height: 520px; overflow-y: auto; }
.chat-msgs { height: 420px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 6px; }
.msg { max-width: 75%; padding: 9px 12px; border-radius: 10px; background: #eef3f7; font-size: 14px; }
.msg.mine { align-self: flex-end; background: #d6f5fc; }
.msg-status { display: block; text-align: right; margin-top: 4px; font-size: 11px; color: var(--muted, #64748b); }
.msg.urgent { border: 2px solid var(--danger); }
.msg small { display: block; color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.tv-preview { background: #050b14; color: #fff; border-radius: 8px; padding: 14px; font-size: 14px; }
.tv-preview .cy { color: var(--cyan); }
.sortable-item { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; background: #fff; }
.sortable-item.inactive { opacity: .55; }
.sortable-item img { width: 70px; height: 40px; object-fit: cover; border-radius: 4px; }
.sortable-item .grow { flex: 1; min-width: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; background: var(--danger); }
.dot.on { background: var(--ok); }

/* ---------- Toasts ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 360px; font-size: 14px; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
.toast.warn { background: var(--warn); }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(5, 15, 25, .5); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.modal { background: #fff; border-radius: 12px; padding: 22px; width: 100%; max-width: 620px; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin-top: 0; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 30% 20%, #163b5d, var(--navy) 60%); padding: 16px; }
.login-card { background: #fff; border-radius: 14px; padding: 30px; width: 100%; max-width: 400px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card .sub { color: var(--cyan-d); font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; margin-bottom: 22px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 6px 0; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-block; }
  .main { padding: 16px; }
  .chat { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 120px 1fr 40px; }
}
@media print {
  .sidebar, .no-print, #toasts { display: none !important; }
  .shell { display: block; }
  .card { border: 0; }
}

/* Controle de acessos por categoria */
.perm-editor { display: grid; gap: 10px; }
.perm-cat { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.perm-cat.locked { background: #f5f7f9; }
.perm-head { display: flex; gap: 8px; align-items: center; color: inherit; font-size: 14px; margin: 0 0 6px; cursor: pointer; }
.perm-head .pill { margin-left: auto; }
.perm-body.off { opacity: .45; }
.perm-level { display: flex; gap: 10px; align-items: flex-start; padding: 4px 0; border-top: 1px dashed var(--line); }
.perm-lv { width: 84px; flex: none; font-size: 12px; font-weight: 700; color: var(--muted); padding-top: 3px; }
.perm-level .checks { flex: 1; }
.perm-locked { color: var(--muted); }
