/* ===============================================
   VARIÁVEIS CSS - MODOS CLARO E ESCURO
   =============================================== */

html {
    --primary: #8a41ff;
    --primary-2: #b55fff;
    --text: #ffffff;
    --text-muted: #a8a8a8;
    --border: rgba(255,255,255,0.12);
    --shadow-md: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --bg-primary: rgba(7, 26, 77, 1);
    --bg-secondary: rgba(6, 18, 56, 1);
    --bg-tertiary: rgba(4, 16, 46, 1);
}

/* MODO ESCURO - Fundo branco e texto preto */
html[data-dark-mode="true"] {
    --primary: #333333;
    --primary-2: #555555;
    --text: #000000;
    --text-muted: #666666;
    --border: rgba(0, 0, 0, 0.12);
    --shadow-md: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #f0f0f0;
}

/* ===============================================
   DARK MODE TOGGLE
   =============================================== */

.dark-mode-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
}

.toggle-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.toggle-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.toggle-btn svg {
    width: 24px;
    height: 24px;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toggle-btn .icon-sun {
    opacity: 1;
    transform: rotate(0deg);
}

.toggle-btn .icon-moon {
    opacity: 0;
    transform: rotate(-90deg);
    position: absolute;
}

html[data-dark-mode="true"] .toggle-btn {
    background-color: rgba(0, 0, 0, 0.1);
    color: #000000;
}

html[data-dark-mode="true"] .toggle-btn:hover {
    background-color: rgba(0, 0, 0, 0.2);
}

html[data-dark-mode="true"] .toggle-btn .icon-sun {
    opacity: 0;
    transform: rotate(90deg);
}

html[data-dark-mode="true"] .toggle-btn .icon-moon {
    opacity: 1;
    transform: rotate(0deg);
}

/* ===============================================
   CORPO E PÁGINAS
   =============================================== */

.admin-body,
.login-page {
    background: var(--bg-primary);
    color: var(--text);
    transition: background-color 0.3s ease, color 0.3s ease;
}

html[data-dark-mode="true"] .admin-body,
html[data-dark-mode="true"] .login-page {
    background: radial-gradient(circle at top, #ffffff 0%, #f5f5f5 50%, #f0f0f0 100%);
}

.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
}

.login-card {
    width: min(100%, 450px);
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 32px;
    box-shadow: var(--shadow-md);
    transition: all 0.3s ease;
}

html[data-dark-mode="true"] .login-card {
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
}

.login-icon,
.brand-icon,
.logo-box,
.entity-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    font-weight: 800;
    margin-bottom: 16px;
    transition: all 0.3s ease;
}

html[data-dark-mode="true"] .login-icon,
html[data-dark-mode="true"] .brand-icon,
html[data-dark-mode="true"] .logo-box,
html[data-dark-mode="true"] .entity-icon {
    background: linear-gradient(135deg, #333333, #555555);
    color: #ffffff;
}

.login-card h1 {
    font-size: 2rem;
    margin-bottom: 6px;
    color: var(--text);
}

.login-card p {
    color: var(--text-muted);
    margin-bottom: 22px;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-card .btn {
    margin-top: 4px;
}

/* ===============================================
   LAYOUT ADMIN
   =============================================== */

.admin-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: rgba(255,255,255,0.04);
    border-right: 1px solid var(--border);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    transition: all 0.3s ease;
}

html[data-dark-mode="true"] .sidebar {
    background: rgba(0, 0, 0, 0.02);
}

.brand {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 8px;
    margin-bottom: 20px;
}

.brand span {
    display: block;
    color: var(--text-muted);
    font-size: .94rem;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 0;
}

.sidebar-nav a {
    position: relative;
    padding: 14px 16px;
    border-radius: 16px;
    color: var(--text);
    font-weight: 600;
    background: transparent;
    transition: all 0.3s ease;
}

.sidebar-nav a::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: rgba(255,255,255,0.35);
    display: inline-block;
    margin-right: 10px;
    vertical-align: middle;
    transition: all 0.3s ease;
}

html[data-dark-mode="true"] .sidebar-nav a::before {
    background: rgba(0, 0, 0, 0.35);
}

.sidebar-nav a.active::before,
.sidebar-nav a:hover::before {
    background: #fff;
}

html[data-dark-mode="true"] .sidebar-nav a.active::before,
html[data-dark-mode="true"] .sidebar-nav a:hover::before {
    background: #000;
}

.sidebar-nav a.active,
.sidebar-nav a:hover {
    background: linear-gradient(90deg, rgba(138,65,255,0.95), rgba(181,95,255,0.95));
    box-shadow: 0 10px 28px rgba(138,65,255,0.28);
}

