/* ==========================================================================
   Gateway API — tema do painel
   Para combinar com a sua logo, altere --brand e --brand-strong abaixo.
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    /* Cores tiradas da logo TI-TEC */
    --brand: #1a8fc0;          /* azul-turquesa: botões, item ativo, destaques */
    --brand-strong: #243c8f;   /* azul-marinho: hover / textos da marca */
    --brand-accent: #4cc38a;   /* verde da logo */
    --brand-soft: #e8f5fb;     /* fundos suaves da marca */

    --bg: #f5f7fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --text: #0f172a;
    --text-2: #475569;
    --text-3: #94a3b8;

    --success: #16a34a;  --success-soft: #dcfce7;
    --danger:  #dc2626;  --danger-soft:  #fee2e2;
    --warning: #d97706;  --warning-soft: #fef3c7;
    --info:    #2563eb;  --info-soft:    #dbeafe;

    --radius: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px -12px rgba(15, 23, 42, .12);
    --shadow-lg: 0 24px 60px -12px rgba(15, 23, 42, .28);
    --ease: cubic-bezier(.4, 0, .2, 1);
    --sidebar-w: 264px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-strong); }
h3 { font-size: 1rem; font-weight: 600; margin-bottom: .75rem; }
h4 { font-size: .9rem; font-weight: 600; margin-bottom: .75rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.icon { flex-shrink: 0; display: block; }

/* ==========================================================================
   Layout: sidebar + topbar + conteúdo
   ========================================================================== */
.main-body { min-height: 100vh; }

.sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    z-index: 1000;
    transition: transform .25s var(--ease);
}

.sidebar-header {
    display: flex; align-items: center; justify-content: center; position: relative;
    padding: 1.1rem 1.25rem .75rem;
    min-height: 76px;
    border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.brand-logo { max-height: 104px; max-width: 200px; object-fit: contain; display: block; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 11px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, var(--brand-accent), var(--brand), var(--brand-strong));
    color: #fff;
    box-shadow: 0 6px 16px -6px var(--brand);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 1rem; font-weight: 700; letter-spacing: -.01em; }
.brand-text small { font-size: .75rem; color: var(--text-3); }

.sidebar-nav { flex: 1; padding: .75rem; overflow-y: auto; }
.nav-label {
    display: block; padding: .5rem .75rem;
    font-size: .7rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
    color: var(--text-3);
}
.sidebar-nav ul { list-style: none; }
.sidebar-nav li + li { margin-top: 2px; }
.sidebar-nav a {
    display: flex; align-items: center; gap: .75rem;
    padding: .65rem .75rem;
    border-radius: var(--radius-sm);
    color: var(--text-2); text-decoration: none; font-weight: 500;
    transition: background .15s, color .15s;
}
.sidebar-nav a:hover { background: var(--surface-2); color: var(--text); }
.sidebar-nav li.active a { background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; }
.sidebar-nav li.active .icon { color: var(--brand); }

.sidebar-footer { padding: .75rem; border-top: 1px solid var(--border); }
.user-chip {
    display: flex; align-items: center; gap: .7rem;
    padding: .55rem; border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    display: grid; place-items: center; flex-shrink: 0;
    background: var(--text); color: #fff; font-weight: 600; font-size: .85rem;
}
.user-meta { flex: 1; min-width: 0; line-height: 1.25; }
.user-meta strong { display: block; font-size: .875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { color: var(--text-3); font-size: .75rem; }

.icon-btn {
    display: inline-grid; place-items: center;
    width: 34px; height: 34px; padding: 0;
    border-radius: 9px; border: 0; background: transparent;
    color: var(--text-2); cursor: pointer; box-shadow: none;
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--border); color: var(--text); transform: none; box-shadow: none; }
.sidebar-close, .menu-btn { display: none; }
.sidebar-close { position: absolute; top: .75rem; right: .75rem; }

.main-wrap { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; gap: .75rem;
    padding: 1rem 2rem;
    background: rgba(245, 247, 250, .85);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid transparent;
}
.topbar-eyebrow { font-size: .75rem; color: var(--text-3); font-weight: 500; }
.topbar-title { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }

