/* =========================================================
   OPTICAL SHOP THEME - MOBILE FIRST (90% Mobile Target)
   ========================================================= */

:root {
    /* Optical/Clinical Color Palette */
    --bg-color: #F0F4F8;
    --card-bg: #FFFFFF;
    --text-main: #0F172A;
    --text-muted: #64748B;
    --accent: #0EA5E9; /* Optical Blue */
    --accent-hover: #0284C7;
    --danger: #EF4444;
    --danger-hover: #DC2626;
    
    /* Layout Variables */
    --radius: 20px;
    --radius-sm: 12px;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 12px 30px rgba(14, 165, 233, 0.15);
    --border: 1px solid rgba(14, 165, 233, 0.1);
    --transition: all 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, sans-serif; 
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Prevent the whole page from bouncing/scrolling */
}

body { 
    background-color: var(--bg-color); 
    color: var(--text-main); 
    -webkit-font-smoothing: antialiased; 
    display: flex;
    flex-direction: column;
}

/* =========================================================
   1. HEADER & NAVIGATION (Glassmorphism)
   ========================================================= */
.shop-header {
    flex-shrink: 0; /* Header stays fixed size at the top */
    z-index: 100;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 16px 20px; 
    border-bottom: 1px solid rgba(0,0,0,0.05);
    display: flex; 
    flex-wrap: wrap; /* Allows search bar to drop on mobile */
    gap: 12px; 
    align-items: center; 
    justify-content: space-between;
}

.shop-header h2 {
    color: var(--accent);
}

/* Mobile-First Search Box */
.search-box {
    flex-grow: 1; 
    width: 100%;
    order: 3; /* Forces search below logo and nav on mobile */
    padding: 14px 20px; 
    font-size: 1rem;
    background: #F8FAFC; 
    border: 1px solid #E2E8F0;
    border-radius: 980px; 
    outline: none; 
    transition: var(--transition);
}

.search-box:focus { 
    background: #FFF; 
    border-color: var(--accent); 
    box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.15); 
}

/* Desktop Header Adjustments */
@media (min-width: 768px) {
    .shop-header { padding: 16px 32px; flex-wrap: nowrap; gap: 32px; }
    .search-box { width: auto; max-width: 600px; order: unset; }
}

/* =========================================================
   2. BUTTONS & ACTIONS
   ========================================================= */
button {
    background: var(--accent); 
    color: white; 
    border: none;
    padding: 14px 24px; 
    border-radius: 980px; 
    font-weight: 600; 
    font-size: 0.95rem;
    cursor: pointer; 
    transition: var(--transition); 
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

button:active { transform: scale(0.96); } /* Mobile tap feedback */
@media (min-width: 768px) { button:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(14, 165, 233, 0.3); } }

button.danger { background: #FEF2F2; color: var(--danger); }
button.danger:active, button.danger:hover { background: var(--danger); color: white; }

button.small { padding: 10px 16px; font-size: 0.85rem; }
button.secondary { background: #F1F5F9; color: var(--text-main); }
button.secondary:active, button.secondary:hover { background: #E2E8F0; }

nav { display: flex; gap: 8px; flex-wrap: wrap; }

/* =========================================================
   3. LAYOUT SHELL & CARDS
   ========================================================= */
.bento-container { 
    max-width: 1200px; 
    margin: 0 auto; 
    padding: 20px 16px 120px 16px; 
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling for iOS */
}

.bento-card {
    background: var(--card-bg); 
    border-radius: var(--radius); 
    padding: 24px 20px;
    box-shadow: var(--shadow); 
    margin-bottom: 24px; 
    border: var(--border);
}

.header-actions { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 16px;
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 20px; 
}

.breadcrumbs {
    padding: 12px 16px;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--accent);
    box-shadow: var(--shadow);
    white-space: nowrap;
    overflow-x: auto; /* Scrollable breadcrumbs on mobile */
    -webkit-overflow-scrolling: touch;
}
.breadcrumbs span { cursor: pointer; }
.breadcrumbs span.active { color: var(--text-main); cursor: default; }

/* =========================================================
   4. PRODUCT & CATEGORY GRID (Mobile Optimized)
   ========================================================= */
.grid-view { 
    display: grid; 
    /* 2 columns on mobile minimum */
    grid-template-columns: repeat(2, 1fr); 
    gap: 12px; 
}

@media (min-width: 600px) { .grid-view { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 20px; } }
@media (min-width: 900px) { .grid-view { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); } }

.cat-card, .product-card {
    background: var(--card-bg); 
    border-radius: var(--radius); 
    padding: 16px; 
    cursor: pointer; 
    text-align: center;
    box-shadow: var(--shadow); 
    transition: var(--transition); 
    border: var(--border);
    display: flex; 
    flex-direction: column; 
    align-items: center; 
}

.cat-card { justify-content: center; aspect-ratio: 1; }
.cat-card:active, .product-card:active { transform: scale(0.97); }
@media (min-width: 768px) { .cat-card:hover, .product-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-hover); border-color: var(--accent); } }

