* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f172a;
    color: #e2e8f0;
    min-height: 100vh;
}

header {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    padding: 1.5rem 2rem;
    border-bottom: 1px solid #334155;
}

header h1 { font-size: 1.5rem; color: #38bdf8; }
.subtitle { color: #94a3b8; font-size: 0.85rem; margin-top: 0.25rem; }

main { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

/* Search Panel */
.search-panel {
    background: #1e293b;
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid #334155;
}

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.form-group {
    flex: 1;
    min-width: 120px;
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    color: #94a3b8;
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: #0f172a;
    border: 1px solid #475569;
    border-radius: 6px;
    color: #e2e8f0;
    font-size: 0.9rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #38bdf8;
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

button {
    padding: 0.6rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

#searchBtn {
    background: #38bdf8;
    color: #0f172a;
    font-weight: 600;
}
#searchBtn:hover { background: #7dd3fc; }
#searchBtn:disabled { background: #475569; cursor: wait; }

#resortBtn {
    background: #334155;
    color: #e2e8f0;
}
#resortBtn:hover:not(:disabled) { background: #475569; }
#resortBtn:disabled { opacity: 0.5; cursor: not-allowed; }

#exportBtn {
    background: #334155;
    color: #e2e8f0;
}
#exportBtn:hover:not(:disabled) { background: #475569; }
#exportBtn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Status */
.status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    margin-top: 1rem;
    background: #1e293b;
    border-radius: 8px;
    border: 1px solid #334155;
}

.spinner {
    width: 20px; height: 20px;
    border: 2px solid #475569;
    border-top-color: #38bdf8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.progress-bar-wrap {
    flex: 1;
    height: 4px;
    background: #334155;
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #38bdf8, #4ade80);
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 2px;
}

/* Summary */
.summary {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: #1e293b;
    border-radius: 8px;
    border: 1px solid #334155;
}

.stats { display: flex; gap: 2rem; }
.stat { font-size: 0.85rem; color: #94a3b8; }
.stat strong { color: #38bdf8; }

.errors {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #451a03;
    border-radius: 4px;
    color: #fbbf24;
    font-size: 0.8rem;
}

/* Results Table */
.results { margin-top: 1rem; overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead th {
    background: #1e293b;
    color: #94a3b8;
    padding: 0.6rem 0.5rem;
    text-align: left;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #334155;
    position: sticky;
    top: 0;
    z-index: 1;
}

tbody tr {
    border-bottom: 1px solid #1e293b;
    transition: background 0.15s;
}

tbody tr:nth-child(even) { background: rgba(30, 41, 59, 0.4); }

tbody tr:hover { background: #1e293b; }
tbody tr.zero-leave { background: rgba(22, 101, 52, 0.15); }
tbody tr.zero-leave:hover { background: rgba(22, 101, 52, 0.25); }

td {
    padding: 0.5rem;
    vertical-align: top;
}

.date-cell {
    white-space: nowrap;
    font-weight: 500;
}

.flight-cell {
    font-size: 0.8rem;
    line-height: 1.4;
}
.flight-cell .airline { color: #38bdf8; font-weight: 500; }
.flight-cell .route { color: #94a3b8; }
.flight-cell .price { color: #fbbf24; }

.price-cell {
    font-weight: 600;
    color: #4ade80;
    white-space: nowrap;
}

.score-cell {
    text-align: center;
}

.score-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}
.score-high { background: #166534; color: #4ade80; }
.score-mid { background: #854d0e; color: #fbbf24; }
.score-low { background: #7f1d1d; color: #fca5a5; }

.leave-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}
.leave-0 { background: #166534; color: #4ade80; }
.leave-low { background: #1e3a5f; color: #7dd3fc; }
.leave-high { background: #78350f; color: #fbbf24; }

.warn-icon { color: #fbbf24; cursor: help; }

.detail-btn, .book-btn {
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 4px;
    text-decoration: none;
    display: inline-block;
    margin: 1px;
}
.detail-btn { background: #334155; color: #94a3b8; }
.detail-btn:hover { background: #475569; color: #e2e8f0; }
.book-btn { background: #166534; color: #4ade80; font-weight: 500; }
.book-btn:hover { background: #15803d; color: #fff; }

.modal-book-btn {
    display: inline-block;
    padding: 0.75rem 2rem;
    background: linear-gradient(135deg, #166534, #15803d);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.2s;
}
.modal-book-btn:hover { background: linear-gradient(135deg, #15803d, #22c55e); transform: scale(1.02); }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: #1e293b;
    border: 1px solid #475569;
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 800px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    background: none;
    color: #94a3b8;
    font-size: 1.5rem;
    padding: 0;
}

.modal h3 { color: #38bdf8; margin-bottom: 1rem; }

.modal table { margin-top: 0.5rem; }
.modal td, .modal th { padding: 0.4rem 0.6rem; }

/* Autocomplete */
.autocomplete-wrap { position: relative; }

.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #1e293b;
    border: 1px solid #475569;
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 50;
}

.autocomplete-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 1px solid #0f172a;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: #334155;
}

.autocomplete-item .ac-label { color: #e2e8f0; }
.autocomplete-item .ac-zh { color: #94a3b8; font-size: 0.8rem; }
.autocomplete-item .ac-value { color: #38bdf8; font-size: 0.75rem; }

/* Mobile responsive */
@media (max-width: 768px) {
    main { padding: 0.75rem; }
    .search-panel { padding: 1rem; }
    .form-row { flex-direction: column; gap: 0.5rem; }
    .form-group { min-width: 100%; }
    .stats { flex-direction: column; gap: 0.5rem; }
    table { font-size: 0.75rem; }
    td, th { padding: 0.3rem 0.25rem; }
    .flight-cell { font-size: 0.7rem; }
    .modal-content { width: 95%; padding: 1rem; }
    header { padding: 1rem; }
    header h1 { font-size: 1.2rem; }
}

@media (max-width: 480px) {
    /* Hide less important columns on very small screens */
    table th:nth-child(5), table td:nth-child(5),
    table th:nth-child(9), table td:nth-child(9) { display: none; }
}

/* Sortable headers */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: #38bdf8; }

.hidden { display: none !important; }
