/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #f59e0b;
    --secondary-dark: #d97706;
    --bg: #ffffff;
    --bg-light: #f9fafb;
    --bg-card: #ffffff;
    --text: #111827;
    --text-light: #6b7280;
    --border: #e5e7eb;
    --border-dark: #d1d5db;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
    --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --header-height: 64px;
}

html {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg-light);
    line-height: 1.5;
    font-size: 16px;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    color: var(--primary-dark);
}

img {
    max-width: 100%;
    height: auto;
}

button {
    cursor: pointer;
    font-family: var(--font);
}

/* === Header === */
.header {
    background: var(--primary);
    color: #fff;
    height: var(--header-height);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-inner {
    max-width: 1280px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-link {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff !important;
}

.header-logo {
    height: 40px;
    width: auto;
    max-width: 140px;
    object-fit: contain;
    border-radius: 4px;
}

.shop-name {
    font-size: 1.25rem;
    font-weight: 700;
    white-space: nowrap;
}

.header-link, .logout-btn {
    color: #fff;
    background: none;
    border: none;
    display: flex;
    align-items: center;
    opacity: 0.85;
    transition: opacity 0.2s;
}

.header-link:hover, .logout-btn:hover {
    opacity: 1;
    color: #fff;
}

.cart-link {
    color: #fff;
    position: relative;
    display: flex;
    align-items: center;
}

.cart-link:hover {
    color: #fff;
    opacity: 0.85;
}

.cart-icon {
    display: block;
}

.cart-badge {
    position: absolute;
    top: -8px;
    right: -10px;
    background: var(--secondary);
    color: #000;
    font-size: 0.7rem;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* === AI Assistant Banner + Overlay === */
.ai-assistant-banner {
    position: sticky;
    top: var(--header-height);
    z-index: 90;
    background: #ecfeff;
    border-bottom: 1px solid #a5f3fc;
    padding: 10px 20px;
}

.ai-assistant-banner-btn {
    max-width: 1280px;
    margin: 0 auto;
    width: 100%;
    display: block;
    border: 1px solid #06b6d4;
    background: #06b6d4;
    color: #fff;
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 0.95rem;
    font-weight: 600;
    transition: background 0.2s;
}

.ai-assistant-banner-btn:hover {
    background: #0891b2;
}

.ai-assistant-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.ai-assistant-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.7);
}

.ai-assistant-overlay-dialog {
    position: relative;
    width: min(1200px, 96vw);
    height: min(780px, 88vh);
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 14px 40px rgba(0,0,0,0.35);
    border: 1px solid var(--border);
}

.ai-assistant-overlay-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.75);
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    z-index: 1;
}

.ai-assistant-overlay-close:hover {
    background: rgba(17, 24, 39, 0.9);
}

.ai-assistant-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
}

/* Hamburger */
.hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
}

.hamburger span {
    display: block;
    width: 24px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
}

/* === Footer === */
.footer {
    background: #1f2937;
    color: #9ca3af;
    padding: 20px;
    text-align: center;
    font-size: 0.875rem;
    margin-top: auto;
}

.footer-inner {
    max-width: 1280px;
    margin: 0 auto;
}

/* === Main Content === */
.main-content {
    flex: 1;
    max-width: 1280px;
    margin: 0 auto;
    width: 100%;
    padding: 24px 20px;
}

/* === Login Page === */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-light);
}

.login-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    margin: 20px;
}

.login-card h1 {
    font-size: 1.5rem;
    margin-bottom: 8px;
    text-align: center;
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 24px;
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="color"],
.form-group input[type="file"],
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: var(--font);
    transition: border-color 0.2s;
    background: #fff;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    gap: 8px;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--secondary);
    color: #000;
}

.btn-secondary:hover {
    background: var(--secondary-dark);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: #fff;
}

.btn-danger {
    background: #ef4444;
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.85rem;
}

.error-msg {
    background: #fef2f2;
    color: #dc2626;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 16px;
    border: 1px solid #fecaca;
}

.success-msg {
    background: #f0fdf4;
    color: #16a34a;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 16px;
    border: 1px solid #bbf7d0;
}

