* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f9fafb;
    min-height: 100vh;
    overflow-y: scroll; /* Force scrollbar */
}

.header {
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.shop-info h1 {
    font-size: 1.5rem;
    color: #1f2937;
    margin-bottom: 0.25rem;
}

.shop-info p {
    font-size: 0.875rem;
    color: #6b7280;
}

.shop-info input {
    font-size: 1.5rem;
    font-weight: bold;
    border: none;
    border-bottom: 2px solid #3b82f6;
    padding: 0.25rem;
    width: 100%;
    max-width: 300px;
}

.shop-info input:focus {
    outline: none;
}

@media (max-width: 768px) {
    .shop-info input {
        font-size: 1.25rem;
        max-width: 100%;
    }
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.sync-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #f0fdf4;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    color: #15803d;
    transition: all 0.3s ease;
    font-weight: 500;
}

.sync-indicator.editing {
    background: #fef3c7;
    color: #92400e;
}

.sync-indicator.saving {
    background: #fef3c7;
    color: #92400e;
}

.sync-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.sync-indicator.editing .sync-dot,
.sync-indicator.saving .sync-dot {
    background: #f59e0b;
    animation: spin 1s linear infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.search-box {
    position: relative;
}

.search-box input {
    padding: 0.5rem 1rem 0.5rem 2.5rem;
    border: 2px solid #e5e7eb;
    border-radius: 0.5rem;
    width: 250px;
    font-size: 0.875rem;
}

.search-box input:focus {
    outline: none;
    border-color: #3b82f6;
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
}

.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.5rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-success {
    background: #10b981;
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

.card {
    background: white;
    border-radius: 0 0 0.5rem 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    border-top: none;
}

.card.standalone {
    border-radius: 0.5rem;
    border-top: 1px solid #e5e7eb;
}

.card h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: #1f2937;
}

.index-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

@media (max-width: 640px) {
    .index-grid {
        grid-template-columns: 1fr;
    }
}

.category-card {
    border: 2px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 1rem;
    transition: all 0.2s;
    overflow: hidden;
    min-width: 0;
}

.category-card:hover {
    border-color: #3b82f6;
}

.category-card.draggable {
    cursor: move;
}

.category-card.dragging {
    opacity: 0.5;
}

.category-card.drag-over {
    border-color: #3b82f6;
    border-style: dashed;
    background-color: #eff6ff;
}

.subcategory-item.draggable {
    cursor: move;
}

.subcategory-item.dragging {
    opacity: 0.5;
}

.subcategory-item.drag-over {
    border-left-color: #10b981;
    background-color: #f0fdf4;
}

tr.draggable {
    cursor: move;
}

tr.dragging {
    opacity: 0.5;
}

tr.drag-over {
    background-color: #fef3c7;
}

.drag-handle {
    cursor: move;
    color: #9ca3af;
    margin-right: 0.5rem;
    font-size: 1.25rem;
    user-select: none;
}

.category-card.hidden {
    display: none;
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.5rem;
    gap: 0.5rem;
    min-width: 0;
}

.category-header h3 {
    font-weight: 600;
    color: #374151;
    flex: 1;
    min-width: 0;
    word-break: break-word;
}

.category-header input {
    flex: 1;
    min-width: 0;
    padding: 0.25rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    font-weight: 600;
    width: 100%;
}

.delete-btn {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1.25rem;
    line-height: 1;
    flex-shrink: 0;
}

.delete-btn:hover {
    color: #dc2626;
}

.subcategory-list {
    list-style: none;
    margin-bottom: 0.75rem;
    padding-left: 0.5rem;
}

.subcategory-item {
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background: #f9fafb;
    border-radius: 0.25rem;
    border-left: 3px solid #3b82f6;
    overflow: hidden;
}

.subcategory-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.subcategory-header input[type="text"] {
    min-width: 0;
    flex: 1;
}

.subcategory-input {
    padding: 0.25rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    width: 100%;
}

.subcategory-input:focus {
    outline: none;
    border-color: #3b82f6;
}

.subcategory-name {
    font-weight: 500;
    color: #1f2937;
    font-size: 0.875rem;
    cursor: pointer;
}

.subcategory-name:hover {
    color: #3b82f6;
    text-decoration: underline;
}

.product-list {
    list-style: none;
    margin-top: 0.25rem;
}

.product-list li {
    margin-bottom: 0.25rem;
}

.product-link {
    color: #3b82f6;
    text-decoration: none;
    font-size: 0.875rem;
    cursor: pointer;
}

.product-link:hover {
    text-decoration: underline;
    color: #2563eb;
}

.expand-btn {
    color: #6b7280;
    text-decoration: none;
    font-size: 0.875rem;
    cursor: pointer;
    font-weight: 500;
    display: inline-block;
}

.expand-btn:hover {
    color: #374151;
    text-decoration: underline;
}

.add-product-link {
    color: #10b981;
    text-decoration: none;
    font-size: 0.875rem;
    cursor: pointer;
    display: block;
    margin-top: 0.5rem;
    font-weight: 500;
}

.add-product-link:hover {
    color: #059669;
    text-decoration: underline;
}

.add-product-inline-form {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.5rem;
}

.add-product-inline-form input {
    flex: 1;
    padding: 0.25rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    font-size: 0.875rem;
}

.add-product-inline-form button {
    background: #10b981;
    color: white;
    border: none;
    padding: 0.25rem 0.75rem;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.875rem;
}

.add-product-inline-form button:hover {
    background: #059669;
}

.add-subcategory-section {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #f0fdf4;
    border-radius: 0.25rem;
    border-left: 3px solid #10b981;
}

.add-subcategory-form {
    display: flex;
    gap: 0.5rem;
}

.add-subcategory-form input {
    flex: 1;
    padding: 0.25rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    font-size: 0.875rem;
}

.add-subcategory-form button {
    background: #10b981;
    color: white;
    border: none;
    padding: 0.25rem 0.75rem;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.875rem;
}

.add-subcategory-form button:hover {
    background: #059669;
}

.add-product-btn {
    background: none;
    border: none;
    color: #10b981;
    font-size: 0.875rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0;
}

.add-product-btn:hover {
    color: #059669;
}

.add-product-row {
    background: #f0fdf4;
}

.add-product-row td {
    padding: 0.75rem 1rem;
}

.add-product-inline-btn {
    background: #10b981;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
}

.add-product-inline-btn:hover {
    background: #059669;
}

.add-category-form {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.5rem;
    width: 100%;
}

.add-category-form input {
    flex: 1;
    min-width: 0;
    padding: 0.5rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 0.5rem;
}

.add-category-form input:focus {
    outline: none;
    border-color: #3b82f6;
}

.category-section {
    margin-bottom: 3rem;
    background: white;
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    /* NO overflow here - this is important for sticky */
}

.category-title {
    background: #eff6ff;
    color: #1f2937;
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid #3b82f6;
}

.category-title h2 {
    font-size: 1.5rem;
    margin: 0;
    color: #1f2937;
}

.category-title input {
    background: white;
    border: 2px solid #3b82f6;
    color: #1f2937;
    padding: 0.5rem;
    border-radius: 0.25rem;
    font-size: 1.5rem;
    font-weight: bold;
    width: 100%
}

.subcategory-section {
    margin-bottom: 2rem;
    padding: 0;
    position: relative;
    /* NO overflow here either */
}

.subcategory-section:last-of-type {
    margin-bottom: 0.5rem;
}

.section-header {
    background: #eff6ff;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem 0.5rem 0 0;
    margin-bottom: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 3px solid #3b82f6;
    border: 1px solid #e5e7eb;
    border-bottom: none;
    position: sticky;
    top: 70px; /* Below main header */
    z-index: 40;
}

/* On mobile, adjust section header position */
@media (max-width: 768px) {
    .section-header {
        position: static; /* Remove sticky on mobile */
        z-index: auto;
    }
}

.section-header h3 {
    font-size: 1.1rem;
    color: #1f2937;
    margin: 0;
}

.section-header input {
    background: white;
    border: 2px solid #3b82f6;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 1rem;
    font-weight: 600;
    width: 100%
}

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    border-radius: 0 0 0.5rem 0.5rem;
}

table {
    width: 100%;
    min-width: 700px;
    border-collapse: separate;
    border-spacing: 0;
}

/* SIMPLE STICKY TABLE HEADER */
thead {
    position: sticky;
    top: 0; /* Below section header on desktop */
    z-index: 30;
}

thead tr {
    background: #f3f4f6;
}

th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.875rem;
    font-weight: 600;
    color: #374151;
    background: #f3f4f6 !important;
    border-bottom: 2px solid #e5e7eb;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

/* On mobile, disable sticky headers - let table scroll naturally */
@media (max-width: 768px) {
    thead {
        position: relative;
        top: 0;
    }
    
    th {
        box-shadow: none;
        position: relative;
    }
}

th.text-right {
    text-align: right;
}

th.text-center {
    text-align: center;
}

td {
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
    background: white;
}

td.text-right {
    text-align: right;
}

td.text-center {
    text-align: center;
}

tbody tr:hover {
    background: #f9fafb !important;
}

/*tr.highlight {
    animation: highlight 2s ease-in-out;
}

@keyframes highlight {
    0% { background-color: transparent; }
    100% { background-color: #fef3c7; }
}*/

/* Product Highlighting Animation */
.product-row-highlight {
  background-color: #fef3c7 !important;
}

.product-row-highlight td {
  background-color: #fef3c7 !important;
}

.table-input {
    width: 100%;
    padding: 0.25rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    min-width: 80px;
}

.table-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.product-name {
    font-weight: 500;
    color: #1f2937;
}

.price {
    color: #4b5563;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6b7280;
}

.no-results {
    text-align: center;
    padding: 2rem;
    color: #6b7280;
    display: none;
}

.no-results.show {
    display: block;
}

.product-section.hidden {
    display: none;
}

.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.show {
    display: flex;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 0.75rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 90%;
    animation: modalSlideIn 0.2s ease-out;
    max-height: 80vh;
    overflow-y: auto;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-content > p {
    color: #6b7280;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.modal-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 2rem;
}

.modal-btn {
    padding: 0.5rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-btn-cancel {
    background: #f3f4f6;
    color: #374151;
}

.modal-btn-cancel:hover {
    background: #e5e7eb;
}

.modal-btn-confirm {
    background: #ef4444;
    color: white;
}

.modal-btn-confirm:hover {
    background: #dc2626;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: #6b7280;
}

.error-message {
    background: #fef2f2;
    border: 2px solid #fca5a5;
    border-radius: 0.5rem;
    padding: 1rem;
    margin: 2rem auto;
    max-width: 600px;
    color: #991b1b;
}

.error-message h3 {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

/* Profile Dropdown */
.profile-dropdown {
    position: relative;
}

.profile-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    min-width: 200px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1000;
}

.dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: #374151;
    transition: background 0.2s;
    text-align: left;
}

.dropdown-item:hover {
    background: #f3f4f6;
}

.dropdown-item:first-child {
    border-radius: 0.5rem 0.5rem 0 0;
}

.dropdown-item:last-child {
    border-radius: 0 0 0.5rem 0.5rem;
}

.dropdown-item .icon {
    font-size: 1rem;
}

.dropdown-item.danger {
    color: #ef4444;
}

.dropdown-item.danger:hover {
    background: #fef2f2;
}

.dropdown-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 0.5rem 0;
}

/* Column Settings Modal - IMPROVED UI */
.column-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin: 1.5rem 0;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    overflow: hidden;
}

