:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0e7490;
  --brand-d: #155e75;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --chip: #f1f5f9;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: #f8fafc; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--bg), var(--brand-d)); }
.login-card { background: #fff; padding: 34px 30px; border-radius: 16px; width: 320px; box-shadow: 0 20px 60px rgba(0,0,0,.35); text-align: center; }
.brand { font-weight: 800; font-size: 30px; letter-spacing: 1px; color: var(--brand-d); }
.brand span { color: var(--warn); }
.brand.small { font-size: 22px; }
.login-card .sub { color: var(--muted); margin: 4px 0 20px; }
.login-card input { width: 100%; padding: 13px; font-size: 20px; text-align: center; letter-spacing: 6px; border: 1px solid var(--line); border-radius: 10px; }
.login-card button { width: 100%; margin-top: 14px; padding: 13px; background: var(--brand); color: #fff; border: 0; border-radius: 10px; font-size: 16px; font-weight: 600; cursor: pointer; }
.login-card button:hover { background: var(--brand-d); }
.erro { color: var(--bad); font-size: 14px; margin-top: 10px; min-height: 18px; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--bg); color: #cbd5e1; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.side .brand { margin: 4px 8px 22px; }
.side .brand span { color: var(--warn); }
#nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
#nav a { padding: 11px 14px; border-radius: 9px; cursor: pointer; font-size: 15px; color: #cbd5e1; text-decoration: none; }
#nav a:hover { background: var(--bg2); color: #fff; }
#nav a.active { background: var(--brand); color: #fff; font-weight: 600; }
.side-foot { border-top: 1px solid var(--bg2); padding-top: 12px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; color: #94a3b8; }
.link { background: none; border: 0; color: var(--warn); cursor: pointer; font-size: 13px; }
main { padding: 26px 30px; overflow-x: hidden; min-width: 0; }

/* ---------- Common ---------- */
h1 { font-size: 22px; margin-bottom: 4px; }
h2 { font-size: 17px; margin: 22px 0 12px; }
.page-sub { color: var(--muted); margin-bottom: 18px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }
input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
button.btn { padding: 9px 15px; border: 0; border-radius: 8px; background: var(--brand); color: #fff; font-weight: 600; cursor: pointer; }
button.btn:hover { background: var(--brand-d); }
button.btn.ghost { background: #fff; color: var(--brand-d); border: 1px solid var(--line); }
button.btn.warn { background: var(--warn); }
button.btn.bad { background: var(--bad); }
button.btn.ok { background: var(--ok); }
button.btn:disabled { opacity: .5; cursor: not-allowed; }
button.btn.sm { padding: 5px 10px; font-size: 13px; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.card .k { color: var(--muted); font-size: 13px; }
.card .v { font-size: 26px; font-weight: 700; margin-top: 4px; }
.card .v.small { font-size: 19px; }
.card.accent { border-left: 4px solid var(--brand); }
.card.bad-accent { border-left: 4px solid var(--bad); }
.card.ok-accent { border-left: 4px solid var(--ok); }

/* Table */
table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { background: #f8fafc; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafc; cursor: pointer; }
.table-wrap { overflow-x: auto; }

/* Chips / badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ativo { background: #dcfce7; color: #166534; }
.badge.suspenso { background: #fef3c7; color: #92400e; }
.badge.cancelado { background: #fee2e2; color: #991b1b; }
.badge.aberto { background: #e0f2fe; color: #075985; }
.badge.pago { background: #dcfce7; color: #166534; }
.badge.vencido { background: #fee2e2; color: #991b1b; }

.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px; }
.pill-filter { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.pill-filter button { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 14px; }
.pill-filter button.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ficha */
.ficha-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 22px; margin-top: 8px; }
.ficha-grid .f-k { color: var(--muted); font-size: 13px; }
.ficha-grid .f-v { font-weight: 500; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
.back { color: var(--brand-d); cursor: pointer; background: none; border: 0; font-size: 14px; margin-bottom: 10px; }

/* alertas de cobranca (7h/13h): flutuante no topo no desktop (no celular vai pra baixo, ver @media) */
#alertas-cob { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 900; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 560px); }

/* chips compactos (ex.: formas de pagamento do dia) — no lugar de um card por forma */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip { background: var(--chip); border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; font-size: 12px; white-space: nowrap; color: var(--muted); }
.chip b { color: var(--ink); }

/* launcher da tela inicial: atalhos grandes pros modulos (estilo tela de apps) */
.launcher { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin: 6px 0 18px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px 8px; text-align: center; cursor: pointer; user-select: none; transition: transform .08s, box-shadow .12s; }
.tile:hover { box-shadow: 0 6px 18px rgba(0,0,0,.08); border-color: #cbd5e1; }
.tile:active { transform: scale(.97); }
.tile:focus-visible { outline: 2px solid var(--brand); }
.tile .ico { font-size: 28px; line-height: 1; }
.tile .lbl { font-size: 13px; font-weight: 600; margin-top: 8px; color: var(--ink); }

/* toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 14px; z-index: 50; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.toast.ok { background: var(--ok); }
.toast.bad { background: var(--bad); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal-box { background: #fff; border-radius: 14px; padding: 22px; width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; }
.modal-box h3 { margin-bottom: 14px; }
.modal-box.wide { max-width: 860px; }
.lista-cards .item { border: 1px solid #e5e7eb; border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: #fff; }
.lista-cards .item .nome { font-weight: 700; cursor: pointer; }
.lista-cards .item .sub { color: #64748b; font-size: 12.5px; margin-top: 2px; line-height: 1.4; }
.lista-cards .item .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid label input, .form-grid label select, .form-grid label textarea { color: var(--ink); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: sp .7s linear infinite; vertical-align: middle; }
@keyframes sp { to { transform: rotate(360deg); } }

/* grafico: no desktop segura largura minima; no mobile encolhe pra caber */
.chart-svg { min-width: 560px; }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  /* barra de topo limpa: logo + menu horizontal rolavel; usuario/sair no canto */
  .side {
    position: sticky; top: 0; z-index: 30;
    height: auto;
    min-width: 0;
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px 8px;
    gap: 8px;
  }
  .side .brand { margin: 0; font-size: 20px; }
  #nav {
    flex: none;
    min-width: 0;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  #nav::-webkit-scrollbar { display: none; }
  #nav a { white-space: nowrap; padding: 8px 13px; font-size: 14px; }
  .side-foot {
    position: absolute; top: 13px; right: 12px;
    border-top: 0; padding-top: 0; gap: 10px; font-size: 12px;
  }
  main { padding: 16px 14px; }
  h1 { font-size: 20px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 13px; }
  .card .v { font-size: 22px; }
  .card .v.small { font-size: 16px; }
  .ficha-grid, .form-grid { grid-template-columns: 1fr; }
  /* grafico: mantem largura legivel e ROLA pro lado, em vez de encolher ate as letras sumirem */
  .chart-svg { min-width: 520px; }
  .pill-filter { gap: 6px; }
  .pill-filter button { padding: 6px 12px; font-size: 13px; }
  /* colunas secundarias das tabelas (marcadas com .hide-m) somem no celular */
  .hide-m { display: none !important; }
  th, td { padding: 8px 8px; font-size: 13px; }
  /* faixas de aviso: texto em cima, botao embaixo com a largura toda */
  .banner .row { flex-direction: column; align-items: stretch; gap: 8px; }
  .banner .btn { width: 100%; }
  /* alertas 7h/13h: no celular ficam EMBAIXO, sem cobrir o menu do topo */
  #alertas-cob { top: auto; bottom: 14px; width: calc(100vw - 20px); }
  h2 { margin: 18px 0 10px; }
  /* launcher: 3 colunas no celular, cabe na primeira tela */
  .launcher { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 4px 0 14px; }
  .tile { padding: 12px 4px; border-radius: 12px; }
  .tile .ico { font-size: 26px; }
  .tile .lbl { font-size: 12px; margin-top: 6px; }
}


/* ---------- Barra do topo (menu lateral removido: o painel de gestao e o menu) ---------- */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.side { flex-direction: row; align-items: center; justify-content: space-between; height: auto; min-height: 0; padding: 10px 18px; position: sticky; top: 0; z-index: 30; box-shadow: 0 2px 8px rgba(15,23,42,.25); }
.side .brand { margin: 0; cursor: pointer; user-select: none; display: flex; align-items: baseline; gap: 8px; }
.side .brand:hover { opacity: .9; }
.side .brand .brand-hint { font-size: 11px; font-weight: 500; letter-spacing: 0; color: #94a3b8; }
#nav { display: none; }
.side-foot { position: static; border-top: 0; padding-top: 0; gap: 12px; font-size: 13px; }
main { padding: 22px 26px; max-width: 1400px; width: 100%; margin: 0 auto; }
@media (max-width: 720px) {
  .side { padding: 8px 12px; }
  .side .brand { font-size: 20px; }
  .side-foot { position: static; font-size: 12px; }
  main { padding: 14px 12px; }
}


/* ---------- Login (cartao responsivo + teclado numerico) ---------- */
.login-wrap { padding: 16px; }
.login-card { width: min(92vw, 360px); padding: 28px 24px 20px; }
.login-card input { letter-spacing: 8px; font-size: 24px; }
.teclado { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.teclado button { width: 100%; margin: 0; padding: 14px 0; font-size: 20px; font-weight: 600; background: #f1f5f9; color: var(--ink, #0f172a); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.teclado button:hover { background: #e2e8f0; }
.teclado button:active { background: var(--brand); color: #fff; }
.teclado button.t-ghost { background: #fff; color: var(--muted); font-weight: 500; }
.login-card #btn-entrar { margin-top: 12px; }
.login-foot { color: var(--muted); font-size: 11px; margin-top: 12px; }


/* ---------- Chat interno ---------- */
.chat-msgs { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; padding: 6px 2px; }
.chat-msg { max-width: min(78%, 620px); border: 1px solid #e5e7eb; border-radius: 12px; padding: 8px 12px; background: #fff; align-self: flex-start; }
.chat-msg.eu { align-self: flex-end; background: #ecfeff; border-color: #a5f3fc; }
.chat-msg .quem { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.chat-msg .quem b { color: var(--ink, #0f172a); }
.chat-msg .txt { white-space: pre-wrap; word-break: break-word; font-size: 14px; margin-top: 2px; }
.chat-msg .hora { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.chat-dia { align-self: center; font-size: 11px; color: var(--muted); background: #f1f5f9; border-radius: 999px; padding: 2px 10px; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.chat-form textarea { flex: 1; min-height: 44px; max-height: 140px; resize: vertical; }
.tile .badge-n { position: absolute; top: 8px; right: 8px; background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 2px 7px; }
.tile { position: relative; }
#chat-topo { display: none; background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 2px 7px; margin-right: 8px; cursor: pointer; }