.main-content {
    flex: 1; width: 100%; max-width: 1280px;
    padding: .5rem 2rem 2.5rem;
    animation: fadeIn .3s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.sidebar-backdrop { display: none; }

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
}
.card h2 {
    display: flex; align-items: center; gap: .6rem;
    font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em;
    margin-bottom: 1.25rem;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.card-header h2 { margin-bottom: 0; }
.card-subtitle { color: var(--text-2); font-size: .85rem; }
.count-pill {
    display: inline-block; padding: .1rem .55rem; border-radius: 99px;
    background: var(--surface-2); border: 1px solid var(--border);
    font-size: .75rem; font-weight: 600; color: var(--text-2);
}

/* ==========================================================================
   Tabelas
   ========================================================================== */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .8rem 1rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
    background: var(--surface-2);
    font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-2); white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfc; }
td.muted, .muted { color: var(--text-3); }
.nowrap { white-space: nowrap; }

/* ==========================================================================
   Formulários
   ========================================================================== */
.form-group { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1.1rem; }
.form-group label { font-weight: 500; font-size: .85rem; color: var(--text-2); }

input[type="text"], input[type="password"], input[type="date"], input[type="time"],
input[type="email"], input[type="number"], select, textarea {
    width: 100%;
    padding: .65rem .85rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit; font-size: .9rem;
    transition: border-color .15s, box-shadow .15s;
}
input[type="text"], input[type="password"], input[type="date"], input[type="time"],
input[type="email"], input[type="number"], select { height: 42px; }
.filter-grid button { height: 42px; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent);
}
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 1rem; align-items: end;
}
.filter-grid .form-group { margin-bottom: 0; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ==========================================================================
   Botões
   ========================================================================== */
button, .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    padding: .62rem 1.1rem;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    background: var(--brand); color: #fff;
    font: inherit; font-size: .875rem; font-weight: 600;
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .1s;
}
button:hover, .btn:hover { background: var(--brand-strong); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: not-allowed; }
button:focus-visible, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-danger-soft { background: var(--danger-soft); color: #b91c1c; }
.btn-danger-soft:hover { background: #fecaca; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #b45309; }
.btn-small { padding: .4rem .75rem; font-size: .8rem; border-radius: 8px; }

.action-btn { padding: .4rem .7rem; font-size: .8rem; border-radius: 8px; }
.view-btn { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.view-btn:hover { background: var(--surface-2); }
.delete-btn { background: var(--danger-soft); color: #b91c1c; }
.delete-btn:hover { background: #fecaca; }
.actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.actions form { display: inline; }

/* ==========================================================================
   Mensagens de feedback
   ========================================================================== */
.feedback-success, .feedback-error, .feedback-info, .feedback-warning {
    display: flex; align-items: flex-start; gap: .75rem;
    padding: .9rem 1.1rem; margin-bottom: 1.25rem;
    border-radius: var(--radius-sm); border: 1px solid;
    font-weight: 500; font-size: .9rem;
}
.feedback-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.feedback-error   { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.feedback-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.feedback-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }

/* ==========================================================================
   Badges de estado
   ========================================================================== */
.status-badge, .pill {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .2rem .6rem; border-radius: 99px;
    font-size: .72rem; font-weight: 600; letter-spacing: .02em; white-space: nowrap;
    background: var(--surface-2); color: var(--text-2);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-badge.success, .pill-success { background: var(--success-soft); color: #166534; }
.status-badge.error,   .pill-fail    { background: var(--danger-soft);  color: #991b1b; }
.status-badge.warning, .pill-queued  { background: var(--warning-soft); color: #92400e; }

/* ==========================================================================
   Modal clássico (Chaves de API) e <dialog> (Relatórios)
   ========================================================================== */
.modal {
    display: none;
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(15, 23, 42, .45);
    backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
    overflow-y: auto; padding: 5vh 1rem;
}
.modal-content {
    position: relative;
    width: 100%; max-width: 520px; margin: 0 auto;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
    animation: pop .2s var(--ease);
}
.modal-content.compact { padding: 0; display: flex; flex-direction: column; max-height: 90vh; }
.modal-header {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.05rem; margin: 0; }
.modal-body { padding: 1.25rem; overflow-y: auto; }
.modal-footer {
    display: flex; justify-content: flex-end; gap: .5rem;
    padding: 1rem 1.25rem; border-top: 1px solid var(--border); background: var(--surface-2);
    border-radius: 0 0 var(--radius) var(--radius);
}
.close-btn {
    width: 32px; height: 32px; padding: 0;
    display: inline-grid; place-items: center;
    background: transparent; border: 0; border-radius: 8px;
    color: var(--text-3); font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.close-btn:hover { background: var(--surface-2); color: var(--text); }

@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

dialog.dlg {
    border: 0; padding: 0;
    width: min(560px, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    margin: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    background: var(--surface); color: var(--text);
}
dialog.dlg[open] { animation: pop .2s var(--ease); display: flex; flex-direction: column; }
dialog.dlg::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(3px); }
dialog.dlg.dlg-sm { width: min(420px, calc(100vw - 2rem)); }

/* Campos de credenciais (Chaves de API) */
.credential-field { margin-bottom: 1rem; }
.credential-field label { display: block; margin-bottom: .35rem; font-weight: 500; font-size: .8rem; color: var(--text-2); }
.field-row { display: flex; gap: .4rem; align-items: center; }
.field-input {
    flex: 1; min-width: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important;
    font-size: .8rem !important;
    background: var(--surface-2) !important;
}
.field-buttons { display: flex; gap: .3rem; }
.field-btn {
    width: 38px; height: 38px; padding: 0; flex-shrink: 0;
    background: var(--surface); color: var(--text-2);
    border: 1px solid var(--border-strong); border-radius: 9px;
}
.field-btn:hover { background: var(--surface-2); color: var(--text); }
.new-key-info {
    background: var(--brand-soft);
    border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent);
    border-radius: var(--radius-sm);
    padding: 1.1rem; margin-bottom: 1.25rem;
}
.new-key-info strong { display: block; margin-bottom: 1rem; font-size: .85rem; color: var(--brand-strong); }

/* ==========================================================================
   Notificações (toast)
   ========================================================================== */
.toast-stack { position: fixed; top: 1rem; right: 1rem; z-index: 3000; display: flex; flex-direction: column; gap: .5rem; }
.toast, .copy-feedback {
    min-width: 240px; max-width: 360px;
    padding: .8rem 1rem; border-radius: var(--radius-sm);
    background: var(--text) !important; color: #fff;
    box-shadow: var(--shadow-lg);
    font-size: .875rem; font-weight: 500;
    border-left: 4px solid var(--brand);
    opacity: 0; transform: translateY(-6px); transition: opacity .25s, transform .25s;
}
.copy-feedback { opacity: 1; transform: none; }
.toast.show { opacity: 1; transform: none; }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }

/* ==========================================================================
   Login
   ========================================================================== */
.login-body {
    min-height: 100vh;
    display: grid; place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--brand) 18%, transparent), transparent 60%),
        radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--brand) 12%, transparent), transparent 60%),
        var(--bg);
}
.login-container {
    width: 100%; max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 2.25rem 2rem;
}
.login-brand { display: flex; justify-content: center; margin-bottom: 1.5rem; }
.login-brand .brand-logo { max-height: 150px; max-width: 260px; }
.login-container h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; text-align: center; }
.login-container > p { color: var(--text-2); text-align: center; margin: .35rem 0 1.75rem; font-size: .9rem; }
.login-container button[type="submit"] { width: 100%; padding: .75rem; margin-top: .25rem; }
.login-footer { text-align: center; margin-top: 1.5rem; font-size: .75rem; color: var(--text-3); }

/* ==========================================================================
   Estado do Gateway
   ========================================================================== */
.status-overview { margin-bottom: 1.5rem; }
.status-overview > div { margin-bottom: 0; }
.status-header { display: flex; align-items: flex-start; gap: .85rem; }
.status-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: rgba(255,255,255,.7); flex-shrink: 0; }
.status-header strong { display: block; font-size: .95rem; margin-bottom: .1rem; }
.status-header p { margin: 0; font-weight: 400; opacity: .9; word-break: break-word; }

