:root { 
    --pinot: #801f42; --pink: #c9508c; --mocha: #292929; --black: #000000; --white: #FFFFFF;
    --dark-grey: #71746B; --light-cream: #ECEDE2; --cream: #E2E4D3; --offwhite: #F5F6F0; --grey: #B8BFAC; --light-grey: #D4D8C6;
    --trr-red: #E31837; --trr-green: #2ecc71; --trr-blue: #004b87;
}

.f-walbaum { font-family: 'Playfair Display', serif; font-weight: 400; text-transform: none; }
.f-avenir { font-family: 'Inter', sans-serif; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.f-georgia { font-family: 'Georgia', serif; }

body { margin: 0; font-family: 'Georgia', serif; background: var(--offwhite); height: 100vh; display: flex; flex-direction: column; overflow: hidden; color: var(--mocha); }

#sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 4999; }
.close-sidebar-btn { display: none; text-align: right; background: transparent; border: none; font-size: 24px; color: var(--mocha); cursor: pointer; padding: 0; margin-bottom: 15px; width: 100%; }

/* Login page */
.login-page-bg { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: rgba(41,41,41,0.97); padding: 20px; box-sizing: border-box; }
.login-card { background: white; padding: 40px; border-radius: 4px; color: var(--mocha); text-align: center; width: 100%; max-width: 450px; border-top: 10px solid var(--pinot); box-sizing: border-box; }

header { background: var(--black); color: var(--white); padding: 10px 25px; display: flex; align-items: center; justify-content: space-between; z-index: 2000; border-bottom: 3px solid var(--pinot); gap: 15px; flex-shrink: 0; flex-wrap: wrap; }
header h1 { font-family: 'Playfair Display', serif; margin: 0; font-size: 20px; white-space: nowrap; }

.header-controls { display: flex; align-items: center; gap: 15px; flex: 1; min-width: 250px; }
#global-search { flex: 1; width: 100%; padding: 8px 15px; border-radius: 2px; border: 1px solid var(--dark-grey); font-size: 13px; outline: none; }
#mobile-filter-btn { display: none; background: var(--pinot); color: var(--white); border: none; height: 33px; padding: 0 15px; border-radius: 2px; cursor: pointer; white-space: nowrap; }

.tabs { display: flex; gap: 5px; align-items: center; }
.tabs button { background: transparent; border: none; color: var(--white); padding: 8px 15px; cursor: pointer; font-family: 'Inter', sans-serif; font-weight: 500; font-size: 10px; text-transform: uppercase; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--pinot); border-bottom: 2px solid var(--pinot); }

.tab-user-menu { position: relative; }
.tab-user-menu > button { background: transparent; border: none; color: var(--white); padding: 8px 15px; cursor: pointer; font-family: 'Inter', sans-serif; font-weight: 500; font-size: 10px; text-transform: uppercase; border-bottom: 2px solid transparent; }
.tab-user-menu > button.active { color: var(--pinot); border-bottom: 2px solid var(--pinot); }
.tab-user-dropdown { display: none; position: absolute; right: 0; top: 100%; background: var(--black); border: 1px solid var(--dark-grey); border-top: 2px solid var(--pinot); min-width: 140px; z-index: 3000; }
.tab-user-dropdown.open { display: block; }
.tab-user-dropdown div, .tab-user-dropdown button { display: block; width: 100%; padding: 10px 15px; font-family: 'Inter', sans-serif; font-size: 10px; font-weight: 500; text-transform: uppercase; color: var(--white); background: transparent; border: none; text-align: left; cursor: pointer; box-sizing: border-box; }
.tab-user-dropdown div:hover, .tab-user-dropdown button:hover { background: var(--mocha); }

main { display: flex; flex: 1; overflow: hidden; position: relative; }
aside { width: 350px; background: var(--light-cream); padding: 20px; border-right: 1px solid var(--light-grey); overflow-y: auto; z-index: 1000; display: flex; flex-direction: column; box-sizing: border-box; }
#view-container { flex: 1; padding: 20px; background: var(--offwhite); overflow-y: auto; position: relative; }

