:root {
    --ac-primary: #2563eb;
    --ac-secondary: #f8fafc;
    --ac-text: #0f172a;
    --ac-sidebar-bg: #0f172a;
    --ac-sidebar-hover: #1e293b;
    --ac-sidebar-text: #f1f5f9;
    --ac-border: #e2e8f0;
    --ac-success: #dcfce7;
    --ac-success-text: #166534;
    --ac-warning: #fef9c3;
    --ac-warning-text: #854d0e;
    --ac-danger: #fee2e2;
    --ac-danger-text: #991b1b;
    --ac-info: #e0f2fe;
    --ac-info-text: #075985;
}

.ac-is-dashboard {
    display: flex;
    direction: rtl;
    text-align: right;
    font-family: 'Cairo', sans-serif;
    min-height: 100vh;
    background: #f1f5f9;
    margin: 0;
    padding: 0;
    border-radius: 0;
    font-size: 0.9rem; /* Global scaling down ~10% */
}

/* Fullscreen Specific Styles */
#ac-is-system-root:-webkit-full-screen { width: 100%; height: 100%; overflow-y: auto; background: #f1f5f9; }
#ac-is-system-root:-ms-fullscreen { width: 100%; height: 100%; overflow-y: auto; background: #f1f5f9; }
#ac-is-system-root:fullscreen { width: 100%; height: 100%; overflow-y: auto; background: #f1f5f9; }

#ac-is-system-root:fullscreen .ac-is-sidebar { height: 100vh; position: fixed; top: 0; right: 0; }
#ac-is-system-root:fullscreen .ac-is-main-content { margin-right: 220px; width: calc(100% - 220px); }

/* Vertical Sidebar - Stable, Slightly Reduced Width */
.ac-is-sidebar {
    width: 220px;
    background: var(--ac-sidebar-bg);
    color: var(--ac-sidebar-text);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    border-radius: 0;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--ac-sidebar-hover) transparent;
}

.ac-is-sidebar::-webkit-scrollbar {
    width: 4px;
}

.ac-is-sidebar::-webkit-scrollbar-thumb {
    background-color: var(--ac-sidebar-hover);
    border-radius: 10px;
}

.ac-is-sidebar-logo {
    padding: 25px 15px;
    background: #1e293b;
    text-align: center;
}

.ac-is-sidebar-logo h2 {
    color: #fff;
    margin: 0;
    font-size: 1.25rem;
    font-weight: 800;
}

.ac-is-sidebar-nav {
    margin-top: 8px;
    flex-grow: 0;
}

.ac-is-sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: #94a3b8;
    text-decoration: none !important;
    transition: all 0.3s;
    font-weight: 600;
    border-radius: 0;
    border-right: 4px solid transparent;
    font-size: 0.85rem;
    font-family: inherit;
}

.ac-is-sidebar-nav a:hover {
    background: var(--ac-sidebar-hover);
    color: #fff;
}

.ac-is-sidebar-nav a.active {
    background: var(--ac-sidebar-hover);
    color: #fff;
    border-right-color: var(--ac-primary);
}

.sidebar-ctrl-icon {
    transition: all 0.2s ease;
}

.sidebar-ctrl-icon:hover {
    color: #fff !important;
    transform: scale(1.1);
}

/* Main Content Area */
.ac-is-main-content {
    flex-grow: 1;
    padding: 30px;
    background: #f1f5f9;
    transition: margin 0.3s ease;
    min-width: 0; /* Prevent layout breaking */
}

.ac-is-content-inner {
    max-width: 1500px;
    margin: 0 auto;
}

/* Professional Flat Buttons - Scaled Down */
.ac-is-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    background: var(--ac-primary);
    color: #fff !important;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    transition: all 0.2s;
    text-decoration: none !important;
    line-height: 1.4;
    font-family: inherit;
}