.qr-section {
    background: var(--surface-2);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 1.75rem; margin: 0 0 1.5rem;
}
.qr-section h3 { display: flex; align-items: center; justify-content: center; gap: .5rem; margin-bottom: 1.25rem; }
.qr-container { display: flex; justify-content: center; gap: 1.5rem; flex-wrap: wrap; align-items: flex-start; margin-bottom: 1.25rem; }
.qr-code { background: var(--surface); padding: 1.25rem; border-radius: var(--radius); border: 1px solid var(--border); text-align: center; }
.qr-code img { width: 260px; max-width: 100%; height: auto; border-radius: 8px; display: block; margin: 0 auto .75rem; }
.qr-refresh-info p { margin: 0; font-size: .8rem; color: var(--text-2); }
.qr-instructions { max-width: 340px; background: var(--surface); padding: 1.25rem; border-radius: var(--radius); border: 1px solid var(--border); }
.qr-instructions > p { font-weight: 600; margin-bottom: .6rem; }
.qr-instructions ol { padding-left: 1.2rem; }
.qr-instructions li { margin-bottom: .35rem; color: var(--text-2); }
.qr-tips { margin-top: 1rem; padding: .85rem 1rem; background: var(--brand-soft); border-radius: var(--radius-sm); }
.qr-tips ul { margin: .35rem 0 0 1.1rem; }
.qr-tips li { font-size: .85rem; color: var(--text-2); }
.qr-alternative { display: flex; justify-content: center; }
.qr-message { background: var(--surface); padding: 1.5rem; border-radius: var(--radius); border: 1px solid var(--border); max-width: 480px; text-align: center; }
.qr-message > p { color: var(--text-2); }
.qr-message > p:first-child { color: var(--text); margin-bottom: .25rem; }
.qr-status-info { margin-top: 1rem; padding: .75rem 1rem; background: var(--warning-soft); border-radius: var(--radius-sm); font-size: .85rem; text-align: left; word-break: break-word; }
.qr-actions, .service-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.service-actions { justify-content: flex-start; }