.view { display: none !important; width: 100%; height: 100%; flex-direction: column; }
.view.active { display: flex !important; }

.bucket-toggle { background: var(--white); padding: 12px; border: 1px solid var(--light-grey); display: flex; align-items: center; gap: 12px; margin-bottom: 8px; cursor: pointer; font-family: 'Inter', sans-serif; font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--mocha); border-radius: 2px; }
.bucket-toggle input { width: 22px; height: 22px; cursor: pointer; accent-color: var(--pinot); }

.ai-matrix { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; background: var(--white); padding: 15px; border: 1px solid var(--light-grey); margin-bottom: 15px;}

.section { margin-top: 15px; margin-bottom: 12px; }
label { display: block; font-family: 'Inter', sans-serif; font-size: 9px; font-weight: 700; color: var(--dark-grey); text-transform: uppercase; margin-bottom: 4px; }
select, input[type="number"], input[type="text"], input[type="url"], textarea { width: 100%; padding: 10px; border: 1px solid var(--light-grey); font-size: 12px; box-sizing: border-box; background: var(--white); font-family: 'Georgia', serif; }

table { width: 100%; border-collapse: collapse; background: var(--white); border: 1px solid var(--light-grey); table-layout: fixed; margin-bottom: 50px; }
th { text-align: left; padding: 10px; background: var(--cream); color: var(--mocha); font-family: 'Inter', sans-serif; font-size: 9px; text-transform: uppercase; border-bottom: 2px solid var(--dark-grey); cursor: pointer; position: relative; vertical-align: top; }
th:after { content: ' \25B4\25BE'; font-size: 8px; color: var(--dark-grey); margin-left: 5px; opacity: 0.2; }
th.sort-asc:after { content: ' \25B4'; opacity: 1; color: var(--pinot); }
th.sort-desc:after { content: ' \25BE'; opacity: 1; color: var(--pinot); }
td { padding: 8px 10px; border-bottom: 1px solid #eee; font-size: 13px; line-height: 1.2; white-space: nowrap; overflow: visible; vertical-align: middle; }

.price-est { color: var(--dark-grey); font-style: italic; }
.price-act { color: var(--black); font-weight: bold; }

.wine-cell { display: flex; justify-content: space-between; align-items: center; width: 100%; min-width: 0; }
.wine-link { font-family: 'Playfair Display', serif; color: var(--black); text-decoration: none; font-size: 15px; cursor: pointer; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 8px; }
.accolade-container { display: flex; gap: 2px; flex-shrink: 0; align-items: center; }
.accolade-icon { height: 20px; width: auto; vertical-align: middle; }

.actions-cell { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.btn { height: 28px; padding: 0 10px; border: 1px solid var(--dark-grey); font-family: 'Inter', sans-serif; font-size: 9px; font-weight: 700; cursor: pointer; text-transform: uppercase; border-radius: 2px; display: inline-flex; align-items: center; justify-content: center; }
.btn-taste { background: var(--pinot); color: var(--white); border: none; }
.btn-tasted { background: var(--trr-green); color: var(--white); border: none; }
.btn-review { background: var(--mocha); color: var(--white); border: none; }
.btn-share { background: var(--trr-blue); color: var(--white); border: none; }
.btn-upgrade { background: var(--trr-red); color: white; border: none; padding: 10px 20px; height: auto; font-size: 11px; margin-top: 10px; letter-spacing: 1px; }
.btn-reset { background: var(--mocha); color: var(--white); width: 100%; height: 44px; margin-top: auto; }
.btn-book.is-saved { background: var(--pink) !important; color: var(--white) !important; border: none; }

.drop-save { position: relative; display: inline-block; overflow: visible; }
.drop-content { display: none; position: absolute; background: var(--white); min-width: 140px; box-shadow: 0 8px 16px rgba(0,0,0,0.15); z-index: 9000; border: 1px solid var(--light-grey); right: 0; top: 100%; }
.drop-save:hover .drop-content { display: block; }
.drop-content div { padding: 10px 12px; font-family: 'Inter', sans-serif; font-size: 10px; text-transform: uppercase; cursor: pointer; border-bottom: 1px solid var(--offwhite); color: var(--mocha); }
.drop-content div:hover { background: var(--light-cream); color: var(--pinot); }

#modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); z-index: 6000; align-items: center; justify-content: center; padding: 15px; box-sizing: border-box; }
.card { background: var(--white); width: 100%; max-width: 550px; border-top: 10px solid var(--pinot); padding: 40px; border-radius: 2px; max-height: 90vh; overflow-y: auto; position: relative; box-sizing: border-box; }
.card h2 { font-family: 'Playfair Display', serif; margin: 0 0 15px 0; font-size: 28px; border-bottom: 1px solid var(--light-grey); padding-bottom: 10px; color: var(--black); }
.card label { font-family: 'Inter', sans-serif; font-size: 10px; color: var(--dark-grey); text-transform: uppercase; margin-top: 20px; display: block; font-weight: 700; letter-spacing: 1px; }
.card p { font-family: 'Georgia', serif; font-size: 15px; line-height: 1.7; margin: 8px 0; color: var(--mocha); }

.admin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 20px; }
.stat-box { background: white; padding: 20px; border: 1px solid var(--light-grey); border-top: 4px solid var(--pinot); }
.stat-val { font-size: 32px; font-weight: bold; color: var(--pinot); margin: 10px 0; }

.editable-field { border: 1px dashed var(--pink); background: #fdf5f8; padding: 10px; cursor: text; border-radius: 2px; min-height: 40px; margin-top: 5px; outline: none; }

#map { flex: 1; width: 100%; min-height: 400px; border: 1px solid var(--light-grey); border-radius: 4px; background: #e5e5e5; z-index: 1; }

.ai-loader { display:flex; flex-direction:column; align-items:center; justify-content:center; padding: 80px 20px; text-align:center; }
.spinner { border: 4px solid rgba(0,0,0,0.1); width: 40px; height: 40px; border-radius: 50%; border-left-color: var(--pinot); animation: spin 1s linear infinite; margin-bottom: 20px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* AI VIEW TOGGLE */
.ai-view-toggle {
    display: flex;
    gap: 0;
    background: var(--cream);
    border: 1px solid var(--light-grey);
    border-radius: 3px;
    padding: 3px;
    width: fit-content;
}
.ai-view-toggle button {
    background: transparent;
    border: none;
    padding: 7px 16px;
    font-family: 'Inter', sans-serif;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border-radius: 2px;
    color: var(--dark-grey);
    transition: all 0.15s;
}
.ai-view-toggle button.active {
    background: var(--pinot);
    color: var(--white);
}

/* PAIRING CHIPS */
.pairing-row td {
    padding: 4px 10px 10px 10px;
    border-bottom: 1px solid var(--light-grey);
    background: #fdf8fa;
}
.pairing-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
}
.pairing-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 20px;
    font-family: 'Inter', sans-serif;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}
.chip-strong { background: #e8f5e9; color: #2e7d32; border: 1px solid #c8e6c9; }
.chip-workable { background: #fff8e1; color: #f57f17; border: 1px solid #ffe082; }
.chip-avoid { background: #fce4ec; color: #c62828; border: 1px solid #f8bbd0; }
.pairing-label {
    font-family: 'Inter', sans-serif;
    font-size: 8px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--dark-grey);
    margin-right: 2px;
}

.pairing-prose-card {
    background: var(--offwhite);
    border-left: 3px solid var(--pinot);
    border-radius: 2px;
    padding: 14px 16px;
    margin-bottom: 12px;
}
.pairing-prose-card.focus {
    background: #f9f0f3;
    border-left-color: var(--pinot);
}
.pairing-prose-dish {
    font-family: 'Inter', sans-serif;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--pinot);
    margin-bottom: 6px;
}
.pairing-prose-text {
    font-family: 'Georgia', serif;
    font-size: 13px;
    line-height: 1.75;
    color: var(--mocha);
}

/* PAIRING DRAWER */
#pairing-drawer {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    height: 100%;
    background: var(--white);
    border-left: 3px solid var(--pinot);
    z-index: 5500;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    transition: right 0.3s ease;
    overflow: hidden;
}
#pairing-drawer.open { right: 0; }
.drawer-header {
    background: var(--mocha);
    color: var(--white);
    padding: 20px 25px;
    flex-shrink: 0;
}
.drawer-header h3 {
    font-family: 'Playfair Display', serif;
    margin: 0 0 4px 0;
    font-size: 18px;
    line-height: 1.3;
}
.drawer-header p {
    margin: 0;
    font-family: 'Inter', sans-serif;
    font-size: 9px;
    text-transform: uppercase;
    color: var(--grey);
    letter-spacing: 0.05em;
}
.drawer-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.drawer-body { flex: 1; overflow-y: auto; padding: 20px 25px; }
.drawer-section { margin-bottom: 20px; }
.drawer-section-title {
    font-family: 'Inter', sans-serif;
    font-size: 8px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--dark-grey);
    border-bottom: 1px solid var(--light-grey);
    padding-bottom: 6px;
    margin-bottom: 10px;
}
.drawer-dish {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 7px 0;
    border-bottom: 1px solid var(--offwhite);
    font-family: 'Georgia', serif;
    font-size: 13px;
    color: var(--mocha);
}
.drawer-dish:last-child { border-bottom: none; }
.drawer-dish-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }
.drawer-score-row {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}
.drawer-score-pill {
    padding: 4px 12px;
    border-radius: 2px;
    font-family: 'Inter', sans-serif;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
}