html[data-dark-mode="true"] .sidebar-nav a.active,
html[data-dark-mode="true"] .sidebar-nav a:hover {
    background: linear-gradient(90deg, rgba(51, 51, 51, 0.95), rgba(85, 85, 85, 0.95));
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.15);
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding-top: 18px;
    margin-top: auto;
}

.sidebar-user strong {
    display: block;
    color: var(--text);
}

.sidebar-user span,
.logout-link {
    color: var(--text-muted);
    font-size: .92rem;
}

.logout-link {
    display: inline-block;
    margin-top: 12px;
}

.admin-content {
    padding: 28px;
    background: var(--bg-primary);
    transition: background-color 0.3s ease;
}

/* ===============================================
   CABEÇALHO E CARDS
   =============================================== */

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.page-header p {
    color: var(--text-muted);
    margin-top: 8px;
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    min-width: 0;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 22px;
    transition: all 0.3s ease;
}

html[data-dark-mode="true"] .stat-card {
    background: rgba(0, 0, 0, 0.03);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card span {
    color: var(--text-muted);
    display: block;
    margin-bottom: 10px;
}

.stat-card strong {
    font-size: 2rem;
    color: var(--text);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: 24px;
    margin-bottom: 24px;
    align-items: stretch;
}

.dashboard-grid .panel {
    display: flex;
    flex-direction: column;
    min-height: 410px;
}

.dashboard-grid .panel .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.list-lines {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex: 1;
    justify-content: flex-start;
}

.line-item,
.bar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    height: 76px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    flex: 0 0 76px;
    transition: all 0.3s ease;
}

.line-item:hover,
.bar-row:hover {
    background: rgba(255, 255, 255, 0.02);
}

html[data-dark-mode="true"] .line-item:hover,
html[data-dark-mode="true"] .bar-row:hover {
    background: rgba(0, 0, 0, 0.02);
}

.line-item:last-child,
.bar-row:last-child {
    border-bottom: 0;
}

