:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-alt: #f8f9fb;
  --text: #12141a;
  --muted: #667085;
  --border: #e4e7ec;

  --primary: #4f46e5;
  --primary-strong: #4338ca;
  --primary-soft: #eef0ff;
  --primary-text: #ffffff;

  --success: #15803d;
  --success-soft: #dcfce7;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --hold: #7c3aed;
  --hold-soft: #f0e9fe;
  --muted-soft: #eceef2;

  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 2px 6px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 4px 10px rgba(16, 24, 40, 0.06), 0 10px 24px rgba(16, 24, 40, 0.08);
  --shadow-primary: 0 6px 16px rgba(79, 70, 229, 0.22);
}

/* Sem escolha manual guardada (nenhum [data-theme]), segue o tema do
   sistema. Escolha manual (botao no cabecalho, ver app.js) grava
   data-theme="dark"|"light" e vence a preferencia do sistema nos dois
   sentidos -- por isso os mesmos valores aparecem duas vezes: uma vez presa
   a media query (:not([data-theme="light"])) e outra vez presa ao atributo
   explicito ([data-theme="dark"]), sem media query nenhuma. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101217;
    --surface: #1a1d24;
    --surface-alt: #20242d;
    --text: #edeef1;
    --muted: #96a0ae;
    --border: #2b2f39;

    --primary: #818cf8;
    --primary-strong: #a5b4fc;
    --primary-soft: rgba(129, 140, 248, 0.16);
    --primary-text: #0c0e14;

    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, 0.14);
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, 0.14);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.14);
    --hold: #c4b5fd;
    --hold-soft: rgba(196, 181, 253, 0.14);
    --muted-soft: rgba(255, 255, 255, 0.06);

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.28);
    --shadow-lg: 0 6px 16px rgba(0, 0, 0, 0.32), 0 14px 32px rgba(0, 0, 0, 0.3);
    --shadow-primary: 0 6px 18px rgba(129, 140, 248, 0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #101217;
  --surface: #1a1d24;
  --surface-alt: #20242d;
  --text: #edeef1;
  --muted: #96a0ae;
  --border: #2b2f39;

  --primary: #818cf8;
  --primary-strong: #a5b4fc;
  --primary-soft: rgba(129, 140, 248, 0.16);
  --primary-text: #0c0e14;

  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.14);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --hold: #c4b5fd;
  --hold-soft: rgba(196, 181, 253, 0.14);
  --muted-soft: rgba(255, 255, 255, 0.06);

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 6px 16px rgba(0, 0, 0, 0.32), 0 14px 32px rgba(0, 0, 0, 0.3);
  --shadow-primary: 0 6px 18px rgba(129, 140, 248, 0.3);
}

* { box-sizing: border-box; }

/* O atributo hidden tem a mesma especificidade de qualquer seletor de
   classe (ex: .modal-overlay, .bottom-nav button) -- sem !important aqui,
   a primeira regra de autor que definir display nesse elemento vence o
   [hidden] do navegador (ele e so um estilo de user-agent, perde por
   origem, nao por especificidade), e o elemento fica visivel mesmo
   "escondido". Foi o que deixava #msisdn-modal sempre visivel (tela
   escurecida pelo overlay a 50% preto, bloqueando todo clique). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  background-image: radial-gradient(560px circle at 12% -8%, color-mix(in srgb, var(--primary) 6%, transparent), transparent 60%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
::-webkit-scrollbar-track { background: transparent; }

i.fa-solid, i.fa-regular { line-height: 1; }

button { cursor: pointer; font-family: inherit; }
button, .card, input, select, textarea {
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease, box-shadow 0.15s ease;
}
button:active { transform: scale(0.97); }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.login-card input:focus-visible,
.form-grid input:focus-visible,
.form-grid select:focus-visible,
.form-grid textarea:focus-visible,
.filters input:focus-visible,
.filters select:focus-visible {
  outline: none;
  border-color: var(--primary);
}

.view { animation: view-in 0.18s ease; }
@keyframes view-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- Login ---------------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 0%, var(--primary-soft), var(--bg) 55%);
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 26px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow-lg);
  animation: view-in 0.3s ease;
}
.login-card::before {
  content: '';
  position: absolute;
  top: 0; left: 18px; right: 18px;
  height: 3px;
  border-radius: 0 0 6px 6px;
  background: linear-gradient(90deg, var(--primary), var(--primary-strong));
  opacity: 0.9;
}

.login-card .brand {
  width: 56px;
  height: 56px;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--primary-soft), color-mix(in srgb, var(--primary) 18%, var(--primary-soft)));
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 20%, transparent);
}
.login-card .brand .bat-icon {
  width: 30px;
  height: 18px;
}
.login-card h1 { margin: 0 0 2px; font-size: 21px; text-align: center; font-weight: 700; }
.login-card .muted { text-align: center; margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.login-card label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 14px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.input-wrap { position: relative; margin-top: 6px; }
.input-wrap i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 14px;
}
.login-card input {
  width: 100%;
  padding: 11px 12px 11px 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 16px;
}
.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}
.login-card button {
  margin-top: 22px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  box-shadow: var(--shadow-primary);
  color: var(--primary-text);
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.login-card button:active { background: var(--primary-strong); }
.error {
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  text-align: center;
  margin: 14px 0 0;
}
.muted { color: var(--muted); }

/* ---------------- App shell ---------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top, 0px));
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface) 60%, color-mix(in srgb, var(--primary) 3%, var(--surface)) 100%);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(16, 24, 40, 0.02), 0 4px 10px rgba(16, 24, 40, 0.04);
  backdrop-filter: saturate(1.3) blur(6px);
}
.app-header h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, var(--text), color-mix(in srgb, var(--primary) 55%, var(--text)));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.app-header button {
  border: none;
  background: var(--muted-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
#config-btn { padding: 7px 10px; font-size: 14px; }
#conta-select {
  border: none;
  background: var(--muted-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 8px;
  border-radius: 8px;
  max-width: 120px;
}

main {
  padding: 14px 12px calc(82px + env(safe-area-inset-bottom, 0px));
  max-width: 720px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-top: 1px solid var(--border);
  padding: 6px 4px env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -4px 16px rgba(16, 24, 40, 0.05);
  z-index: 10;
}
.bottom-nav button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  padding: 7px 2px;
  margin: 0 3px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: background 0.15s ease, color 0.15s ease;
}
.bottom-nav button i {
  font-size: 17px;
  height: 20px;
  display: flex;
  align-items: center;
}
.bottom-nav button.active {
  color: var(--primary);
  font-weight: 700;
  background: var(--primary-soft);
}
@media (hover: hover) {
  .bottom-nav button:not(.active):hover { color: var(--text); background: var(--muted-soft); }
  .actions button:not(.primary):not(.danger):hover { background: var(--muted-soft); }
  .app-header button:hover { background: var(--border); }
  .actions button:hover { transform: translateY(-1px); }
  .pager button:not(:disabled):hover {
    background: var(--muted-soft);
    border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
  }
  .mais-item:not(.active):hover { border-color: color-mix(in srgb, var(--primary) 30%, var(--border)); background: var(--surface); }
}

/* Folha "Mais" (Relatorios/Eventos/Contas/Planos/Testemunhos) -- fora da
   barra principal pra nao apertar 10 botoes num ecra de telemovel. */
