/* =============================================================
   Голосовой Todo List — оформление в стиле Google
   Тёмная тема по умолчанию + светлая. Чистый CSS, без библиотек.
   Тема переключается атрибутом <html data-theme="dark|light">
   (его ставит js/theme.js ещё до первой отрисовки страницы).
   ============================================================= */


/* 1. ПЕРЕМЕННЫЕ ТЕМ ------------------------------------------- */

:root {
    /* Тёмная тема (по умолчанию) */
    color-scheme: dark;

    --bg-color: #202124;
    --card-bg: #202124;
    --card-border: #3c4043;
    --field-bg: #303134;
    --row-hover: #292a2d;

    --primary-text: #e8eaed;
    --secondary-text: #9aa0a6;

    --accent-color: #8ab4f8;
    --accent-hover: #aecbfa;
    --on-accent: #202124;
    --hover-bg: rgba(138, 180, 248, 0.08);
    --press-bg: rgba(138, 180, 248, 0.16);

    --status-success: #81c995;
    --on-success: #202124;

    /* Идёт запись голоса / ошибки */
    --rec-color: #f28b82;
    --rec-hover: #f6aea9;
    --on-rec: #202124;
    --rec-glow: rgba(242, 139, 130, 0.45);
    --rec-bg: rgba(242, 139, 130, 0.12);

    --disabled-bg: rgba(232, 234, 237, 0.12);
    --disabled-text: rgba(232, 234, 237, 0.38);

    --scroll-thumb: #303134;
    --scroll-thumb-hover: #80868b;

    --pad: 24px;
    --sb: 6px;      /* ширина полос прокрутки */
    --row-h: 49px;  /* высота однострочной задачи вместе с линией: по ней считается лимит блока «Выполнено» */
    --font: "Google Sans", "Google Sans Text", Roboto, "Segoe UI", system-ui,
        -apple-system, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="light"] {
    /* Светлая тема */
    color-scheme: light;

    --bg-color: #ffffff;
    --card-bg: #ffffff;
    --card-border: #dadce0;
    --field-bg: #f1f3f4;
    --row-hover: #f8f9fa;

    --primary-text: #202124;
    --secondary-text: #5f6368;

    --accent-color: #1a73e8;
    --accent-hover: #1765cc;
    --on-accent: #ffffff;
    --hover-bg: rgba(66, 133, 244, 0.04);
    --press-bg: rgba(66, 133, 244, 0.12);

    --status-success: #1e8e3e;
    --on-success: #ffffff;

    --rec-color: #d93025;
    --rec-hover: #b31412;
    --on-rec: #ffffff;
    --rec-glow: rgba(217, 48, 37, 0.35);
    --rec-bg: rgba(217, 48, 37, 0.08);

    --disabled-bg: rgba(60, 64, 67, 0.12);
    --disabled-text: rgba(60, 64, 67, 0.38);

    --scroll-thumb: #bdc1c6;
    --scroll-thumb-hover: #9aa0a6;
}


