/* ====================================
   AI Diet - Styles
   ==================================== */

:root {
    /* Light Theme (default) */
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #eef2f7;
    --text-primary: #2d3436;
    --text-secondary: #636e72;
    --text-muted: #b2bec3;
    --accent: #00b894;
    --accent-light: #55efc4;
    --accent-dark: #00a884;
    --danger: #e74c3c;
    --danger-light: #fab1a0;
    --warning: #f39c12;
    --warning-light: #ffeaa7;
    --success: #27ae60;
    --success-light: #a8e6cf;
    --border: #dfe6e9;
    --shadow: rgba(0, 0, 0, 0.08);
    --shadow-strong: rgba(0, 0, 0, 0.15);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* Border radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 50%;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #eaeaea;
    --text-secondary: #b2bec3;
    --text-muted: #636e72;
    --accent: #4ecca3;
    --accent-light: #7bf1c0;
    --accent-dark: #38b789;
    --border: #2d3748;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-strong: rgba(0, 0, 0, 0.5);
}

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

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.5;
    overflow-x: hidden;
}

#app {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    z-index: 9999;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Header */
.header {
    background: var(--bg-secondary);
    padding: var(--space-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-title {
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.header-actions {
    display: flex;
    gap: var(--space-sm);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: var(--space-md);
    padding-bottom: calc(70px + var(--space-md) + env(safe-area-inset-bottom));
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    display: flex;
    justify-content: space-around;
    padding: var(--space-sm) 0;
    padding-bottom: calc(var(--space-sm) + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 12px var(--shadow);
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-xs) var(--space-md);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.75rem;
    transition: color var(--transition-fast);
    cursor: pointer;
    background: none;
    border: none;
}

.nav-item.active {
    color: var(--accent);
}

.nav-item:hover {
    color: var(--accent-light);
}

.nav-icon {
    font-size: 1.5rem;
    margin-bottom: 2px;
}

/* Cards */
.card {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    box-shadow: 0 2px 8px var(--shadow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-sm);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
}

/* Product Item */
.product-item {
    display: flex;
    align-items: center;
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--border);
}

.product-item:last-child {
    border-bottom: none;
}

.product-icon {
    font-size: 1.5rem;
    margin-right: var(--space-sm);
}

.product-info {
    flex: 1;
}

.product-name {
    font-weight: 500;
}

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

.product-quantity {
    font-weight: 600;
    color: var(--accent);
}

/* Status badges */
.status-ok {
    color: var(--success);
}

.status-caution {
    color: var(--warning);
}

.status-danger {
    color: var(--danger);
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-ok {
    background: var(--success-light);
    color: var(--success);
}

.badge-caution {
    background: var(--warning-light);
    color: #d68910;
}

.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

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

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

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--radius-full);
}

.btn-lg {
    padding: var(--space-md) var(--space-lg);
    font-size: 1.1rem;
}

.btn-block {
    width: 100%;
}

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

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

.form-input {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color var(--transition-fast);
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23636e72' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* Search */
.search-container {
    position: relative;
    margin-bottom: var(--space-md);
}

.search-input {
    width: 100%;
    padding: var(--space-md);
    padding-left: 48px;
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.25rem;
    color: var(--text-muted);
}

/* Autocomplete */
.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    max-height: 300px;
    overflow-y: auto;
    z-index: 50;
    box-shadow: 0 4px 12px var(--shadow);
}

.autocomplete-item {
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    border-bottom: 1px solid var(--border);
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background: var(--bg-tertiary);
}

.autocomplete-item.highlighted {
    background: var(--accent-light);
}

/* Category Header */
.category-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) 0;
    margin-top: var(--space-md);
    margin-bottom: var(--space-sm);
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
}

.category-icon {
    font-size: 1.25rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 1;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: var(--space-xs);
}

.modal-body {
    padding: var(--space-md);
}

/* Fix lists inside modal */
.modal-body ul,
.modal-body ol {
    margin-left: 20px;
    margin-bottom: 16px;
}

.modal-body li {
    margin-bottom: 8px;
}

.modal-footer {
    padding: var(--space-md);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
    gap: var(--space-sm);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: var(--space-md);
}

.tab {
    flex: 1;
    padding: var(--space-sm) var(--space-md);
    text-align: center;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition-fast);
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-size: 0.95rem;
}

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

/* Shopping List Item */
.shopping-item {
    display: flex;
    align-items: flex-start;
    padding: var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    box-shadow: 0 2px 4px var(--shadow);
}

.shopping-item.purchased {
    opacity: 0.6;
}

.shopping-item.purchased .shopping-name {
    text-decoration: line-through;
}

.shopping-checkbox {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-radius: 6px;
    margin-right: var(--space-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.shopping-checkbox.checked {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.shopping-info {
    flex: 1;
}

.shopping-name {
    font-weight: 500;
}

.shopping-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Recipe Card */
.recipe-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    box-shadow: 0 2px 8px var(--shadow);
}

.recipe-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: var(--space-xs);
}

.recipe-meta {
    display: flex;
    gap: var(--space-md);
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: var(--space-sm);
}

.recipe-meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.recipe-rating {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--warning);
}

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

/* Filter bar */
.filter-bar {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
}

.filter-chip {
    padding: var(--space-xs) var(--space-md);
    background: var(--bg-tertiary);
    border: none;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.filter-chip.active {
    background: var(--accent);
    color: white;
}

/* Login page */
.login-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
}

.login-logo {
    font-size: 4rem;
    margin-bottom: var(--space-md);
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: var(--space-lg);
}

.login-form {
    width: 100%;
    max-width: 320px;
}

/* Toast notifications */
.toast-container {
    position: fixed;
    top: var(--space-md);
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    background: var(--bg-secondary);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px var(--shadow-strong);
    animation: slideDown 0.3s ease;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.toast-success {
    border-left: 4px solid var(--success);
}

.toast-error {
    border-left: 4px solid var(--danger);
}

.toast-warning {
    border-left: 4px solid var(--warning);
}

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

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

/* Empty state */
.empty-state {
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: var(--space-md);
    opacity: 0.5;
}

.empty-state-text {
    font-size: 1.1rem;
    margin-bottom: var(--space-md);
}

/* Quantity controls */
.quantity-control {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.quantity-btn {
    width: 36px;
    height: 36px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
}

.quantity-input {
    width: 60px;
    text-align: center;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--space-xs);
    font-size: 1rem;
}

/* FAB */
.fab-container {
    position: fixed;
    bottom: calc(70px + var(--space-md) + env(safe-area-inset-bottom));
    right: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 90;
    touch-action: none;
    user-select: none;
}

.fab {
    width: 56px;
    height: 56px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--shadow-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast);
}

.fab:hover {
    transform: scale(1.1);
}

.fab-ai {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.fab-left {
    position: fixed;
    left: var(--space-md);
    right: auto;
    bottom: calc(70px + var(--space-md) + env(safe-area-inset-bottom));
    background: var(--warning);
}

/* Offline Indicator */
.offline-indicator {
    position: fixed;
    bottom: calc(85px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: var(--bg-primary);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-lg);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: 0 4px 12px var(--shadow-strong);
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

body.online .offline-indicator {
    display: none;
}

/* Shopping History */
.history-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-sm);
}

.history-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.history-icon.added {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent);
}

.history-icon.purchased {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.history-icon.deleted {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.history-content {
    flex: 1;
    min-width: 0;
}

.history-content>div:first-child {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-time {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}