/* ===========================
   Variables & Reset
   =========================== */
:root {
    --bg-primary: #f9fafb;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --accent-1: #111827;
    --accent-2: #059669;
    --accent-red: #dc2626;
    --accent-green: #059669;
    --border-color: #e5e7eb;
    --border-hover: #d1d5db;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-soft: 0 1px 3px rgba(0, 0, 0, 0.1);
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --max-width: 1200px;
}

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

html { scroll-behavior: smooth; }

body {
    background: linear-gradient(to bottom right, #ffffff, #f3f4f6);
    background-attachment: fixed;
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

/* ===========================
   Page Layout
   =========================== */
.page-wrapper {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* ===========================
   Header
   =========================== */
.page-header {
    padding: 2.5rem 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.page-title {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 800;
    letter-spacing: -1px;
    margin-top: 0.5rem;
    background: linear-gradient(90deg, #111827, #4f46e5);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 1.05rem;
    margin-top: 0.25rem;
}

/* Category Navigation */
.category-nav {
    display: flex;
    gap: 1.5rem;
    margin-top: 2rem;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 2px; /* For border */
}

.category-nav::-webkit-scrollbar {
    display: none;
}

.category-tab {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.category-tab:hover {
    color: var(--text-primary);
}

.category-tab.active {
    color: var(--accent-1);
    border-bottom-color: var(--accent-1);
}

/* ===========================
   Stats Bar
   =========================== */
.stats-bar {
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.stats-inner {
    display: flex;
    gap: 3rem;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    font-family: var(--font-mono);
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

/* ===========================
   Main Content
   =========================== */
.main-content {
    padding: 2rem 0;
}

/* ===========================
   Submit Section
   =========================== */
.submit-section {
    margin-bottom: 2.5rem;
}

.submit-toggle {
    width: 100%;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border: 1px dashed var(--border-hover);
    border-radius: var(--radius-lg);
    color: var(--accent-2);
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all 0.2s;
}

.submit-toggle:hover {
    background: rgba(5, 150, 105, 0.05);
    border-color: var(--accent-2);
}

.submit-form {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    margin-top: 1rem;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.form-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.form-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.form-group-wide {
    grid-column: 1 / -1;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.required { color: var(--accent-red); }

.form-group select,
.form-group input {
    width: 100%;
    padding: 0.65rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: var(--accent-1);
    box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.1);
}

.form-group select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.form-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.btn-submit {
    padding: 0.7rem 2rem;
    background: linear-gradient(135deg, #111827, #374151);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-weight: 700;
    font-size: 0.95rem;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(17, 24, 39, 0.25);
    background: linear-gradient(135deg, #1f2937, #4b5563);
}

.btn-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-cancel {
    padding: 0.7rem 1.5rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: border-color 0.2s;
}

.btn-cancel:hover {
    border-color: var(--text-muted);
}

.form-message {
    margin-top: 1rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.form-message.success { color: var(--accent-green); }
.form-message.error { color: var(--accent-red); }

/* ===========================
   Tag Input Component
   =========================== */
.tag-input-wrapper {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    min-height: 42px;
    cursor: text;
    transition: border-color 0.2s;
}

.tag-input-wrapper:focus-within {
    border-color: var(--accent-1);
    box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.1);
}

.tag-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.5rem;
    background: #f3f4f6;
    border: 1px solid var(--border-color);
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    animation: tagPop 0.15s ease;
}

@keyframes tagPop {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.tag-pill-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    border-radius: 50%;
    transition: all 0.15s;
    padding: 0;
}

.tag-pill-remove:hover {
    color: var(--accent-red);
    background: rgba(220, 38, 38, 0.1);
}

.tag-text-input {
    flex: 1;
    min-width: 120px;
    border: none !important;
    background: transparent !important;
    padding: 0.2rem 0 !important;
    font-size: 0.9rem;
    outline: none !important;
    box-shadow: none !important;
}

.tag-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.tag-suggestion {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.1s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tag-suggestion:hover,
.tag-suggestion.active {
    background: #f3f4f6;
}

.tag-suggestion-group {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===========================
   Search Bar
   =========================== */
.search-input-wrapper {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-field {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    transition: border-color 0.2s;
}

.search-field:focus {
    outline: none;
    border-color: var(--accent-1);
    box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.1);
}

/* ===========================
   Data Section
   =========================== */
.data-section {
    margin-bottom: 3rem;
}

.filters-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.data-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.filters {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    flex: 1;
    max-width: 500px;
}

.filter-select {
    padding: 0.5rem 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: var(--accent-1);
}

.filter-select option {
    background: var(--bg-secondary);
}

/* ===========================
   Table
   =========================== */
.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table thead {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    padding: 0.85rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}

.data-table th.sortable:hover {
    color: var(--accent-1);
}

.data-table th.sort-active {
    color: var(--accent-2);
}

.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table tbody tr {
    transition: all 0.2s ease;
}

.data-table tbody tr:hover {
    background: #ffffff;
    transform: translateY(-1px) scale(1.002);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    position: relative;
    z-index: 10;
}

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

.table-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem 1rem !important;
    font-style: italic;
}

/* Price styling */
.price-cell {
    font-family: var(--font-mono);
    font-weight: 600;
}

.savings-positive {
    color: var(--accent-green);
    font-weight: 600;
    font-family: var(--font-mono);
}

.savings-negative {
    color: var(--accent-red);
    font-weight: 600;
    font-family: var(--font-mono);
}

/* Tag badges in table */
.tag-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    max-width: 300px;
}

.tag-badge {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    background: #f3f4f6;
    border: 1px solid var(--border-color);
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

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

/* ===========================
   Auth Modal & Styles
   =========================== */
.btn-login, .btn-logout {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all 0.2s;
}

.btn-login {
    background: transparent;
    border: 1px solid var(--accent-1);
    color: var(--accent-1);
}
.btn-login:hover {
    background: rgba(17, 24, 39, 0.05);
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.btn-logout:hover {
    border-color: var(--accent-red);
    color: var(--accent-red);
}

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    position: relative;
    box-shadow: var(--shadow-soft);
    animation: scaleUp 0.2s ease;
}

@keyframes scaleUp {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-close {
    position: absolute;
    top: 1rem; right: 1rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-align: center;
}

.modal-desc {
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: center;
    margin-bottom: 2rem;
}

.btn-google {
    width: 100%;
    padding: 0.75rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: #333;
    font-weight: 600;
    font-size: 0.95rem;
    font-family: var(--font-sans);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    margin-bottom: 1.5rem;
}
.btn-google:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.modal-divider {
    text-align: center;
    position: relative;
    margin-bottom: 1.5rem;
}
.modal-divider::before {
    content: '';
    position: absolute;
    top: 50%; left: 0; right: 0;
    border-top: 1px solid var(--border-color);
    z-index: 1;
}
.modal-divider span {
    background: var(--bg-card);
    padding: 0 0.75rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    position: relative;
    z-index: 2;
}

.email-auth-form .form-group {
    margin-bottom: 1rem;
}

.email-auth-form input {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
}
.email-auth-form input:focus {
    outline: none;
    border-color: var(--accent-1);
}

.auth-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}
.auth-buttons button {
    flex: 1;
}

.btn-delete {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.2rem;
    border-radius: 4px;
    transition: all 0.2s;
}
.btn-delete:hover {
    color: var(--accent-red);
    background: rgba(239, 68, 68, 0.1);
}

/* ===========================
   Responsive
   =========================== */
@media (max-width: 768px) {
    .stats-inner {
        gap: 1.5rem;
    }
    .stat-value {
        font-size: 1.3rem;
    }
    .form-grid {
        grid-template-columns: 1fr 1fr;
    }
    .filters-bar {
        flex-direction: column;
        align-items: flex-start;
    }
    .filters {
        width: 100%;
        max-width: none;
    }
    .search-input-wrapper {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    .form-actions {
        flex-direction: column;
    }
    .btn-submit, .btn-cancel {
        width: 100%;
        text-align: center;
    }
}