.status-details h3 { margin-bottom: 1rem; }
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.status-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1.1rem 1.25rem; }
.status-item h4 { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.status-item table { border: 0; }
.status-item td { padding: .4rem 0; border: 0; background: transparent !important; font-size: .875rem; word-break: break-word; }
.status-item td:first-child { color: var(--text-2); width: 42%; }
.action-buttons { display: flex; flex-direction: column; gap: .45rem; margin-bottom: 1rem; }
.action-buttons button { justify-content: flex-start; }
.service-info { font-size: .8rem; color: var(--text-2); }
.service-info p { margin: .15rem 0; }

.troubleshoot-tips h3 { margin: 1.5rem 0 1rem; }
.troubleshoot-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.troubleshoot-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1.1rem; }
.troubleshoot-item p { color: var(--text-2); font-size: .85rem; margin-bottom: .5rem; }
.troubleshoot-item code { display: block; background: var(--text); color: #e2e8f0; padding: .55rem .75rem; border-radius: 8px; font-size: .8rem; overflow-x: auto; white-space: nowrap; }

/* ==========================================================================
   Relatórios
   ========================================================================== */
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.1rem 1.25rem; box-shadow: var(--shadow-sm);
    display: flex; align-items: center; gap: .9rem;
}
.stat-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0; }
.stat-label { font-size: .78rem; color: var(--text-2); font-weight: 500; }
.stat-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.stat-total .stat-icon { background: var(--info-soft); color: var(--info); }
.stat-ok .stat-icon    { background: var(--success-soft); color: var(--success); }
.stat-fail .stat-icon  { background: var(--danger-soft); color: var(--danger); }
.stat-queue .stat-icon { background: var(--warning-soft); color: var(--warning); }
a.stat { text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s; }
a.stat:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
a.stat.is-active { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
a.stat.stat-fail.is-active { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

.message-cell { max-width: 340px; }
.message-preview { display: block; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-btn {
    padding: 0; background: none; border: 0; color: var(--brand-strong);
    font-size: .78rem; font-weight: 600; cursor: pointer;
}
.link-btn:hover { background: none; text-decoration: underline; }
tr.row-fail td { background: #fffafa; }
tr.row-selected td { background: #fef2f2 !important; }
.col-check { width: 40px; padding-right: 0; }
.col-actions { width: 1%; white-space: nowrap; text-align: right; }

.bulk-bar {
    display: none; align-items: center; gap: .75rem; flex-wrap: wrap;
    padding: .7rem 1rem; margin-bottom: 1rem;
    background: var(--text); color: #fff; border-radius: var(--radius-sm);
}
.bulk-bar.show { display: flex; animation: pop .2s var(--ease); }
.bulk-bar .bulk-count { font-weight: 600; margin-right: auto; font-size: .875rem; }
.bulk-bar .btn-secondary { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.2); }
.bulk-bar .btn-secondary:hover { background: rgba(255,255,255,.18); }

.report-period { display: flex; gap: 1.25rem; flex-wrap: wrap; font-size: .85rem; color: var(--text-2); margin-bottom: 1rem; }
.report-period strong { color: var(--text); font-weight: 600; }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--text-2); }
.empty-state .icon { margin: 0 auto .75rem; color: var(--text-3); }

/* Diálogo de mensagem falhada */
.dlg-head { display: flex; align-items: flex-start; gap: .9rem; padding: 1.25rem 1.25rem 0; }
.dlg-head .dlg-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; background: var(--danger-soft); color: var(--danger); }
.dlg-head .dlg-icon.neutral { background: var(--info-soft); color: var(--info); }
.dlg-head h3 { margin: 0; font-size: 1.05rem; }
.dlg-head p { color: var(--text-2); font-size: .85rem; }
.dlg-head .close-btn { margin-left: auto; margin-top: -4px; }
.dlg-body { padding: 1.1rem 1.25rem; overflow-y: auto; }
.dlg-meta { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; font-size: .85rem; margin-bottom: .9rem; }
.dlg-meta dt { color: var(--text-3); }
.dlg-meta dd { font-weight: 500; word-break: break-word; }
.dlg-message {
    white-space: pre-wrap; word-break: break-word;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: .85rem 1rem; max-height: 260px; overflow-y: auto; font-size: .875rem;
}
.dlg-foot {
    display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap;
    padding: 1rem 1.25rem; border-top: 1px solid var(--border); background: var(--surface-2);
}
.dlg-foot .spacer { flex: 1; }

/* ==========================================================================
   Utilitários
   ========================================================================== */
.text-center { text-align: center; }
.mt-2 { margin-top: 2rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 2rem; }

/* ==========================================================================
   Responsivo
   ========================================================================== */
@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    body.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 999; }
    .sidebar-close, .menu-btn { display: inline-grid; }
    .main-wrap { margin-left: 0; }
    .topbar { padding: .85rem 1rem; }
    .main-content { padding: .5rem 1rem 2rem; }
}

