/**
 * Dashboard Frontend Styles
 */

/* Theme Isolation Resets */
.cwp-standalone-body {
    margin: 0 !important;
    padding: 0 !important;
    background: #f8fafc !important;
}

.cwp-dashboard-container, 
.cwp-dashboard-container * {
    box-sizing: border-box !important;
}

.cwp-dashboard-container {
    all: initial; /* Reset all inherited properties */
    display: grid;
    grid-template-areas: 
        "header header"
        "nav body";
    grid-template-rows: auto 1fr;
    grid-template-columns: 260px 1fr;
    width: 100vw;
    height: 100vh; height: 100dvh;
    background: #f8fafc;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99998;
    overflow: hidden;
}

/* Container Setup */

body.admin-bar .cwp-dashboard-container {
    top: 32px;
    height: calc(100vh - 32px);
}

@media (max-width: 782px) {
    body.admin-bar .cwp-dashboard-container {
        top: 46px;
        height: calc(100vh - 46px);
    }
}

/* Header */
.cwp-dash-header {
    grid-area: header;
    background: #1e293b;
    color: #ffffff;
    padding: 16px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.cwp-dash-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
    color: #ffffff;
}

.cwp-user-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.cwp-user-info span {
    font-size: 14px;
    opacity: 0.9;
}

/* Buttons */
.cwp-btn {
    display: inline-block;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    text-align: center;
    text-decoration: none;
}

.cwp-btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.cwp-btn-primary {
    background: #3b82f6;
    color: #fff;
}
.cwp-btn-primary:hover { background: #2563eb; color: #fff; }

.cwp-btn-secondary {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #cbd5e1;
}
.cwp-btn-secondary:hover { background: #e2e8f0; color: #0f172a; }

.cwp-btn-outline {
    background: transparent;
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.3);
}
.cwp-btn-outline:hover { background: rgba(255, 255, 255, 0.1); color: #ffffff; }

.cwp-btn-danger {
    background: #ef4444;
    color: #ffffff;
}
.cwp-btn-danger:hover { background: #dc2626; color: #ffffff; }

/* Navigation Tabs (Sidebar) */
.cwp-dash-nav {
    grid-area: nav;
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
    overflow-y: auto;
}

.cwp-dash-nav ul {
    list-style: none;
    padding: 24px 0;
    margin: 0;
    display: flex;
    flex-direction: column;
}

.cwp-dash-nav li {
    padding: 14px 24px;
    font-weight: 500;
    color: #64748b;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    margin-bottom: 4px;
}

.cwp-dash-nav li:hover {
    color: #0f172a;
    background: #f8fafc;
}

.cwp-dash-nav li.active {
    color: #3b82f6;
    border-left-color: #3b82f6;
    background: #eff6ff;
}

/* Body and Content */
.cwp-dash-body {
    grid-area: body;
    padding: 32px;
    overflow-y: auto;
}

.cwp-tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
    background: #ffffff;
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    max-width: 1000px;
}

.cwp-tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.cwp-tab-content h3 {
    margin-top: 0;
    margin-bottom: 24px;
    font-size: 20px;
    color: #0f172a;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 12px;
}

.cwp-flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 12px;
}

.cwp-flex-between h3 {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

/* Forms */
.cwp-form-group {
    margin-bottom: 20px;
}

.cwp-form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: #334155;
    font-size: 14px;
}

.cwp-form-group input[type="text"],
.cwp-form-group textarea,
.cwp-form-group select,
.cwp-form-group input[type="color"] {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    color: #0f172a;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
}

.cwp-form-group input[type="text"]:focus,
.cwp-form-group textarea:focus,
.cwp-form-group select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.cwp-form-group input[type="color"] {
    padding: 4px;
    height: 42px;
    cursor: pointer;
}

.cwp-form-group small {
    display: block;
    margin-top: 6px;
    color: #64748b;
    font-size: 12px;
}

.cwp-form-row {
    display: flex;
    gap: 20px;
}

.cwp-form-row .cwp-form-group {
    flex: 1;
}

.cwp-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
}

.cwp-form-actions .cwp-btn-outline {
    border-color: #cbd5e1;
    color: #475569;
}
.cwp-form-actions .cwp-btn-outline:hover {
    background: #f1f5f9;
}

/* Image Uploader */
.cwp-image-upload {
    display: flex;
    align-items: center;
    gap: 16px;
}

.cwp-image-preview {
    width: 64px;
    height: 64px;
    background: #f1f5f9;
    border-radius: 6px;
    border: 1px dashed #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.cwp-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Table */
.cwp-dash-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.cwp-dash-table th,
.cwp-dash-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

.cwp-dash-table th {
    font-weight: 600;
    color: #475569;
    background: #f8fafc;
    font-size: 14px;
}

.cwp-dash-table td {
    font-size: 14px;
    color: #0f172a;
    vertical-align: middle;
}

#cwp-product-list {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Notice / Toast */
#cwp-dash-notice {
    padding: 14px 20px;
    border-radius: 8px;
    margin-bottom: 24px;
    font-weight: 500;
    font-size: 15px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    display: none;
    animation: slideInDown 0.3s ease;
    border-left: 5px solid transparent;
}
@keyframes slideInDown {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
#cwp-dash-notice.success {
    background: #f0fdf4;
    color: #166534;
    border-color: #22c55e;
}
#cwp-dash-notice.error {
    background: #fef2f2;
    color: #991b1b;
    border-color: #ef4444;
}

/* Button Loading State */
.cwp-btn[disabled] {
    opacity: 0.7;
    cursor: not-allowed;
    position: relative;
    color: transparent !important;
}
.cwp-btn[disabled]::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: calc(50% - 8px);
    left: calc(50% - 8px);
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: cwp-spin 0.6s linear infinite;
}
.cwp-btn-secondary[disabled]::after {
    border-top-color: #334155;
}
@keyframes cwp-spin {
    to { transform: rotate(360deg); }
}

/* Loading Overlay */
.cwp-loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}
.cwp-loading::after {
    content: "Carregando...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #1e293b;
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .cwp-dashboard-container {
        grid-template-areas: 
            "header"
            "nav"
            "body";
        grid-template-rows: auto auto 1fr;
        grid-template-columns: 1fr;
        position: fixed; /* Still full screen */
    }

    .cwp-dash-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 16px 20px;
    }

    .cwp-dash-nav {
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
        background: #ffffff;
    }

    .cwp-dash-nav ul {
        flex-direction: row;
        overflow-x: auto;
        padding: 0;
    }

    .cwp-dash-nav li {
        width: auto;
        white-space: nowrap;
        text-align: center;
        padding: 14px 20px;
        border-left: none;
        border-bottom: 3px solid transparent;
        margin-bottom: 0;
    }

    .cwp-dash-nav li.active {
        border-left: none;
        border-bottom-color: #3b82f6;
    }

    .cwp-dash-body {
        padding: 16px;
        padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
    }

    .cwp-tab-content {
        padding: 16px;
        margin-bottom: 20px;
    }

    .cwp-form-actions {
        position: sticky; bottom: -16px; 
        background: #fff; margin: 20px -16px -16px; 
        padding: 16px; border-top: 1px solid #e2e8f0;
        z-index: 5;
    }
}
