:root {
    /* Colors */
    --color-primary: #007bff;
    --color-primary-hover: #0056b3;
    --color-danger: #dc3545;
    --color-danger-hover: #c82333;
    --color-success: #28a745;
    --color-success-hover: #218838;

    /* Light theme */
    --color-bg: #ffffff;
    --color-text: #333333;
    --color-text-secondary: #666666;
    --color-border: #dddddd;
    --color-input-bg: #ffffff;
    --color-section-bg: #f8f9fa;
    --color-card-bg: #ffffff;

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;

    /* Spacing */
    --space-xs: 0.5rem;
    --space-sm: 0.75rem;
    --space-md: 1rem;
    --space-lg: 2rem;

    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-md: 0 2px 10px rgba(0,0,0,0.1);

    /* Typography */
    --font-family: system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #404040;
        --color-text: #ffffff;
        --color-text-secondary: #cccccc;
        --color-border: #666666;
        --color-input-bg: #505050;
        --color-section-bg: #4a4a4a;
        --color-card-bg: #484848;
        --shadow-md: 0 2px 10px rgba(0,0,0,0.3);
    }
}

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

html {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

body {
    font-family: var(--font-family);
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    background: var(--color-bg);
    color: var(--color-text);
    color-scheme: light dark;
}

/* Form elements */
.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    margin-bottom: var(--space-xs);
    font-weight: 500;
}

input[type="text"],
input[type="password"],
input[type="email"],
select {
    width: 100%;
    padding: var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    box-sizing: border-box;
    background: var(--color-input-bg);
    color: var(--color-text);
}

input:focus,
select:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

/* Buttons */
.btn {
    padding: var(--space-sm) var(--space-md);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: background-color 0.15s ease;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
}

.btn-danger {
    background: var(--color-danger);
    color: white;
}

.btn-danger:hover {
    background: var(--color-danger-hover);
}

.btn-success {
    background: var(--color-success);
    color: white;
}

.btn-success:hover {
    background: var(--color-success-hover);
}

/* Cards/Containers */
.card {
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.section {
    background: var(--color-section-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
}

/* Messages */
.message {
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-md);
}

.message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

@media (prefers-color-scheme: dark) {
    .message.success {
        background: #1a3d1a;
        color: #d4edda;
        border-color: #155724;
    }

    .message.error {
        background: #3d1a1a;
        color: #f8d7da;
        border-color: #721c24;
    }
}

/* Utility classes */
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.w-100 { width: 100%; }
/* App shell with friends panel */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.friends-panel {
    width: 220px;
    flex-shrink: 0;
    border-right: 1px solid var(--color-border);
    background: var(--color-section-bg);
    display: flex;
    flex-direction: column;
}

.friends-panel-header {
    padding: 1rem;
    font-weight: 600;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--color-border);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-secondary);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.friends-section {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--color-border);
}

.friends-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0.75rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.friends-section-header--sub {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
}

.friend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    text-decoration: none;
    color: var(--color-text);
    border-radius: var(--radius-sm);
    margin: 0 0.25rem;
    transition: background 0.15s;
}

.friend-item:hover {
    background: var(--color-border);
}

.friend-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    flex-shrink: 0;
}

.anon-item .friend-avatar {
    background: var(--color-text-secondary);
}

.friend-name {
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.follower-item {
    cursor: default;
}

.remove-friend-btn {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 0.25rem;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s;
}

.anon-item:hover .remove-friend-btn {
    opacity: 1;
}

@media (hover: none) {
    .remove-friend-btn {
        opacity: 1;
    }
}

.friends-empty {
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    margin: 0;
}

.friends-loading {
    padding: 0.75rem;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
}

.share-btn {
    background: none;
    border: 1px solid var(--color-primary);
    color: var(--color-primary);
    border-radius: var(--radius-sm);
    padding: 0.15rem 0.4rem;
    font-size: 0.7rem;
    cursor: pointer;
}

.share-btn:hover {
    background: var(--color-primary);
    color: #fff;
}

@media (prefers-color-scheme: dark) {
    .friends-panel {
        background: #1e1e1e;
        border-color: #333;
    }
    .friends-section {
        border-color: #333;
    }
    .friends-panel-header {
        border-color: #333;
    }
}

@media (max-width: 600px) {
    .app-shell {
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
    }

    .friends-panel {
        width: 260px;
        min-width: 260px;
        scroll-snap-align: start;
    }

    .main-content {
        min-width: 100vw;
        scroll-snap-align: start;
    }
}

/* Nav active state */
.friend-item.nav-active {
    background: var(--color-primary);
    color: #fff;
}

.friend-item.nav-active .friend-avatar {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

.nav-home {
    font-style: normal;
}

/* Anon name display */
.friends-anon-name {
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    margin: 0 0 0.25rem;
}

/* Anon follower clickable */
.anon-item {
    cursor: pointer;
}

/* Wishlist page shared styles */
.wishlist-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-lg);
}

