/* ===== CSS-переменные (цвета, размеры — меняем в одном месте) ===== */
:root {
    --bg-color: #f5f5f5;
    --card-bg: #ffffff;
    --primary: #4a90d9;
    --primary-hover: #357abd;
    --danger: #e74c3c;
    --text-color: #333333;
    --text-muted: #999999;
    --border-color: #e0e0e0;
    --checked-bg: #f0f0f0;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --header-height: 56px;
    --add-bar-height: 72px;
}

/* ===== Сброс стилей и общие настройки ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

/* ===== Утилиты ===== */
.hidden {
    display: none !important;
}

/* ===== Экран авторизации ===== */
.auth-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    width: 100%;
    max-width: 360px;
}

.auth-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.auth-tab.active {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(74, 144, 217, 0.05);
}

.auth-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 16px;
    outline: none;
    margin-bottom: 12px;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.auth-input:focus {
    border-color: var(--primary);
}

.auth-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius);
    background: var(--primary);
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 12px;
}

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

.auth-btn:active {
    transform: scale(0.98);
}

.auth-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.auth-switch-text {
    font-size: 14px;
    color: var(--text-muted);
    text-align: center;
    margin-top: 4px;
}

.auth-switch-text a {
    color: var(--primary);
    text-decoration: none;
}

.auth-switch-text a:hover {
    text-decoration: underline;
}

.auth-error {
    margin-top: 12px;
    color: var(--danger);
    font-size: 14px;
    text-align: center;
}

.auth-error.hidden {
    display: none;
}

.auth-hint {
    margin-top: 20px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
}

/* Кнопка выхода */
.btn-logout {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    transition: color 0.2s;
}

.btn-logout:hover {
    color: white;
}

/* ===== Экраны (переключение) ===== */
.screen {
    display: none;
    flex-direction: column;
    height: 100vh;          /* fallback для старых браузеров */
    height: 100dvh;         /* dvh пересчитывается при появлении клавиатуры (iOS Safari 16+) */
    max-width: 480px;
    margin: 0 auto;
    overflow: hidden;
}

.screen.active {
    display: flex;
}

/* ===== Шапка ===== */
.header {
    display: flex;
    align-items: center;
    height: var(--header-height);
    padding: 0 20px;
    background: var(--primary);
    color: white;
    flex-shrink: 0;
    z-index: 10;
}

.header h1,
.header h2 {
    font-size: 20px;
    font-weight: 600;
    flex: 1;
}

.btn-back {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0 12px 0 0;
    line-height: 1;
}

/* ===== Кнопка Share ===== */
.share-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    padding: 6px;
    line-height: 0;
    border-radius: 8px;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.share-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.share-btn:active {
    transform: scale(0.93);
}

.share-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== Контейнер со списком (прокручиваемая область) ===== */
.container {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    -webkit-overflow-scrolling: touch;
}

/* ===== Карточки списков (экран 1) ===== */
.list-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 8px;
    box-shadow: var(--shadow);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.15s ease, background 0.15s ease;
}

.list-card:active {
    transform: scale(0.98);
    background: #f8f8f8;
}

.list-card-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.list-card-name {
    font-size: 16px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-card-count {
    font-size: 13px;
    color: var(--text-muted);
}

/* Поле редактирования названия списка (inline) */
.list-card-edit-input {
    font-size: 16px;
    font-weight: 500;
    font-family: inherit;
    border: none;
    border-bottom: 2px solid var(--primary);
    background: transparent;
    outline: none;
    padding: 2px 0;
    flex: 1;
    min-width: 0;
    color: var(--text-color);
}

/* Badge "Shared" */
.shared-badge {
    display: inline-block;
    background: var(--primary);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    margin-left: 8px;
    flex-shrink: 0;
    letter-spacing: 0.3px;
}

/* ===== Элементы списка (экран 2) ===== */
.item-row {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
    margin-bottom: 6px;
}

.item-content {
    background: var(--card-bg);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    position: relative;
    z-index: 2;
    transition: transform 0.25s ease;
}

.item-content.swiping {
    transition: none;
}

/* Чекбокс */
.item-checkbox {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
}

.item-checkbox.checked {
    background: var(--primary);
    border-color: var(--primary);
}

.item-checkbox.checked::after {
    content: "✓";
    color: white;
    font-size: 13px;
    font-weight: bold;
}

/* Название продукта */
.item-name {
    font-size: 16px;
    flex: 1;
    transition: all 0.25s ease;
}

.item-name.checked {
    text-decoration: line-through;
    color: var(--text-muted);
}

/* Зачёркнутый элемент — фон */
.item-content.checked {
    background: var(--checked-bg);
}

/* Ручка перетаскивания */
.drag-handle {
    cursor: grab;
    color: var(--text-muted);
    font-size: 16px;
    padding: 0 4px;
    user-select: none;
    touch-action: none;
    flex-shrink: 0;
}

/* Элемент во время перетаскивания */
.item-row.item-dragging {
    opacity: 0.9;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    border-radius: var(--radius);
}

/* Плейсхолдер — место, куда упадёт элемент */
.drag-placeholder {
    background: var(--primary);
    opacity: 0.15;
    border-radius: var(--radius);
    margin-bottom: 6px;
}

/* Красная зона при свайпе */
.item-delete-bg {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: var(--danger);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 20px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    z-index: 1;
}

/* ===== Нижняя панель ввода ===== */
.add-bar {
    width: 100%;
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    z-index: 10;
    flex-shrink: 0;
}

.input-wrapper {
    flex: 1;
    position: relative;
}

.add-bar input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
}

