/* Tema compartilhado — painéis admin e lojista */

:root,
[data-theme="dark"] {
    --bg: #0f172a;
    --card: #1e293b;
    --muted: #94a3b8;
    --text: #e2e8f0;
    --accent: #22c55e;
    --accent2: #3b82f6;
    --danger: #ef4444;
    --warn: #f59e0b;
    --border: #334155;
    --input-bg: #0b1220;
    --sidebar-hover: rgba(59, 130, 246, 0.12);
    --sidebar-active-bg: rgba(59, 130, 246, 0.12);
    --shadow: none;
}

[data-theme="light"] {
    --bg: #eef2f7;
    --card: #ffffff;
    --muted: #64748b;
    --text: #334155;
    --accent: #16a34a;
    --accent2: #2563eb;
    --danger: #dc2626;
    --warn: #d97706;
    --border: #cbd5e1;
    --input-bg: #f8fafc;
    --sidebar-hover: rgba(37, 99, 235, 0.08);
    --sidebar-active-bg: rgba(37, 99, 235, 0.1);
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

[data-theme="light"] .badge.ok  { background: rgba(22, 163, 74, 0.12); color: #15803d; }
[data-theme="light"] .badge.off { background: rgba(220, 38, 38, 0.1); color: #b91c1c; }
[data-theme="light"] .badge.warn { background: rgba(217, 119, 6, 0.12); color: #b45309; }
[data-theme="light"] .badge.pro { background: rgba(37, 99, 235, 0.1); color: #1d4ed8; }
[data-theme="light"] .alert-success { background: rgba(22, 163, 74, 0.08); border-color: rgba(22, 163, 74, 0.25); color: #15803d; }
[data-theme="light"] .alert-error { background: rgba(220, 38, 38, 0.08); border-color: rgba(220, 38, 38, 0.25); color: #b91c1c; }
[data-theme="light"] .admin-banner { background: rgba(37, 99, 235, 0.08); border-color: rgba(37, 99, 235, 0.25); color: #1d4ed8; }
[data-theme="light"] .admin-banner a { color: #fff; }
[data-theme="light"] .btn-success { color: #fff; }
[data-theme="light"] .btn-primary.loja { color: #fff; }

.theme-toggle {
    position: fixed;
    top: 14px;
    right: 16px;
    z-index: 300;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    box-shadow: var(--shadow);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.theme-toggle:hover {
    border-color: var(--accent2);
    transform: scale(1.04);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--accent2);
    outline-offset: 2px;
}

.theme-toggle .theme-icon-light,
.theme-toggle .theme-icon-dark {
    display: none;
}

[data-theme="dark"] .theme-toggle .theme-icon-light,
:root:not([data-theme]) .theme-toggle .theme-icon-light {
    display: inline;
}

[data-theme="light"] .theme-toggle .theme-icon-dark {
    display: inline;
}

[data-theme="light"] .stat-card { box-shadow: var(--shadow); }
[data-theme="light"] .theme-toggle { box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08); }

.form-group input,
.form-group textarea,
.form-group select {
    background: var(--input-bg);
    color: var(--text);
}

.panel-inset {
    background: var(--input-bg) !important;
}

/* -------- Layout responsivo (painéis loja + admin) -------- */

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
}

.grid-form-sidebar {
    display: grid;
    grid-template-columns: minmax(280px, 340px) 1fr;
    gap: 24px;
    align-items: start;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    margin-top: 4px;
}

.table-wrap table {
    min-width: 560px;
}

.mobile-topbar {
    display: none;
}

.sidebar-overlay {
    display: none;
}

.menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}

.menu-toggle:focus-visible {
    outline: 2px solid var(--accent2);
    outline-offset: 2px;
}

@media (max-width: 900px) {
    .grid-2,
    .grid-form-sidebar {
        grid-template-columns: 1fr;
    }

    body.panel-layout {
        overflow-x: hidden;
    }

    body.panel-layout .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 12px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        padding: 0 16px;
        background: var(--card);
        border-bottom: 1px solid var(--border);
        z-index: 200;
        box-shadow: var(--shadow);
    }

    body.panel-layout .mobile-topbar-title {
        font-size: 15px;
        font-weight: 700;
        color: var(--text);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-width: 0;
        flex: 1;
    }

    body.panel-layout .sidebar {
        width: min(280px, 88vw);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 250;
    }

    body.panel-layout.panel-nav-open .sidebar {
        transform: translateX(0);
    }

    body.panel-layout .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.55);
        z-index: 240;
        border: none;
        padding: 0;
        cursor: pointer;
    }

    body.panel-layout.panel-nav-open .sidebar-overlay {
        display: block;
    }

    body.panel-layout .main {
        margin-left: 0 !important;
        padding: 16px !important;
        padding-top: calc(56px + 16px) !important;
    }

    body.panel-layout .page-header h1 {
        font-size: 20px;
    }

    body.panel-layout .card {
        padding: 18px;
    }

    body.panel-layout .stat-card .num {
        font-size: 26px;
    }

    body.panel-layout .theme-toggle {
        top: auto;
        bottom: 16px;
        right: 16px;
    }

    body.panel-layout .admin-banner {
        flex-direction: column;
        align-items: flex-start;
    }

    body.panel-layout .actions {
        flex-direction: column;
        align-items: stretch;
    }

    body.panel-layout .actions .btn,
    body.panel-layout .actions form {
        width: 100%;
    }

    body.panel-layout .actions .btn {
        justify-content: center;
    }
}

@media (max-width: 640px) {
    body.panel-layout .grid2 {
        grid-template-columns: 1fr;
    }
}
