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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0a0a0a;
    color: #fff;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ==================== LAYOUT ==================== */
.dashboard-container { display: flex; min-height: 100vh; }

/* ==================== SIDEBAR ==================== */
.sidebar {
    width: 240px; background: #111; border-right: 1px solid #1e1e1e;
    display: flex; flex-direction: column; position: fixed;
    top: 0; left: 0; height: 100vh; z-index: 100; transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px; border-bottom: 1px solid #1e1e1e;
    display: flex; align-items: center; gap: 10px;
}

.sidebar-header h1 { font-size: 16px; font-weight: 700; color: #fff; }

.badge {
    background: var(--primary, #8B0000); color: #fff; font-size: 10px; font-weight: 600;
    padding: 3px 8px; border-radius: 4px; text-transform: uppercase; letter-spacing: 0.5px;
}

.sidebar-nav { flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 11px 14px;
    color: #777; text-decoration: none; border-radius: 8px;
    font-size: 14px; font-weight: 500; transition: all 0.15s ease;
}

.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item:hover { background: #1a1a1a; color: #ccc; }
.nav-item.active { background: var(--primary, #8B0000); color: #fff; }

.sidebar-footer {
    padding: 12px; border-top: 1px solid #1e1e1e;
    display: flex; flex-direction: column; gap: 2px;
}

.back-link {
    display: flex; align-items: center; gap: 12px; padding: 10px 14px;
    color: #666; text-decoration: none; border-radius: 8px;
    font-size: 13px; transition: all 0.15s ease;
}

.back-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.back-link:hover { background: #1a1a1a; color: #aaa; }
.logout-link { color: #ef4444; }
.logout-link:hover { background: rgba(239, 68, 68, 0.1) !important; }

/* ==================== MAIN CONTENT ==================== */
.main-content { flex: 1; margin-left: 240px; padding: 28px; min-height: 100vh; }
.content-section { display: none; }
.content-section.active { display: block; }

.section-header { margin-bottom: 24px; }
.section-header h2 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.section-header p { color: #666; font-size: 14px; }

/* ==================== STAT CARDS (Stats Section) ==================== */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 24px; }

.stat-card {
    background: #141414; border: 1px solid #1e1e1e; border-radius: 12px;
    padding: 18px; display: flex; align-items: center; gap: 14px; transition: border-color 0.2s;
}

.stat-card:hover { border-color: #333; }

.stat-icon {
    width: 44px; height: 44px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.blue { background: rgba(59, 130, 246, 0.12); color: #3b82f6; }
.stat-icon.gold { background: rgba(212, 175, 55, 0.12); color: #d4af37; }
.stat-icon.green { background: rgba(34, 197, 94, 0.12); color: #22c55e; }
.stat-icon.red { background: rgba(239, 68, 68, 0.12); color: #ef4444; }
.stat-icon.purple { background: rgba(147, 51, 234, 0.12); color: #9333ea; }

.stat-info h3 { font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat-info p { font-size: 12px; color: #666; margin-top: 2px; }

/* ==================== UPLOAD SECTION ==================== */
.upload-container { max-width: 640px; }

.upload-card {
    background: #141414; border: 1px solid #1e1e1e; border-radius: 12px; padding: 24px;
}

.upload-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 20px; }

.plate-form { display: flex; flex-direction: column; gap: 16px; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.form-row.checkboxes { display: flex; flex-wrap: wrap; gap: 14px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12px; font-weight: 500; color: #777; }

.form-group input,
.form-group select {
    padding: 11px 14px; background: #0a0a0a; border: 1px solid #2a2a2a;
    border-radius: 8px; color: #fff; font-size: 14px; transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus { outline: none; border-color: var(--primary, #8B0000); }
.form-group input::placeholder { color: #444; }

/* ==================== CHECKBOXES ==================== */
.checkbox-label {
    display: flex; align-items: center; gap: 10px; cursor: pointer;
    font-size: 13px; color: #aaa; user-select: none; white-space: nowrap;
}

.checkbox-label input[type="checkbox"] { display: none; }

.checkbox-custom {
    width: 18px; height: 18px; border: 2px solid #333; border-radius: 4px;
    position: relative; transition: all 0.15s; flex-shrink: 0;
}

.checkbox-label input:checked + .checkbox-custom {
    background: var(--primary, #8B0000); border-color: var(--primary, #8B0000);
}

.checkbox-label input:checked + .checkbox-custom::after {
    content: ''; position: absolute; left: 5px; top: 1px;
    width: 5px; height: 9px; border: solid #fff;
    border-width: 0 2px 2px 0; transform: rotate(45deg);
}

.highest-offer-label { color: #d4af37; }

/* ==================== BUTTONS ==================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px; padding: 11px 20px; border: none; border-radius: 8px;
    font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.15s;
    text-decoration: none; white-space: nowrap;
}

.btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.btn-primary { background: var(--primary, #8B0000); color: #fff; }
.btn-primary:hover { background: var(--primary-dark, #5c0000); }
.btn-secondary { background: #1a1a1a; color: #aaa; border: 1px solid #2a2a2a; }
.btn-secondary:hover { background: #222; color: #fff; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }

/* ==================== MANAGE SECTION ==================== */
.manage-toolbar {
    display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap;
}

.search-box {
    display: flex; align-items: center; gap: 10px; background: #0a0a0a;
    border: 1px solid #1e1e1e; border-radius: 8px; padding: 0 14px;
    flex: 1; min-width: 180px; max-width: 340px;
}

.search-box svg { width: 16px; height: 16px; color: #444; flex-shrink: 0; }

.search-box input {
    flex: 1; padding: 10px 0; background: transparent;
    border: none; color: #fff; font-size: 13px; outline: none;
}

.search-box input::placeholder { color: #444; }

.filter-buttons { display: flex; gap: 6px; }

.filter-btn {
    padding: 7px 14px; background: transparent; border: 1px solid #1e1e1e;
    border-radius: 6px; color: #555; font-size: 12px; font-weight: 500;
    cursor: pointer; transition: all 0.15s;
}

.filter-btn:hover { background: #1a1a1a; color: #aaa; }
.filter-btn.active { background: var(--primary, #8B0000); border-color: var(--primary, #8B0000); color: #fff; }

/* ==================== TABLES ==================== */
.plates-table-container { overflow: hidden; }

.plates-table,
.users-table {
    width: 100%; border-collapse: collapse;
    background: #141414; border: 1px solid #1e1e1e; border-radius: 12px;
    overflow: hidden;
}

.plates-table th, .plates-table td,
.users-table th, .users-table td {
    padding: 12px 14px; text-align: left; border-bottom: 1px solid #1e1e1e; font-size: 13px;
}

.plates-table th, .users-table th {
    background: #0f0f0f; color: #666; font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap;
}

.plates-table tbody tr:hover,
.users-table tbody tr:hover { background: #1a1a1a; }

.col-checkbox { width: 40px; }

/* Action buttons in table */
.action-buttons { display: flex; gap: 6px; }

.action-btn {
    width: 30px; height: 30px; display: flex; align-items: center;
    justify-content: center; border: none; border-radius: 6px;
    cursor: pointer; transition: all 0.15s; background: transparent;
}

.action-btn svg { width: 14px; height: 14px; }
.action-btn.edit { background: rgba(59, 130, 246, 0.12); color: #3b82f6; }
.action-btn.edit:hover { background: #3b82f6; color: #fff; }
.action-btn.delete { background: rgba(239, 68, 68, 0.12); color: #ef4444; }
.action-btn.delete:hover { background: #ef4444; color: #fff; }

/* Plate status badges */
.plate-status {
    display: inline-flex; align-items: center; padding: 3px 10px;
    border-radius: 20px; font-size: 11px; font-weight: 500; white-space: nowrap;
}

.plate-status.sponsored { background: rgba(139, 0, 0, 0.15); color: #d44; }
.plate-status.champagne { background: rgba(212, 175, 55, 0.12); color: #d4af37; }
.plate-status.locked { background: rgba(156, 163, 175, 0.12); color: #9ca3af; }

/* Bulk actions */
.bulk-actions {
    display: flex; align-items: center; gap: 14px; padding: 12px 16px;
    background: #141414; border: 1px solid #1e1e1e; border-radius: 10px; margin-top: 12px;
}

.bulk-actions span { color: #666; font-size: 13px; }

/* ==================== LOADING & EMPTY ==================== */
.loading-indicator {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 48px 16px;
}

.spinner {
    width: 32px; height: 32px; border: 3px solid #1e1e1e;
    border-top-color: var(--primary, #8B0000); border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-indicator p { margin-top: 12px; color: #555; font-size: 13px; }

.empty-state {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 48px 16px;
}

.empty-state svg { width: 40px; height: 40px; color: #333; margin-bottom: 12px; }
.empty-state p { color: #555; font-size: 13px; }

.loading-row { text-align: center; color: #555; padding: 32px 16px !important; }

/* ==================== CHARTS SECTION ==================== */
.charts-section {
    background: #141414; border: 1px solid #1e1e1e; border-radius: 12px;
    padding: 20px; margin-bottom: 20px;
}

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

.charts-header h3 { font-size: 16px; font-weight: 600; }

.chart-period-selector { display: flex; gap: 6px; flex-wrap: wrap; }

.period-btn {
    padding: 6px 14px; border: 1px solid #2a2a2a; background: transparent;
    color: #666; border-radius: 6px; cursor: pointer; font-size: 12px;
    font-weight: 500; transition: all 0.15s;
}

.period-btn:hover { background: #1e1e1e; color: #aaa; }
.period-btn.active { background: var(--primary, #8B0000); border-color: var(--primary, #8B0000); color: #fff; }

.custom-date-picker {
    display: flex; align-items: flex-end; gap: 12px; padding: 14px;
    background: #1a1a1a; border-radius: 8px; margin-bottom: 16px; flex-wrap: wrap;
}

.date-input-group { display: flex; flex-direction: column; gap: 4px; }
.date-input-group label { font-size: 11px; color: #666; font-weight: 500; }

.date-input-group input[type="date"] {
    padding: 8px 12px; background: #0a0a0a; border: 1px solid #2a2a2a;
    border-radius: 6px; color: #fff; font-size: 13px;
}

.date-input-group input[type="date"]:focus { outline: none; border-color: var(--primary, #8B0000); }
.date-input-group input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); cursor: pointer; }

.charts-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }

.chart-card { background: #1a1a1a; border-radius: 10px; padding: 16px; }

.chart-card-header {
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px;
}

.chart-card-header h4 { font-size: 13px; color: #666; font-weight: 500; }
.chart-total { font-size: 18px; font-weight: 700; }
.chart-card canvas { width: 100% !important; height: 160px !important; }

/* ==================== ACTIVITY TIMELINE ==================== */
.timeline-section {
    background: #141414; border: 1px solid #1e1e1e; border-radius: 12px;
    padding: 20px; margin-top: 20px;
}

.timeline-header { margin-bottom: 16px; }
.timeline-header h3 { font-size: 16px; font-weight: 600; margin-bottom: 2px; }
.timeline-header p { font-size: 12px; color: #555; }

.activity-timeline { display: flex; flex-direction: column; gap: 8px; max-height: 380px; overflow-y: auto; }

.timeline-item {
    display: flex; gap: 12px; align-items: flex-start;
    padding: 10px 12px; background: #1a1a1a; border-radius: 8px;
}

.timeline-item:hover { background: #1e1e1e; }

.timeline-icon {
    width: 34px; height: 34px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

.timeline-icon svg { width: 16px; height: 16px; }
.timeline-icon.plate_added { background: rgba(59, 130, 246, 0.12); color: #3b82f6; }
.timeline-icon.favorited { background: rgba(239, 68, 68, 0.12); color: #ef4444; }

.timeline-content { flex: 1; min-width: 0; }
.timeline-title { font-weight: 600; font-size: 13px; margin-bottom: 1px; }
.timeline-subtitle { color: #666; font-size: 12px; }
.timeline-time { color: #444; font-size: 11px; }
.timeline-loading, .timeline-empty, .timeline-error { text-align: center; padding: 32px 16px; color: #555; font-size: 13px; }

/* ==================== USERS SECTION ==================== */
.users-stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 24px; }

.users-stat-card {
    background: #141414; border: 1px solid #1e1e1e; border-radius: 12px;
    padding: 18px; display: flex; align-items: center; gap: 14px;
}

.users-stat-icon {
    width: 44px; height: 44px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; background: rgba(147, 51, 234, 0.12); color: #9333ea;
}

.users-stat-icon svg { width: 20px; height: 20px; }
.users-stat-icon.green { background: rgba(34, 197, 94, 0.12); color: #22c55e; }
.users-stat-icon.blue { background: rgba(59, 130, 246, 0.12); color: #3b82f6; }

.users-stat-info { display: flex; flex-direction: column; }
.users-stat-number { font-size: 24px; font-weight: 700; line-height: 1.1; }
.users-stat-label { font-size: 12px; color: #666; margin-top: 2px; }

.users-table-container {
    background: #141414; border: 1px solid #1e1e1e; border-radius: 12px;
    overflow: hidden;
}

.users-table-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 14px 16px; border-bottom: 1px solid #1e1e1e; flex-wrap: wrap;
}

.users-search {
    display: flex; align-items: center; gap: 10px; background: #0a0a0a;
    border: 1px solid #1e1e1e; border-radius: 8px; padding: 0 14px;
    flex: 1; min-width: 180px; max-width: 340px;
}

.users-search svg { width: 16px; height: 16px; color: #444; flex-shrink: 0; }

.users-search input {
    flex: 1; padding: 10px 0; background: transparent;
    border: none; color: #fff; font-size: 13px; outline: none;
}

.users-search input::placeholder { color: #444; }

.users-table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.users-table { border: none; border-radius: 0; }

.users-pagination {
    display: flex; justify-content: center; align-items: center;
    gap: 14px; padding: 12px 16px; border-top: 1px solid #1e1e1e;
}

.pagination-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; background: #1a1a1a; border: 1px solid #2a2a2a;
    border-radius: 6px; color: #aaa; font-size: 13px; cursor: pointer; transition: all 0.15s;
}

.pagination-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.pagination-btn:hover:not(:disabled) { background: #222; color: #fff; }
.pagination-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.pagination-info { font-size: 12px; color: #555; }

/* ==================== MODALS ==================== */
.modal {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.75);
    display: none; align-items: center; justify-content: center;
    z-index: 1000; padding: 16px;
}

.modal.active { display: flex; }

.modal-content {
    background: #141414; border: 1px solid #1e1e1e; border-radius: 14px;
    padding: 28px; max-width: 480px; width: 100%;
}

.modal-icon {
    width: 52px; height: 52px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
}

.modal-icon svg { width: 24px; height: 24px; }
.modal-icon.danger { background: rgba(239, 68, 68, 0.12); color: #ef4444; }
.modal-icon.edit { background: rgba(59, 130, 246, 0.12); color: #3b82f6; }

.modal-content h3 { font-size: 18px; margin-bottom: 8px; text-align: center; }
.modal-content > p { color: #777; font-size: 13px; line-height: 1.5; margin-bottom: 20px; text-align: center; }

.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

/* Modal form overrides */
.modal-content .plate-form { gap: 14px; }
.modal-content .form-row { grid-template-columns: 1fr; }

/* ==================== STATUS MESSAGE ==================== */
.status-message { padding: 12px 16px; border-radius: 8px; margin-top: 16px; font-size: 13px; display: none; }
.status-message.success { background: rgba(34, 197, 94, 0.1); color: #22c55e; border: 1px solid rgba(34, 197, 94, 0.2); display: block; }
.status-message.error { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.2); display: block; }

/* ==================== MOBILE MENU ==================== */
.mobile-menu-btn {
    display: none; position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); left: 12px; z-index: 200;
    width: 42px; height: 42px; background: #141414; border: 1px solid #1e1e1e;
    border-radius: 8px; align-items: center; justify-content: center;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
}

.mobile-menu-btn svg { width: 22px; height: 22px; color: #fff; }

/* ==================== GLOBAL SVG CONSTRAINT ==================== */
svg { max-width: 100%; height: auto; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .charts-grid { grid-template-columns: 1fr; }
    .sidebar { width: 200px; }
    .main-content { margin-left: 200px; padding: 24px; }
}

@media (max-width: 768px) {
    .mobile-menu-btn { display: flex; }
    .sidebar { transform: translateX(-100%); width: 260px; box-shadow: none; }
    .sidebar.mobile-open { transform: translateX(0); box-shadow: 4px 0 30px rgba(0, 0, 0, 0.5); }
    .main-content { margin-left: 0; padding: 60px 16px 24px; }
    .section-header h2 { font-size: 20px; }

    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { padding: 14px; gap: 10px; }
    .stat-icon { width: 38px; height: 38px; }
    .stat-icon svg { width: 18px; height: 18px; }
    .stat-info h3 { font-size: 20px; }
    .stat-info p { font-size: 11px; }

    .users-stats-row { grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
    .users-stat-card { padding: 14px; gap: 10px; }
    .users-stat-icon { width: 38px; height: 38px; }
    .users-stat-icon svg { width: 18px; height: 18px; }
    .users-stat-number { font-size: 20px; }

    .upload-card { padding: 18px; }
    .form-row { grid-template-columns: 1fr; }

    .manage-toolbar { flex-direction: column; gap: 10px; }
    .search-box { max-width: none; width: 100%; }
    .filter-buttons { width: 100%; overflow-x: auto; }
    .filter-btn { flex-shrink: 0; }

    .plates-table th, .plates-table td,
    .users-table th, .users-table td { padding: 10px 8px; font-size: 12px; }
    .hide-mobile { display: none !important; }

    .charts-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .chart-period-selector { width: 100%; overflow-x: auto; padding-bottom: 4px; }
    .period-btn { flex-shrink: 0; }
    .chart-card canvas { height: 130px !important; }

    .users-table-header { flex-direction: column; }
    .users-search { max-width: none; width: 100%; }

    .modal-content { padding: 20px; max-width: 95%; }
    .modal-actions { flex-direction: column; }

    .bulk-actions { flex-direction: column; gap: 10px; }
    .bulk-actions .btn { width: 100%; }

    .custom-date-picker { flex-direction: column; gap: 10px; }
    .date-input-group { width: 100%; }
}

@media (max-width: 480px) {
    .main-content { padding: 56px 12px 20px; }
    .stats-grid { grid-template-columns: 1fr; gap: 8px; }
    .users-stats-row { grid-template-columns: 1fr; gap: 8px; }
    .charts-grid { gap: 10px; }
    .chart-card { padding: 12px; }
    .chart-card canvas { height: 110px !important; }
    .form-row.checkboxes { flex-direction: column; gap: 10px; }
    .btn { padding: 10px 16px; font-size: 13px; }
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .main-content { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
        .sidebar { padding-bottom: env(safe-area-inset-bottom); }
    }
}

@media (max-width: 768px) {
    .sidebar.mobile-open::after {
        content: ''; position: fixed; top: 0; left: 260px;
        right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5);
    }
}
