:root {
    --brand: #35B69B;
    --brand-dark: #173241;
    --bg: #f5f7fa;
    --card: #ffffff;
    --muted: #6b7280;
    --border: #e5e7eb;
    --success: #10b981;
    --error-bg: #fff1f2;
    --error-border: #fecdd3;
    --error-text: #b91c1c;
}

* { box-sizing: border-box; }

body {
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto;
    background: var(--bg);
    margin: 0;
    color: #111827;
}

/* Global Header Styles */
.main-header {
    background: linear-gradient(135deg, #35B69B, #7b6bff);
    color: #fff;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 12px 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.header-logo {
    height: 40px;
    width: auto;
    display: block;
}

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

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

.header-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
}

.pill {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.pill-version {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.login-branding .pill-version {
    background: #e2e8f0;
    color: var(--brand-dark);
    border: 1px solid var(--border);
}

.pill-test {
    background: #f59e0b;
    color: #fff;
}

.pill-submitted {
    background: #e0f2fe;
    color: #0369a1;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    border: 1px solid #bae6fd;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.history-meta-item .pill-submitted i {
    color: #0369a1;
    width: auto;
}


.header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 8px;
    transition: all 0.2s;
}

.nav-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.nav-btn.active {
    color: #fff;
    background: var(--brand);
}

.header-nav {
    grid-area: toggle;
    display: flex;
    align-items: center;
    gap: 8px;
}

.main-nav-links {
    display: flex;
    gap: 8px;
}

.mobile-menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
}

.user-menu {
    position: relative;
    cursor: pointer;
    padding-bottom: 10px;
    margin-bottom: -10px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--brand);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    min-width: 200px;
    display: none;
    overflow: hidden;
    z-index: 100;
}

.user-dropdown::before {
    content: '';
    position: absolute;
    top: -20px;
    left: 0;
    right: 0;
    height: 20px;
    background: transparent;
}

.user-menu:hover .user-dropdown {
    display: block;
}

.user-dropdown-info {
    padding: 10px 16px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.75rem;
    color: #94a3b8;
    text-transform: none;
    letter-spacing: 0.025em;
    font-weight: 600;
    word-break: break-all;
}

.user-dropdown a {
    display: flex;
    padding: 10px 16px;
    color: var(--brand-dark);
    text-decoration: none;
    font-size: 0.9rem;
    transition: background 0.2s;
    align-items: center;
    gap: 8px;
}

.user-dropdown a:hover, .user-dropdown a.active {
    background: #f8fafc;
}

main {
    max-width: 1400px;
    margin: 28px auto;
    padding: 0 40px;
}

.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.06);
    padding: 20px;
    margin-bottom: 25px;
}

/* Form Styles */
#giftForm label { display: block; margin-bottom: 8px; font-weight: 600; color: var(--brand-dark); }
#giftForm textarea {
    width: 100%;
    height: 120px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 1rem;
    margin-bottom: 16px;
    resize: vertical;
}
#giftForm textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(53, 182, 155, 0.1); }

.actions { display: flex; align-items: center; gap: 15px; }

#searchBtn {
    background: var(--brand);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}
#searchBtn:hover { background: #2da189; }
#searchBtn:disabled { background: #94a3b8; cursor: not-allowed; }

.hint { color: var(--muted); font-size: 0.85rem; }

.empty {
    padding: 30px;
    text-align: center;
    color: var(--muted);
    background: #f9fafb;
    border-radius: 10px;
    border: 1px dashed var(--border);
    font-style: italic;
}

.error-box {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error-text);
    padding: 16px;
    border-radius: 10px;
    margin: 20px 0;
}
.error-box strong { display: block; margin-bottom: 5px; }

/* History Detail Meta Card */
.meta-card h3 { margin-top: 0; color: var(--brand-dark); }
.meta-card p { margin: 8px 0; display: flex; align-items: center; gap: 10px; }

.history-detail-header {
    margin-bottom: 30px;
}

.query-bubble {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 18px;
    border-bottom-left-radius: 2px;
    padding: 20px 25px;
    position: relative;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    color: var(--brand-dark);
    display: block;
    width: 100%;
}

.query-text {
    font-size: 1.1rem;
    line-height: 1.6;
    font-style: italic;
    margin-bottom: 15px;
}

.detail-meta-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 20px;
    color: var(--muted);
    font-size: 0.9rem;
    padding-top: 15px;
    border-top: 1px solid #f1f5f9;
}

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

.detail-meta-item i {
    color: var(--brand);
    font-size: 1rem;
}

.status-pill {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 700;
}

/* Products and Results */
.results h2 { margin-top: 20px; }

.product {
    display:grid; grid-template-columns:1fr auto; gap:8px 14px;
    padding:14px; border:1px solid var(--border);
    border-radius:12px; background:#fafafa; margin-bottom:10px;
    align-items:center;
}

.product a { color:var(--brand); font-weight:600; text-decoration:none; }
.product a:hover { text-decoration:underline; }