.cat-img { width: 50px; height: 50px; object-fit: contain; margin-bottom: 12px; }
.cat-title { font-weight: 700; font-size: 0.95rem; color: var(--text-main); }

.product-card { justify-content: flex-start; text-align: left; align-items: flex-start; }
.product-img { 
    width: 100%; 
    height: 120px; 
    object-fit: contain; 
    margin-bottom: 12px; 
    border-radius: var(--radius-sm); 
    background: #F8FAFC; 
    padding: 8px;
    mix-blend-mode: multiply; 
}
.product-path-text { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; font-weight: 700; width: 100%; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-model { font-weight: 700; font-size: 1rem; margin-bottom: 8px; width: 100%; line-height: 1.3; }
.product-price { font-weight: 800; font-size: 1.15rem; color: var(--accent); width: 100%; margin-top: auto; }

/* =========================================================
   5. NATIVE-FEEL MODALS (Bottom Sheet on Mobile)
   ========================================================= */
.product-modal-overlay, .modal-overlay {
    position: fixed; 
    top: 0; left: 0; 
    width: 100vw; height: 100dvh;
    background: rgba(15, 23, 42, 0.6); 
    backdrop-filter: blur(8px); 
    -webkit-backdrop-filter: blur(8px);
    display: flex; 
    justify-content: center; 
    align-items: flex-end; /* Bottom alignment for mobile */
    opacity: 0; pointer-events: none; 
    transition: var(--transition); 
    z-index: 1000;
}
.product-modal-overlay.active, .modal-overlay.active { opacity: 1; pointer-events: auto; }

.product-modal, .modal-content {
    background: var(--card-bg); 
    width: 100%; 
    max-height: 95dvh;
    border-radius: 32px 32px 0 0; /* Rounded top only */
    box-shadow: 0 -10px 40px rgba(0,0,0,0.2);
    display: flex; 
    flex-direction: column; 
    overflow-y: auto;
    transform: translateY(100%); 
    transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-content { padding: 30px 24px; }
.product-modal-overlay.active .product-modal, .modal-overlay.active .modal-content { transform: translateY(0); }

.modal-img-col { background: #F8FAFC; padding: 30px; display: flex; align-items: center; justify-content: center; }
.modal-img-col img { max-width: 100%; max-height: 250px; object-fit: contain; mix-blend-mode: multiply; }
.modal-info-col { padding: 30px 24px; display: flex; flex-direction: column; }
.modal-path { font-size: 0.85rem; color: var(--accent); margin-bottom: 8px; font-weight: 700; text-transform: uppercase; }
.modal-title { font-size: 2rem; font-weight: 800; margin-bottom: 12px; line-height: 1.2; }
.modal-price { font-size: 2rem; font-weight: 800; color: var(--text-main); margin-bottom: 24px; }
.modal-info-col button { width: 100%; padding: 18px; font-size: 1.1rem; } /* Massive tap target */

.modal-actions { display: flex; gap: 12px; margin-top: 24px; flex-direction: column-reverse; }
.modal-actions button { width: 100%; }

/* Desktop Modal Overrides */
@media (min-width: 768px) {
    .product-modal-overlay, .modal-overlay { align-items: center; }
    .product-modal, .modal-content {
        flex-direction: row; 
        width: 90%; 
        max-width: 900px;
        height: auto;
        border-radius: 32px; 
        transform: translateY(30px) scale(0.95);
        overflow: hidden;
    }
    .modal-content { flex-direction: column; max-width: 550px; }
    .product-modal-overlay.active .product-modal, .modal-overlay.active .modal-content { transform: translateY(0) scale(1); }
    .modal-img-col { flex: 1.2; }
    .modal-info-col { flex: 1; padding: 48px; justify-content: center; }
    .modal-info-col button { width: auto; align-self: flex-start; }
    .modal-actions { flex-direction: row; justify-content: flex-end; }
    .modal-actions button { width: auto; }
}

/* =========================================================
   6. FORMS & INPUTS
   ========================================================= */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 600; color: var(--text-muted); font-size: 0.95rem; }
.form-group input, .form-group select, .modal-input {
    width: 100%; 
    padding: 16px; 
    border: 2px solid #E2E8F0; 
    border-radius: var(--radius-sm);
    font-size: 1.05rem; 
    background: #F8FAFC; 
    transition: var(--transition); 
    appearance: none; /* Cleaner mobile selects */
}
.form-group input:focus, .form-group select:focus, .modal-input:focus { 
    border-color: var(--accent); 
    background: #FFF; 
    outline: none; 
}
.form-group input[type="file"] { padding: 12px; font-size: 0.9rem; background: #FFF; border: 2px dashed #CBD5E1; }

/* =========================================================
   7. RESPONSIVE DATA TABLE (Magic Mobile Cards)
   ========================================================= */
.data-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.data-table th, .data-table td { padding: 16px; text-align: left; }
.data-table th { font-weight: 700; color: var(--text-muted); text-transform: uppercase; font-size: 0.85rem; border-bottom: 2px solid #E2E8F0; }
.data-table img { width: 50px; height: 50px; object-fit: contain; border-radius: var(--radius-sm); background: #F8FAFC; border: 1px solid #E2E8F0; }

/* Mobile Card View Transformation */
@media (max-width: 768px) {
    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr { display: block; width: 100%; }
    .data-table tr { 
        display: flex; 
        flex-wrap: wrap; 
        align-items: center; 
        gap: 12px; 
        background: #FFF; 
        border: 1px solid #E2E8F0; 
        border-radius: var(--radius-sm); 
        margin-bottom: 16px; 
        padding: 16px; 
        box-shadow: 0 2px 8px rgba(0,0,0,0.02);
    }
    .data-table td { padding: 0; border: none; display: block; }
    .data-table td:nth-child(1) { width: 60px; } /* Image */
    .data-table td:nth-child(2) { flex: 1; min-width: calc(100% - 80px); } /* Model & Path */
    .data-table td:nth-child(3) { width: 100%; font-size: 1.4rem; font-weight: 800; color: var(--accent); margin-top: 8px; } /* Price */
    .data-table td:nth-child(4) { width: 100%; display: flex; gap: 8px; margin-top: 12px; border-top: 1px dashed #E2E8F0; padding-top: 16px; } /* Actions */
    .data-table td:nth-child(4) button { flex: 1; } /* Buttons split width */
}

/* =========================================================
   8. TREE VIEW & SETTINGS (Thumb Friendly)
   ========================================================= */
.tree-container { background: #F8FAFC; border-radius: var(--radius); padding: 12px; border: var(--border); }
.tree-container ul { list-style: none; }
.tree-children { padding-left: 16px !important; border-left: 2px solid #E2E8F0; margin-top: 8px; }

.node-content {
    display: flex; 
    flex-direction: column; /* Stack actions below on mobile */
    gap: 12px;
    background: #FFF; 
    padding: 16px; 
    border-radius: var(--radius-sm); 
    margin-bottom: 10px;
    border: 1px solid #E2E8F0; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.node-info { display: flex; align-items: center; gap: 12px; flex: 1; }
.node-img { width: 44px; height: 44px; border-radius: var(--radius-sm); object-fit: contain; background: #F1F5F9; }
.node-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.toggle-btn { 
    background: #E0F2FE; 
    color: var(--accent); 
    padding: 0; 
    border-radius: 50%; 
    font-size: 0.9rem; 
    width: 36px; height: 36px; 
    display: flex; align-items: center; justify-content: center; 
    transition: transform 0.2s;
}
.toggle-btn.open { transform: rotate(90deg); background: var(--accent); color: #FFF; }

@media (min-width: 768px) {
    .tree-children { padding-left: 32px !important; }
    .node-content { flex-direction: row; justify-content: space-between; align-items: center; }
    .tree-container { padding: 24px; }
}

/* Template Setup Items */
.template-item-row { 
    display: flex; 
    flex-wrap: wrap;
    justify-content: space-between; 
    align-items: center; 
    gap: 12px;
    padding: 16px; 
    background: #FFF; 
    border: 1px solid #E2E8F0; 
    border-radius: var(--radius-sm); 
    margin-bottom: 10px; 
}
.template-item-left { display: flex; align-items: center; gap: 12px; flex: 1; }
/* Enlarge checkboxes for mobile */
.template-item-left input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--accent); cursor: pointer; }

/* =========================================================
   9. TOAST NOTIFICATIONS
   ========================================================= */
.toast {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: #0F172A;
    color: #FFF;
    padding: 16px 32px;
    border-radius: 980px;
    font-weight: 600;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 9999;
    transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.toast.show { bottom: 30px; }