/* --- CORE WIDGET STYLING --- */
.sac-widget {
    --sac-bg: #fdfdfc;
    --sac-card: #ffffff;
    --sac-text: #1f2a1f;
    --sac-accent: #2f6e3f;
    --sac-accent-hover: #1e4a29;
    --sac-accent-soft: #edf3e6;
    --sac-border: #e2e8dc;
    --sac-widget-max-width: 100%;
    
    border: 1px solid var(--sac-border);
    border-radius: 16px;
    background: var(--sac-bg);
    color: var(--sac-text);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
    padding: 24px;
    overflow: hidden;
    max-width: var(--sac-widget-max-width);
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
}

.sac-widget:hover {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}

.sac-widget.is-loading {
    pointer-events: none;
    opacity: 0.7;
    animation: sacPulseLoading 1.5s infinite alternate;
}

/* --- LAYOUT SIZES --- */
.sac-widget.sac-layout-sidebar { --sac-widget-max-width: 360px; }
.sac-widget.sac-layout-banner { --sac-widget-max-width: 760px; }
.sac-widget.sac-layout-full { --sac-widget-max-width: 1000px; }
.sac-widget.sac-layout-page { --sac-widget-max-width: 100%; }

.sac-widget.is-collapsed {
    box-shadow: 0 10px 22px rgba(31, 42, 31, 0.08);
}

.sac-layout-sidebar.is-collapsed, .sac-layout-banner.is-collapsed {
    padding-bottom: 14px;
}

/* --- HEADER & ANIMATIONS --- */
.sac-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.sac-header h3 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 700;
    color: #17321f;
}

.sac-live-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    animation: sacLivePulse 2s infinite;
}

.sac-live-text {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--sac-accent);
    font-weight: 700;
}

.sac-toggle-details {
    margin-left: auto;
    border: 1px solid #bbccb4;
    background: #fff;
    color: #23422d;
    border-radius: 999px;
    padding: 7px 12px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
}

.sac-layout-badge-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.sac-layout-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 10px;
    border-radius: 999px;
    background: #14391e;
    color: #fff;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.sac-layout-hint {
    font-size: 0.84rem;
    color: #4b5c47;
}

.sac-meta {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.9rem;
    color: #42523d;
    margin-bottom: 10px;
}

/* --- CONTROLS & BUTTONS --- */
.sac-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin: 16px 0;
    align-items: end;
}

.sac-controls label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #304732;
}

.sac-controls select, .sac-refresh-btn, .sac-timeframe-btn {
    border: 1px solid var(--sac-border);
    border-radius: 8px;
    background: #fff;
    padding: 10px 14px;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.sac-controls select:hover, .sac-timeframe-btn:hover {
    border-color: var(--sac-accent);
}

.sac-refresh-btn {
    background: var(--sac-accent);
    color: #fff;
    font-weight: 700;
    border: none;
}

.sac-refresh-btn:hover {
    background: var(--sac-accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(47, 110, 63, 0.2);
}

.sac-export-row {
    display: flex;
    justify-content: flex-end;
    margin: 8px 0 12px;
}

.sac-export-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 8px;
    background: #14391e;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    border: 1px solid #14391e;
}

.sac-export-btn:hover {
    background: #0f2a16;
    color: #fff;
}

.sac-timeframe-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
}

.sac-timeframe-btn {
    min-width: 60px;
}

.sac-timeframe-btn.is-active {
    background: #14391e;
    color: #fff;
    border-color: #14391e;
}

.sac-infographic-panel {
    background: #fff;
    border: 1px solid #d7e4d2;
    border-radius: 12px;
    padding: 10px;
    height: 290px;
    margin-bottom: 12px;
}

