/* ============================================================================
   CyberFy — Identidade visual Segfy (brandbook oficial)
   Primárias: #f26326 (laranja-vermelho) · #ff9129 (laranja) · #454040 (grafite) · #fff
   Apoio:     #8d4ace (roxo) · #e8368b (rosa) · #00b0cc (ciano) · #69d170 (verde)
   Papéis semânticos: aviso→laranja · perigo→rosa · sucesso→verde · info→ciano · destaque→roxo
   ============================================================================ */
:root {
  --seg-orange: #f26326; --seg-orange2: #ff9129; --graphite: #454040; --white: #ffffff;
  --purple: #8d4ace; --pink: #e8368b; --cyan: #00b0cc; --green: #69d170;

  --bg: #f6f7f9; --bg2: #eef1f5;
  --panel: #ffffff; --panel-soft: #fafbfc;
  --border: #e6e8ee; --border-strong: #d5d9e2;
  --text: #2b2b2b; --muted: #7a7f8a; --muted2: #9aa0ac;
  --primary: var(--seg-orange); --primary2: var(--seg-orange2);
  --danger: var(--pink); --success: var(--green); --info: var(--cyan); --accent: var(--purple);
  --shadow: 0 6px 20px rgba(69,64,64,.08); --shadow-lg: 0 14px 40px rgba(69,64,64,.14);
  --radius: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--text); background: var(--bg);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--seg-orange); text-decoration: none; }
button { cursor: pointer; font: inherit; }
img { max-width: 100%; }

/* ---- Logo ---- */
.logo-img { height: 30px; width: auto; display: block; }
.logo-img.sm { height: 24px; }
.logo-img.lg { height: 46px; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1100px 520px at 85% -10%, #ffe7d3 0%, var(--bg) 55%); }
.login-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 20px; padding: 36px; box-shadow: var(--shadow-lg); text-align: center; }
.login-card .logo-img { margin: 0 auto 18px; height: 42px; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 24px; }
.login-card form { text-align: left; }

label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
input, select, textarea { width: 100%; padding: 11px 12px; background: #fff; border: 1px solid var(--border-strong);
  border-radius: 10px; color: var(--text); font-size: 14px; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--seg-orange);
  box-shadow: 0 0 0 3px rgba(242,99,38,.14); }
textarea { min-height: 88px; resize: vertical; font-family: ui-monospace, "Cascadia Code", monospace; }

.btn { display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 11px 18px; border: none; border-radius: 11px; font-weight: 700; font-size: 14px;
  background: linear-gradient(135deg, var(--seg-orange), var(--seg-orange2)); color: #fff;
  box-shadow: 0 4px 12px rgba(242,99,38,.28); transition: transform .08s, box-shadow .15s, opacity .15s; }
.btn:hover { box-shadow: 0 6px 16px rgba(242,99,38,.36); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .6; cursor: default; box-shadow: none; }
.btn.block { width: 100%; margin-top: 22px; padding: 13px; }
.btn.secondary { background: #fff; color: var(--graphite); border: 1px solid var(--border-strong);
  box-shadow: none; }
