/* VeilWatch Spectra */
:root {
    --vw-blue: #023047;
    --vw-blue-light: #034a6e;
    --vw-orange: #f79520;
    --vw-orange-light: #fbb040;
    --bg: #f4f6f8;
    --card-bg: #ffffff;
    --border: #d9dfe7;
    --text: #1a2332;
    --text-muted: #6b7b8d;
    --danger: #c0392b;
    --success: #27ae60;
    --radius: 8px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

/* ---- Nav ---- */
.nav-bar {
    background: var(--vw-blue);
    color: #fff;
    padding: 0 2rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.12);
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
    white-space: nowrap;
}
.nav-links { display: flex; gap: 1.2rem; }
.nav-links a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.15s;
}
.nav-links a:hover { color: #fff; }

/* ---- Container ---- */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* ---- Upload ---- */
.upload-section h1 {
    margin: 0 0 0.25rem 0;
    font-size: 1.8rem;
}
.subtitle { color: var(--text-muted); margin: 0 0 1.5rem 0; }

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    background: var(--card-bg);
    margin-bottom: 1rem;
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--vw-orange);
    background: #fffbf5;
}
.upload-icon { color: var(--text-muted); margin-bottom: 0.5rem; }
.upload-text { margin: 0.5rem 0 0.25rem 0; font-size: 1rem; }
.upload-hint { color: var(--text-muted); font-size: 0.85rem; margin: 0; }

.preview {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}
.preview img {
    max-height: 100px;
    max-width: 100px;
    border-radius: 6px;
    object-fit: cover;
    border: 2px solid var(--vw-orange);
}

.form-row {
    margin-bottom: 1rem;
}
.form-row label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: var(--text-muted);
}
.form-row input[type="text"] {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    -webkit-appearance: none;
}
.form-row input[type="text"]:focus {
    outline: none;
    border-color: var(--vw-orange);
    box-shadow: 0 0 0 3px rgba(247,149,32,0.15);
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.65rem 1.4rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.btn-primary {
    background: var(--vw-blue);
    color: #fff;
}
.btn-primary:hover { background: var(--vw-blue-light); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }
.btn-sm {
    padding: 0.3rem 0.8rem;
    font-size: 0.8rem;
    background: var(--vw-blue);
    color: #fff;
    border-radius: 4px;
}
.btn-sm:hover { background: var(--vw-blue-light); }

/* ---- Spinner ---- */
.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Alerts ---- */
.alert {
    padding: 0.8rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-error {
    background: #fdecea;
    color: var(--danger);
    border: 1px solid #f5c6cb;
}

/* ---- Status badges ---- */
.status-badge {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.status-pending { background: #fef3c7; color: #92400e; }
.status-uploading, .status-searching, .status-saving, .status-downloading { background: #dbeafe; color: #1e40af; }
.status-complete { background: #d1fae5; color: #065f46; }
.status-error { background: #fdecea; color: var(--danger); }

/* ---- Data table (desktop) ---- */
.history-section { margin-top: 2.5rem; }
.history-section h2 { margin-bottom: 1rem; }
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.data-table th, .data-table td {
    padding: 0.65rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    white-space: nowrap;
}
.data-table th {
    background: var(--vw-blue);
    color: #fff;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.data-table tbody tr:hover { background: #f8fafc; }

/* ---- History cards (mobile) ---- */
.history-cards {
    display: none;
    flex-direction: column;
    gap: 0.75rem;
}
.history-card {
    display: block;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--text);
    transition: box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.history-card:active { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.history-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}
.history-card-id {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--vw-blue);
}
.history-card-label {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.history-card-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ---- Results page ---- */
.back-link {
    color: var(--vw-blue);
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    display: inline-block;
}
.back-link:hover { text-decoration: underline; }

.search-meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem;
    margin: 1rem 0;
}
.meta-left { min-width: 0; flex: 1; }
.meta-left h1 { margin: 0 0 0.5rem 0; font-size: 1.5rem; }
.meta-details {
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.uploaded-thumb {
    max-height: 100px;
    max-width: 100px;
    border-radius: var(--radius);
    object-fit: cover;
    border: 2px solid var(--border);
    flex-shrink: 0;
}

.result-count {
    font-size: 1rem;
    margin: 0 0 1.5rem 0;
    color: var(--text-muted);
}

/* ---- Results grid ---- */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.result-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: box-shadow 0.15s;
}
.result-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }

.result-image {
    width: 100%;
    height: 200px;
    background: #eee;
    display: flex;
    align-items: center;
    justify-content: center;
}
.result-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.no-image {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.result-info {
    padding: 0.75rem 1rem;
}
.score-badge {
    display: inline-block;
    background: var(--vw-orange);
    color: #fff;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 0.4rem;
}
.site-name {
    font-weight: 600;
    font-size: 0.85rem;
    margin: 0.25rem 0;
    color: var(--text);
}
.source-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--vw-blue);
    font-size: 0.8rem;
    word-break: break-all;
    text-decoration: none;
}
.source-link:hover { text-decoration: underline; }
.download-link {
    display: block;
    margin-top: 0.4rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-decoration: none;
}
.download-link:hover { color: var(--vw-blue); }

/* ---- Empty state ---- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

/* ---- Raw data section ---- */
.raw-data {
    margin-top: 2rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}
.raw-data summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ---- Footer ---- */
.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 3rem;
    border-top: 1px solid var(--border);
}

/* ---- Responsive: tablet ---- */
@media (max-width: 768px) {
    .container { padding: 1.25rem 1rem; }
    .results-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
    .upload-zone { padding: 2rem 1.5rem; }
    .upload-section h1 { font-size: 1.5rem; }
}

/* ---- Responsive: mobile ---- */
@media (max-width: 640px) {
    .container { padding: 1rem 0.75rem; }

    .nav-bar {
        padding: 0 0.75rem;
        height: 50px;
    }
    .nav-brand { font-size: 0.95rem; gap: 0.4rem; }
    .nav-brand svg { width: 22px; height: 22px; }
    .nav-links { gap: 0.8rem; }
    .nav-links a { font-size: 0.8rem; }

    .upload-section h1 { font-size: 1.3rem; }
    .upload-zone { padding: 1.5rem 1rem; }
    .upload-icon svg { width: 36px; height: 36px; }
    .upload-text { font-size: 0.9rem; }

    .btn-primary {
        width: 100%;
        justify-content: center;
        padding: 0.75rem;
    }
    .form-row input[type="text"] {
        font-size: 16px; /* prevents iOS zoom on focus */
    }

    /* Hide table, show cards on mobile */
    .table-wrap { display: none; }
    .history-cards { display: flex; }

    /* Results page */
    .results-grid { grid-template-columns: 1fr; }
    .search-meta { flex-direction: column; gap: 0.75rem; }
    .meta-left h1 { font-size: 1.2rem; }
    .uploaded-thumb { max-height: 80px; max-width: 80px; }
    .result-image { height: 180px; }
    .result-info { padding: 0.6rem 0.75rem; }
    .source-link { font-size: 0.75rem; }

    .footer { margin-top: 2rem; padding: 1rem; }
}

/* ---- Responsive: very small ---- */
@media (max-width: 380px) {
    .nav-brand span { display: none; }
    .container { padding: 0.75rem 0.5rem; }
    .results-grid { gap: 0.75rem; }
}