/* === Breadcrumbs === */
.breadcrumbs {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 0.875rem;
    color: var(--text-light);
    margin-bottom: 20px;
    padding: 10px 0;
}

.breadcrumbs a {
    color: var(--primary);
}

.breadcrumbs a:hover {
    text-decoration: underline;
}

.breadcrumbs .sep {
    margin: 0 4px;
    color: var(--border-dark);
}

.breadcrumbs .current {
    color: var(--text);
    font-weight: 600;
}

/* === Shop Layout (sidebar + content) === */
.shop-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 16px;
    position: sticky;
    top: calc(var(--header-height) + 24px);
    max-height: calc(100vh - var(--header-height) - 48px);
    overflow-y: auto;
}

.sidebar h3 {
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-light);
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.content-area {
    flex: 1;
    min-width: 0;
}

/* === Category Tree === */
.category-tree {
    list-style: none;
}

.category-tree li {
    margin-bottom: 2px;
}

.category-tree a {
    display: block;
    padding: 6px 10px;
    border-radius: 4px;
    color: var(--text);
    font-size: 0.9rem;
    transition: background 0.15s;
}

.category-tree a:hover {
    background: var(--bg-light);
    color: var(--primary);
}

.category-tree a.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.category-tree .subcategories {
    list-style: none;
    margin-left: 16px;
    border-left: 2px solid var(--border);
    padding-left: 4px;
}

.category-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-light);
    padding: 2px 4px;
    margin-right: 4px;
    transition: transform 0.2s;
    display: inline-block;
    width: 18px;
    text-align: center;
}

.category-toggle.open {
    transform: rotate(90deg);
}

/* === Category Tiles === */
.category-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.category-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px 16px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-weight: 600;
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
    min-height: 80px;
}

.category-tile:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
    color: var(--primary);
}

/* === Product Grid === */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
}

.product-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.2s;
    cursor: pointer;
}

.product-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.product-card-img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
    background: var(--bg-light);
}

.product-card-body {
    padding: 14px;
}

.product-card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-card-desc {
    font-size: 0.85rem;
    color: var(--text-light);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* === Filter Sidebar === */
.filter-section {
    margin-bottom: 20px;
}

.filter-section h4 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    margin-bottom: 6px;
    cursor: pointer;
}

.filter-checkbox input[type="checkbox"] {
    accent-color: var(--primary);
    cursor: pointer;
}

.search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: var(--font);
    margin-bottom: 16px;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* === Product Detail === */
.product-detail {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 24px;
}

.product-gallery {
    position: relative;
}

.gallery-main {
    width: 100%;
    height: 400px;
    object-fit: contain;
    border-radius: var(--radius);
    background: var(--bg-light);
    display: block;
}

.gallery-thumbs {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.gallery-thumb {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.2s;
}

.gallery-thumb:hover, .gallery-thumb.active {
    border-color: var(--primary);
}

.product-info h1 {
    font-size: 1.75rem;
    margin-bottom: 16px;
}

.product-info .description {
    color: var(--text-light);
    line-height: 1.7;
    margin-bottom: 24px;
    white-space: pre-line;
}

.attributes-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
}

.attributes-table th,
.attributes-table td {
    text-align: left;
    padding: 8px 12px;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
}

.attributes-table th {
    font-weight: 600;
    color: var(--text-light);
    width: 40%;
}

.product-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* === Cart === */
.cart-page h1 {
    font-size: 1.5rem;
    margin-bottom: 20px;
}

.cart-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
}

.cart-item-img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 4px;
    background: var(--bg-light);
    flex-shrink: 0;
}

.cart-item-info {
    flex: 1;
    min-width: 0;
}

.cart-item-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.cart-item-remove {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 4px 8px;
    border-radius: 4px;
}

.cart-item-remove:hover {
    background: #fef2f2;
}

.cart-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.cart-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

/* === Order Confirmation === */
.order-confirmation {
    text-align: center;
    padding: 60px 20px;
}

.order-confirmation h1 {
    font-size: 1.75rem;
    margin-bottom: 12px;
    color: #16a34a;
}

