/**
 * Admin Panel - Estilos
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --admin-bg: #0d1117;
    --admin-sidebar: #161b22;
    --admin-card: #1c2128;
    --admin-border: #30363d;
    --admin-text: #e6edf3;
    --admin-muted: #8b949e;
    --admin-primary: #10b981;
    --admin-primary-dark: #059669;
}

body.admin-body,
body.login-page {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--admin-bg);
    color: var(--admin-text);
    min-height: 100vh;
}

/* ======= LOGIN ======= */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-container {
    background: var(--admin-sidebar);
    border: 1px solid var(--admin-border);
    border-radius: 16px;
    width: 100%;
    max-width: 420px;
    padding: 40px 32px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.login-header {
    text-align: center;
    margin-bottom: 28px;
}

.login-header h1 {
    color: var(--admin-primary);
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.login-header p {
    color: var(--admin-muted);
    font-size: 0.9rem;
}

.btn-login,
.btn-verify {
    width: 100%;
    padding: 12px;
    background: var(--admin-primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    margin-top: 8px;
}

.btn-login:hover,
.btn-verify:hover {
    background: var(--admin-primary-dark);
}

/* Token input */
.token-input {
    letter-spacing: 8px;
    font-size: 1.8rem;
    text-align: center;
    font-weight: 700;
}

.token-timer {
    text-align: center;
    color: var(--admin-muted);
    margin-top: 12px;
    font-size: 0.85rem;
}

.token-timer span {
    color: #f59e0b;
    font-weight: 600;
}

/* ======= SIDEBAR ======= */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 240px;
    height: 100vh;
    background: var(--admin-sidebar);
    border-right: 1px solid var(--admin-border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--admin-border);
}

.sidebar-header h2 {
    font-size: 1.1rem;
    color: var(--admin-primary);
}

.sidebar-header small {
    color: var(--admin-muted);
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--admin-muted);
    text-decoration: none;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.nav-item:hover {
    color: var(--admin-text);
    background: rgba(255, 255, 255, 0.03);
}

.nav-item.active {
    color: var(--admin-primary);
    background: rgba(16, 185, 129, 0.08);
    border-right: 3px solid var(--admin-primary);
}

.nav-item.logout {
    color: #ef4444;
}

.nav-item.logout:hover {
    background: rgba(239, 68, 68, 0.08);
}

.sidebar-footer {
    padding: 12px 0;
    border-top: 1px solid var(--admin-border);
}

/* ======= MAIN ======= */
.admin-main {
    margin-left: 240px;
    min-height: 100vh;
}

.admin-topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--admin-border);
    background: var(--admin-sidebar);
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--admin-text);
    font-size: 1.2rem;
    cursor: pointer;
}

.page-title {
    font-size: 1.1rem;
    flex: 1;
}

.admin-email {
    color: var(--admin-muted);
    font-size: 0.8rem;
}

.admin-content {
    padding: 24px;
}

/* ======= CARDS ======= */
.card {
    background: var(--admin-card);
    border: 1px solid var(--admin-border);
    border-radius: 12px;
    margin-bottom: 20px;
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--admin-border);
}

.card-header h3 {
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-header h3 i {
    color: var(--admin-primary);
}

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--admin-border);
}

.card-logo {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    object-fit: contain;
}

.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.status-card .card-header {
    gap: 12px;
    justify-content: flex-start;
}

.status-card .card-header>div {
    flex: 1;
}

.provider-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.provider-thumb {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: contain;
}

/* ======= FORMS ======= */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: #c9d1d9;
    margin-bottom: 5px;
}

.form-group small {
    display: block;
    color: var(--admin-muted);
    font-size: 0.72rem;
    margin-top: 3px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 9px 12px;
    background: var(--admin-bg);
    border: 1px solid var(--admin-border);
    border-radius: 8px;
    color: var(--admin-text);
    font-size: 0.85rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--admin-primary);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

