/* ===== CSS Reset & Variables ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colors */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-hover: #30363d;
    --bg-active: #388bfd1a;
    
    --border-primary: #30363d;
    --border-secondary: #21262d;
    
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    
    --accent-primary: #58a6ff;
    --accent-success: #3fb950;
    --accent-warning: #d29922;
    --accent-danger: #f85149;
    --accent-info: #58a6ff;
    
    --status-available: #3fb950;
    --status-reserved: #d29922;
    --status-sold: #f85149;
    --status-defect: #6e7681;
    --status-returned: #58a6ff;
    
    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-success: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    --gradient-revenue: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(88, 166, 255, 0.3);
    
    /* Spacing */
    --sidebar-width: 240px;
    --header-height: 64px;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    
    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
}

/* ===== Base Styles ===== */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
}

/* ===== App Layout ===== */
.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    margin-bottom: 24px;
}

.logo-icon {
    font-size: 28px;
}

.logo h1 {
    font-size: 18px;
    font-weight: 600;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
}

.nav-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-btn.active {
    background: var(--bg-active);
    color: var(--accent-primary);
}

.nav-icon {
    font-size: 18px;
}

.sidebar-footer {
    padding-top: 16px;
    border-top: 1px solid var(--border-primary);
}

.quick-stats {
    display: flex;
    gap: 12px;
}

.quick-stat {
    flex: 1;
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: var(--radius-md);
    text-align: center;
}

.quick-stat .stat-value {
    display: block;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.quick-stat .stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== Main Content ===== */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.header {
    height: var(--header-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-primary);
    background: var(--bg-secondary);
}

.page-title {
    font-size: 20px;
    font-weight: 600;
}

.header-right {
    display: flex;
    gap: 12px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-primary);
}

.btn-danger {
    background: var(--accent-danger);
    color: white;
}

.btn-danger:hover {
    filter: brightness(1.1);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-icon:hover {
    background: var(--bg-hover);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

/* ===== Sections ===== */
.section {
    flex: 1;
    display: none;
    flex-direction: column;
    padding: 24px;
    overflow: hidden;
}

.section.active {
    display: flex;
}

/* ===== Filters ===== */
.filters {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.filter-group {
    flex: 1;
    max-width: 300px;
}

.filter-input,
.filter-select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    transition: all var(--transition-fast);
}

.filter-input:focus,
.filter-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
}

.filter-input::placeholder {
    color: var(--text-muted);
}

/* ===== Table ===== */
.table-container {
    flex: 1;
    overflow: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
}

.accounts-table {
    width: 100%;
    border-collapse: collapse;
}

.accounts-table th,
.accounts-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-secondary);
}

.accounts-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.accounts-table tr:hover {
    background: var(--bg-hover);
}

.accounts-table td {
    font-family: 'Consolas', 'Monaco', monospace;
}

.accounts-table td:nth-child(2) {
    color: var(--accent-primary);
}

.accounts-table td:nth-child(3) {
    color: var(--text-muted);
    font-size: 13px;
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
}

.status-badge.available {
    background: rgba(63, 185, 80, 0.15);
    color: var(--status-available);
}

.status-badge.reserved {
    background: rgba(210, 153, 34, 0.15);
    color: var(--status-reserved);
}

.status-badge.sold {
    background: rgba(248, 81, 73, 0.15);
    color: var(--status-sold);
}

.status-badge.defect {
    background: rgba(110, 118, 129, 0.15);
    color: var(--status-defect);
}

.status-badge.returned {
    background: rgba(88, 166, 255, 0.15);
    color: var(--status-returned);
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 16px 0;
}