/* 2. БАЗОВЫЕ СТИЛИ -------------------------------------------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Атрибут hidden не должен проигрывать display из наших классов */
[hidden] {
    display: none !important;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    font: 400 14px/20px var(--font);
    color: var(--primary-text);
    background-color: var(--bg-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button,
input {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Полосы прокрутки: тонкие (6px), без стрелок. Chrome, Edge, Safari, Opera */
::-webkit-scrollbar {
    width: var(--sb);
    height: var(--sb);
}

::-webkit-scrollbar-track,
::-webkit-scrollbar-corner {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    border-radius: calc(var(--sb) / 2);
    background-color: var(--scroll-thumb);
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--scroll-thumb-hover);
}

::-webkit-scrollbar-button {
    display: none;
}

/* Firefox: точную ширину задать нельзя, доступна только «тонкая» (thin) */
@supports not selector(::-webkit-scrollbar) {
    * {
        scrollbar-width: thin;
        scrollbar-color: var(--scroll-thumb) transparent;
    }
}

/* Плавная смена темы: класс вешается на <html> только на время перехода */
@media (prefers-reduced-motion: no-preference) {
    html.theme-anim,
    html.theme-anim *,
    html.theme-anim *::before,
    html.theme-anim *::after {
        transition: background-color 0.3s ease, color 0.3s ease,
            border-color 0.3s ease, box-shadow 0.3s ease !important;
    }
}


/* 3. КАРКАС СТРАНИЦЫ ------------------------------------------ */

.app {
    display: flex;
    flex-direction: column;
    max-width: 840px;
    height: 100vh;                       /* запасной вариант */
    height: calc(var(--vh, 1vh) * 100);  /* js/viewport.js: реальная высота окна (браузеры без dvh) */
    height: 100dvh;                      /* видимая область без учёта скрытой адресной строки */
    margin: 0 auto;
    padding: 16px;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex: none;
    padding: 8px 0 16px;
}

.app-title {
    margin: 0;
    font-size: 22px;
    line-height: 28px;
    font-weight: 400;
}

/* «Voice ToDo | Задачи 4» */
.app-heading {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.app-heading-sep {
    flex: none;
    width: 1px;
    height: 20px;
    background-color: var(--card-border);
}

.app-heading .section-title {
    font-size: 16px;
    line-height: 24px;
}

.card {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    background-color: var(--card-bg);
}

/* Секции внутри карточки отделяются линией на всю ширину */
.card > section,
.card > details {
    padding: 24px var(--pad);
}

.card > * + * {
    border-top: 1px solid var(--card-border);
}

/* Карточка не выше экрана: форма добавления закреплена, а список задач прокручивается внутри */
.composer {
    flex: none;
}

/* Блок задач занимает всё свободное место, поэтому «Выполнено» всегда прижато к низу карточки */
.card > .todos-active {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 120px;
    padding-block: 8px;
}

.todos-active > .todo-list {
    flex: 0 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.card > .todos-done {
    flex: none;
}

/* В «Выполнено» видно не больше трёх задач, дальше — прокрутка (и не выше 30% окна на низких экранах) */
.todos-done .todo-list {
    max-height: min(calc(var(--row-h) * 3), 30vh);
    max-height: min(calc(var(--row-h) * 3), 30dvh);
    overflow-y: auto;
}

.section-title {
    margin: 0;
    font-size: 14px;
    line-height: 20px;
    font-weight: 500;
    color: var(--secondary-text);
}

.count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background-color: var(--field-bg);
    color: var(--secondary-text);
    font-size: 12px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}


/* 4. КНОПКИ --------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 36px;
    padding: 0 24px;
    border: 1px solid transparent;
    border-radius: 20px;
    background: transparent;
    font-size: 14px;
    line-height: 20px;
    font-weight: 500;
    white-space: nowrap;
    transition: background-color 0.2s, border-color 0.2s, color 0.2s,
        box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn .icon {
    flex: none;
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.btn-sm {
    padding: 0 16px;
}

.btn-lg {
    height: 48px;
    border-radius: 24px;
}

/* Контурная кнопка — как «Скачать» в примере */
.btn-outlined {
    color: var(--accent-color);
    border-color: var(--card-border);
}

.btn-outlined:hover {
    background-color: var(--hover-bg);
    border-color: var(--accent-color);
}

.btn-outlined:active {
    background-color: var(--press-bg);
}

/* Основная кнопка */
.btn-filled {
    color: var(--on-accent);
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

.btn-filled:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn:disabled,
.btn:disabled:hover {
    cursor: not-allowed;
    color: var(--disabled-text);
    background-color: var(--disabled-bg);
    border-color: transparent;
}

/* Переключатель темы: иконка и подпись показывают, НА какую тему перейдём */
.theme-toggle {
    position: relative;
    color: var(--primary-text);
}

:root:not([data-theme="light"]) .theme-toggle .icon-moon,
:root:not([data-theme="light"]) .theme-toggle .label-to-dark,
:root[data-theme="light"] .theme-toggle .icon-sun,
:root[data-theme="light"] .theme-toggle .label-to-light {
    display: none;
}


/* 5. ДОБАВЛЕНИЕ ЗАДАЧИ ---------------------------------------- */

.input-group {
    display: flex;
    gap: 8px;
}

.field {
    flex: 1 1 auto;
    min-width: 0;
    height: 48px;
    padding: 0 20px;
    border: 1px solid var(--card-border);
    border-radius: 24px;
    background-color: var(--field-bg);
    color: var(--primary-text);
    font-size: 16px;
    line-height: 24px;
    outline: none;
    caret-color: var(--accent-color);
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

.field::placeholder {
    color: var(--secondary-text);
    opacity: 1;
}

.field:hover {
    border-color: var(--secondary-text);
}

.field:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 1px var(--accent-color);
}

/* Микрофон: в покое — иконка и «Записать голосом», при записи — эквалайзер и «Слушаю…» */
.btn-mic .eq,
.btn-mic .label-rec {
    display: none;
}

.eq {
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: 20px;
    height: 20px;
}

.eq i {
    display: block;
    width: 3px;
    height: 16px;
    border-radius: 2px;
    background-color: currentColor;
    animation: eq 0.9s ease-in-out infinite;
}

.eq i:nth-child(1) { animation-delay: -0.45s; }
.eq i:nth-child(2) { animation-delay: -0.15s; }
.eq i:nth-child(3) { animation-delay: -0.60s; }
.eq i:nth-child(4) { animation-delay: -0.30s; }

@keyframes eq {
    0%, 100% { transform: scaleY(0.3); }
    50%      { transform: scaleY(1); }
}

/* Класс .recording ставит и снимает js/app.js */
.btn-mic.recording {
    color: var(--on-rec);
    background-color: var(--rec-color);
    border-color: var(--rec-color);
    animation: rec-pulse 1.4s ease-out infinite;
}

.btn-mic.recording:hover {
    background-color: var(--rec-hover);
    border-color: var(--rec-hover);
}

.btn-mic.recording .icon-mic,
.btn-mic.recording .label-idle {
    display: none;
}

.btn-mic.recording .eq {
    display: inline-flex;
}

.btn-mic.recording .label-rec {
    display: inline;
}

/* Пока говорим — поле ввода тоже подсвечивается */
.input-group:has(.btn-mic.recording) .field {
    border-color: var(--rec-color);
    box-shadow: 0 0 0 1px var(--rec-color);
}

@keyframes rec-pulse {
    0%   { box-shadow: 0 0 0 0 var(--rec-glow); }
    70%, 100% { box-shadow: 0 0 0 12px transparent; }
}

/* Микрофон недоступен — длинная подпись может переноситься */
.btn-mic:disabled {
    height: auto;
    min-height: 48px;
    padding-block: 8px;
    white-space: normal;
    text-align: center;
    line-height: 18px;
}


/* 6. СПИСОК ЗАДАЧ --------------------------------------------- */

/* Список выходит на всю ширину карточки, чтобы подсветка строк и линии были «от края до края» */
.todo-list {
    margin: 0 calc(-1 * var(--pad));
    padding: 0;
    list-style: none;
    scrollbar-gutter: stable; /* место под полосу резервируется всегда: колонки времени в обоих списках выровнены */
}

.todo-item {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    column-gap: 8px;
    align-items: start;
    padding: 4px calc(var(--pad) - var(--sb)) 4px var(--pad);
    border-bottom: 1px solid var(--card-border);
    transition: background-color 0.2s;
    animation: item-in 0.16s ease-out;
}

.todo-item:last-child {
    border-bottom: 0;
}

.todo-item:hover {
    background-color: var(--row-hover);
}

@keyframes item-in {
    from { opacity: 0; }
}

/* Чекбокс: кнопка 40×40 (удобная зона нажатия), кружок и галочка рисуются псевдоэлементами */
.todo-checkbox {
    position: relative;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background-color: transparent;
    color: var(--secondary-text);
    transition: background-color 0.2s, color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.todo-checkbox::before {
    content: "";
    position: absolute;
    inset: 10px;
    border: 2px solid currentColor;
    border-radius: 50%;
    transition: background-color 0.15s, border-color 0.15s;
}

.todo-checkbox::after {
    content: "";
    position: absolute;
    left: 17px;
    top: 13px;
    width: 6px;
    height: 11px;
    border: solid var(--on-success);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) scale(0);
    transition: transform 0.15s ease-out;
}

.todo-checkbox:hover {
    color: var(--accent-color);
    background-color: var(--hover-bg);
}

.todo-checkbox.done::before {
    background-color: var(--status-success);
    border-color: var(--status-success);
}

.todo-checkbox.done::after {
    transform: rotate(45deg) scale(1);
}

.todo-checkbox.done:hover {
    color: var(--status-success);
}

/* Текст задачи (contenteditable) */
.text-box {
    display: block;
    min-height: 40px;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 16px;
    line-height: 24px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    outline: none;
    cursor: text;
    caret-color: var(--accent-color);
    transition: background-color 0.2s, box-shadow 0.2s;
}

.text-box:focus {
    background-color: var(--field-bg);
    box-shadow: inset 0 0 0 2px var(--accent-color);
}

.text-box:empty::before {
    content: "Пустая задача";
    color: var(--secondary-text);
}

/* Первая буква заглавная и пока набираете (в данных её поправит app.js при выходе из поля) */
.text-box::first-letter {
    text-transform: uppercase;
}

/* Выполненная задача: чекбокс стоит прямо перед текстом */
.todo-checkbox.done + .text-box {
    color: var(--secondary-text);
    text-decoration: line-through;
}

.todo-meta {
    padding: 4px 0;
    text-align: right;
    color: var(--secondary-text);
    font-size: 12px;
    line-height: 16px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}


/* 7. СЕКЦИЯ «ВЫПОЛНЕНО» И СОСТОЯНИЯ ---------------------------- */

.todos-done > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: -8px calc(-1 * var(--pad)) 0;
    padding: 8px var(--pad);
    list-style: none;
    cursor: pointer;
    transition: background-color 0.2s;
}

.todos-done > summary::-webkit-details-marker {
    display: none;
}

.todos-done > summary:hover {
    background-color: var(--row-hover);
}

.chevron {
    flex: none;
    width: 20px;
    height: 20px;
    fill: var(--secondary-text);
    transform: rotate(-90deg);
    transition: transform 0.2s;
}

.todos-done[open] .chevron {
    transform: rotate(0);
}

.empty {
    margin: 0;
    padding: 24px 0 16px;
    text-align: center;
    color: var(--secondary-text);
}

.notice {
    margin: 0 0 12px;
    padding: 12px 16px;
    border: 1px solid var(--rec-color);
    border-radius: 8px;
    background-color: var(--rec-bg);
}


/* 8. АДАПТИВ -------------------------------------------------- */

/* Форма добавления: первая строка — поле и круглая кнопка «+»,
   вторая — микрофон на всю ширину. Подпись «Добавить» скрыта визуально,
   но остаётся доступной для скринридеров. */
@media (max-width: 720px) {
    .input-group {
        flex-wrap: wrap;
    }

    .field {
        flex: 1 1 0;
    }

    .btn-add {
        position: relative;
        flex: none;
        width: 48px;
        padding: 0;
    }

    .btn-add .btn-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .btn-mic {
        flex: 1 1 100%;
    }
}

@media (max-width: 640px) {
    :root {
        --pad: 16px;
    }

    .app {
        padding: 12px;
    }

    .card > section,
    .card > details {
        padding-block: 16px;
    }
}

/* Телефоны: у переключателя темы остаётся только иконка (подпись — для скринридеров),
   а время и дата задачи уходят под текст, чтобы текст не сжимался в узкую колонку */
@media (max-width: 480px) {
    :root {
        --row-h: 73px; /* время и дата под текстом — строка выше */
    }

    .app-title {
        font-size: 20px;
        line-height: 26px;
    }

    .theme-toggle {
        padding: 0 10px;
    }

    .theme-toggle .theme-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .todo-item {
        grid-template-columns: 40px minmax(0, 1fr);
    }

    .todo-meta {
        grid-column: 2;
        display: flex;
        gap: 8px;
        padding: 0 10px 8px;
        text-align: left;
    }
}


/* 8б. НИЗКИЕ ОКНА (клавиатура на экране, ландшафт) ------------ */

/* Уплотняем отступы и сжимаем «Выполнено», чтобы всё помещалось без прокрутки страницы */
@media (max-height: 600px) {
    .app {
        padding-block: 8px;
    }

    .app-header {
        padding: 4px 0 8px;
    }

    .card > .composer {
        padding-block: 8px;
    }

    .card > .todos-active {
        min-height: 56px;
        padding-block: 4px;
    }

    .card > .todos-done {
        padding-block: 8px;
    }

    .todos-done .todo-list {
        max-height: min(calc(var(--row-h) * 3), 18vh);
        max-height: min(calc(var(--row-h) * 3), 18dvh);
    }
}

/* Совсем низко (например, маленький телефон с клавиатурой) блок «Выполнено» не показываем */
@media (max-height: 360px) {
    .card > .todos-done {
        display: none;
    }
}


/* 9. ПОНИЖЕННАЯ АНИМАЦИЯ -------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition-duration: 0.01ms !important;
    }

    /* Эквалайзер без анимации — просто разновысокие столбики */
    .eq i:nth-child(1) { transform: scaleY(0.5); }
    .eq i:nth-child(2) { transform: scaleY(1); }
    .eq i:nth-child(3) { transform: scaleY(0.65); }
    .eq i:nth-child(4) { transform: scaleY(0.85); }
}