/* ======= TOGGLE ======= */
.toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #30363d;
    border-radius: 24px;
    transition: 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: 0.3s;
}

.toggle input:checked+.toggle-slider {
    background: var(--admin-primary);
}

.toggle input:checked+.toggle-slider::before {
    transform: translateX(20px);
}

/* ======= TABLE ======= */
.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.table th {
    text-align: left;
    color: var(--admin-muted);
    font-weight: 500;
    padding: 8px 12px;
    border-bottom: 1px solid var(--admin-border);
}

.table td {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(48, 54, 61, 0.5);
}

/* ======= BADGES ======= */
.badge {
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.badge-muted {
    background: rgba(139, 148, 158, 0.15);
    color: #8b949e;
}

.badge-info {
    background: rgba(14, 165, 233, 0.15);
    color: #0ea5e9;
}

/* ======= BUTTONS ======= */
.btn-save {
    padding: 10px 20px;
    background: var(--admin-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    transition: background 0.2s;
    font-family: inherit;
}

.btn-save:hover {
    background: var(--admin-primary-dark);
}

.btn-full {
    width: 100%;
    justify-content: center;
    padding: 12px;
}

.btn-sm {
    padding: 5px 12px;
    background: rgba(16, 185, 129, 0.1);
    color: var(--admin-primary);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: 6px;
    font-size: 0.75rem;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-sm:hover {
    background: rgba(16, 185, 129, 0.2);
}

/* ======= ALERTS ======= */
.alert {
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #10b981;
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #f59e0b;
}

/* ======= STATS ======= */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--admin-card);
    border: 1px solid var(--admin-border);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.stat-card i {
    font-size: 1.5rem;
    color: var(--admin-primary);
}

.stat-card.stat-success i {
    color: #10b981;
}

.stat-card.stat-danger i {
    color: #ef4444;
}

.stat-number {
    font-size: 1.4rem;
    font-weight: 700;
    display: block;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--admin-muted);
}

/* ======= ACTION BAR ======= */
.action-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 16px;
    gap: 8px;
}

.btn-primary {
    padding: 10px 20px;
    background: var(--admin-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-family: inherit;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--admin-primary-dark);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-secondary {
    padding: 10px 20px;
    background: transparent;
    color: var(--admin-muted);
    border: 1px solid var(--admin-border);
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    font-family: inherit;
    transition: 0.2s;
}

.btn-secondary:hover {
    color: var(--admin-text);
    border-color: var(--admin-text);
}

/* ======= BADGES EXTRAS ======= */
.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.badge-evolution {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.badge-apipro {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
}

.badge-premium {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

/* ======= ICON BUTTONS ======= */
.btn-icon {
    background: none;
    border: none;
    color: var(--admin-muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: 0.2s;
    font-size: 0.85rem;
}

.btn-icon:hover {
    color: var(--admin-text);
    background: rgba(255, 255, 255, 0.05);
}

.btn-delete:hover {
    color: #ef4444;
}

.btn-notify:hover {
    color: #25d366;
}

.actions-cell {
    white-space: nowrap;
}

/* ======= MODAL ======= */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--admin-sidebar);
    border: 1px solid var(--admin-border);
    border-radius: 16px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.modal-sm {
    max-width: 420px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--admin-border);
}

.modal-header h3 {
    font-size: 1rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--admin-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: var(--admin-text);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--admin-border);
}

/* ======= FORM EXTRAS ======= */
.form-group textarea {
    width: 100%;
    padding: 9px 12px;
    background: var(--admin-bg);
    border: 1px solid var(--admin-border);
    border-radius: 8px;
    color: var(--admin-text);
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
}

.form-group textarea:focus {
    outline: none;
    border-color: var(--admin-primary);
}

.form-hint {
    color: var(--admin-muted);
    font-size: 0.72rem;
}

.checkbox-group {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--admin-text);
}

/* ======= INSTANCES LIST ======= */
.instances-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--admin-border);
}