@media (max-width: 600px) {
    .card { padding: 1.1rem; }
    .stats-grid { gap: .6rem; }
    .stat { padding: .85rem; gap: .6rem; }
    .stat-icon { width: 34px; height: 34px; }
    .stat-value { font-size: 1.2rem; }
    .field-row { flex-wrap: wrap; }
    .qr-section { padding: 1.1rem; }
    th, td { padding: .65rem .75rem; }
    .dlg-foot { justify-content: stretch; }
    .dlg-foot button { flex: 1; }
    .dlg-foot .spacer { display: none; }
}

/* Utilizadores: dois cartões lado a lado */
.users-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; align-items: start; }
.users-grid .card { margin-bottom: 0; }

/* ==========================================================================
   Números de WhatsApp (vários gateways)
   ========================================================================== */
.add-gw-form { display: flex; gap: .5rem; flex-wrap: wrap; }
.add-gw-form input { width: 280px; max-width: 100%; }
.gw-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.gw-card {
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
    padding: 1.1rem 1.15rem; display: flex; flex-direction: column; gap: .85rem;
    border-top: 3px solid var(--warning);
}
.gw-card.is-online { border-top-color: var(--success); }
.gw-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.gw-title { display: flex; align-items: baseline; gap: .45rem; min-width: 0; }
.gw-title strong { font-size: 1rem; word-break: break-word; line-height: 1.3; }
.gw-id { font-size: .75rem; color: var(--text-3); font-weight: 600; }
.gw-meta { display: grid; grid-template-columns: auto 1fr; gap: .3rem .9rem; font-size: .85rem; }
.gw-meta dt { color: var(--text-3); }
.gw-meta dd { font-weight: 500; word-break: break-word; }
.gw-qr { text-align: center; background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: .9rem; }
.gw-qr img { width: 220px; max-width: 100%; display: block; margin: 0 auto .5rem; border-radius: 8px; background: #fff; }
.gw-qr p { font-size: .78rem; color: var(--text-2); }
.gw-msg { font-size: .8rem; color: var(--text-2); word-break: break-word; }
.gw-msg:empty { display: none; }
.gw-actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-top: auto; padding-top: .75rem; border-top: 1px solid var(--border); }
.gw-head-right { display: flex; align-items: center; gap: .15rem; flex-shrink: 0; }
.gw-head-right .pill { margin-right: .25rem; }
.gw-head-right .icon-btn { width: 30px; height: 30px; }
[hidden] { display: none !important; }
.gw-del:hover { color: var(--danger); background: var(--danger-soft); }
.gw-select { height: 34px !important; padding: .3rem .6rem !important; font-size: .82rem !important; min-width: 140px; }
.d-block { display: block; }

