/* ── Sylectus Mini App — Premium Dark Theme ─────────────── */

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-card: #1c2128;
    --bg-elevated: #21262d;
    --border: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --go-green: #3fb950;
    --review-yellow: #d29922;
    --nogo-red: #f85149;
    --pickup-blue: #58a6ff;
    --deliver-green: #3fb950;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.6);
    --radius: 12px;
    --radius-sm: 8px;
    --nav-height: 60px;
    --header-height: 52px;
    --filter-height: 44px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Header ────────────────────────────────────────────── */
#app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-logo { font-size: 22px; }

.header-title {
    font-size: 18px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--deliver-green));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

.badge {
    background: var(--accent);
    color: var(--bg-primary);
    font-size: 12px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 24px;
    text-align: center;
}

.header-status {
    font-size: 10px;
    color: var(--go-green);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Filter Bar ────────────────────────────────────────── */
.filter-bar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    height: var(--filter-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    overflow-x: auto;
    z-index: 999;
    scrollbar-width: none;
}

.filter-bar::-webkit-scrollbar { display: none; }

.filter-chip {
    flex-shrink: 0;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.filter-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.filter-chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg-primary);
    font-weight: 600;
}

/* ── Main Content ──────────────────────────────────────── */
#main-content {
    position: fixed;
    top: calc(var(--header-height) + var(--filter-height));
    left: 0;
    right: 0;
    bottom: var(--nav-height);
    overflow: hidden;
}

.tab-content {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
}

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

/* ── Map ───────────────────────────────────────────────── */
#map {
    width: 100%;
    height: 100%;
}

/* Leaflet popup overrides */
.leaflet-popup-content-wrapper {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
    border: 1px solid var(--border) !important;
    box-shadow: var(--shadow-lg) !important;
}

.leaflet-popup-tip {
    background: var(--bg-card) !important;
    border-right: 1px solid var(--border) !important;
    border-bottom: 1px solid var(--border) !important;
}

.leaflet-popup-content {
    margin: 10px 14px !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
}

.popup-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

.popup-route {
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.popup-miles {
    color: var(--accent);
    font-weight: 600;
}

.popup-truck {
    color: var(--text-muted);
    font-size: 11px;
}

.popup-bid-btn {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 6px;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    text-align: center;
}

/* ── Loads List ─────────────────────────────────────────── */
.loads-list {
    padding: 8px 12px 20px;
}

.load-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 10px;
    transition: all 0.2s;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.load-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
}

.load-card.status-GO::before { background: var(--go-green); }
.load-card.status-REVIEW::before { background: var(--review-yellow); }
.load-card.status-NO_GO::before { background: var(--nogo-red); }

.load-card:active {
    transform: scale(0.98);
    border-color: var(--accent);
}

.load-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.load-id {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
}

.load-confidence {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
}

.conf-high { background: rgba(63,185,80,0.15); color: var(--go-green); }
.conf-med { background: rgba(210,153,34,0.15); color: var(--review-yellow); }
.conf-low { background: rgba(248,81,73,0.15); color: var(--nogo-red); }

.load-route {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 14px;
}

.route-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.route-dot.pickup { background: var(--pickup-blue); }
.route-dot.deliver { background: var(--deliver-green); }

.route-line {
    width: 2px;
    height: 16px;
    background: var(--border);
    margin-left: 3px;
}

.route-city {
    font-weight: 500;
}

.route-state {
    color: var(--text-secondary);
    font-weight: 400;
}

.load-meta {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--text-secondary);
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.load-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.load-broker {
    font-size: 12px;
    color: var(--text-muted);
    max-width: 60%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.load-bid {
    font-size: 14px;
    font-weight: 700;
    color: var(--go-green);
}

.load-notes {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    padding: 6px 8px;
    background: var(--bg-elevated);
    border-radius: 6px;
    line-height: 1.4;
    font-style: italic;
}

/* ── Order Detail ──────────────────────────────────────── */
.order-detail {
    padding: 16px;
}

.detail-back {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--accent);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 16px;
    background: none;
    border: none;
    font-family: inherit;
}

.detail-header {
    margin-bottom: 20px;
}

.detail-header h2 {
    font-size: 20px;
    margin-bottom: 4px;
}

.detail-status {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.detail-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 12px;
}

.detail-section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.detail-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.detail-value {
    font-size: 13px;
    font-weight: 600;
}

.detail-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.btn-bid {
    flex: 1;
    padding: 14px;
    border-radius: var(--radius-sm);
    border: none;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-bid-primary {
    background: var(--go-green);
    color: var(--bg-primary);
}

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

/* ── Stats ───────────────────────────────────────────── */
.stats-container {
    padding: 16px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.stat-card.wide {
    grid-column: span 2;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--deliver-green));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

/* ── Bottom Navigation ─────────────────────────────────── */
#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    font-family: inherit;
}

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

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

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

