/* 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;
}

.grid-form-stack {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.form-grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.produto-edit-form {
    max-width: 640px;
    width: 100%;
}

.panel-form-stack {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

.panel-form-stack .card {
    width: 100%;
    max-width: none;
}

.panel-form-stack .form-group textarea {
    width: 100%;
    resize: vertical;
}

.comandos-whats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}

.comando-item {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--input-bg);
}

.comando-item code {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent2);
    background: rgba(59, 130, 246, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
}

.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;
        padding-right: 44px;
    }

    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: 8px;
        bottom: auto;
        right: 12px;
        width: 40px;
        height: 40px;
        font-size: 17px;
        z-index: 210;
    }

    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,
    .form-grid2 {
        grid-template-columns: 1fr;
    }
}

/* Suporte da agência — painel lojista */
.sidebar-support {
    margin-top: auto;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    line-height: 1.5;
}

.sidebar-support-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 6px;
}

.sidebar-support-link {
    display: block;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 6px;
}

.sidebar-support-link:hover {
    text-decoration: underline;
}

.sidebar-support-meta {
    color: var(--muted);
    font-size: 11px;
    margin: 0;
}

.sidebar-support-meta a {
    color: var(--accent2);
    text-decoration: none;
}

.sidebar-support-meta a:hover {
    text-decoration: underline;
}

.panel-support-card {
    border-color: rgba(34, 197, 94, 0.25);
    background: rgba(34, 197, 94, 0.04);
}

.panel-support-list {
    list-style: none;
    font-size: 14px;
    line-height: 1.8;
    margin: 0;
    padding: 0;
}

.panel-support-credit {
    margin: 12px 0 0;
    font-size: 12px;
    color: var(--muted);
}

/* Catálogo de produtos — cards no mobile */
@media (max-width: 768px) {
    .table-wrap:has(.catalog-table) {
        overflow-x: visible;
    }

    .catalog-table {
        min-width: 0 !important;
        width: 100%;
    }

    .catalog-table thead {
        display: none;
    }

    .catalog-table tbody tr {
        display: grid;
        grid-template-columns: 64px 1fr auto;
        grid-template-areas:
            "foto info preco"
            "desc desc desc"
            "variant status status"
            "tags tags tags"
            "actions actions actions";
        gap: 8px 12px;
        padding: 14px;
        margin-bottom: 12px;
        border: 1px solid var(--border);
        border-radius: 12px;
        background: var(--input-bg);
    }

    .catalog-table tbody tr:last-child {
        margin-bottom: 0;
    }

    .catalog-table tbody td {
        border: none;
        padding: 0;
    }

    .catalog-table .cat-foto {
        grid-area: foto;
        align-self: start;
    }

    .catalog-table .cat-foto img,
    .catalog-table .cat-foto .cat-foto-placeholder {
        width: 64px;
        height: 64px;
    }

    .catalog-table .cat-info {
        grid-area: info;
        min-width: 0;
        display: contents;
    }

    .catalog-table .cat-info strong {
        grid-area: info;
        display: block;
        font-size: 15px;
        line-height: 1.35;
        word-break: break-word;
    }

    .catalog-table .cat-warn {
        grid-area: desc;
        display: block;
        margin: 0;
    }

    .catalog-table .cat-desc {
        display: none;
    }

    .catalog-table .cat-desc-mobile {
        grid-area: desc;
        display: block;
        margin: 0;
        font-size: 13px;
        line-height: 1.55;
        color: var(--muted);
        word-break: break-word;
    }

    .catalog-table .cat-preco {
        grid-area: preco;
        align-self: start;
        text-align: right;
        font-size: 15px;
        font-weight: 700;
        white-space: nowrap;
    }

    .catalog-table .cat-variant {
        grid-area: variant;
        font-size: 12px;
    }

    .catalog-table .cat-variant::before {
        content: "Cor / tam.: ";
        color: var(--muted);
        font-weight: 600;
    }

    .catalog-table .cat-status {
        grid-area: status;
        justify-self: end;
    }

    .catalog-table .cat-tags {
        grid-area: tags;
        font-size: 12px;
        max-width: none;
    }

    .catalog-table .cat-tags::before {
        content: "Tags: ";
        color: var(--muted);
        font-weight: 600;
    }

    .catalog-table .cat-actions {
        grid-area: actions;
        padding-top: 4px;
        border-top: 1px solid var(--border);
    }

    .catalog-table .cat-actions > div {
        width: 100%;
    }

    .catalog-table .cat-actions .btn {
        flex: 1;
        justify-content: center;
    }
}

@media (min-width: 769px) {
    .catalog-table .cat-desc-mobile,
    .catalog-table .cat-warn {
        display: none;
    }

    .catalog-table .cat-info {
        display: table-cell;
    }

    .catalog-table .cat-warn {
        display: block;
        margin-top: 4px;
        font-size: 11px;
        color: #b45309;
    }

    .catalog-table .cat-desc {
        display: block;
        margin-top: 4px;
        font-size: 12px;
        line-height: 1.45;
    }
}
