/* === Базовые переменные темы (переопределяются из Telegram themeParams) === */
:root {
    --bg-color: #ffffff;
    --text-color: #000000;
    --hint-color: #999999;
    --link-color: #2481cc;
    --button-color: #2481cc;
    --button-text-color: #ffffff;
    --destructive-color: #ff3b30;
    --section-bg: #f4f4f6;
    --separator-color: #e3e3e5;
    --card-bg: #ffffff;
    --radius: 12px;
}

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

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 16px;
    line-height: 1.4;
    padding-bottom: env(safe-area-inset-bottom);
    overflow-x: hidden;
}

#app {
    min-height: 100vh;
    max-width: 600px;
    margin: 0 auto;
    position: relative;
}

/* === Экраны === */
.view {
    display: none;
    min-height: 100vh;
    flex-direction: column;
}

.view.active {
    display: flex;
}

/* === Заголовок === */
.header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top));
    position: sticky;
    top: 0;
    background: var(--bg-color);
    z-index: 10;
    border-bottom: 1px solid var(--separator-color);
}

.header h1 {
    flex: 1;
    font-size: 20px;
    font-weight: 600;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-btn, .back-btn {
    background: none;
    border: none;
    color: var(--link-color);
    font-size: 26px;
    font-weight: 400;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s;
    flex-shrink: 0;
}

.header-btn:active, .back-btn:active {
    background: var(--separator-color);
}

/* Кнопка удаления списка — деструктивное действие */
.delete-btn {
    font-size: 19px;
}

.delete-btn:active {
    background: var(--destructive-color);
    color: #fff;
}

.back-btn {
    font-size: 32px;
    line-height: 1;
}

/* === Контейнеры === */
.lists-container, .items-container {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.loading {
    text-align: center;
    color: var(--hint-color);
    padding: 40px 16px;
}

.empty-state {
    text-align: center;
    color: var(--hint-color);
    padding: 60px 24px;
}

.empty-state .emoji {
    font-size: 48px;
    display: block;
    margin-bottom: 12px;
}

/* === Карточки списков === */
.list-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: transform 0.1s, box-shadow 0.15s;
    border: 1px solid var(--separator-color);
}

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

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

.list-card .list-title {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-card .list-meta {
    font-size: 13px;
    color: var(--hint-color);
}

.list-card .progress-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

/* === Задачи === */
.item {
    background: var(--card-bg);
    border-radius: var(--radius);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--separator-color);
    cursor: pointer;
    transition: background 0.1s;
}

.item:active {
    background: var(--section-bg);
}

.item .checkbox {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--hint-color);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.item.done .checkbox {
    background: var(--link-color);
    border-color: var(--link-color);
}

.item.done .checkbox::after {
    content: "✓";
    color: var(--button-text-color);
    font-size: 14px;
    font-weight: 700;
}

.item .item-text {
    flex: 1;
    word-break: break-word;
}

.item.done .item-text {
    color: var(--hint-color);
    text-decoration: line-through;
}

.item .item-delete {
    background: none;
    border: none;
    color: var(--hint-color);
    font-size: 20px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.15s;
}

.item:hover .item-delete {
    opacity: 1;
}

.item .item-delete:active {
    color: var(--destructive-color);
}

/* === Форма добавления === */
.add-form {
    padding: 12px;
    background: var(--bg-color);
    border-top: 1px solid var(--separator-color);
    display: flex;
    gap: 8px;
    position: sticky;
    bottom: 0;
}

.add-form.hidden {
    display: none;
}

.add-form input {
    flex: 1;
    padding: 12px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--separator-color);
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 16px;
    outline: none;
}

.add-form input:focus {
    border-color: var(--link-color);
}

.add-form button, .primary-btn {
    padding: 12px 20px;
    border-radius: var(--radius);
    border: none;
    background: var(--button-color);
    color: var(--button-text-color);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}

.add-form button:active, .primary-btn:active {
    opacity: 0.85;
}

/* === Полоса участников === */
.members-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    overflow-x: auto;
    background: var(--section-bg);
    border-bottom: 1px solid var(--separator-color);
}

.member-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--button-color);
    color: var(--button-text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
    border: 2px solid var(--bg-color);
}

.members-count {
    font-size: 13px;
    color: var(--hint-color);
    margin-left: 4px;
    white-space: nowrap;
}

/* === Экран шеринки === */
.share-container {
    padding: 24px 16px;
    flex: 1;
}

.share-hint {
    color: var(--hint-color);
    font-size: 14px;
    margin-bottom: 16px;
}

.share-link-box {
    background: var(--section-bg);
    border-radius: var(--radius);
    padding: 16px;
    font-family: monospace;
    font-size: 13px;
    word-break: break-all;
    margin-bottom: 16px;
    color: var(--text-color);
    user-select: all;
}

.primary-btn {
    width: 100%;
    margin-bottom: 8px;
}

.secondary-btn {
    width: 100%;
    padding: 12px 20px;
    border-radius: var(--radius);
    border: 1px solid var(--link-color);
    background: transparent;
    color: var(--link-color);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.members-list {
    margin-top: 24px;
}

.members-list-title {
    font-size: 13px;
    text-transform: uppercase;
    color: var(--hint-color);
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

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

.member-row .member-info {
    flex: 1;
}

.member-row .member-name {
    font-weight: 500;
}

.member-row .member-role {
    font-size: 12px;
    color: var(--hint-color);
}

/* === Тосты === */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 1000;
    animation: toast-in 0.3s;
    max-width: 90%;
    text-align: center;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* === Тёмная тема === */
@media (prefers-color-scheme: dark) {
    :root {
        --section-bg: #1c1c1e;
        --separator-color: #38383a;
        --card-bg: #2c2c2e;
    }
}