.sac-insights {
    display: grid;
    grid-template-columns: repeat(3, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.sac-insight-card {
    background: #fff;
    border: 1px solid #d9e5d4;
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.sac-insight-card span {
    font-size: 0.78rem;
    text-transform: uppercase;
    color: #4f664f;
}

.sac-insight-card strong {
    font-size: 1rem;
    color: #1e3a25;
}

/* --- COLLAPSED STATE LOGIC --- */
.sac-widget.is-collapsed .sac-controls, 
.sac-widget.is-collapsed .sac-meta, 
.sac-widget.is-collapsed .sac-timeframe-tabs, 
.sac-widget.is-collapsed .sac-collapsible {
    display: none;
}

.sac-widget.is-collapsed .sac-infographic-panel {
    min-height: 0;
    height: 0;
    padding: 0;
    border: 0;
    margin: 0;
    overflow: hidden;
}

.sac-widget.is-collapsed .sac-header {
    margin-bottom: 4px;
}

.sac-widget.is-collapsed .sac-layout-hint {
    max-width: 100%;
}

.sac-widget.is-collapsed .sac-toggle-details {
    background: #14391e;
    color: #fff;
    border-color: #14391e;
}

/* --- DATA TABLE --- */
.sac-table-wrap {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid var(--sac-border);
    margin-top: 16px;
}

.sac-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--sac-card);
    text-align: left;
}

.sac-table th {
    background: var(--sac-accent-soft);
    color: #23422d;
    font-weight: 700;
    padding: 14px 12px;
    white-space: nowrap;
}

.sac-table td {
    padding: 12px;
    border-bottom: 1px solid #f0f4eb;
    font-size: 0.95rem;
    transition: background 0.2s ease;
    white-space: nowrap;
}

.sac-table tr:hover td {
    background: #f9fbf7;
}

.sac-icon {
    font-size: 1.15rem;
    margin-right: 8px;
    vertical-align: middle;
    display: inline-block;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.06));
}

.sac-powered-by {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px dashed #cfdbc8;
    font-size: 0.82rem;
    color: #466046;
    text-align: right;
}

.sac-powered-by a {
    color: #14391e;
    font-weight: 700;
    text-decoration: none;
}

.sac-powered-by a:hover {
    text-decoration: underline;
}

/* --- ADMIN DASHBOARD GRIDS --- */
.sac-admin .sac-settings-form, 
.sac-admin .sac-manual-form {
    background: #fff;
    border: 1px solid #d8e2d0;
    border-radius: 10px;
    padding: 16px;
    max-width: 980px;
}

.sac-admin-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin: 20px 0;
}

.sac-admin .notice.inline {
    max-width: 980px;
    margin-left: 0;
    margin-right: 0;
}

.sac-stat-card {
    background: #fff;
    border: 1px solid #d5e3d0;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.02);
    transition: transform 0.3s ease;
}

.sac-stat-card:hover {
    transform: translateY(-5px);
}

.sac-stat-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: #446046;
    letter-spacing: 0.04em;
}

.sac-stat-card strong {
    font-size: 1.8rem;
    color: #18361f;
    display: block;
    margin-top: 8px;
}

/* --- HEIGHT ADJUSTMENTS FOR LAYOUTS --- */
.sac-widget.sac-layout-sidebar .sac-infographic-panel { height: 220px; }
.sac-widget.sac-layout-banner .sac-infographic-panel { height: 260px; }
.sac-widget.sac-layout-full .sac-infographic-panel, 
.sac-widget.sac-layout-page .sac-infographic-panel { height: 330px; }

/* --- KEYFRAMES --- */
@keyframes sacLivePulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
    70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

@keyframes sacPulseLoading {
    0% { opacity: 1; }
    100% { opacity: 0.6; }
}

/* --- THEME COMPATIBILITY & OVERFLOW PROTECTION --- */
.sac-widget, 
.sac-widget * {
    box-sizing: border-box !important;
}

.sac-widget {
    width: 100%;
    max-width: 100% !important;
    word-wrap: break-word;
}

.sac-infographic-panel {
    position: relative;
    width: 100%;
    max-width: 100%;
}

.sac-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    display: block;
}

.sac-controls select {
    width: 100%;
    text-overflow: ellipsis;
}

/* --- MOBILE RESPONSIVE BREAKPOINTS --- */
@media (max-width: 768px) {
    .sac-widget { 
        padding: 16px; 
    }
    
    .sac-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .sac-header h3 { 
        font-size: 1.15rem; 
        line-height: 1.4;
    }

    .sac-toggle-details {
        width: 100%;
        text-align: center;
        margin-top: 8px;
    }

    .sac-controls { 
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 12px;
    }

    .sac-timeframe-tabs { 
        display: flex; 
        flex-wrap: nowrap; 
        overflow-x: auto; 
        -webkit-overflow-scrolling: touch;
        padding-bottom: 8px; 
    }

    .sac-timeframe-btn {
        flex: 0 0 auto;
    }

    .sac-insights {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .sac-table th, .sac-table td { 
        padding: 10px 8px; 
        font-size: 0.85rem; 
    }
    
    .sac-admin-stats {
        grid-template-columns: 1fr;
    }
    
    .sac-export-row {
        justify-content: stretch;
    }
    
    .sac-export-btn {
        width: 100%;
    }
    
    .sac-powered-by {
        text-align: left;
    }
}