:root {
    /* Color System - Dark Theme */
    --bg-color: #0E0F13;
    --surface: #1C1D22;
    --surface-highlight: #2A2B32;

    --primary: #8B5CF6;
    /* Electric Violet */
    --primary-rgb: 139, 92, 246;
    --primary-dark: #7C3AED;
    --primary-light: #A78BFA;

    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-tertiary: #64748B;

    --border: #2E3038;

    --danger: #EF4444;
    --success: #10B981;
    --warning: #F59E0B;

    /* Shadows & Elevation */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
    --glow: 0 0 20px rgba(139, 92, 246, 0.15);
    /* Primary glow */

    /* Typography & Radius */
    --radius-sm: 0.5rem;
    --radius: 0.75rem;
    --radius-lg: 1rem;
    --radius-full: 9999px;

    --font-heading: 'Inter', system-ui, sans-serif;
    --font-body: 'Inter', system-ui, sans-serif;

    --safe-area-bottom: env(safe-area-inset-bottom);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    letter-spacing: 0.02em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    height: 100%;
    width: 100%;
    position: relative;
    overflow: hidden;
    max-width: 600px;
    /* Mobile first limit on desktop */
    margin: 0 auto;
    background: var(--bg-color);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--surface-highlight);
    border-radius: 10px;
}

.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    display: none;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: calc(85px + var(--safe-area-bottom));
    /* More space for floating bottom nav */
    opacity: 0;
    transition: opacity 0.2s ease-out;
}

.view.active {
    display: flex;
    opacity: 1;
}

/* Loading Screen */
#loading-screen {
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    margin-bottom: 1.5rem;
}

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

/* Welcome View */
.welcome-view {
    justify-content: center;
    padding: 2rem;
    text-align: center;
    background: radial-gradient(circle at top right, rgba(139, 92, 246, 0.1), transparent 40%);
}

.welcome-container {
    background: var(--surface);
    padding: 2.5rem 2rem;
    border-radius: 1.5rem;
    box-shadow: var(--shadow-lg);
    width: 100%;
    border: 1px solid var(--border);
}

.lang-toggle {
    position: absolute;
    top: 2rem;
    right: 2rem;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-full);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}

.lang-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tagline {
    color: var(--text-secondary);
    margin-bottom: 2.5rem;
    font-size: 1.1rem;
}

.form-group {
    text-align: left;
    margin-bottom: 2rem;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

input[type="text"] {
    width: 100%;
    padding: 1rem 1.25rem;
    background: var(--bg-color);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: white;
    font-size: 1.1rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

input[type="text"]::placeholder {
    color: var(--text-tertiary);
}

input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.15);
    background: var(--surface-highlight);
}

/* Button System */
.btn {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: var(--radius-full);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: 0.02em;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 6px 16px rgba(139, 92, 246, 0.5);
    transform: translateY(-2px);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(139, 92, 246, 0.4);
}

.btn-secondary {
    background: var(--surface-highlight);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
    background: var(--surface-highlight);
    color: var(--text-tertiary);
}

.info-text {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    margin-top: 1.5rem;
}

/* Header */
.app-header {
    background: var(--bg-color);
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.app-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.user-profile {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary-light);
    background: rgba(139, 92, 246, 0.1);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    gap: 8px;
}

.edit-username-btn {
    background: transparent;
    border: none;
    color: var(--primary-light);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    opacity: 0.7;
    transition: all 0.2s;
}

.edit-username-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    opacity: 1;
}

/* Lists Grid */
.lists-grid {
    padding: 1.5rem;
    display: grid;
    grid-template-columns: 1fr;
    /* Mobile first: single column cards */
    gap: 1rem;
}

.list-card {
    background: var(--surface);
    border-radius: 1.25rem;
    padding: 1.5rem;
    display: flex;
    flex-direction: row;
    /* Horizontal cards for better mobile fitting */
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.list-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
    opacity: 0;
    transition: opacity 0.2s;
}

.list-card:active {
    transform: scale(0.98);
    background: var(--surface-highlight);
}

.list-card h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.list-meta {
    font-size: 0.85rem;
    color: var(--text-tertiary);
}

.section-divider {
    padding: 0 1.5rem;
    margin: 1.5rem 0 0.5rem 0;
}

