/* ---------------------------------------------------------------------------
   CSS Custom Properties
   --------------------------------------------------------------------------- */
:root {
    --primary:       #2563EB;
    --primary-dark:  #1D4ED8;
    --primary-light: #EFF6FF;
    --bg:            #F8FAFC;
    --surface:       #FFFFFF;
    --text:          #1E293B;
    --text-muted:    #64748B;
    --border:        #E2E8F0;
    --error:         #EF4444;
    --error-bg:      #FEF2F2;
    --success:       #10B981;
    --radius:        8px;
    --radius-lg:     12px;
    --shadow-sm:     0 1px 2px rgba(0,0,0,.06);
    --shadow:        0 4px 12px rgba(0,0,0,.08);
    --shadow-lg:     0 8px 32px rgba(0,0,0,.12);
    --nav-height:    56px;
}

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

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

a:hover {
    text-decoration: underline;
}

/* ---------------------------------------------------------------------------
   Nav
   --------------------------------------------------------------------------- */
.nav, .navbar {
    height: var(--nav-height);
    background: #111827;
    border-bottom: 1px solid #1F2937;
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.nav-brand {
    font-size: 1.125rem;
    font-weight: 700;
    color: #FFFFFF;
    letter-spacing: -0.01em;
    text-decoration: none;
}

.nav-brand:hover {
    color: var(--primary-light);
    text-decoration: none;
}

/* ---------------------------------------------------------------------------
   Main content
   --------------------------------------------------------------------------- */
.main-content {
    flex: 1;
}

/* ---------------------------------------------------------------------------
   Footer
   --------------------------------------------------------------------------- */
.footer {
    border-top: 1px solid var(--border);
    padding: 20px 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    background: var(--surface);
}

/* ---------------------------------------------------------------------------
   Container
   --------------------------------------------------------------------------- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* ---------------------------------------------------------------------------
   Card
   --------------------------------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 32px;
}

/* ---------------------------------------------------------------------------
   Hero
   --------------------------------------------------------------------------- */
.hero {
    min-height: calc(100vh - var(--nav-height) - 61px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    background: linear-gradient(160deg, #F0F7FF 0%, var(--bg) 60%);
}

.hero-content {
    width: 100%;
    max-width: 560px;
    text-align: center;
}

.hero-badge {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 4px 12px;
    border-radius: 999px;
    margin-bottom: 20px;
    border: 1px solid #BFDBFE;
}

.hero-title {
    font-size: clamp(2rem, 5vw, 2.75rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.15;
    color: var(--text);
    margin-bottom: 16px;
}

.hero-subtitle {
    font-size: 1.0625rem;
    color: var(--text-muted);
    line-height: 1.65;
    margin-bottom: 36px;
}

.hero-subtitle strong {
    color: var(--text);
    font-weight: 600;
}

/* ---------------------------------------------------------------------------
   Form card
   --------------------------------------------------------------------------- */
.form-card {
    text-align: left;
    margin-bottom: 40px;
}

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

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

.form-input {
    width: 100%;
    padding: 12px 14px;
    font-size: 1rem;
    font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
    letter-spacing: 0.04em;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
    background: var(--surface);
}

.form-input--error {
    border-color: var(--error) !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
}

.form-input--valid {
    border-color: var(--success);
}

.form-hint {
    display: block;
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 5px;
}

.form-error-inline {
    display: none;
    font-size: 0.8125rem;
    color: var(--error);
    margin-top: 5px;
}

/* ---------------------------------------------------------------------------
   Error message (server-side)
   --------------------------------------------------------------------------- */
.error-message {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid #FECACA;
    border-radius: var(--radius);
    padding: 12px 14px;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 20px;
}

.error-message svg {
    flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
   Button
   --------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    width: 100%;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
    text-decoration: none;
    color: #fff;
}

/* ---------------------------------------------------------------------------
   How it works
   --------------------------------------------------------------------------- */
.how-it-works {
    text-align: left;
}

.how-title {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 16px;
    text-align: center;
}

.steps {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.step {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.step-number {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 700;
    border: 1px solid #BFDBFE;
}

.step-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.step-heading {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
}

.step-desc {
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ---------------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------------- */
@media (max-width: 600px) {
    .hero {
        padding: 32px 16px;
        align-items: flex-start;
    }

    .card {
        padding: 24px 20px;
    }

    .nav {
        padding: 0 16px;
    }
}

/* ---------------------------------------------------------------------------
   Analysis Dashboard
   --------------------------------------------------------------------------- */
.card {
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    margin-bottom: 24px;
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

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

.btn-secondary:hover {
    background: #E2E8F0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.btn {
    transition: all 0.2s ease;
}

/* Status Card */
.status-card {
    border-left: 6px solid var(--border);
}
.status-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.receipt-number {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}
.status-title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 8px;
    color: var(--text);
}
.status-desc {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}
.status-meta {
    display: flex;
    gap: 16px;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}
.muted, .cache-info {
    color: var(--text-muted);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.badge-type { background: #E0E7FF; color: #1E40AF; border-color: #BFDBFE; }
.badge-you { background: #FCE7F3; color: #3730A3; border-color: #C7D2FE; }

/* Status variants */
.status-received { border-left-color: #3B82F6; }
.status-approved { border-left-color: var(--success); }
.status-processing { border-left-color: #14B8A6; }
.status-invalid { border-left-color: #F43F5E; }
.status-rejected { border-left-color: #EF4444; }

/* Stats Bar */
.stats-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    justify-content: space-between;
    padding: 24px 32px;
}
.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    min-width: 120px;
    text-align: center;
}
.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1.2;
}
.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: 4px;
}

/* Charts Grid */
.charts-grid, .charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}
.chart-card {
    margin-bottom: 0;
}
.chart-card h3 {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text);
}
canvas#status-chart, canvas#type-chart {
    height: 300px !important;
    width: 100% !important;
}

/* Range Blocks Grid */
.range-blocks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.range-block {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: 0.2s ease;
}
.range-block:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}
.range-block-label {
    font-weight: 700;
    font-size: 0.875rem;
    color: var(--text);
}
.range-block-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
}
.range-valid { color: var(--success); font-weight: 600; }
.range-invalid { color: var(--error); font-weight: 600; }
.range-block-total {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.range-block-breakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.status-chip {
    font-size: 0.625rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: #E2E8F0;
    color: #334155;
    font-weight: 600;
    text-transform: uppercase;
}

/* Cases Table */
.table-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}
#case-filter, .filter-input {
    width: 100%;
    max-width: 400px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    outline: none;
    transition: 0.2s ease;
}
#case-filter:focus, .filter-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.row-count {
    font-size: 0.875rem;
    color: var(--text-muted);
}
.table-wrapper {
    overflow-x: auto;
}
table.cases-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.875rem;
}
table.cases-table th {
    padding: 12px 16px;
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.75rem;
}
table.cases-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
table.cases-table tbody tr {
    transition: 0.2s ease;
}
table.cases-table tbody tr:hover {
    background: var(--bg);
}
.sortable {
    cursor: pointer;
    user-select: none;
    transition: 0.2s ease;
}
.sortable:hover {
    color: var(--primary);
}
.sort-icon {
    font-size: 0.75rem;
    margin-left: 4px;
    opacity: 0.5;
}
.status-badge {
    display: inline-flex;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #F1F5F9;
    color: #475569;
}
.case-number {
    font-family: "SF Mono", "Fira Code", monospace;
    font-weight: 600;
    color: var(--primary-dark);
}

/* Progress Section */
.scanning-section, .scan-progress {
    text-align: center;
    padding: 48px 24px;
}
.progress-container, .progress-bar-outer {
    width: 100%;
    max-width: 600px;
    height: 12px;
    background: var(--border);
    border-radius: 9999px;
    margin: 24px auto;
    overflow: hidden;
}
.progress-bar, .progress-bar-fill, .progress-bar-inner {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s ease;
}

/* Footer improvements */
.footer {
    background: #111827;
    color: #9CA3AF;
    padding: 32px 24px;
    border-top: none;
}

@media (max-width: 768px) {
    .charts-grid, .charts-row {
        grid-template-columns: 1fr;
    }
    .stats-bar {
        flex-direction: column;
        gap: 16px;
    }
    .range-blocks-grid {
        grid-template-columns: 1fr;
    }
}

/* ---------------------------------------------------------------------------
   Demo Data Banner
   --------------------------------------------------------------------------- */
.demo-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
    border: 1px solid #F59E0B;
    border-radius: var(--radius-lg);
    padding: 14px 20px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.demo-banner-icon {
    flex-shrink: 0;
    font-size: 1.25rem;
}

.demo-banner-text {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    color: #92400E;
    line-height: 1.4;
}

.demo-banner-text strong {
    font-weight: 700;
}

.demo-banner-dismiss {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid #D97706;
    border-radius: var(--radius);
    color: #92400E;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 6px 12px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.demo-banner-dismiss:hover {
    background: #FDE68A;
    border-color: #B45309;
}
