:root {
    /* Colors - HSL for easy swatching */
    --primary: 220 90% 56%;
    /* #3b82f6 Blue */
    --primary-dark: 224 76% 48%;
    --secondary: 215 25% 27%;
    /* Slate 800 */
    --accent: 262 83% 58%;
    /* Purple for highlights */

    --bg-body: 210 40% 98%;
    /* Light Blueish Gray */
    --bg-card: 0 0% 100%;
    /* White */
    --bg-sidebar: 215 28% 17%;
    /* Dark Slate */

    --text-main: 215 28% 17%;
    --text-muted: 215 16% 47%;
    --text-light: 210 40% 98%;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --color-border: 210 20% 90%;
    /* Light border */

    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Outfit', sans-serif;
}

body.dark-mode {
    --bg-body: 220 15% 12%;
    /* Very Dark Blue/Gray */
    --bg-card: 220 15% 16%;
    /* Slightly lighter */
    --bg-sidebar: 220 15% 10%;
    /* Darkest */

    --text-main: 220 20% 96%;
    --text-muted: 220 10% 65%;
    --text-light: 220 20% 96%;

    --color-border: 220 15% 25%;
    /* Dark border */

    /* Adjust input backgrounds for dark mode */
    --input-bg: 220 15% 14%;
}

/* Transition for smooth toggle */
body,
.sidebar,
.card,
.btn,
input,
textarea {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    background-color: hsl(var(--bg-body));
    color: hsl(var(--text-main));
    height: 100vh;
    overflow: hidden;
    /* App-like feel */
}

/* Base Layout */
.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: hsl(var(--bg-sidebar));
    color: hsl(var(--text-light));
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: width 0.3s ease;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 3rem;
    color: white;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    color: hsl(var(--text-light) / 0.7);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.nav-item:hover {
    background-color: hsl(255 100% 100% / 0.05);
    color: white;
    transform: translateX(4px);
}

.nav-item.active {
    background-color: hsl(var(--primary));
    color: white;
    box-shadow: 0 4px 12px hsl(var(--primary) / 0.3);
}

.nav-item i {
    font-size: 1.25rem;
}

/* User Profile in Sidebar */
.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid hsl(255 100% 100% / 0.1);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, hsl(var(--accent)), hsl(var(--primary)));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    color: white;
}

.user-profile .info {
    display: flex;
    flex-direction: column;
}

.user-profile .name {
    font-weight: 600;
    font-size: 0.9rem;
}

.user-profile .role {
    font-size: 0.75rem;
    color: hsl(var(--text-light) / 0.5);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background: hsl(var(--bg-card));
    border-top-left-radius: 32px;
    border-bottom-left-radius: 32px;
    margin: 10px 10px 10px 0;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.05);
}

.top-bar {
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid hsl(var(--color-border));
}

#page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: hsl(var(--text-main));
}

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    background-color: hsl(var(--bg-body));
}

/* Components */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-primary {
    background-color: hsl(var(--primary));
    color: white;
    box-shadow: 0 4px 12px hsl(var(--primary) / 0.25);
}

.btn-primary:hover {
    background-color: hsl(var(--primary-dark));
    transform: translateY(-1px);
    box-shadow: 0 6px 16px hsl(var(--primary) / 0.35);
}

.btn-secondary {
    background-color: transparent;
    color: hsl(var(--text-main));
    border: 1px solid hsl(var(--color-border));
}

.btn-secondary:hover {
    background-color: hsl(var(--text-main) / 0.05);
    border-color: hsl(var(--text-main) / 0.2);
}

