/* Wine Cellar — Mobile-first responsive CSS */
:root {
    --wine-red: #722F37;
    --wine-dark: #4A1A20;
    --wine-light: #F5E6E8;
    --gold: #C9A84C;
    --bg: #FAFAFA;
    --card-bg: #FFFFFF;
    --text: #2D2D2D;
    --text-muted: #777;
    --border: #E5E5E5;
    --success: #4CAF50;
    --danger: #E53935;
    --radius: 10px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding-bottom: 80px;
}

/* Navbar */
.navbar {
    background: var(--wine-red);
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.nav-brand {
    color: white;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.15rem;
}
.nav-links { display: flex; gap: 4px; }
.nav-links a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s;
}
.nav-links a:hover, .nav-links a.active {
    background: rgba(255,255,255,0.2);
    color: white;
}

/* Container */
.container { max-width: 960px; margin: 0 auto; padding: 16px; }

/* Flash messages */
.flash-container { padding: 8px 16px; }
.flash {
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    font-size: 0.9rem;
}
.flash-success { background: #E8F5E9; color: #2E7D32; }
.flash-danger { background: #FFEBEE; color: #C62828; }
.flash-info { background: #E3F2FD; color: #1565C0; }

/* Stats bar */
.stats-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.stat { text-align: center; flex: 1; }
.stat-val { display: block; font-size: 1.4rem; font-weight: 700; color: var(--wine-red); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* Filters */
.filters { margin-bottom: 16px; }
.filter-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.filter-form select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    font-size: 0.9rem;
    flex: 1;
    min-width: 100px;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: all 0.2s;
}
.btn:hover { background: #f0f0f0; }
.btn-primary { background: var(--wine-red); color: white; border-color: var(--wine-red); }
.btn-primary:hover { background: var(--wine-dark); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { opacity: 0.85; }
.btn-outline { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-icon {
    width: 32px; height: 32px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: white;
    color: var(--text);
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.btn-icon:hover { background: var(--wine-light); }
.inline-form { display: inline; }

/* Wine grid */
.wine-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}
.wine-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: transform 0.15s;
    border-left: 4px solid var(--border);
}
.wine-card:hover { transform: translateY(-2px); }
.wine-card.red { border-left-color: #8B0000; }
.wine-card.white { border-left-color: #DAA520; }
.wine-card.rose { border-left-color: #FFB6C1; }
.wine-card.sparkling { border-left-color: #C0C0C0; }
.wine-card.dessert { border-left-color: #DEB887; }
.wine-card.fortified { border-left-color: #8B4513; }

.wine-card-link { text-decoration: none; color: inherit; display: flex; }
.wine-image {
    width: 80px;
    min-height: 100px;
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f8f8;
}
.wine-image img { width: 100%; height: 100%; object-fit: cover; }
.wine-image-placeholder { background: var(--wine-light); }
.wine-icon { font-size: 2rem; }

.wine-card-body { padding: 10px 12px; flex: 1; min-width: 0; }
.wine-name { font-size: 0.95rem; font-weight: 600; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wine-producer { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; }

.wine-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.wine-type {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.type-red { background: #FFEBEE; color: #8B0000; }
.type-white { background: #FFF8E1; color: #8D6E00; }
.type-rose { background: #FCE4EC; color: #C2185B; }
.type-sparkling { background: #F5F5F5; color: #666; }
.type-dessert { background: #FFF3E0; color: #BF360C; }
.type-fortified { background: #EFEBE9; color: #4E342E; }

.wine-vintage, .wine-country { font-size: 0.8rem; color: var(--text-muted); }
.wine-stats { display: flex; gap: 12px; font-size: 0.8rem; }
.wine-rating { color: var(--gold); font-weight: 600; }
.wine-price { color: var(--text-muted); }

.wine-card-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-top: 1px solid var(--border);
    background: #FAFAFA;
}
.qty-badge {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--wine-red);
    min-width: 30px;
}

/* Drinking window badges */
.drinking-window { margin-top: 4px; }
.dw {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}
.dw-ready { background: #E8F5E9; color: #2E7D32; }
.dw-early { background: #E3F2FD; color: #1565C0; }
.dw-past { background: #FFF3E0; color: #E65100; }

/* Wine detail */
.detail-header { margin-bottom: 12px; }
.back-link { color: var(--wine-red); text-decoration: none; font-size: 0.9rem; }
.back-link:hover { text-decoration: underline; }

.detail-top { display: flex; gap: 20px; }
.detail-image { width: 200px; flex-shrink: 0; border-radius: var(--radius); overflow: hidden; }
.detail-image img { width: 100%; display: block; }
.detail-info { flex: 1; }
.detail-info h1 { font-size: 1.5rem; margin-bottom: 4px; }
.detail-producer { font-size: 1rem; color: var(--text-muted); margin-bottom: 8px; }
.detail-badges { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.badge {
    font-size: 0.8rem;
    padding: 3px 10px;
    border-radius: 12px;
    background: #f0f0f0;
    color: var(--text);
}
.detail-grape { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 8px; }
.detail-numbers { display: flex; gap: 20px; margin: 12px 0; }
.detail-num { text-align: center; }
.num-val { display: block; font-size: 1.3rem; font-weight: 700; color: var(--wine-red); }
.num-label { font-size: 0.75rem; color: var(--text-muted); }
.detail-drinking { margin: 8px 0; font-size: 0.9rem; }
.detail-notes { margin: 8px 0; font-size: 0.9rem; color: var(--text-muted); }
.detail-links { display: flex; gap: 8px; margin-top: 8px; }
.detail-actions { display: flex; gap: 8px; margin: 16px 0; flex-wrap: wrap; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal.show { display: flex; }
.modal-content {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-content h3 { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }

/* Forms */
label { display: block; margin-bottom: 12px; font-size: 0.9rem; font-weight: 500; color: var(--text-muted); }
input[type="text"], input[type="number"], input[type="url"], select, textarea {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    margin-top: 4px;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--wine-red); box-shadow: 0 0 0 3px var(--wine-light); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

/* Star rating input — numbers 1-5, selected one highlighted */
.star-input { display: flex; gap: 4px; margin-top: 4px; }
.star-input input { display: none; }
.star-input label {
    cursor: pointer;
    font-size: 1.1rem;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #f0f0f0;
    color: var(--text-muted);
    margin: 0;
    font-weight: 600;
    transition: all 0.2s;
}
.star-input label:hover { background: var(--wine-light); color: var(--wine-red); }
.star-input input:checked + label { background: var(--gold); color: white; }

/* Scan section */
.scan-section {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.scan-buttons { display: flex; gap: 8px; margin-top: 12px; }
#scan-preview { margin-top: 12px; }
#scan-preview img { max-width: 200px; border-radius: 8px; }
.scan-status { margin-top: 8px; font-size: 0.9rem; }
.scan-status.scanning { color: var(--wine-red); }
.scan-status.success { color: var(--success); }
.scan-status.error { color: var(--danger); }

/* Pairing */
.pairing-form { margin-bottom: 24px; }
.food-input { font-size: 1.1rem !important; padding: 14px 16px !important; }
.pairing-results { display: flex; flex-direction: column; gap: 12px; }
.pairing-card {
    display: flex;
    gap: 16px;
    background: var(--card-bg);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.pairing-rank {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--wine-red);
    min-width: 40px;
    display: flex;
    align-items: center;
}
.pairing-body { flex: 1; }
.pairing-body h3 { margin-bottom: 4px; }
.pairing-body a { color: var(--wine-red); text-decoration: none; }
.pairing-reasoning { font-size: 0.9rem; color: var(--text-muted); margin-top: 4px; }
.pairing-score {
    display: inline-block;
    margin-top: 8px;
    padding: 3px 10px;
    background: var(--wine-light);
    color: var(--wine-red);
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* History */
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-entry {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.history-date { font-size: 0.8rem; color: var(--text-muted); min-width: 80px; flex-shrink: 0; }
.history-body a { color: var(--wine-red); text-decoration: none; }
.history-occasion { font-size: 0.85rem; margin-top: 4px; }
.history-notes { font-size: 0.85rem; color: var(--text-muted); margin-top: 2px; font-style: italic; }
.history-actions { display: flex; gap: 6px; margin-top: 6px; }
.history-edit-form { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.history-edit-form label { margin-bottom: 6px; }
.history-edit-form select, .history-edit-form input, .history-edit-form textarea { margin-top: 2px; }
.personal-rating { color: var(--gold); margin-left: 8px; }
.text-muted { color: var(--text-muted); }
.small { font-size: 0.7rem; padding: 1px 6px; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state p { margin-bottom: 16px; }

/* Utility */
.hidden { display: none !important; }
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* Pairing price range slider */
.price-range-section {
    margin: 12px 0;
}
.price-range-section > label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
}
#range-label {
    font-weight: 400;
    color: var(--wine-red);
}
.dual-range {
    position: relative;
    height: 36px;
}
.dual-range input[type="range"] {
    position: absolute;
    width: 100%;
    top: 6px;
    height: 0;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
    background: none;
    margin: 0;
    z-index: 2;
}
.dual-range input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 22px;
    width: 22px;
    border-radius: 50%;
    background: var(--wine-red);
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    pointer-events: auto;
    cursor: grab;
}
.dual-range input[type="range"]::-moz-range-thumb {
    height: 22px;
    width: 22px;
    border-radius: 50%;
    background: var(--wine-red);
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    pointer-events: auto;
    cursor: grab;
}
.range-track {
    position: absolute;
    top: 13px;
    left: 0;
    right: 0;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    z-index: 1;
}
.range-fill {
    position: absolute;
    height: 100%;
    background: var(--wine-red);
    border-radius: 3px;
}
.range-bounds {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Pairing loading state */
.pairing-loading {
    text-align: center;
    padding: 40px 20px;
}
.pairing-loading.hidden { display: none; }
.loading-animation { font-size: 3rem; margin-bottom: 16px; }
.wine-glass-spin {
    display: inline-block;
    animation: swirl 2s ease-in-out infinite;
}
@keyframes swirl {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(15deg); }
    75% { transform: rotate(-15deg); }
}
.loading-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--wine-red);
    margin-bottom: 4px;
}
.loading-sub {
    color: var(--text-muted);
    font-size: 0.9rem;
    transition: opacity 0.3s;
}

/* Search page */
.search-form { margin-bottom: 16px; }
.search-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.search-input {
    flex: 1;
    font-size: 1.05rem !important;
    padding: 12px 16px !important;
}
.search-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.search-filters select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    font-size: 0.9rem;
    min-width: 100px;
}
.buyable-toggle {
    display: flex !important;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    white-space: nowrap;
    cursor: pointer;
    margin: 0 !important;
}
.buyable-toggle input { display: inline; width: auto; margin: 0; }
.search-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.results-count { font-weight: 600; color: var(--text); }
.dn-wine-card .wine-card-link { cursor: default; }
.dn-wine-card .wine-card-actions { justify-content: flex-end; }

/* DN Score badge */
.dn-score {
    font-weight: 700;
    font-size: 0.8rem;
    color: #1565C0;
    background: #E3F2FD;
    padding: 2px 8px;
    border-radius: 12px;
}
.buyable-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 12px;
    background: #E8F5E9;
    color: #2E7D32;
    font-weight: 500;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
    padding: 12px 0;
}

/* Modal large */
.modal-large { max-width: 560px; max-height: 80vh; overflow-y: auto; }
.detail-section { margin: 12px 0; font-size: 0.9rem; line-height: 1.6; }
.detail-section p { margin-bottom: 4px; }

/* Quick food buttons */
.quick-foods {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin: 8px 0 16px 0;
}
.quick-food-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: white;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}
.quick-food-btn:hover {
    background: var(--wine-light);
    border-color: var(--wine-red);
    color: var(--wine-red);
}

/* Source toggle */
.pairing-options { margin-bottom: 16px; }
.source-toggle { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toggle-label { font-weight: 600; font-size: 0.9rem; margin: 0 !important; }
.toggle-btns { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.toggle-btn {
    padding: 8px 16px;
    border: none;
    background: white;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}
.toggle-btn:first-child { border-right: 1px solid var(--border); }
.toggle-btn.active {
    background: var(--wine-red);
    color: white;
    font-weight: 600;
}
.toggle-btn:hover:not(.active) { background: #f0f0f0; }

/* Norwegian wine type mappings */
.type-rodvin { background: #FFEBEE; color: #8B0000; }
.type-hvitvin { background: #FFF8E1; color: #8D6E00; }
.type-rosevin { background: #FCE4EC; color: #C2185B; }
.type-musserende-vin { background: #F5F5F5; color: #666; }

/* Drinking window badge in search results */
.dw-badge {
    font-size: 0.78em;
    color: #5a8a5a;
    background: #e8f5e8;
    padding: 2px 6px;
    border-radius: 4px;
}

/* DN Status page */
.dn-status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.status-card {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.status-card h2 {
    font-size: 1.1rem;
    margin: 0 0 12px 0;
    color: var(--wine-dark, #4A1A20);
}
.status-ok { color: #2a7; font-weight: 600; }
.status-warn { color: #c84; font-weight: 600; }
.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid #f0e8e9;
}
.stat-label { color: #888; }
.stat-value { font-weight: 500; }
.text-muted { color: #999; font-size: 0.9em; }

/* Progress bar */
.progress-bar {
    height: 8px;
    background: #f0e8e9;
    border-radius: 4px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--wine, #722F37);
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* Responsive */
@media (max-width: 600px) {
    .wine-grid { grid-template-columns: 1fr; }
    .detail-top { flex-direction: column; }
    .detail-image { width: 100%; max-height: 300px; }
    .form-grid { grid-template-columns: 1fr; }
    .nav-links a { padding: 6px 8px; font-size: 0.8rem; }
    .stats-bar { gap: 8px; padding: 10px; }
    .stat-val { font-size: 1.1rem; }
    .search-bar { flex-direction: column; }
    .search-filters { flex-direction: column; }
    .search-filters select { width: 100%; }
    .source-toggle { flex-direction: column; align-items: flex-start; }
}