.order-confirmation p {
    color: var(--text-light);
    margin-bottom: 24px;
    font-size: 1.1rem;
}

.checkmark-circle {
    width: 80px;
    height: 80px;
    margin: 0 auto 24px;
    background: #f0fdf4;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.checkmark-circle svg {
    color: #16a34a;
}

/* === Settings === */
.settings-page {
    max-width: 700px;
}

.settings-page h1 {
    font-size: 1.5rem;
    margin-bottom: 24px;
}

.settings-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}

.settings-section h2 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.color-input-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.color-input-group input[type="color"] {
    width: 50px;
    height: 40px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
}

.color-input-group input[type="text"] {
    width: 120px;
}

.color-preview {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.color-swatch {
    width: 60px;
    height: 40px;
    border-radius: 4px;
    border: 1px solid var(--border);
}

.logo-preview {
    max-width: 200px;
    max-height: 80px;
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 12px;
    background: var(--bg-light);
    padding: 8px;
}

/* === Mobile Nav === */
.mobile-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    height: 100vh;
    background: var(--bg-card);
    z-index: 200;
    overflow-y: auto;
    box-shadow: 4px 0 12px rgba(0,0,0,0.15);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

.mobile-nav.open {
    transform: translateX(0);
    display: block !important;
}

.mobile-nav-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 199;
}

.mobile-nav-backdrop.open {
    display: block !important;
}

.mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 1.1rem;
}

.mobile-nav-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text);
}

.mobile-nav-tree {
    padding: 12px 16px;
}

/* === Filter Overlay (Mobile) === */
.filter-overlay-toggle {
    display: none;
    margin-bottom: 16px;
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.empty-state h2 {
    font-size: 1.25rem;
    margin-bottom: 8px;
    color: var(--text);
}

.empty-state p {
    margin-bottom: 20px;
}

/* === Loading === */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
}

.loading::after {
    content: "";
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

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

/* === Home page category cards === */
.home-categories {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

.home-category-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    transition: box-shadow 0.2s, border-color 0.2s;
    display: block;
    color: var(--text);
}

.home-category-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
    color: var(--primary);
}

.home-category-card h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.home-category-card .count {
    font-size: 0.85rem;
    color: var(--text-light);
}

/* === User Management === */
.user-list {
    list-style: none;
}

.user-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 6px;
    background: var(--bg-light);
    font-size: 0.95rem;
}

.user-badge {
    font-size: 0.8rem;
    color: var(--text-light);
    font-style: italic;
}

/* === Scrape Progress === */
.scrape-progress {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-light);
}

.scrape-bar-track {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.scrape-bar-fill {
    height: 100%;
    width: 40%;
    background: var(--primary);
    border-radius: 3px;
    animation: scrape-slide 1.4s ease-in-out infinite;
}

@keyframes scrape-slide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

.scrape-status {
    font-size: 0.82rem;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === Responsive === */
@media (max-width: 900px) {
    .shop-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        position: static;
        display: none;
    }

    .sidebar.show-mobile {
        display: block;
    }

    .filter-overlay-toggle {
        display: inline-flex;
    }

    .product-detail {
        grid-template-columns: 1fr;
    }

    .gallery-main {
        height: 280px;
    }
}

@media (max-width: 640px) {
    .hamburger {
        display: flex;
    }

    .shop-name {
        font-size: 1rem;
    }

    .header-inner {
        padding: 0 12px;
    }

    .main-content {
        padding: 16px 12px;
    }

    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 12px;
    }

    .product-card-img {
        height: 140px;
    }

    .login-card {
        padding: 24px;
    }

    .category-tiles {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .cart-item {
        flex-wrap: wrap;
    }

    .ai-assistant-banner {
        top: var(--header-height);
        padding: 8px 12px;
    }

    .ai-assistant-banner-btn {
        font-size: 0.9rem;
        padding: 9px 12px;
    }

    .ai-assistant-overlay {
        padding: 8px;
    }

    .ai-assistant-overlay-dialog {
        width: 100%;
        height: 92vh;
        border-radius: 8px;
    }
}