/* Cards */
.card {
    background: hsl(var(--bg-card));
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid hsl(var(--color-border));
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: hsl(var(--text-muted));
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid hsl(var(--primary) / 0.1);
    border-top-color: hsl(var(--primary));
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Utilities */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mb-4 {
    margin-bottom: 1rem;
}

.text-muted {
    color: hsl(var(--text-muted));
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

/* --- NEW FORMS & TABLE STYLES --- */
input.w-full,
textarea.w-full {
    width: 100%;
    padding: 0.75rem;
    background-color: transparent;
    color: hsl(var(--text-main));
    border: 1px solid hsl(var(--color-border));
    border-radius: var(--radius-sm);
    outline: none;
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

input.w-full:focus,
textarea.w-full:focus {
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 3px hsl(var(--primary) / 0.1);
}

label.block {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: hsl(var(--text-main));
}

.table-header {
    background: hsl(var(--text-main) / 0.05);
    border-bottom: 1px solid hsl(var(--color-border));
}

/* Helper Class Overrides for safety */
.w-full {
    width: 100%;
}

.p-2 {
    padding: 0.5rem;
}

.border {
    border: 1px solid #e2e8f0;
}

.rounded {
    border-radius: var(--radius-sm);
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mt-4 {
    margin-top: 1rem;
}

.text-sm {
    font-size: 0.875rem;
}

.font-medium {
    font-weight: 500;
}

.text-red-500 {
    color: #ef4444;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s;
    color: #ef4444;
}

.btn-icon:hover {
    background-color: #fee2e2;
}

/* === PRINT STYLES === */
/* === PRINT STYLES (PDF ENGINE) === */
@media print {
    @page {
        size: A4;
        margin: 1.5cm;
    }

    /* Reset Theme for Print (Always White/Clean) */
    :root {
        --font-body: 'Arial', 'Helvetica', sans-serif;
        /* System fonts print better */
    }

    /* Hide UI Elements */
    .sidebar,
    .top-bar,
    .no-print,
    .btn,
    .btn-icon,
    .user-profile,
    #btn-theme-toggle,
    .modal-backdrop {
        display: none !important;
    }

    body,
    .app-container,
    .main-content,
    .content-area {
        background: white !important;
        color: #000 !important;
        margin: 0 !important;
        padding: 0 !important;
        height: auto !important;
        overflow: visible !important;
        display: block !important;
    }

    /* Reset Card Styles for Paper */
    .card,
    .sheet {
        box-shadow: none !important;
        border: none !important;
        background: white !important;
        padding: 0 !important;
        margin: 0 !important;
        color: #000 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Print Typography Improvements */
    h1,
    h2,
    h3,
    h4 {
        color: #000 !important;
        page-break-after: avoid;
    }

    p,
    td,
    li {
        color: #1a1a1a !important;
        font-size: 11pt !important;
        line-height: 1.4 !important;
    }

    /* Table optimization */
    table {
        width: 100% !important;
        border-collapse: collapse !important;
        page-break-inside: auto;
    }

    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }

    thead {
        display: table-header-group;
    }

    tfoot {
        display: table-footer-group;
    }

    th {
        border-bottom: 2px solid #000 !important;
        font-weight: bold !important;
        color: #000 !important;
        text-transform: uppercase;
        font-size: 9pt !important;
    }

    td {
        border-bottom: 1px solid #ddd !important;
    }

    /* Helper Utilities for Print */
    .text-muted {
        color: #444 !important;
    }

    /* Ensure Logos print clearly */
    img {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* END PRINT STYLES */

/* --- MOBILE & RESPONSIVE LUXURY --- */
.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}

@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    /* Main Content adjustments */
    .app-container {
        position: relative;
    }

    /* Mobile Sidebar - Hidden by default */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        width: 280px;
        box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Overlay when sidebar open */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 900;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }
    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: all;
    }

    .main-content {
        margin: 0;
        border-radius: 0;
        width: 100%;
        height: 100vh;
    }

    .content-area {
        padding: 1rem;
        padding-bottom: 80px; /* Space for bottom interaction if needed */
    }

    /* Grids become 1 column */
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Typography adjustments for mobile */
    #page-title {
        font-size: 1.25rem;
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .top-bar {
        padding: 1rem;
        gap: 0.5rem;
    }

    /* Hamburger Menu Button (visible only on mobile) */
    #mobile-menu-btn {
        display: flex !important;
        margin-right: 0.5rem;
    }
    
    .actions .btn span {
        display: none; /* Icon only for actions */
    }

    /* Card Luxury on Mobile */
    .card {
        padding: 1.25rem;
        border-radius: var(--radius-lg);
        /* Glossy effect */
        background: hsla(var(--bg-card), 0.8);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255,255,255,0.5);
    }
}

/* Helper for Mobile Menu Button */
#mobile-menu-btn {
    display: none;
    font-size: 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
    color: hsl(var(--text-main));
}

/* ==========================================
   DECORATIVE POS & MODAL ANIMATIONS (2027)
   ========================================== */