.instances-section h4 {
    font-size: 0.85rem;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--admin-muted);
}

.instance-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    background: var(--admin-bg);
    border-radius: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.instance-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.82rem;
}

.instance-key {
    font-size: 0.7rem;
    background: rgba(16, 185, 129, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    color: var(--admin-primary);
    word-break: break-all;
}

.instance-actions {
    display: flex;
    gap: 10px;
}

.failure-count {
    background: #ef4444;
    color: #fff;
    font-size: 0.65rem;
    padding: 1px 5px;
    border-radius: 10px;
    margin-left: 4px;
    font-weight: 700;
}

.btn-delete-instance:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.btn-qr:hover {
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}

/* ======= EMPTY STATE ======= */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--admin-muted);
}

.empty-state i {
    font-size: 2rem;
    margin-bottom: 12px;
    opacity: 0.4;
}

/* ======= TOAST ======= */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 300;
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s;
    font-family: inherit;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast-success {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #10b981;
}

.toast-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

/* ======= UTILS ======= */
.text-muted {
    color: var(--admin-muted);
}

.text-center {
    text-align: center;
}

.preview-footer {
    background: var(--admin-bg);
    padding: 16px;
    border-radius: 8px;
    text-align: center;
    color: var(--admin-muted);
    font-size: 0.8rem;
}

/* ======= RESPONSIVE ======= */
/* ======= RESPONSIVE (Mobile First Improvements) ======= */
@media (max-width: 768px) {

    /* Layout Geral */
    .admin-main {
        margin-left: 0;
        padding-top: 60px;
        /* Espaço para Topbar fixa se necessário, mas aqui ela flui */
    }

    .admin-content {
        padding: 16px;
    }

    /* Sidebar Mobile (Drawer) */
    .sidebar {
        transform: translateX(-100%);
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .menu-toggle {
        display: block;
        padding: 8px;
        /* Aumenta área de toque */
    }

    .page-title {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Cards e Grid */
    .dashboard-cards,
    .stats-row,
    .form-row {
        grid-template-columns: 1fr;
    }

    /* Tabela Responsiva (Card View Pattern) */
    .table thead {
        display: none;
        /* Esconde cabeçalho */
    }

    .table,
    .table tbody,
    .table tr,
    .table td {
        display: block;
        width: 100%;
    }

    .table tr {
        margin-bottom: 16px;
        background: var(--admin-card);
        border: 1px solid var(--admin-border);
        border-radius: 12px;
        padding: 8px 0;
        /* Espaçamento interno no card */
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }

    .table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
        padding: 12px 16px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        font-size: 0.9rem;
    }

    .table td:last-child {
        border-bottom: none;
    }

    /* Label via data-attribute */
    .table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--admin-muted);
        text-transform: uppercase;
        font-size: 0.75rem;
        text-align: left;
        margin-right: 16px;
    }

    /* Célula de Ações */
    .table td.actions-cell {
        justify-content: flex-end;
        /* Alinha botões à direita/centro */
        gap: 12px;
        padding-top: 16px;
        border-top: 1px solid var(--admin-border);
        background: rgba(0, 0, 0, 0.1);
        /* Destaca área de ação */
    }

    .table td.actions-cell::before {
        display: none;
        /* Esconde label "Ações" para limpar visual */
    }

    /* Botões Mobile */
    .btn-icon {
        padding: 10px;
        /* Touch target maior */
        font-size: 1.1rem;
        background: rgba(255, 255, 255, 0.05);
        /* Fundo sutil para identificar touch area */
        border-radius: 8px;
    }

    /* Modais Fullscreen ou Bottom Sheet style se preferir */
    .modal {
        max-height: 100vh;
        border-radius: 0;
        height: 100%;
        max-width: 100%;
    }

    .modal-overlay {
        padding: 0;
        align-items: flex-end;
        /* Pode simular bottom sheet, ou center */
    }

    .modal-header,
    .modal-footer {
        padding: 16px;
    }
}