/* === Переменные тем === */
:root,
[data-theme="light"] {
    --bg: #ffffff;
    --bg-secondary: #f5f5f5;
    --text: #1a1a1a;
    --text-secondary: #8e8e93;
    --border: #e5e5ea;
    --accent: #007aff;
    --accent-light: #e3f0ff;
    --danger: #ff3b30;
    --badge-author: #007aff;
    --badge-admin: #8e8e93;
    --input-bg: #f2f2f7;
    --pinned-bg: #fffde7;
    --reaction-bg: #f2f2f7;
    --reaction-active: #e3f0ff;
    --context-bg: #ffffff;
    --overlay: rgba(0, 0, 0, 0.3);
    --shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --bg: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --text: #ffffff;
    --text-secondary: #8e8e93;
    --border: #38383a;
    --accent: #0a84ff;
    --accent-light: #1a3a5c;
    --danger: #ff453a;
    --badge-author: #0a84ff;
    --badge-admin: #636366;
    --input-bg: #2c2c2e;
    --pinned-bg: #2c2c1e;
    --reaction-bg: #2c2c2e;
    --reaction-active: #1a3a5c;
    --context-bg: #2c2c2e;
    --overlay: rgba(0, 0, 0, 0.5);
    --shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}

/* === Системная тема === */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #1c1c1e;
        --bg-secondary: #2c2c2e;
        --text: #ffffff;
        --text-secondary: #8e8e93;
        --border: #38383a;
        --accent: #0a84ff;
        --accent-light: #1a3a5c;
        --danger: #ff453a;
        --badge-author: #0a84ff;
        --badge-admin: #636366;
        --input-bg: #2c2c2e;
        --pinned-bg: #2c2c1e;
        --reaction-bg: #2c2c2e;
        --reaction-active: #1a3a5c;
        --context-bg: #2c2c2e;
        --overlay: rgba(0, 0, 0, 0.5);
        --shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
    }
}

/* === Базовые стили === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.4;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.hidden { display: none !important; }

/* === Шапка === */
header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.header-title {
    font-size: 17px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.header-icon { font-size: 20px; }

.header-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* === Состояния === */
.state-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-secondary);
}

.state-icon { font-size: 48px; }

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* === Список комментариев === */
#comments-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
}

/* === Закреплённый === */
.pinned-wrapper {
    background: var(--pinned-bg);
    border-bottom: 1px solid var(--border);
    padding: 4px 0;
}

.pinned-label {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 16px 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* === Комментарий === */
.comment {
    padding: 8px 16px;
    display: flex;
    gap: 10px;
    transition: background 0.3s;
}

.comment.highlight {
    background: var(--accent-light);
}

.comment.reply {
    margin-left: 40px;
    padding-left: 12px;
    border-left: 2px solid var(--border);
}

.comment-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-secondary);
    flex-shrink: 0;
    object-fit: cover;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.comment-body {
    flex: 1;
    min-width: 0;
}

.comment-header {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.comment-name {
    font-weight: 600;
    font-size: 14px;
}

.badge {
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    color: #fff;
    text-transform: uppercase;
}

.badge-author { background: var(--badge-author); }
.badge-admin { background: var(--badge-admin); }

.comment-time {
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: auto;
}

.comment-edited {
    font-size: 11px;
    color: var(--text-secondary);
    font-style: italic;
}

.comment-text {
    margin-top: 2px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* === Реакции === */
.comment-reactions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.reaction-chip {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    border-radius: 12px;
    background: var(--reaction-bg);
    font-size: 13px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
}

.reaction-chip.active {
    background: var(--reaction-active);
    border-color: var(--accent);
}

.reaction-chip:active {
    transform: scale(0.95);
}

.reaction-count {
    font-size: 12px;
    color: var(--text-secondary);
}

/* === Reply ссылка === */
.comment-reply-link {
    font-size: 13px;
    color: var(--accent);
    margin-top: 4px;
    cursor: pointer;
}

.reply-quote {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 4px 8px;
    border-radius: 6px;
    border-left: 2px solid var(--accent);
    margin-bottom: 4px;
    cursor: pointer;
}

/* === Индикатор новых === */
#new-indicator {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 10;
    animation: slideUp 0.3s ease;
}

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

/* === Форма ввода === */
#input-area {
    border-top: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
    padding: 0 0 env(safe-area-inset-bottom);
}

#reply-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    background: var(--bg-secondary);
    font-size: 13px;
    color: var(--accent);
    border-bottom: 1px solid var(--border);
}

#reply-bar button {
    background: none;
    border: none;
    font-size: 16px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 12px;
}

#comment-input {
    flex: 1;
    background: var(--input-bg);
    border: none;
    border-radius: 18px;
    padding: 8px 14px;
    font-size: 15px;
    color: var(--text);
    resize: none;
    max-height: 120px;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
}

#comment-input::placeholder {
    color: var(--text-secondary);
}

#send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s;
}

#send-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.input-meta {
    padding: 0 16px 6px;
    font-size: 11px;
    color: var(--text-secondary);
    text-align: right;
}

/* === Контекстное меню (bottom sheet) === */
.context-overlay, .reaction-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--overlay);
    z-index: 100;
}

.context-sheet {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--context-bg);
    border-radius: 16px 16px 0 0;
    padding: 8px 0 env(safe-area-inset-bottom);
    z-index: 101;
    max-height: 60vh;
    overflow-y: auto;
    animation: sheetUp 0.25s ease;
}

@keyframes sheetUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.context-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.1s;
}

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

.context-item.danger {
    color: var(--danger);
}

/* === Панель реакций === */
.reaction-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--context-bg);
    border-radius: 16px 16px 0 0;
    padding: 16px 20px env(safe-area-inset-bottom);
    z-index: 101;
    display: flex;
    justify-content: space-around;
    animation: sheetUp 0.25s ease;
}

.reaction-bar button {
    font-size: 28px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: transform 0.1s, background 0.1s;
}

.reaction-bar button:active {
    transform: scale(1.2);
    background: var(--bg-secondary);
}

/* === Админ бар === */
#admin-bar {
    padding: 8px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

#admin-bar button {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
}

/* === Брендинг === */
#branding {
    text-align: center;
    padding: 6px;
    font-size: 12px;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
}

#branding a {
    color: var(--text-secondary);
    text-decoration: none;
}