/* ==========================================================================
   Revenda
   ========================================================================== */
.ctx-banner {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
    padding: .7rem 1rem; margin-bottom: 1.25rem; border-radius: var(--radius-sm);
    background: var(--brand-strong); color: #fff; font-size: .875rem;
}
.ctx-banner span { display: flex; align-items: center; gap: .5rem; }
.ctx-banner .btn-secondary { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.3); }
.ctx-banner .btn-secondary:hover { background: rgba(255,255,255,.22); }
.sidebar-nav .nav-label { margin-top: .5rem; }
.sidebar-nav ul + .nav-label { margin-top: 1rem; }

.meter { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.meter.warn > span { background: var(--warning); }
.meter.full > span { background: var(--danger); }
.usage-row { display: grid; gap: .35rem; margin-bottom: 1rem; }
.usage-row .usage-top { display: flex; justify-content: space-between; font-size: .85rem; }
.usage-row .usage-top span:last-child { color: var(--text-2); }

.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.25rem; align-items: start; }
.plan-grid .card { margin-bottom: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .45rem 1.25rem; font-size: .875rem; }
.kv dt { color: var(--text-3); }
.kv dd { font-weight: 500; word-break: break-word; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.secret-box {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem;
    background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
    padding: .75rem 1rem; word-break: break-all; user-select: all;
}
.inline-form { display: inline; }
.hint { font-size: .78rem; color: var(--text-3); margin-top: -.6rem; margin-bottom: 1rem; }
td .muted-sm, .muted-sm { font-size: .78rem; color: var(--text-3); }
.row-link { color: var(--text); font-weight: 600; text-decoration: none; }
.row-link:hover { color: var(--brand-strong); text-decoration: underline; }
.code-block {
    background: var(--text); color: #e2e8f0; padding: 1rem 1.1rem; border-radius: var(--radius-sm);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem;
    overflow-x: auto; white-space: pre; line-height: 1.6;
}
.col-actions .actions { flex-wrap: nowrap; }