@keyframes popIn {
    0% { transform: scale(0.95) translateY(10px); opacity: 0; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

.animate-pop-in {
    animation: popIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Opaque High-Contrast Form Inputs for Modals & Forms */
.input,
input,
select,
textarea {
    background-color: #ffffff !important;
    color: #0f172a !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 8px !important;
    padding: 0.5rem 0.75rem !important;
    font-size: 0.9rem !important;
    outline: none !important;
    opacity: 1 !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

body.dark-mode .input,
body.dark-mode input,
body.dark-mode select,
body.dark-mode textarea {
    background-color: #1e293b !important;
    color: #f8fafc !important;
    border-color: #475569 !important;
}

.input:focus,
input:focus,
select:focus,
textarea:focus {
    border-color: #6366f1 !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25) !important;
}

/* Modal Backdrop & Content Styling */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 1rem;
    overflow-y: auto;
}

.modal-content {
    background-color: #ffffff !important;
    color: #0f172a !important;
    border: 1px solid #e2e8f0;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.3);
}

body.dark-mode .modal-content {
    background-color: #0f172a !important;
    color: #f8fafc !important;
    border-color: #1e293b;
}

.modal-content label {
    color: #334155 !important;
    font-weight: 700;
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
    display: block;
}

body.dark-mode .modal-content label {
    color: #cbd5e1 !important;
}

.modal-content li,
.modal-content p {
    color: #1e293b;
}

body.dark-mode .modal-content li,
body.dark-mode .modal-content p {
    color: #f1f5f9;
}

.line-clamp-1 {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.text-3xs {
    font-size: 0.65rem;
    line-height: 0.85rem;
}

.btn-success {
    background-color: #10b981;
    color: white;
    border: none;
}

.btn-success:hover {
    background-color: #059669;
    color: white;
}

.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.max-h-500 {
    max-height: 500px;
}

/* Compact Grid Columns & Decor Thumbnails */
.decor-catalog-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)) !important;
    gap: 0.85rem !important;
    width: 100% !important;
}

.decor-product-card {
    background: #ffffff !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 14px !important;
    padding: 0.75rem !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    transition: all 0.2s ease !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05) !important;
}

.decor-product-card:hover {
    border-color: #3b82f6 !important;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15) !important;
}

/* STRICT 45x45 px THUMBNAIL ENFORCEMENT & GLOBAL LIMIT FOR DECOR IMAGES */
#decor-content img {
    max-width: 120px !important;
    max-height: 120px !important;
    object-fit: cover !important;
}

.decor-thumb,
.decor-thumb img,
.decor-modal-thumb,
.decor-modal-thumb img,
#decor-catalog-grid img,
.decor-catalog-grid img,
.decor-product-card img {
    width: 45px !important;
    height: 45px !important;
    min-width: 45px !important;
    min-height: 45px !important;
    max-width: 45px !important;
    max-height: 45px !important;
    object-fit: cover !important;
    border-radius: 8px !important;
    display: block !important;
}

.decor-thumb,
.decor-modal-thumb {
    width: 45px !important;
    height: 45px !important;
    background-color: #f1f5f9 !important;
    border: 1px solid #cbd5e1 !important;
    overflow: hidden !important;
    flex-shrink: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Compact Grid Columns */
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
@media (min-width: 640px) {
    .sm\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
    .lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 1280px) {
    .xl\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Modal Animations & Visual Utilities */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleUp {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.animate-fade-in {
    animation: fadeIn 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.animate-scale-up {
    animation: scaleUp 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.backdrop-blur-xs {
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}


/* =========================================================
   IPHONE PWA SAFE-AREA, BOTTOM DOCK & UPDATE POPUP (2026.9)
   ========================================================= */
.ios-bottom-dock {
    display: none;
}

@media (max-width: 768px) {
    .top-bar {
        padding-top: calc(0.75rem + env(safe-area-inset-top, 0px)) !important;
        flex-wrap: wrap;
    }

    .content-area {
        padding-bottom: calc(92px + env(safe-area-inset-bottom, 16px)) !important;
    }

    .ios-bottom-dock {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(15, 23, 42, 0.96);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        border-top: 1px solid rgba(148, 163, 184, 0.2);
        padding: 6px 6px calc(8px + env(safe-area-inset-bottom, 8px)) 6px;
        z-index: 950;
        box-shadow: 0 -8px 25px rgba(0, 0, 0, 0.28);
    }

    .ios-dock-btn {
        background: transparent;
        border: none;
        color: #94a3b8;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        font-size: 10px;
        font-weight: 700;
        padding: 4px 2px;
        border-radius: 10px;
        cursor: pointer;
    }

    .ios-dock-btn i {
        font-size: 20px;
    }

    .ios-dock-btn.active {
        color: #38bdf8;
    }

    .ios-dock-btn.dock-cta {
        color: #ffffff;
    }

    .ios-dock-btn.dock-cta span.cta-circle {
        background: linear-gradient(135deg, #2563eb, #10b981);
        width: 38px;
        height: 38px;
        border-radius: 9999px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: -16px;
        box-shadow: 0 6px 16px rgba(37, 99, 235, 0.45);
    }
}

@media print {
    .ios-bottom-dock {
        display: none !important;
    }
}