.account-banner {
    background: #fff3cd;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-lg);
    border: 1px solid #ffeaa7;
}

.account-banner p {
    margin: 0 0 var(--space-xs) 0;
    color: #856404;
}

.account-banner p:last-child {
    margin-bottom: 0;
}

.account-banner a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
}

.account-banner a:hover {
    text-decoration: underline;
}

.add-product-section {
    background: var(--color-card-bg);
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-lg);
    border: 1px solid var(--color-border);
}

#add-product-form {
    display: flex;
    gap: var(--space-sm);
}

#product-url {
    flex: 1;
    padding: var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--color-input-bg);
    color: var(--color-text);
}

#product-url:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

#add-button {
    padding: var(--space-sm) var(--space-lg);
    white-space: nowrap;
}

#empty-state {
    background: var(--color-card-bg);
    padding: 4rem 2rem;
    border-radius: var(--radius-md);
    text-align: center;
    border: 1px solid var(--color-border);
}

#empty-state h2 {
    color: var(--color-text-secondary);
    margin-bottom: var(--space-sm);
}

#empty-state p {
    color: var(--color-text-secondary);
}

#wishlist-grid, .wishlist-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-lg);
}

.product-card {
    background: var(--color-card-bg);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
}

.product-card.fade-in {
    animation: fadeIn 0.4s ease-out;
}

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

.product-card.scanning {
    position: relative;
}

.scanning-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    color: white;
    font-weight: 500;
    z-index: 10;
    border-radius: var(--radius-md);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.product-image {
    width: 100%;
    height: 200px;
    background: var(--color-section-bg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.no-image {
    color: var(--color-text-secondary);
    font-size: 0.9rem;
}

.product-info {
    padding: var(--space-md);
    flex: 1;
}

.product-title {
    font-size: 1rem;
    color: var(--color-text);
    margin-bottom: var(--space-sm);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-price {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--color-text);
    margin-bottom: var(--space-sm);
}

.product-price.price-down { color: var(--color-success); }
.product-price.price-up { color: var(--color-danger); }

.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-sm);
}

.badge.not-trackable {
    background: #ffc107;
    color: #000;
}

.product-link {
    display: inline-block;
    color: var(--color-primary);
    text-decoration: none;
    font-size: 0.9rem;
}

.product-link:hover {
    text-decoration: underline;
}

.remove-button {
    width: 100%;
    padding: var(--space-sm);
    background: var(--color-danger);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
}

.remove-button:hover { background: var(--color-danger-hover); }

.edit-button {
    width: 100%;
    padding: var(--space-sm);
    background: var(--color-primary);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    margin-bottom: var(--space-xs);
}

.edit-button:hover { background: var(--color-primary-hover); }

.edit-form {
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.edit-form input,
.edit-form select {
    padding: var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: var(--color-input-bg);
    color: var(--color-text);
}

.edit-form input:focus,
.edit-form select:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

.edit-actions {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
}

.save-button, .cancel-button {
    flex: 1;
    padding: var(--space-sm);
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
}

.save-button { background: var(--color-success); color: white; }
.cancel-button { background: var(--color-secondary, #6c757d); color: white; }

.edit-form label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    cursor: pointer;
}

@media (prefers-color-scheme: dark) {
    .account-banner {
        background: #3d3d00;
        border-color: #5a5a00;
    }

    .account-banner p {
        color: #ffd966;
    }

    .badge.not-trackable {
        background: #ffb74d;
    }
}

@media (max-width: 768px) {
    .wishlist-container {
        padding: var(--space-md);
    }

    #add-product-form {
        flex-direction: column;
    }

    #wishlist-grid, .wishlist-grid {
        grid-template-columns: 1fr;
    }
}