.column-setting-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    transition: background 0.2s;
}

.column-setting-row:last-child {
    border-bottom: none;
}

.column-setting-row:hover {
    background: #f9fafb;
}

.column-setting-row input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: #3b82f6;
}

.column-setting-row input[type="text"] {
    flex: 1;
    padding: 0.625rem 0.875rem;
    border: 2px solid #e5e7eb;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.column-setting-row input[type="text"]:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.column-setting-row input[type="text"]:disabled {
    background: #f9fafb;
    color: #6b7280;
    cursor: not-allowed;
}

/* Special styling for first row (Product Name - no checkbox) */
.column-setting-row:first-child {
    background: #f9fafb;
    font-weight: 600;
}

.column-setting-row .spacer {
    width: 1.25rem;
    flex-shrink: 0;
}

.col-hidden {
    display: none !important;
}

/* Column settings helper text */
.column-settings-helper {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: #1e40af;
    display: flex;
    align-items: start;
    gap: 0.5rem;
}

.column-settings-helper .icon {
    font-size: 1.125rem;
    flex-shrink: 0;
    margin-top: 0.125rem;
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        align-items: stretch;
    }

    .header-actions {
        flex-direction: column;
        width: 100%;
    }

    .search-box {
        width: 100%;
    }

    .search-box input {
        width: 100%;
    }

    .shop-info input {
        width: 100%;
    }

    .sync-indicator {
        width: 100%;
        justify-content: center;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    table {
        font-size: 0.875rem;
    }

    th, td {
        padding: 0.5rem;
    }

    .container {
        padding: 1rem;
    }

    .card {
        padding: 1rem;
    }
    
    .profile-dropdown {
        width: 100%;
    }
    
    .profile-btn {
        width: 100%;
        justify-content: center;
    }
    
    .dropdown-menu {
        left: 0;
        right: 0;
        min-width: auto;
    }

    .column-setting-row {
        padding: 0.75rem 1rem;
    }

    /* Mobile-specific fixes for edit mode */
    .subcategory-header {
        gap: 0.25rem;
    }

    .subcategory-item {
        padding: 0.25rem;
    }

    .drag-handle {
        font-size: 1rem;
        margin-right: 0.25rem;
    }

    .delete-btn {
        padding: 0.125rem;
        font-size: 1rem;
    }

    .subcategory-input {
        padding: 0.25rem;
        font-size: 0.8125rem;
    }

    .category-card {
        padding: 0.75rem;
    }
}

.sticky-table-header {
    position: fixed;
    z-index: 90;
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    pointer-events: none;
}

/* Hide JavaScript sticky headers on mobile - use CSS sticky instead */
@media (max-width: 768px) {
    .sticky-table-header {
        display: none !important;
    }
}