.mais-sheet-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.mais-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}
.mais-item i { font-size: 20px; color: var(--primary); }
.mais-item[hidden] { display: none; }
.mais-item.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

/* ---------------- Componentes ---------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.kpi-card {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px 14px 14px;
  box-shadow: var(--shadow);
}
/* Barra de destaque no topo, na cor do tipo do cartao (achada pelo icone lá
   dentro) -- so CSS, sem precisar mexer no HTML gerado pelo app.js. */
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--muted);
  opacity: 0.35;
}
.kpi-card:has(.icon-primary)::before { background: var(--primary); opacity: 1; }
.kpi-card:has(.icon-success)::before { background: var(--success); opacity: 1; }
.kpi-card:has(.icon-danger)::before { background: var(--danger); opacity: 1; }
.kpi-card:has(.icon-hold)::before { background: var(--hold); opacity: 1; }
.kpi-card:has(.icon-warning)::before { background: var(--warning); opacity: 1; }

@media (hover: hover) {
  .kpi-card:hover, .card:hover {
    transform: translateY(-1px);
    border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
    box-shadow: var(--shadow-lg);
  }
}
.kpi-card .icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  margin-bottom: 12px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
}
.kpi-card .value { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.kpi-card .label { font-size: 11.5px; color: var(--muted); margin-top: 3px; font-weight: 600; }

.icon-primary { background: linear-gradient(135deg, var(--primary-soft), color-mix(in srgb, var(--primary) 22%, var(--primary-soft))); color: var(--primary); }
.icon-success { background: linear-gradient(135deg, var(--success-soft), color-mix(in srgb, var(--success) 22%, var(--success-soft))); color: var(--success); }
.icon-danger { background: linear-gradient(135deg, var(--danger-soft), color-mix(in srgb, var(--danger) 22%, var(--danger-soft))); color: var(--danger); }
.icon-hold { background: linear-gradient(135deg, var(--hold-soft), color-mix(in srgb, var(--hold) 22%, var(--hold-soft))); color: var(--hold); }
.icon-warning { background: linear-gradient(135deg, var(--warning-soft), color-mix(in srgb, var(--warning) 22%, var(--warning-soft))); color: var(--warning); }

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 14px;
  padding: 13px 14px 13px 13px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
/* Barra lateral na cor do estado do pedido/deposito (achada pelo badge lá
   dentro) -- ajuda a escanear a lista sem ler cada linha. */
.card:has(.badge-dispatched) { border-left-color: var(--warning); }
.card:has(.badge-hold) { border-left-color: var(--hold); }
.card:has(.badge-delivered) { border-left-color: var(--success); }
.card:has(.badge-failed) { border-left-color: var(--danger); }

.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row + .row { margin-top: 7px; }
.row:first-child strong { font-size: 15px; letter-spacing: -0.01em; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.badge i { font-size: 9px; }
.badge-queued, .badge-dispatching { background: var(--muted-soft); color: var(--muted); }
.badge-dispatched { background: var(--warning-soft); color: var(--warning); }
.badge-delivered { background: var(--success-soft); color: var(--success); }
.badge-failed { background: var(--danger-soft); color: var(--danger); }
.badge-hold { background: var(--hold-soft); color: var(--hold); }
.badge-cancelled { background: var(--muted-soft); color: var(--muted); }
.badge-aguardando_cartao { background: var(--hold-soft); color: var(--hold); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-success { background: var(--success-soft); color: var(--success); }

.actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.actions button {
  flex: 1;
  min-width: 90px;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.actions button.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: var(--primary-text);
  border-color: var(--primary);
  box-shadow: var(--shadow-primary);
}
.actions button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.filters select, .filters input {
  flex: 1;
  min-width: 120px;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.section-title {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 22px 0 9px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.section-title i {
  color: var(--primary);
  font-size: 11px;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: var(--primary-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pager { display: flex; justify-content: center; gap: 12px; margin-top: 12px; align-items: center; }
.pager button {
  padding: 7px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
}
.pager button:disabled { opacity: 0.4; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 0;
  font-size: 13px;
}
.empty i { display: block; font-size: 22px; margin-bottom: 8px; opacity: 0.5; }

.hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--primary-soft);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.5;
  margin: 0 0 12px;
}
.hint i { color: var(--primary); margin-top: 1px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.form-grid label { grid-column: span 2; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.form-grid label.half { grid-column: span 1; }
.form-grid input, .form-grid select, .form-grid textarea {
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.form-grid button { grid-column: span 2; margin-top: 6px; }
.form-grid label.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}
.form-grid label.checkbox-label input[type="checkbox"] {
  width: auto;
  padding: 0;
  accent-color: var(--primary);
}
.feature-checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 6px 10px;
  margin-top: 4px;
}
.feature-checkbox { font-size: 13px; }

.toast {
  position: fixed;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: var(--bg);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 20;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.event-line {
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
  padding: 10px 2px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.event-line:last-child { border-bottom: none; }
.event-line .badge-icon {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  flex-shrink: 0;
  margin-top: 1px;
}
.event-line .meta { color: var(--muted); margin-top: 2px; }
.level-error .badge-icon { background: var(--danger-soft); color: var(--danger); }
.level-warn .badge-icon { background: var(--warning-soft); color: var(--warning); }
.level-info .badge-icon { background: var(--primary-soft); color: var(--primary); }

.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.status-dot.online { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); animation: pulse-online 2s ease-in-out infinite; }
.status-dot.offline { background: var(--muted); }
@keyframes pulse-online {
  0%, 100% { box-shadow: 0 0 0 3px var(--success-soft); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

/* Bloco de token/URL pronto a copiar — toque/clique seleciona tudo. */
.code-box {
  display: block;
  width: 100%;
  font-family: 'SFMono-Regular', Consolas, Menlo, monospace;
  font-size: 0.82em;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  resize: vertical;
  margin-top: 4px;
}
label.code-label { display: block; font-size: 12px; color: var(--muted); margin-top: 10px; }
label.code-label:first-child { margin-top: 0; }

/* Numero clicavel (Pedidos/Depositos) que abre o historico -- mesma cor do
   texto, so o sublinhado pontilhado sinaliza que da pra clicar. */
.msisdn-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.msisdn-link:hover, .msisdn-link:focus-visible { color: var(--primary); }

/* Modal de historico do numero */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  animation: modal-fade-in 0.15s ease;
}
@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 18px 16px 24px;
  box-shadow: var(--shadow-lg);
  animation: view-in 0.2s ease;
}
@media (min-width: 560px) {
  .modal-overlay { align-items: center; }
  .modal-card { border-radius: 16px; }
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-header h2 { font-size: 16px; margin: 0; font-family: monospace; }
.modal-close {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.history-counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 16px; }
.history-counts div {
  text-align: center;
  padding: 10px 4px;
  border-radius: 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}
.history-counts .value { display: block; font-size: 18px; font-weight: 700; }
.history-counts .label { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin-top: 2px; }
.history-counts .confirmados .value { color: var(--success); }
.history-counts .aResolver .value { color: var(--hold); }
.history-counts .refeitos .value { color: var(--danger); }

/* ---------------- Ajuda (documentacao) ---------------- */
.doc-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.doc-chip {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}
.doc-chip.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

.doc-acoes { display: flex; gap: 6px; margin: -4px 0 4px; }
.doc-acoes button {
  padding: 6px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.doc-card { padding: 0; border-left-color: var(--primary); }
.doc-card[data-doc-nivel="superadmin"] { border-left-color: var(--hold); }
.doc-card > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
}
.doc-card > summary::-webkit-details-marker { display: none; }
.doc-card > summary::after {
  content: '\f078';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  font-size: 11px;
  color: var(--muted);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.doc-card[open] > summary::after { transform: rotate(180deg); }
.doc-summary-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.doc-summary-title i { color: var(--primary); width: 16px; text-align: center; flex-shrink: 0; }
.doc-card[data-doc-nivel="superadmin"] .doc-summary-title i { color: var(--hold); }
.doc-badges { display: flex; gap: 4px; margin-left: auto; flex-shrink: 0; }

.doc-body {
  padding: 0 14px 14px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  overflow-wrap: anywhere;
}
.doc-body p { margin: 8px 0; }
.doc-body ul, .doc-body ol { margin: 8px 0; padding-left: 20px; }
.doc-body li { margin: 4px 0; }
.doc-body code {
  font-family: 'SFMono-Regular', Consolas, Menlo, monospace;
  font-size: 0.86em;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
}

.doc-table-wrap { overflow-x: auto; margin: 10px 0; border: 1px solid var(--border); border-radius: 10px; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.doc-table th, .doc-table td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.doc-table th { background: var(--surface-alt); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.doc-table tr:last-child td { border-bottom: none; }
.doc-table td { min-width: 110px; }

.doc-aviso, .doc-dica {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 12.5px;
  margin: 10px 0;
}
.doc-aviso { background: var(--warning-soft); }
.doc-aviso i { color: var(--warning); margin-top: 3px; }
.doc-dica { background: var(--primary-soft); }
.doc-dica i { color: var(--primary); margin-top: 3px; }

.doc-formula {
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 700;
  text-align: center;
}

.doc-faq dt { font-weight: 700; margin-top: 12px; }
.doc-faq dt:first-child { margin-top: 0; }
.doc-faq dd { margin: 4px 0 0; color: var(--text); }

/* Interruptores do bot por grupo (Configuracoes) */
.grupo-bot { padding: 10px 0; border-top: 1px solid var(--border); display: grid; gap: 6px; }
.grupo-bot:first-child { border-top: none; padding-top: 0; }
.grupo-bot.desligado strong { color: var(--muted); }
.grupo-bot-id { font-size: 11px; overflow-wrap: anywhere; }
.grupo-bot .checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.grupo-bot .checkbox-label input { width: 18px; height: 18px; accent-color: var(--primary); }
.grupo-bot .checkbox-label:has(input:disabled) { opacity: 0.5; }
.grupo-bot-horario { display: grid; gap: 6px; padding: 8px 10px; border-radius: 10px; background: var(--surface-alt); }
.grupo-bot-horario[hidden] { display: none; }
.grupo-bot-horario label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--text); }
.grupo-bot-horario input[type="time"] { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.grupo-bot-horario label.checkbox-label { justify-content: flex-start; }
.grupo-bot-guardar-horario { padding: 8px 10px; border-radius: 9px; border: 1px solid var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; font-size: 12px; }