.score-badge {
    padding:6px 10px; border-radius:999px;
    border:1px solid var(--border); background:#fff;
    font-size:.9rem;
}

.meta { color:var(--muted); font-size:.9rem; margin-top:8px; }

.view-more-link {
    color: #aaa9a9;
    text-decoration: none;
    margin: 20px 5px;
    font-weight: bold;
    display: block;
}
.view-more-link:hover { text-decoration: underline; }

/* Feedback Styles */
.feedback-tools {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
    grid-column: 1 / -1;
}

.sentiment-btns, .checkbox-group { display: flex; gap: 8px; }

.btn-icon, .btn-check {
    background: #fff;
    border: 1px solid var(--border);
    padding: 5px 10px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--muted);
    transition: all 0.2s;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 4px;
    user-select: none;
}
.btn-icon:hover, .btn-check:hover { background: #f9fafb; border-color: #d1d5db; }
.btn-icon:disabled, .btn-check.disabled { 
    cursor: not-allowed; 
    opacity: 0.6; 
    background: #f1f5f9;
}
.btn-icon:disabled:hover, .btn-check.disabled:hover {
    background: #f1f5f9;
    border-color: var(--border);
}

.btn-icon.active-like { 
    background: #dcfce7; 
    color: #166534; 
    border-color: #bbf7d0; 
    animation: pulse-green 0.4s ease-out;
}
.btn-icon.active-dislike { 
    background: #fee2e2; 
    color: #991b1b; 
    border-color: #fecaca; 
    animation: shake 0.3s ease-in-out; 
}

.btn-check input { display: none; }
.btn-check.active { 
    background: #e0f2fe; 
    color: #075985; 
    border-color: #bae6fd; 
    animation: pop 0.3s ease-out; 
}

/* History List Styles */
.history-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}


.history-checkbox {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    z-index: 10;
}

.history-item {
    position: relative;
    flex: 1;
    padding: 24px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.history-item:hover { 
    border-color: var(--brand); 
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transform: translateY(-2px);
}

.history-item.item-completed {
    background: #f0fdf4;
    border-color: #bbf7d0;
}
.history-item.item-completed:hover {
    border-color: #4ade80;
    box-shadow: 0 4px 6px -1px rgba(22, 163, 74, 0.1), 0 2px 4px -1px rgba(22, 163, 74, 0.06);
}

.history-item.item-submitted {
    opacity: 0.65;
    filter: grayscale(0.2);
}

.history-item.item-submitted:hover {
    opacity: 0.85;
    filter: grayscale(0);
}

.history-item .request-text {
    font-size: 1.15rem;
    line-height: 1.5;
    font-weight: 600;
    color: var(--brand-dark);
    margin-bottom: 12px;
    padding-right: 30px;
    display: block;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.history-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}

.stat-item {
    font-size: 0.9rem;
    color: #475569;
    background: #f8fafc;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.item-completed .stat-item {
    background: #ecfdf5;
    border-color: #d1fae5;
    color: #065f46;
}

.history-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    font-size: 0.85rem;
    color: var(--muted);
    padding-top: 15px;
    border-top: 1px solid #f1f5f9;
}

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

.history-meta-item i, .meta-card i {
    color: var(--muted);
    width: 16px;
    text-align: center;
}


/* History Controls & Filters */
.history-controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 30px;
}

.filters-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.filter-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
}

.filter-group input, .filter-group select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
}

.btn-filter {
    padding: 8px 16px;
    background: var(--brand-dark);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
    height: 38px;
}

.btn-filter:hover { background: #0f172a; }

.export-panel {
    display: flex;
    gap: 10px;
}

.btn-export {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--brand-dark);
    transition: all 0.2s;
}

.btn-export:hover {
    background: #f8fafc;
    border-color: var(--brand);
}

.btn-export i { color: var(--brand); }

/* Login Page Styles */
.login-container {
    max-width: 400px;
    margin: 60px auto;
}

.login-branding {
    text-align: center;
    margin-bottom: 30px;
}

.login-logo {
    height: 60px;
    width: auto;
    filter: brightness(0) saturate(100%) invert(14%) sepia(26%) saturate(1313%) hue-rotate(158deg) brightness(97%) contrast(93%); /* var(--brand-dark) #173241 */
    margin-bottom: 15px;
}

.login-app-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    color: var(--brand-dark);
}

.login-panel {
    background: #fff;
    padding: 40px;
    border-radius: 14px;
    border: 1px solid var(--border);
    box-shadow: 0 15px 35px rgba(0,0,0,0.05);
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-header h2 {
    margin: 0;
    color: var(--brand-dark);
}

.login-form .form-group, .form-group {
    margin-bottom: 20px;
}

.login-form label, .form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--brand-dark);
}

.login-form input[type="email"],
.login-form input[type="password"],
.login-form input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="text"],
.form-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: #fff;
    font-family: inherit;
}

.login-form input:focus, .form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(53, 182, 155, 0.1);
}

.login-form .checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--muted);
}

