/* ============================================================================
   ROOT VARIABLES & THEMES
   ============================================================================ */

:root {
    /* Colors */
    --primary: #0088cc;
    --primary-dark: #0070a8;
    --secondary: #31a24c;
    --accent: #f59e0b;
    --danger: #ef4444;
    --warning: #f97316;

    /* Backgrounds */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #f0f2f5;

    /* Text */
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --text-light: #ffffff;

    /* Borders */
    --border-color: #e5e7eb;
    --border-light: #f3f4f6;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);

    /* Spacing */
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

/* Dark Theme */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a1a;
        --bg-secondary: #2d2d2d;
        --bg-tertiary: #3a3a3a;

        --text-primary: #ffffff;
        --text-secondary: #b0b0b0;
        --text-tertiary: #808080;

        --border-color: #444444;
        --border-light: #333333;
    }
}

/* ============================================================================
   RESET & BASE STYLES
   ============================================================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    transition: background-color 0.3s ease;
}

body.dark-mode {
    color-scheme: dark;
}

/* ============================================================================
   HEADER
   ============================================================================ */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.header-title-section h1 {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
}

.header-subtitle {
    font-size: 12px;
    opacity: 0.9;
    margin: 4px 0 0 0;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 0;
}

.btn-icon:active {
    background-color: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

.btn-icon svg {
    width: 24px;
    height: 24px;
}

/* ============================================================================
   NAVIGATION TABS
   ============================================================================ */

.nav-tabs {
    display: flex;
    gap: 0;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.nav-tab {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    position: relative;
    transition: color 0.3s ease;
    white-space: nowrap;
}

.nav-tab.active {
    color: var(--primary);
    font-weight: 600;
}

.nav-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 3px;
    background-color: var(--primary);
}

.nav-tab:active {
    opacity: 0.8;
}

.tab-icon {
    font-size: 16px;
}

.tab-label {
    font-size: 13px;
}

/* ============================================================================
   MAIN CONTENT
   ============================================================================ */

.main-content {
    padding: 20px;
    padding-bottom: 100px;
    max-width: 1200px;
    margin: 0 auto;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Section Headers */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 22px;
    font-weight: 700;
    margin: 0;
}

.section-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.btn-add {
    padding: 8px 16px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
}

.btn-add:active {
    background-color: var(--primary-dark);
    transform: scale(0.98);
}

/* ============================================================================
   PRODUCTS GRID
   ============================================================================ */

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

@media (max-width: 768px) {
    .products-grid {
        grid-template-columns: 1fr;
    }
}

.product-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

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

.product-image {
    width: 100%;
    height: 160px;
    background-color: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-content {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.product-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-site {
    display: inline-block;
    font-size: 11px;
    background-color: var(--border-light);
    color: var(--text-secondary);
    padding: 2px 6px;
    border-radius: 4px;
    margin-bottom: 8px;
    width: fit-content;
}

.product-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 8px;
}

.product-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

.product-price-old {
    font-size: 12px;
    color: var(--text-tertiary);
    text-decoration: line-through;
}

.product-status {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: auto;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 500;
}

.status-badge.enabled {
    background-color: rgba(49, 162, 76, 0.1);
    color: var(--secondary);
}

.status-badge.disabled {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

/* Empty State */
.empty-state {
    grid-column: 1 / -1;
    padding: 60px 20px;
    text-align: center;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.empty-state-small {
    padding: 20px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 13px;
}

/* ============================================================================
   STATS GRID
   ============================================================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px 12px;
    text-align: center;
}

.stat-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
}

/* ============================================================================
   CHARTS
   ============================================================================ */

.charts-section {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 24px;
}

.chart-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.period-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.period-btn {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    color: var(--text-secondary);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.period-btn.active {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
}

.period-btn:active {
    transform: scale(0.95);
}

.chart-container {
    position: relative;
    height: 300px;
    margin-bottom: 24px;
}

#priceChart {
    width: 100% !important;
    height: 100% !important;
}

/* ============================================================================
   PRICE LIST
   ============================================================================ */

.price-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.price-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.price-item-img {
    width: 60px;
    height: 60px;
    background-color: var(--bg-tertiary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    flex-shrink: 0;
}

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

.price-item-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.price-item-meta {
    font-size: 11px;
    color: var(--text-secondary);
}

.price-item-price {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
}

/* ============================================================================
   MODALS
   ============================================================================ */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    align-items: flex-end;
}

.modal.active {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    position: relative;
    background-color: var(--bg-primary);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    width: 100%;
    max-width: 500px;
    animation: slideUp 0.3s ease;
    overflow-y: auto;
}

.modal-lg {
    max-width: 100%;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    sticky: 0;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

.modal-close:active {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

/* ============================================================================
   FORMS
   ============================================================================ */

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

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.2s ease;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 136, 204, 0.1);
}

.form-help {
    display: block;
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 4px;
}

.form-buttons {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.form-buttons button {
    flex: 1;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

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

.btn-primary:active {
    background-color: var(--primary-dark);
    transform: scale(0.98);
}

.btn-secondary {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:active {
    background-color: var(--border-light);
}

.btn-danger {
    background-color: var(--danger);
    color: white;
}

.btn-danger:active {
    background-color: #dc2626;
    transform: scale(0.98);
}

/* ============================================================================
   TOAST NOTIFICATIONS
   ============================================================================ */

.toast {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    max-width: 400px;
    padding: 12px 16px;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    display: none;
    animation: slideUp 0.3s ease;
    z-index: 2000;
    border-left: 4px solid var(--primary);
}

.toast.show {
    display: block;
}

.toast.success {
    border-left-color: var(--secondary);
    background-color: rgba(49, 162, 76, 0.1);
    color: var(--secondary);
}

.toast.error {
    border-left-color: var(--danger);
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.toast.warning {
    border-left-color: var(--warning);
    background-color: rgba(249, 115, 22, 0.1);
    color: var(--warning);
}

/* ============================================================================
   UTILITIES
   ============================================================================ */

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.text-center {
    text-align: center;
}

.mt-8 {
    margin-top: 32px;
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 640px) {
    .main-content {
        padding: 16px;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .section-header h2 {
        font-size: 20px;
    }

    .modal-content {
        max-height: 100%;
    }
}

/* ============================================================================
   LOADING STATES
   ============================================================================ */

.loading {
    opacity: 0.6;
    pointer-events: none;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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