.line-badge {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    font-size: .95rem;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.line-badge.blue {
    background: linear-gradient(135deg, #1dd4f2, #0ea5e9);
}

html[data-dark-mode="true"] .line-badge.blue {
    background: linear-gradient(135deg, #333333, #555555);
}

.line-content {
    flex: 1;
    min-width: 0;
}

.line-content strong,
.bar-left strong {
    word-break: break-word;
    color: var(--text);
}

.line-content small,
.line-meta small {
    color: var(--text-muted);
    display: block;
}

.line-meta {
    min-width: 90px;
    text-align: right;
}

.line-meta strong {
    color: var(--text);
}

.bar-left,
.bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bar-left {
    flex: 1;
    min-width: 0;
}

.bar-right {
    min-width: 280px;
    justify-content: flex-end;
}

.bar-right strong {
    min-width: 24px;
    text-align: right;
    color: var(--text);
}

.progress {
    width: 220px;
    height: 10px;
    border-radius: 999px;
    background: rgba(255,255,255,0.08);
    overflow: hidden;
    flex-shrink: 0;
}

html[data-dark-mode="true"] .progress {
    background: rgba(0, 0, 0, 0.08);
}

.progress span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #00b8ff, #38f9d7);
}

html[data-dark-mode="true"] .progress span {
    background: linear-gradient(90deg, #333333, #555555);
}

/* ===============================================
   GRÁFICOS
   =============================================== */

.chart-bars {
    display: flex;
    align-items: end;
    gap: 18px;
    min-height: 220px;
    overflow-x: auto;
}

.chart-bar {
    flex: 1;
    min-width: 70px;
    text-align: center;
}

.chart-bar .bar {
    width: 100%;
    border-radius: 16px 16px 0 0;
    background: linear-gradient(180deg, var(--primary-2), var(--primary));
    min-height: 12px;
    margin-bottom: 10px;
    transition: all 0.3s ease;
}

.chart-bar span {
    color: var(--text);
}

.chart-bar small {
    color: var(--text-muted);
}

/* ===============================================
   FILTROS E CARDS
   =============================================== */

.filters-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
    gap: 16px;
}

.filters-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.list-cards {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.entity-card {
    display: grid;
    grid-template-columns: 1.1fr 1fr auto auto;
    gap: 16px;
    align-items: center;
    padding: 18px;
    border-radius: 18px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

html[data-dark-mode="true"] .entity-card {
    background: rgba(0, 0, 0, 0.02);
}

.entity-card:hover {
    background: rgba(255,255,255,0.08);
    transform: translateY(-2px);
}

html[data-dark-mode="true"] .entity-card:hover {
    background: rgba(0, 0, 0, 0.05);
}

.entity-main {
    display: flex;
    gap: 14px;
    align-items: center;
}

.entity-main h3 {
    margin-bottom: 4px;
    color: var(--text);
}

.entity-main p,
.entity-meta p {
    color: var(--text-muted);
}

.entity-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
}

/* ===============================================
   PAINEL QR
   =============================================== */

.qr-panel {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 24px;
    align-items: center;
}

.qr-preview {
    background: #fff;
    border-radius: 22px;
    padding: 20px;
}

html[data-dark-mode="true"] .qr-preview {
    background: #f5f5f5;
}

.qr-info input {
    background: rgba(255,255,255,0.04);
    color: var(--text);
    border-color: var(--border);
    transition: all 0.3s ease;
}

html[data-dark-mode="true"] .qr-info input {
    background: rgba(0, 0, 0, 0.03);
    color: var(--text);
}

.qr-info input::placeholder {
    color: var(--text-muted);
}

.panel {
    min-width: 0;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 22px;
    transition: all 0.3s ease;
}

html[data-dark-mode="true"] .panel {
    background: rgba(0, 0, 0, 0.02);
}

/* só aplica espaçamento vertical entre painéis fora do grid */
.admin-content > .panel + .panel {
    margin-top: 24px;
}

/* dentro do dashboard, não pode empurrar o segundo card */
.dashboard-grid > .panel {
    margin-top: 0 !important;
}

.panel h3,
.panel h2 {
    color: var(--text);
}

.table {
    background: transparent;
}

.table tr:last-child td {
    border-bottom: 0;
}

.table td,
.table th {
    color: var(--text);
    border-color: var(--border);
}

.table th {
    background: rgba(255, 255, 255, 0.02);
    font-weight: 600;
}

html[data-dark-mode="true"] .table th {
    background: rgba(0, 0, 0, 0.02);
}

/* ===============================================
   AÇÕES E SWITCH
   =============================================== */

.actions-inline {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.status-switch-form {
    display: inline-flex;
    align-items: center;
    margin: 0;
}

.switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 30px;
    margin: 0;
    cursor: pointer;
}

.switch input {
    display: none;
}

.slider {
    position: absolute;
    inset: 0;
    background: #d1d5db;
    border-radius: 999px;
    transition: 0.25s ease;
}

.slider::before {
    content: "";
    position: absolute;
    width: 24px;
    height: 24px;
    left: 3px;
    top: 3px;
    background: #ffffff;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: 0.25s ease;
}

.switch input:checked + .slider {
    background: #34c759;
}

.switch input:checked + .slider::before {
    transform: translateX(22px);
}

/* ===============================================
   CEP E INPUTS
   =============================================== */

.cep-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: nowrap;
}

.cep-row input {
    flex: 1;
    min-width: 0;
    background: rgba(255,255,255,0.04);
    color: var(--text);
    border-color: var(--border);
    transition: all 0.3s ease;
}

html[data-dark-mode="true"] .cep-row input {
    background: rgba(0, 0, 0, 0.03);
}

.cep-row input::placeholder {
    color: var(--text-muted);
}

.cep-row .btn {
    white-space: nowrap;
    height: 54px;
    padding: 0 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#cep-feedback {
    display: block;
    margin-top: 8px;
    color: var(--text-muted);
}

/* ===============================================
   RESPONSIVO
   =============================================== */

@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-grid .panel {
        min-height: auto;
    }

    .entity-card {
        grid-template-columns: 1fr;
    }

    .entity-actions {
        justify-content: flex-start;
    }

    .filters-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 992px) {
    .admin-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .filters-grid {
        grid-template-columns: 1fr;
    }

    .qr-panel {
        grid-template-columns: 1fr;
    }

    .dark-mode-toggle {
        top: 10px;
        right: 10px;
    }
}

@media (max-width: 768px) {
    .admin-content {
        padding: 20px;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .bar-row {
        flex-direction: column;
        align-items: flex-start;
        height: auto;
        padding: 16px 0;
        flex: initial;
    }

    .bar-right {
        min-width: 100%;
        justify-content: space-between;
    }

    .progress {
        width: 100%;
        max-width: 220px;
    }

    .cep-row {
        flex-direction: column;
        align-items: stretch;
    }

    .cep-row .btn {
        width: 100%;
    }

    .toggle-btn {
        width: 45px;
        height: 45px;
    }

    .toggle-btn svg {
        width: 20px;
        height: 20px;
    }
}

.entity-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: linear-gradient(135deg, #f8fafc, #eef2f7);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.entity-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 6px;
}