.delete-list-btn {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 8px;
    margin-right: -8px;
    display: flex;
    align-items: center;
    border-radius: 50%;
    transition: all 0.2s;
    opacity: 0.6;
}

.delete-list-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    opacity: 1;
}

.list-card:hover .delete-list-btn {
    opacity: 1;
}

.section-divider h3 {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-tertiary);
    letter-spacing: 0.08em;
}

/* FAB */
.fab {
    position: fixed;
    bottom: calc(90px + var(--safe-area-bottom));
    right: 1.5rem;
    width: 60px;
    height: 60px;
    border-radius: 20px;
    /* Squircle */
    background: var(--primary);
    color: white;
    border: none;
    box-shadow: var(--shadow-lg), var(--glow);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    /* Bouncy */
    z-index: 40;
}

.fab:active {
    transform: scale(0.9) rotate(5deg);
}

.fab svg {
    width: 28px;
    height: 28px;
}

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 40px);
    max-width: 400px;
    background: rgba(28, 29, 34, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    /* Frosted glass border */
    border-radius: 2rem;
    display: flex;
    justify-content: space-evenly;
    padding: 0.75rem 0.5rem;
    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
    z-index: 100;
}

.nav-item {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    color: var(--text-tertiary);
    font-size: 0.7rem;
    font-weight: 600;
    width: 60px;
    height: 50px;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 12px;
}

.nav-item svg {
    stroke-width: 2;
    transition: all 0.2s;
    opacity: 0.7;
}

.nav-item.active {
    color: var(--primary-light);
    background: rgba(139, 92, 246, 0.1);
}

.nav-item.active svg {
    transform: translateY(-2px);
    stroke: var(--primary);
    opacity: 1;
}

/* List Detail View */
.list-detail-view .app-header {
    display: flex;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--bg-color);
    /* Details view often feels better solid at top */
    border-bottom: 0;
}

.back-btn,
.share-btn,
.edit-title-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 44px;
    height: 44px;
    padding: 0;
    color: var(--text-primary);
    transition: all 0.2s;
}

.back-btn:active,
.share-btn:active {
    transform: scale(0.9);
    background: var(--surface-highlight);
}

#list-title {
    flex: 1;
    text-align: left;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.add-item-container {
    padding: 1.5rem;
    background: var(--bg-color);
    position: sticky;
    top: 60px;
    /* Adjusted to prevent gap */
    z-index: 30;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 4px 12px -4px rgba(0, 0, 0, 0.3);
    margin-bottom: 1rem;
}

#add-item-form {
    display: flex;
    gap: 0.75rem;
    background: var(--surface);
    padding: 0.5rem;
    border-radius: 999px;
    /* Pill shape */
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: border-color 0.2s;
    height: 58px;
    /* Fixed height for consistency */
    align-items: center;
    /* Ensure vertical centering */
}

#add-item-form:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.15);
}

#new-item-input {
    flex: 1;
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    border-radius: 0;
    font-size: 1rem;
    box-shadow: none !important;
    /* Override default input focus */
}

#add-item-form button {
    background: var(--primary);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s;
    width: 44px;
    height: 44px;
}

#add-item-form button:active {
    transform: scale(0.9);
}

/* Items List */
.items-list {
    padding: 1.5rem;
    margin: 0 1rem 1.5rem 1rem;
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 200px;
    transition: all 0.3s ease;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.item-row {
    background: var(--surface);
    padding: 1rem 1.25rem;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
}

.item-row:active {
    transform: scale(0.98);
}

.item-row.bought {
    opacity: 0.5;
    background: transparent;
    border: 1px solid var(--border);
}

/* Checkbox */
.checkbox {
    width: 24px;
    height: 24px;
    border: 2px solid var(--text-tertiary);
    border-radius: 8px;
    /* Softer square */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    /* For hit area */
}

.checkbox::after {
    content: '';
    position: absolute;
    top: -10px;
    bottom: -10px;
    left: -10px;
    right: -10px;
}

.item-row.bought .checkbox {
    background: var(--success);
    border-color: var(--success);
    color: white;
    transform: scale(1.1);
}

.item-text {
    flex: 1;
    font-size: 1.05rem;
    font-weight: 500;
}

.item-row.bought .item-text {
    text-decoration: line-through;
    color: var(--text-tertiary);
    text-decoration-color: var(--text-tertiary);
}

.delete-item-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: transparent;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.delete-item-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.bought-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 2rem 0 1rem 0;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.bought-header::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

#new-item-quantity {
    width: 60px;
    padding: 0.5rem;
    border: none;
    background: var(--bg-color);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
}