/* Responsive Sidebar */
@media (max-width: 1024px) {
    .ac-is-dashboard {
        flex-direction: column;
        padding-bottom: 70px; /* Space for fixed bottom bar */
    }
    .ac-is-sidebar {
        width: 100%;
        height: auto;
        position: relative;
        overflow-y: visible;
    }
    .ac-is-sidebar-nav {
        display: flex;
        overflow-x: auto;
        scrollbar-width: none;
    }
    .ac-is-sidebar-nav::-webkit-scrollbar { display: none; }

    .ac-is-sidebar-nav a {
        padding: 12px 15px;
        white-space: nowrap;
        border-right: none;
        border-bottom: 4px solid transparent;
    }
    .ac-is-sidebar-nav a.active {
        border-bottom-color: var(--ac-primary);
    }

    .ac-is-sidebar-footer {
        display: none !important; /* Hide standard footer */
    }

    .ac-is-mobile-bottom-bar {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 65px;
        background: var(--ac-sidebar-bg);
        z-index: 10005;
        justify-content: space-around;
        align-items: center;
        border-top: 1px solid var(--ac-sidebar-hover);
    }

    .ac-is-mobile-bottom-bar .sidebar-ctrl-icon {
        color: #94a3b8;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        font-size: 0.6rem;
        padding: 10px;
        background: none;
        border: none;
        cursor: pointer;
        flex: 1;
    }

    .ac-is-mobile-bottom-bar .sidebar-ctrl-icon span.dashicons {
        font-size: 20px;
    }

    .ac-is-mobile-bottom-bar .logout {
        color: #ef4444 !important;
    }

    #ac-is-system-root:fullscreen .ac-is-main-content { margin-right: 0; width: 100%; }

    .ac-is-cart-area {
        position: static !important;
    }

    /* Hide non-critical sections on mobile */
    .ac-is-sidebar-nav a[href*="ac_view=payroll"],
    .ac-is-sidebar-nav a[href*="ac_view=sales-history"],
    .ac-is-sidebar-nav a[href*="ac_view=inventory"] {
        display: none !important;
    }

    /* Mobile Dashboard Card Optimization - HARD ENFORCED 3 PER ROW */
    .ac-is-metrics-row {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
        padding-bottom: 15px;
        flex-wrap: nowrap !important;
        overflow: hidden !important;
    }

    .ac-is-metric-card {
        flex: none !important;
        width: 100% !important;
        min-width: 0 !important;
        padding: 5px 2px !important;
        margin-bottom: 0;
        gap: 2px !important;
        border-right-width: 2px;
        border-radius: 4px !important;
        flex-direction: column !important;
        text-align: center;
        justify-content: center;
    }

    .ac-is-metric-icon {
        width: 20px !important;
        height: 20px !important;
        font-size: 12px !important;
        margin: 0 auto;
    }

    .ac-is-metric-title {
        font-size: 0.5rem !important;
        margin-bottom: 1px !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-weight: 700;
    }

    .ac-is-metric-value {
        font-size: 0.65rem !important;
        font-weight: 800;
    }

    .ac-is-metric-content div:last-child {
        font-size: 0.5rem !important;
        margin-top: 1px;
    }

    /* Water Filter Tracking Mobile Optimization */
    .col-filter { display: none !important; }
}

@media (max-width: 768px) {
    .ac-is-grid {
        grid-template-columns: 1fr !important;
        gap: 20px;
    }

    .ac-is-main-content {
        padding: 15px;
    }

    /* Hard enforce 3 per row even on 768px and smaller */
    .ac-is-metrics-row {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 5px !important;
    }
}

/* Sales Form Mobile Optimization */
.ac-is-cart-area {
    position: sticky;
    top: 20px;
}

/* Table Optimization - Reduced Row Height & Padding */
.ac-is-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid var(--ac-border);
}

.ac-is-table th {
    background: #f8fafc;
    padding: 12px 15px;
    text-align: right;
    font-weight: 700;
    color: #334155;
    border-bottom: 2px solid var(--ac-border);
    font-size: 0.85rem;
}

.ac-is-table td {
    padding: 10px 15px;
    border-bottom: 1px solid var(--ac-border);
    color: #475569;
    font-size: 0.85rem;
}

/* Quick Sales Mode Toggles */
.ac-is-mode-toggles {
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.ac-is-mode-box {
    padding: 6px 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 4px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: #64748b;
    border: 1px solid transparent;
}

.ac-is-mode-box:hover {
    background: #f8fafc;
}

.ac-is-mode-box.active {
    background: var(--ac-primary);
    color: #fff;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
}

.ac-is-mode-box .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}

/* Sidebar Footer Controls */
.ac-is-sidebar-footer {
    padding: 15px;
    border-top: 1px solid var(--ac-sidebar-hover);
}