/* MENU MATCH VIEW */
#ai-menu-view { display: none; }
.menu-dish-card {
    background: var(--white);
    border: 1px solid var(--light-grey);
    border-left: 4px solid var(--pinot);
    margin-bottom: 12px;
    border-radius: 2px;
    overflow: visible;
    position: relative;
}
.menu-dish-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: var(--white);
    cursor: pointer;
    user-select: none;
}
.menu-dish-header:hover { background: var(--offwhite); }
.dish-emoji { font-size: 20px; flex-shrink: 0; }
.dish-name {
    font-family: 'Playfair Display', serif;
    font-size: 16px;
    flex: 1;
    color: var(--black);
}
.dish-category {
    font-family: 'Inter', sans-serif;
    font-size: 8px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--dark-grey);
    background: var(--cream);
    padding: 3px 8px;
    border-radius: 2px;
}
.dish-match-count {
    font-family: 'Inter', sans-serif;
    font-size: 9px;
    font-weight: 700;
    color: var(--pinot);
}
.dish-chevron {
    font-size: 10px;
    color: var(--grey);
    transition: transform 0.2s;
}
.menu-dish-card.expanded .dish-chevron { transform: rotate(180deg); }
.dish-wines {
    display: none;
    border-top: 1px solid var(--light-grey);
    background: #fdf8fa;
    overflow: visible;
}
.menu-dish-card.expanded .dish-wines { display: block; }
.dish-wine-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--offwhite);
}
.dish-wine-row:last-child { border-bottom: none; }
.dish-wine-match-badge {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.badge-strong { background: #2e7d32; }
.badge-workable { background: #f57f17; }
.dish-wine-name {
    font-family: 'Playfair Display', serif;
    font-size: 13px;
    flex: 1;
    color: var(--mocha);
}
.dish-wine-meta {
    display: flex;
    gap: 6px;
    align-items: center;
}
.dish-wine-score {
    font-family: 'Inter', sans-serif;
    font-size: 9px;
    font-weight: 700;
    background: var(--mocha);
    color: white;
    padding: 2px 6px;
    border-radius: 2px;
}
.dish-wine-price {
    font-family: 'Inter', sans-serif;
    font-size: 9px;
    color: var(--dark-grey);
    font-weight: 700;
}
.dish-wine-match-label {
    font-family: 'Inter', sans-serif;
    font-size: 8px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--dark-grey);
}

/* AI HEADER SECTION LABEL */
.ai-section-header {
    font-family: 'Inter', sans-serif;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--white);
    background: var(--mocha);
    padding: 8px 12px;
    margin: 15px 0 0 0;
}

/* WINE NAME CLICKABLE IN AI TABLE */
.wine-link-drawer {
    font-family: 'Playfair Display', serif;
    color: var(--pinot);
    font-size: 15px;
    cursor: pointer;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 8px;
    text-decoration: underline dotted;
}
.wine-link-drawer:hover { color: var(--black); }

/* RESPONSIVE */
@media (max-width: 1024px) {
    header { padding: 10px 15px; }
    #mobile-filter-btn { display: inline-flex; }
    aside { position: fixed; top: 0; left: -350px; height: 100%; z-index: 5000; transition: left 0.3s ease; box-shadow: 2px 0 15px rgba(0,0,0,0.3); }
    aside.open { left: 0; }
    #sidebar-overlay.open { display: block; }
    .close-sidebar-btn { display: block; }
    #pairing-drawer { width: 100%; right: -100%; }
}

@media (max-width: 768px) {
    header h1 { font-size: 16px; width: 100%; text-align: center; }
    .header-controls { width: 100%; }
    .tabs { position: fixed; bottom: 0; left: 0; width: 100%; background: var(--black); justify-content: space-around; padding: 5px 0; overflow-x: auto; white-space: nowrap; z-index: 4500; border-top: 1px solid var(--mocha); }
    .tabs button { flex: 1; padding: 12px 5px; font-size: 9px; border-bottom: none !important; border-top: 2px solid transparent; }
    .tabs button.active { border-top: 2px solid var(--pinot); color: var(--pinot); }
    body { padding-bottom: 50px; }
    #view-container { padding: 10px; }
    .card { padding: 20px; }
    .admin-grid { grid-template-columns: 1fr; }

    table { border: none; background: transparent; }
    thead { display: none; }
    tr { display: flex; flex-direction: column; background: var(--white); margin-bottom: 15px; border: 1px solid var(--light-grey); border-radius: 4px; padding: 12px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
    td { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--offwhite); font-size: 13px; text-align: right; white-space: normal; word-break: break-word; }
    td:last-child { border-bottom: none; }
    td::before { content: attr(data-label); font-family: 'Inter', sans-serif; font-size: 9px; text-transform: uppercase; font-weight: 700; color: var(--dark-grey); text-align: left; padding-right: 15px; }
    td[data-label="Wine"] { flex-direction: column; align-items: flex-start; border-bottom: 2px solid var(--pinot); padding-bottom: 10px; margin-bottom: 5px; }
    td[data-label="Wine"]::before { display: none; }
    .wine-cell { width: 100%; flex-direction: column; align-items: flex-start; gap: 8px; }
    .wine-link { font-size: 16px; white-space: normal; }
    .actions-cell { justify-content: flex-end; width: 100%; }
}

@media print {
    body * { visibility: hidden; }
    #modal, #modal-container, #modal-container * { visibility: visible; }
    #modal { position: absolute; left: 0; top: 0; width: 10.5cm; height: 14.8cm; background: white; display: block; }
    .card { width: 100%; border: none; padding: 0; box-shadow: none; }
    .btn { display: none !important; }
}