.nav-icon {
    font-size: 20px;
    transition: transform 0.2s;
}

.nav-label {
    font-size: 10px;
    font-weight: 600;
}

/* ── Loading ───────────────────────────────────────────── */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

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

/* ── Empty State ───────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.empty-state-text {
    font-size: 14px;
}

/* ── Search Settings ────────────────────────────────────── */
.search-settings-container {
    padding: 16px;
}
.search-title {
    font-size: 18px;
    margin-bottom: 16px;
    color: var(--accent);
}
.search-subtitle {
    font-size: 14px;
    margin: 20px 0 10px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
}
.form-group {
    margin-bottom: 14px;
}
.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.form-group input[type="text"],
.form-group input[type="number"] {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 10px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
}
.form-group input:focus {
    border-color: var(--accent);
    outline: none;
}
.form-group.row {
    display: flex;
    gap: 10px;
}
.form-group.row .col {
    flex: 1;
}
.autocomplete-wrapper {
    position: relative;
}
.autocomplete-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    z-index: 10;
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}
.autocomplete-results.active {
    display: block;
}
.autocomplete-item {
    padding: 10px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.autocomplete-item:last-child {
    border-bottom: none;
}
.autocomplete-item:hover {
    background: var(--bg-elevated);
}
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 0;
}
.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    margin-top: 16px;
    cursor: pointer;
}
.search-hint {
    margin-top: 12px;
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
}

/* ── Smart Slider ───────────────────────────────────────── */
.bid-slider-container {
    margin-top: 16px;
    padding: 16px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    text-align: center;
    border: 1px solid var(--border);
}
.bid-slider {
    width: 100%;
    margin: 10px 0;
    accent-color: var(--go-green);
}
.bid-slider-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--go-green);
    margin-bottom: 4px;
}
.bid-slider-hint {
    font-size: 11px;
    color: var(--text-muted);
}

/* ── Swipe-to-Action ────────────────────────────────────── */
.load-swipe-container {
    position: relative;
    overflow: hidden;
    margin-bottom: 10px;
    border-radius: var(--radius);
}
.swipe-bg {
    position: absolute;
    top: 0; bottom: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    font-weight: bold;
    font-size: 18px;
    z-index: 0;
    border-radius: var(--radius);
}
.swipe-left-bg {
    background: #471111; /* dark red */
    color: var(--nogo-red);
    justify-content: flex-end;
}
.swipe-right-bg {
    background: #11361c; /* dark green */
    color: var(--go-green);
    justify-content: flex-start;
}
.load-card {
    position: relative;
    z-index: 1;
    margin-bottom: 0 !important;
}

/* ── Scrollbar ─────────────────────────────────────────── */
.tab-content::-webkit-scrollbar {
    width: 4px;
}

.tab-content::-webkit-scrollbar-track {
    background: transparent;
}

.tab-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* ── Mobile / Telegram WebApp Adaptation ──────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
    #bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(var(--nav-height) + env(safe-area-inset-bottom));
    }
    #main-content {
        bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
    }
}

@media (max-width: 480px) {
    :root {
        --header-height: 48px;
        --filter-height: 40px;
        --nav-height: 56px;
    }

    .header-title { font-size: 16px; }
    .header-logo { font-size: 18px; }

    .filter-chip {
        padding: 5px 12px;
        font-size: 11px;
    }

    .load-card { padding: 12px; }
    .load-id { font-size: 12px; }
    .load-route { font-size: 13px; }
    .load-meta { font-size: 11px; }
    .load-footer { margin-top: 8px; padding-top: 8px; }
    .load-bid { font-size: 13px; }
    .load-broker { font-size: 11px; }

    .stat-value { font-size: 24px; }
    .stat-label { font-size: 11px; }
    .stat-card { padding: 12px; }

    .detail-header h2 { font-size: 18px; }
    .detail-section { padding: 12px; }
    .detail-label, .detail-value { font-size: 12px; }

    .popup-title { font-size: 13px; }
    .popup-route { font-size: 12px; }
    .popup-bid-btn { padding: 8px; font-size: 13px; }

    .nav-icon { font-size: 18px; }
    .nav-label { font-size: 9px; }
}

/* Touch feedback for cards */
@media (hover: none) {
    .load-card:active {
        background: var(--bg-elevated);
        transform: scale(0.98);
    }
    .filter-chip:active {
        transform: scale(0.95);
    }
    .nav-btn:active {
        background: rgba(88,166,255,0.1);
    }
}

/* Landscape orientation (typical for desktop testing) */
@media (min-width: 768px) {
    .loads-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding: 12px 16px;
    }
    .load-card { margin-bottom: 0; }
    .stats-container {
        grid-template-columns: repeat(3, 1fr);
    }
}