.page-info {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ===== Empty State ===== */
.empty-state {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
    text-align: center;
}

.empty-state.visible {
    display: flex;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 20px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.empty-state p {
    color: var(--text-muted);
    margin-bottom: 24px;
}

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all var(--transition-normal);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card-icon {
    font-size: 32px;
}

.stat-card-value {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-card-label {
    font-size: 13px;
    color: var(--text-muted);
}

.stat-card.revenue {
    background: var(--gradient-revenue);
    border: none;
}

.stat-card.revenue .stat-card-value,
.stat-card.revenue .stat-card-label {
    color: white;
}

/* ===== Customers Grid ===== */
.customers-header {
    margin-bottom: 20px;
}

.customers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.customer-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: all var(--transition-normal);
}

.customer-card:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}

.customer-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.customer-avatar {
    width: 48px;
    height: 48px;
    background: var(--gradient-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    color: white;
}

.customer-name {
    font-size: 16px;
    font-weight: 600;
}

.customer-telegram {
    font-size: 13px;
    color: var(--accent-primary);
}

.customer-stats {
    display: flex;
    gap: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-secondary);
}

.customer-stat {
    flex: 1;
    text-align: center;
}

.customer-stat-value {
    display: block;
    font-size: 18px;
    font-weight: 600;
}

.customer-stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.customer-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

/* ===== Settings ===== */
.settings-container {
    max-width: 600px;
}

.settings-group {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
}

.settings-group h3 {
    margin-bottom: 16px;
    font-size: 16px;
}

.settings-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.settings-group.danger {
    border-color: rgba(248, 81, 73, 0.3);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: auto;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.2s ease;
}

.modal-sm {
    max-width: 400px;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-primary);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-primary);
}

/* ===== Form Elements ===== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

.form-hint {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== Drop Zone ===== */
.drop-zone {
    border: 2px dashed var(--border-primary);
    border-radius: var(--radius-lg);
    padding: 48px;
    text-align: center;
    transition: all var(--transition-normal);
    cursor: pointer;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--accent-primary);
    background: rgba(88, 166, 255, 0.05);
}

.drop-zone-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.drop-zone p {
    font-size: 16px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.drop-zone span {
    color: var(--text-muted);
}

.drop-zone .btn {
    margin-top: 16px;
}

/* ===== Import Preview ===== */
.import-preview {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-top: 16px;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
}

.preview-filename {
    font-weight: 500;
}

.preview-count {
    color: var(--accent-success);
    font-weight: 600;
}

.preview-meta {
    font-size: 13px;
    color: var(--text-muted);
}

/* ===== Sell Summary ===== */
.sell-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    font-size: 16px;
}

.sell-total {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent-success);
}

/* ===== Account Info ===== */
.account-info {
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-family: 'Consolas', monospace;
    word-break: break-all;
}

/* ===== Toast Notifications ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 2000;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-lg);
    animation: toastSlideIn 0.3s ease;
    max-width: 400px;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast.success {
    border-left: 4px solid var(--accent-success);
}

.toast.error {
    border-left: 4px solid var(--accent-danger);
}

.toast.info {
    border-left: 4px solid var(--accent-info);
}

.toast-icon {
    font-size: 20px;
}

.toast-message {
    flex: 1;
}

/* ===== Checkbox ===== */
input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent-primary);
}

/* ===== Sales History ===== */
.chart-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.chart-container h3 {
    margin-bottom: 20px;
}

.sales-history {
    max-height: 300px;
    overflow-y: auto;
}

.sale-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-secondary);
}

.sale-item:last-child {
    border-bottom: none;
}

.sale-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sale-customer {
    font-weight: 500;
}

.sale-count {
    color: var(--text-muted);
    font-size: 13px;
}

.sale-amount {
    font-weight: 600;
    color: var(--accent-success);
}

.sale-date {
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-primary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--bg-hover);
}

/* ===== Action Buttons in Table ===== */
.action-btn {
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.action-btn.copy {
    color: var(--accent-primary);
}

.action-btn.edit {
    color: var(--accent-warning);
}

/* ===== Selection ===== */
.accounts-table tr.selected {
    background: var(--bg-active);
}

/* ===== Hide scrollbar for table header sync ===== */
.table-container {
    scrollbar-gutter: stable;
}