#new-item-quantity:focus {
    outline: 2px solid var(--primary);
    background: var(--surface-highlight);
}

/* Quantity Selector in Add Item Form */
.quantity-selector {
    display: flex;
    align-items: center;
    background: var(--surface-highlight);
    border-radius: 99px;
    padding: 2px;
    height: 44px;
    /* Match button height roughly */
    margin-right: 0.5rem;
}

.quantity-selector button {
    background: transparent !important;
    border: none;
    color: var(--text-secondary) !important;
    width: 40px !important;
    height: 40px !important;
    border-radius: 50% !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background 0.2s;
}

.quantity-selector button:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    color: var(--text-primary) !important;
}

.quantity-selector input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 30px;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0;
    appearance: textfield;
    -moz-appearance: textfield;
}

.quantity-selector input::-webkit-outer-spin-button,
.quantity-selector input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.item-quantity {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary-light);
    background: rgba(139, 92, 246, 0.15);
    padding: 2px 8px;
    border-radius: 99px;
    margin-right: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.item-quantity:hover {
    background: var(--primary);
    color: white;
}

/* Category Input */
.category-input-wrapper {
    position: relative;
    margin-top: 0.75rem;
}

.category-input-container {
    background: var(--surface);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    width: 100%;
    transition: all 0.2s;
    height: 58px;
    /* Match the add item form height exactly */
}

.category-input-container:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

.category-icon {
    color: var(--text-tertiary);
    margin-right: 0.5rem;
    display: flex;
    align-items: center;
}

#new-item-category {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    flex: 1;
    outline: none;
}

#new-item-category:focus {
    width: auto;
}

#new-item-category::placeholder {
    color: var(--text-tertiary);
}

/* Custom Category Dropdown */
.category-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    animation: slideDown 0.2s ease-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.category-option {
    padding: 0.875rem 1rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
    font-size: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.category-option:last-child {
    border-bottom: none;
}

.category-option:hover,
.category-option:active {
    background: var(--surface-highlight);
    color: var(--primary-light);
}

.category-option.highlighted {
    background: var(--surface-highlight);
}

.category-dropdown-empty {
    padding: 1rem;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.9rem;
}


/* Category Headers in List */
.category-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-tertiary);
    font-weight: 700;
    margin: 1.5rem 0 0.5rem 0.5rem;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.category-header::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
    opacity: 0.5;
}

/* Edit Categories Button */
.edit-categories-btn {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0.5rem;
    margin-left: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    flex-shrink: 0;
}

.edit-categories-btn:hover {
    background: var(--surface-highlight);
    color: var(--primary-light);
}

.edit-categories-btn:active {
    transform: scale(0.9);
}

/* Category Edit View */
.category-edit-view .app-header {
    display: flex;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--bg-color);
}

.category-edit-container {
    padding: 1.5rem;
    flex: 1;
    overflow-y: auto;
}

.categories-edit-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.category-edit-row {
    background: var(--surface);
    padding: 1rem 1.25rem;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border);
}

.category-edit-row:hover {
    background: var(--surface-highlight);
}

.category-name {
    flex: 1;
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--text-primary);
}

.category-name-input {
    flex: 1;
    background: var(--bg-color);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    color: var(--text-primary);
    font-size: 1.05rem;
    font-weight: 500;
    outline: none;
}

.category-edit-actions {
    display: flex;
    gap: 0.5rem;
}

.category-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    width: 36px;
    height: 36px;
}

.category-btn:hover {
    background: var(--surface-highlight);
    color: var(--text-primary);
}

.category-btn.delete-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border-color: var(--danger);
}

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

.category-btn.save-btn:hover {
    background: var(--primary-dark);
}

.category-btn:active {
    transform: scale(0.9);
}

.empty-state {
    text-align: center;
    color: var(--text-tertiary);
    padding: 3rem 1.5rem;
    font-size: 0.95rem;
}

.empty-state p {
    margin: 0;
}