.ac-is-top-controls {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.ac-is-top-controls .control-btn {
    flex: 1;
    height: 40px;
    background: #334155;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.ac-is-top-controls .control-btn:hover {
    background: #475569;
}

.ac-is-top-controls .control-btn.logout {
    background: #991b1b;
}

.ac-is-top-controls .control-btn.logout:hover {
    background: #dc2626;
}

.ac-is-mode-box small {
    font-weight: 700;
    font-size: 0.8rem;
}

/* Mobile Barcode Scanner Professional UI */
#ac-is-reader-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    background: #000;
    overflow: hidden;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}

#ac-is-reader {
    width: 100% !important;
    border: none !important;
}

.ac-is-scan-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ac-is-scan-frame {
    width: 250px;
    height: 150px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    position: relative;
    box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.5);
}

.ac-is-scan-frame::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: #ef4444;
    box-shadow: 0 0 15px #ef4444;
    animation: scanMove 2s infinite linear;
}

@keyframes scanMove {
    0% { top: 0; }
    50% { top: 100%; }
    100% { top: 0; }
}

.ac-is-scan-corners {
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
}

.ac-is-scan-corners::before, .ac-is-scan-corners::after {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    border: 4px solid var(--ac-primary);
}

/* Top Left */
.ac-is-scan-corners::before { top: 0; left: 0; border-right: none; border-bottom: none; }
/* Top Right - pseudo element hack for 4 corners */
.ac-is-scan-frame-corner-tr { position: absolute; top: -2px; right: -2px; width: 20px; height: 20px; border: 4px solid var(--ac-primary); border-left: none; border-bottom: none; }
.ac-is-scan-frame-corner-bl { position: absolute; bottom: -2px; left: -2px; width: 20px; height: 20px; border: 4px solid var(--ac-primary); border-right: none; border-top: none; }
.ac-is-scan-frame-corner-br { position: absolute; bottom: -2px; right: -2px; width: 20px; height: 20px; border: 4px solid var(--ac-primary); border-left: none; border-top: none; }

.ac-is-scan-status {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    white-space: nowrap;
    z-index: 20;
}

.scan-success-flash {
    animation: flashGreen 0.5s ease-out;
}

@keyframes flashGreen {
    0% { background: rgba(5, 150, 105, 0); }
    50% { background: rgba(5, 150, 105, 0.5); }
    100% { background: rgba(5, 150, 105, 0); }
}

/* Card Styles - Scaled Down */
.ac-is-card {
    background: #fff;
    padding: 22px;
    border-radius: 0;
    border: 1px solid var(--ac-border);
}

.ac-is-card h3 {
    margin: 0 0 12px 0;
    font-size: 0.95rem;
    color: #64748b;
    font-weight: 600;
}

.ac-is-card .value {
    font-size: 1.8rem;
    font-weight: 800;
}

/* Horizontal Metrics Cards */
.ac-is-metrics-row {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.ac-is-metric-card {
    flex: 1;
    background: #fff;
    padding: 22px;
    border-right: 5px solid var(--ac-primary);
    display: flex;
    align-items: center;
    gap: 22px;
    border: 1px solid var(--ac-border);
    border-right: 5px solid var(--ac-primary);
    transition: transform 0.2s, box-shadow 0.2s;
}

.ac-is-metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.ac-is-metric-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.ac-is-metric-content {
    flex-grow: 1;
}

.ac-is-metric-title {
    font-size: 0.85rem;
    color: #64748b;
    font-weight: 600;
    margin-bottom: 5px;
}

.ac-is-metric-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--ac-text);
}


/* Form Styles - Reduced Gaps & Padding */
.ac-is-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.ac-is-form-group {
    margin-bottom: 18px;
}

.ac-is-form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.85rem;
}

.ac-is-form-group input,
.ac-is-form-group select,
.ac-is-form-group textarea {
    padding: 8px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: inherit;
}

/* Capsules - Smaller */
.ac-is-capsule {
    display: inline-block;
    padding: 2px 8px;
    font-size: 0.75rem;
    border-radius: 4px;
    font-weight: 600;
}

.capsule-primary { background: var(--ac-info); color: var(--ac-info-text); }
.capsule-success { background: var(--ac-success); color: var(--ac-success-text); }
.capsule-warning { background: var(--ac-warning); color: var(--ac-warning-text); }
.capsule-danger { background: var(--ac-danger); color: var(--ac-danger-text); }

.spin {
    display: inline-block;
    animation: rotate 1.5s linear infinite;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes popIn {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