.btn.secondary:hover { border-color: var(--seg-orange); color: var(--seg-orange); }
.btn.small { padding: 8px 13px; font-size: 13px; }
.btn.ghost { background: transparent; color: var(--muted); box-shadow: none; }
.btn.danger { background: linear-gradient(135deg, #f65fa0, var(--pink)); box-shadow: 0 4px 12px rgba(232,54,139,.28); }
.btn.vpending { background: #f4a01f; color: #4a2d00; box-shadow: none; }
.btn.vpending:hover { background: #e8951a; }
.btn.vvalid { background: #2f6fed; color: #fff; box-shadow: none; }
.btn.vvalid:hover { background: #2a63d6; }

.error { color: var(--pink); font-size: 13px; margin-top: 12px; min-height: 18px; }
.ok-text { color: #1f9c50; }
.hint { color: var(--muted); font-size: 12px; margin-top: 20px; line-height: 1.8;
  border-top: 1px solid var(--border); padding-top: 16px; background: var(--panel-soft);
  border-radius: 10px; padding: 14px; }
.hint strong { color: var(--graphite); }

/* ---- App shell ---- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px;
  border-bottom: 1px solid var(--border); background: #fff; position: sticky; top: 0; z-index: 20;
  box-shadow: 0 1px 0 rgba(69,64,64,.04); }
.topbar .right { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--muted); }
.topbar .uname { font-weight: 600; color: var(--graphite); }

.badge { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .03em; }
.badge.owner { background: #f2e9fb; color: #6d31b0; }
.badge.tenant { background: #e0f6fa; color: #067d92; }
.badge.client { background: #e7f8ea; color: #2f9d4a; }
.badge.pill-green { background: #e7f8ea; color: #2f9d4a; }
.badge.pill-red { background: #fde4f0; color: #c02574; }
.badge.pill-amber { background: #ffedd8; color: #c85e12; }
.badge.pill-cyan { background: #e0f6fa; color: #067d92; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px; }
.tabs { display: flex; gap: 6px; margin-bottom: 22px; flex-wrap: wrap; }
.tab { padding: 9px 16px; border-radius: 10px; background: #fff; border: 1px solid var(--border);
  color: var(--muted); font-weight: 600; font-size: 14px; transition: all .12s; }
.tab:hover { color: var(--graphite); }
.tab.active { background: linear-gradient(135deg, var(--seg-orange), var(--seg-orange2)); color: #fff;
  border-color: transparent; box-shadow: 0 4px 12px rgba(242,99,38,.24); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); position: relative; overflow: hidden; }
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--seg-orange2); }
.card.alert::before { background: var(--pink); }
.card.good::before { background: var(--green); }
.card .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.card .v { font-size: 30px; font-weight: 800; margin-top: 6px; color: var(--graphite); }
.card.alert .v { color: var(--pink); }
.card.good .v { color: #2f9d4a; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; margin-bottom: 20px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 4px; font-size: 16px; color: var(--graphite); }
.panel .desc { color: var(--muted); font-size: 13px; margin: 0 0 16px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11px; letter-spacing: .03em;
  padding: 10px 12px; border-bottom: 2px solid var(--border); text-transform: uppercase; }
td { padding: 11px 12px; border-bottom: 1px solid var(--border); color: var(--text); }
tr:hover td { background: #fff8f3; }
.empty { color: var(--muted); padding: 26px; text-align: center; font-size: 14px; }

.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > div { flex: 1; min-width: 150px; }
.row > div.grow0 { flex: 0; }
.tree-item { border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 12px; background: var(--panel-soft); }
.tree-item .th { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.tree-item .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Code", monospace; font-size: 12px; }
.spacer { height: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: #fff; border: 1px solid var(--border-strong); border-radius: 999px; padding: 4px 10px;
  font-size: 12px; color: var(--graphite); font-family: ui-monospace, monospace; }

/* ---- Modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(69,64,64,.45); display: grid; place-items: center;
  z-index: 100; padding: 20px; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal { width: 100%; max-width: 480px; background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg);
  overflow: hidden; animation: pop .16s ease; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: .6; } to { transform: none; opacity: 1; } }
.modal .mhead { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px;
  border-bottom: 1px solid var(--border); }
.modal .mhead h3 { margin: 0; font-size: 16px; color: var(--graphite); }
.modal .mhead .x { background: none; border: none; font-size: 22px; color: var(--muted); line-height: 1; padding: 0 4px; }
.modal .mbody { padding: 22px; max-height: 66vh; overflow-y: auto; }
.modal .mfoot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal .merror { color: var(--pink); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ---- Menu (dropdown de ações) ---- */
.menu { position: absolute; background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 90; min-width: 190px; }
.menu button { display: block; width: 100%; text-align: left; padding: 9px 12px; border: none; background: none;
  border-radius: 8px; font-size: 13px; color: var(--graphite); }
.menu button:hover { background: #fff3ea; color: var(--seg-orange); }

/* ---- Toast ---- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--seg-orange2);
  border-radius: 12px; padding: 12px 16px; box-shadow: var(--shadow-lg); font-size: 13px; color: var(--text);
  min-width: 240px; max-width: 360px; animation: slidein .2s ease; }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--pink); }
.toast.info { border-left-color: var(--cyan); }
.toast .tt { font-weight: 700; color: var(--graphite); margin-bottom: 2px; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.provider-pick { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 4px; }
.provider-pick .opt { flex: 1; min-width: 200px; border: 1.5px solid var(--border-strong); border-radius: 12px;
  padding: 14px; cursor: pointer; background: #fff; transition: all .12s; }
.provider-pick .opt:hover { border-color: var(--seg-orange2); }
.provider-pick .opt.sel { border-color: var(--seg-orange); background: #fff8f3; box-shadow: 0 0 0 3px rgba(242,99,38,.1); }
.provider-pick .opt h4 { margin: 0 0 4px; font-size: 14px; color: var(--graphite); }
.provider-pick .opt p { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.on { background: var(--green); } .status-dot.off { background: var(--muted2); } .status-dot.wait { background: var(--seg-orange2); }

/* Evita rolagem horizontal da página inteira em qualquer tamanho. */
html, body { max-width: 100%; overflow-x: hidden; }
img { max-width: 100%; height: auto; }

/* ===================== RESPONSIVO — TABLET (<= 900px) ===================== */
@media (max-width: 900px) {
  .container { padding: 18px 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

/* ===================== RESPONSIVO — CELULAR (<= 640px) ===================== */
@media (max-width: 640px) {
  .container { padding: 14px 12px; }

  /* Topbar quebra em duas linhas e centraliza os controles */
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .topbar .right { width: 100%; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
  #waStatus { display: none; }                 /* status interno não é essencial no celular */
  .logo-img { height: 26px !important; }
  .brandbox span[style*="22px"] { font-size: 17px !important; } /* nome do revendedor menor */

  /* Abas viram uma faixa que rola na horizontal (uma linha só) */
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: 4px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; }

  /* Cards: 1 coluna, números um pouco menores */
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card .v { font-size: 24px; }

  /* Painéis mais compactos */
  .panel { padding: 16px; border-radius: 12px; }

  /* Formulários: cada campo ocupa a linha inteira (empilha) */
  .row { gap: 10px; }
  .row > div { flex: 1 1 100% !important; min-width: 0 !important; }
  input, select, textarea { font-size: 16px; }   /* 16px evita zoom automático do iOS */

  /* Tabelas rolam na horizontal dentro do próprio espaço, sem quebrar a página */
  table { display: block; width: 100%; overflow-x: auto; white-space: nowrap;
    -webkit-overflow-scrolling: touch; }
  thead, tbody, tr { width: 100%; }

  /* Botões de ação embrulham e não estouram */
  .actions { flex-wrap: wrap; }
  .btn.small, .btn.secondary.small { font-size: 12px; padding: 7px 10px; }

  /* Modal ocupa quase a tela toda */
  .modal { max-width: 100%; }
  .modal .mbody { max-height: 70vh; }
  .modal .mfoot { flex-wrap: wrap; }
  .modal .mfoot .btn { flex: 1 1 auto; }

  /* Login mais enxuto */
  .login-card { padding: 26px 20px; border-radius: 16px; }

  /* Provider cards (WhatsApp) empilham */
  .provider-pick .opt { min-width: 100%; }
}

/* Telas muito estreitas: cards em 1 coluna */
@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
}