.add-bar input:focus {
    border-color: var(--primary);
}

.btn-add {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    border: none;
    background: var(--primary);
    color: white;
    font-size: 24px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}

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

.btn-add:active {
    transform: scale(0.95);
}

/* ===== Выпадающие подсказки ===== */
.suggestions {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: 4px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    max-height: 200px;
    overflow-y: auto;
    z-index: 20;
}

.suggestions.hidden {
    display: none;
}

.suggestion-item {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 15px;
    border-bottom: 1px solid var(--border-color);
}

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

.suggestion-item:active {
    background: #f0f0f0;
}

/* ===== Модал Share ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.hidden {
    display: none !important;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.modal-content {
    position: relative;
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    z-index: 1;
}

.modal-content h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-color);
}

.modal-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.invite-url-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 16px;
    word-break: break-all;
}

.invite-url-text {
    flex: 1;
    font-size: 13px;
    color: var(--text-color);
    line-height: 1.4;
}

.btn-copy {
    flex-shrink: 0;
    padding: 6px 12px;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

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

.btn-secondary {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

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

/* ===== Invite-экран ===== */
#invite-screen .container {
    padding-top: 0;
}

/* Баннер приглашения */
.invite-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
    color: white;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.invite-banner span {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    min-width: 0;
}

.invite-banner-btn {
    padding: 7px 14px;
    border: 2px solid rgba(255, 255, 255, 0.7);
    border-radius: 20px;
    background: transparent;
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}

.invite-banner-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: white;
}

.invite-banner-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ===== Анимации ===== */
@keyframes slide-in {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slide-out {
    from {
        opacity: 1;
        max-height: 60px;
        margin-bottom: 6px;
    }
    to {
        opacity: 0;
        max-height: 0;
        margin-bottom: 0;
        padding: 0;
    }
}

.item-row.adding {
    animation: slide-in 0.25s ease forwards;
}

.item-row.removing {
    animation: slide-out 0.3s ease forwards;
    pointer-events: none;
}

/* ===== Сообщение об ошибке на экране списков ===== */
.lists-error {
    margin: 8px 16px 0;
    padding: 10px 14px;
    background: #fdecea;
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    color: var(--danger);
    font-size: 14px;
    text-align: center;
    transition: opacity 0.2s ease;
}

.lists-error.hidden {
    display: none;
}

/* ===== Пустые состояния ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: #aaa;
    text-align: center;
}
.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
}
.empty-state-title {
    font-size: 18px;
    font-weight: 500;
    margin: 0 0 8px;
    color: #999;
}
.empty-state-hint {
    font-size: 14px;
    margin: 0;
    color: #bbb;
}

/* ===== Аватар-кнопка в шапке ===== */
.avatar-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.6);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, transform 0.15s;
}

.avatar-btn:hover {
    border-color: white;
    transform: scale(1.05);
}

/* ===== Экран профиля ===== */
.profile-container {
    padding: 16px;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 0 24px;
}

.profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 28px;
    font-weight: 700;
    flex-shrink: 0;
}

.profile-name {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-color);
}

.profile-email {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 2px;
}

.settings-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}

.settings-section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.settings-input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 15px;
    color: var(--text-color);
    background: transparent;
    outline: none;
    box-sizing: border-box;
    margin-bottom: 10px;
    transition: border-color 0.2s;
    font-family: inherit;
}

.settings-input:focus {
    border-color: var(--primary);
}

.settings-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.settings-input-row .settings-input {
    margin-bottom: 0;
}

.btn-save {
    padding: 10px 16px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s;
}

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

.auth-success {
    color: #2e7d32;
    font-size: 14px;
    text-align: center;
    margin-top: 8px;
}

.danger-zone {
    border: 1px solid #ffcdd2;
}

.danger-title {
    color: #e53935 !important;
}

.danger-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.4;
}

.btn-danger {
    width: 100%;
    padding: 12px;
    background: #e53935;
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-danger:hover {
    background: #c62828;
}

.btn-danger:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

/* ===== Модал участников ===== */
.members-list {
    max-height: 320px;
    overflow-y: auto;
    margin-bottom: 16px;
}

.member-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.member-row:last-child {
    border-bottom: none;
}

.member-info {
    flex: 1;
    min-width: 0;
}

.member-name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-color);
}

.member-email {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.member-owner-badge {
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    background: rgba(74, 144, 217, 0.1);
    padding: 2px 8px;
    border-radius: 20px;
    flex-shrink: 0;
}

.btn-remove-member {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(231, 76, 60, 0.1);
    color: var(--danger);
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

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

.btn-remove-member:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.members-loading {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 14px;
}
