/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --oppo-color: #1a8a3f;
    --oppo-bg: #ecfdf5;
    --oppo-border: #a7f3d0;
    --realme-color: #f59e0b;
    --realme-bg: #fffbeb;
    --realme-border: #fde68a;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --radius: 16px;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

body {
    padding-bottom: calc(80px + var(--safe-bottom));
}

/* ===== Bottom Navigation ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    justify-content: space-around;
    padding: 8px 0 calc(8px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    z-index: 1000;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.06);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 11px;
    font-family: inherit;
    padding: 6px 16px;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 12px;
}

.nav-btn i {
    font-size: 20px;
    transition: all 0.2s;
}

.nav-btn.active {
    color: var(--primary);
}

.nav-btn.active i {
    transform: scale(1.15);
}

.nav-btn:active {
    transform: scale(0.92);
}

/* ===== Header ===== */
.header {
    padding: 20px 16px 8px;
    text-align: center;
}

.header h1 {
    font-size: 22px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

/* ===== Tabs ===== */
.tab-content {
    display: none;
    padding: 0 12px 20px;
    animation: fadeIn 0.3s ease;
}

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

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

/* ===== Cards ===== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card h2 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--primary);
}

/* ===== Input ===== */
.input-label {
    display: block;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--text);
}

textarea {
    width: 100%;
    min-height: 160px;
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
    resize: vertical;
    transition: border-color 0.2s;
    background: #f8fafc;
    color: var(--text);
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
}

/* ===== Buttons ===== */
.btn-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: 0 4px 12px rgba(99,102,241,0.35);
}

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

.btn-success {
    background: linear-gradient(135deg, var(--success), #059669);
    color: #fff;
    box-shadow: 0 4px 12px rgba(16,185,129,0.35);
}

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

.btn-sm {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 8px;
}

/* ===== Brand Badges ===== */
.brand-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.brand-badge.oppo {
    background: var(--oppo-bg);
    color: var(--oppo-color);
    border: 1px solid var(--oppo-border);
}

.brand-badge.realme {
    background: var(--realme-bg);
    color: #b45309;
    border: 1px solid var(--realme-border);
}

.brand-badge.unknown {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

/* ===== Summary Cards ===== */
.summary-card.oppo-card {
    border-left: 4px solid var(--oppo-color);
}

.summary-card.realme-card {
    border-left: 4px solid var(--realme-color);
}

.summary-card.unknown-card {
    border-left: 4px solid var(--danger);
}

/* ===== Price Range Items ===== */
.price-range-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 6px;
    background: #f8fafc;
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.price-range-item:last-child {
    margin-bottom: 0;
}

.price-range-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.price-range-count {
    font-size: 15px;
    font-weight: 800;
    padding: 4px 12px;
    border-radius: 20px;
    min-width: 42px;
    text-align: center;
}

.count-zero {
    background: #f1f5f9;
    color: #94a3b8;
}

.count-has {
    background: linear-gradient(135deg, var(--primary), #a855f7);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99,102,241,0.3);
}

/* ===== Parsed Items ===== */
.parsed-item {
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 6px;
    background: #f8fafc;
    border: 1px solid var(--border);
    font-size: 13px;
}

.parsed-item .model-name {
    font-weight: 700;
    color: var(--text);
}

.parsed-item .model-color {
    color: var(--primary-light);
    font-size: 12px;
}

.parsed-item .model-imei {
    font-family: 'SF Mono', monospace;
    font-size: 11px;
    color: var(--text-secondary);
    word-break: break-all;
}

.parsed-item .model-date {
    font-size: 11px;
    color: var(--text-secondary);
}

.parsed-item .model-price {
    font-weight: 700;
    color: var(--success);
    font-size: 13px;
}

.parsed-item .model-no-price {
    font-weight: 600;
    color: var(--danger);
    font-size: 12px;
}

/* ===== Model Group ===== */
.model-group {
    margin-bottom: 8px;
}

.model-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-radius: 10px;
    background: #f8fafc;
    border: 1px solid var(--border);
    margin-bottom: 4px;
}

.model-group-name {
    font-weight: 600;
    font-size: 13px;
}

.model-group-count {
    font-weight: 800;
    font-size: 14px;
    color: var(--primary);
    background: rgba(99,102,241,0.1);
    padding: 2px 10px;
    border-radius: 12px;
}

.model-group-price {
    font-size: 12px;
    color: var(--success);
    font-weight: 600;
}

/* ===== Total Row ===== */
.total-row {
    margin-top: 12px;
    padding: 12px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), #a855f7);
    color: #fff;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 15px;
}

.grand-total-card {
    background: linear-gradient(135deg, #1e1b4b, #312e81);
    color: #fff;
    border: none;
}

.grand-total-card h2 {
    color: #fff;
}

.grand-total-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    font-size: 14px;
}

.grand-total-item:last-child {
    border-bottom: none;
    padding-top: 12px;
    font-size: 18px;
    font-weight: 800;
}

/* ===== Filter ===== */
.filter-row {
    display: flex;
    gap: 6px;
}

.filter-btn {
    flex: 1;
    padding: 8px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.filter-btn.active {
    border-color: var(--primary);
    background: rgba(99,102,241,0.08);
    color: var(--primary);
}

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

/* ===== Form ===== */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.form-row .form-input:nth-child(2) {
    grid-column: 1 / -1;
}

.form-input, .form-select {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 14px;
    background: #f8fafc;
    color: var(--text);
    transition: border-color 0.2s;
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
}

.form-row .btn-success {
    grid-column: 1 / -1;
}

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

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

/* ===== Table ===== */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: -4px;
    padding: 4px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    padding: 10px 8px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    white-space: nowrap;
    position: sticky;
    top: 0;
}

thead th:first-child {
    border-radius: 10px 0 0 0;
}

thead th:last-child {
    border-radius: 0 10px 0 0;
}

tbody td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:hover {
    background: rgba(99,102,241,0.04);
}

tbody tr:last-child td:first-child {
    border-radius: 0 0 0 10px;
}

tbody tr:last-child td:last-child {
    border-radius: 0 0 10px 0;
}

.action-btns {
    display: flex;
    gap: 4px;
    white-space: nowrap;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.modal-content h3 {
    font-size: 18px;
    margin-bottom: 16px;
    color: var(--primary);
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30,41,59,0.95);
    color: #fff;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    z-index: 3000;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    max-width: calc(100% - 40px);
    text-align: center;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Utilities ===== */
.hidden {
    display: none !important;
}

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

.center-text p {
    margin-top: 8px;
}

/* ===== Responsive ===== */
@media (max-width: 380px) {
    .header h1 {
        font-size: 19px;
    }
    
    .btn {
        padding: 8px 14px;
        font-size: 13px;
    }
    
    textarea {
        font-size: 11px;
        min-height: 140px;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 768px) {
    .tab-content {
        max-width: 700px;
        margin: 0 auto;
        padding: 0 20px 20px;
    }
    
    .bottom-nav {
        max-width: 500px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 20px 20px 0 0;
    }
    
    .form-row {
        grid-template-columns: 1fr 2fr 1fr auto;
    }
    
    .form-row .form-input:nth-child(2) {
        grid-column: auto;
    }
    
    .form-row .btn-success {
        grid-column: auto;
    }
}

/* ===== Loading Spinner ===== */
.loading {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.6s linear infinite;
}

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

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