.login-form .btn-login, .btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 10px;
    display: inline-block;
    text-align: center;
    text-decoration: none;
    font-family: inherit;
    line-height: normal;
}

.login-form .btn-login:hover, .btn-primary:hover {
    background: #2da189;
}

.btn-secondary {
    padding: 12px 20px;
    background: #94a3b8;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-block;
    text-align: center;
    text-decoration: none;
    font-family: inherit;
    margin-top: 10px;
    line-height: normal;
}

.btn-secondary:hover {
    background: #64748b;
}

.login-error, .success-box {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.login-error {
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.success-box {
    background: #dcfce7;
    border: 1px solid #bbf7d0;
    color: #166534;
}

/* Data Table Styles */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.data-table th {
    text-align: left;
    padding: 12px;
    border-bottom: 2px solid var(--border);
    color: var(--muted);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.data-table td {
    padding: 16px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover {
    background: #f8fafc;
}

.btn-refine {
    background: #7b6bff;
    color: #fff;
    border-color: #7b6bff;
}

.btn-refine:hover {
    background: #6d5dfc;
    border-color: #6d5dfc;
}

.btn-refine i { color: #fff; }

/* Modal styles for export scope selection */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background: #fff;
    padding: 24px;
    border-radius: 12px;
    max-width: 400px;
    width: 90%;
}

.modal-header {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--brand-dark);
}

.modal-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.modal-btn {
    padding: 12px;
    text-align: left;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    display: flex;
    align-items: center;
}

.modal-btn:hover {
    background: #f8fafc;
    border-color: var(--brand);
}

/* Pagination */
.pagination-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.pagination-pages {
    display: flex;
    gap: 8px;
}

.page-link {
    display: inline-block;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    text-decoration: none;
    color: var(--muted);
    font-size: 0.9rem;
    transition: all 0.2s;
}

.page-link:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.page-link.active {
    background: var(--brand);
    color: white;
    border-color: var(--brand);
}

.limit-selector select {
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--brand-dark);
}

@keyframes pulse-green {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
    50% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(34, 197, 94, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

.dislike-reason {
    margin-top: 8px;
    grid-column: 1 / -1;
    display: none;
}
.dislike-reason select {
    width: 100%;
    padding: 6px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 0.85rem;
}

@media (max-width: 850px) {
    .detail-meta-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .detail-meta-item:last-child {
        margin-left: 0 !important;
        width: 100%;
        justify-content: flex-start;
    }

    .header-container {
        padding: 12px 20px 0;
        display: grid;
        grid-template-areas:
            "left center toggle"
            "nav nav nav";
        grid-template-columns: auto 1fr auto;
        gap: 15px;
        align-items: center;
    }

    .header-left {
        grid-area: left;
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }

    .header-logo {
        height: 30px;
    }

    .header-center {
        grid-area: center;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 8px;
        margin-top: 0;
    }

    .header-title {
        font-size: 1.1rem;
        text-align: left;
        white-space: nowrap;
    }

    .pill {
        display: none; /* Hide pills on small screens to keep title on one line if needed, or keep them if they fit */
    }

    @media (min-width: 480px) {
        .pill {
            display: inline-block;
        }
    }

    .mobile-menu-toggle {
        grid-area: toggle;
        display: block;
        justify-self: end;
        align-self: center;
    }

    .header-nav {
        grid-area: nav;
        display: none;
        flex-direction: column;
        width: 100%;
        background: rgba(0, 0, 0, 0.1);
        border-radius: 8px;
        padding: 10px;
        gap: 0;
        margin-top: 10px;
        margin-bottom: 20px;
    }

    .main-nav-links {
        display: flex;
        flex-direction: column-reverse;
        gap: 5px;
        padding-bottom: 10px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        margin-bottom: 5px;
        width: 100%;
    }

    .header-nav.open {
        display: flex;
    }

    .nav-btn {
        width: 100%;
        justify-content: flex-start;
    }

    .login-container {
        margin: 40px auto;
        padding: 0 15px;
    }

    .login-logo {
        height: 50px;
    }

    .login-title {
        font-size: 1.3rem;
    }

    .user-menu {
        width: 100%;
        margin-bottom: 0;
        padding-bottom: 0;
        margin-top: 5px;
    }

    .user-menu .user-avatar {
        display: none; /* Hide avatar in mobile menu to simplify */
    }

    .user-dropdown {
        position: static;
        display: block;
        box-shadow: none;
        border: none;
        background: transparent;
        min-width: 0;
        width: 100%;
    }

    .user-dropdown-info {
        display: none;
    }

    .user-dropdown a {
        color: rgba(255, 255, 255, 0.8);
        padding: 10px 12px;
    }

    .user-dropdown a:hover, .user-dropdown a.active {
        background: rgba(255, 255, 255, 0.1);
        color: #fff;
    }

    .user-dropdown::before {
        display: none;
    }

    .user-menu:hover .user-dropdown {
        display: block;
    }

    main {
        padding: 0 15px;
        margin: 15px auto;
    }
}