:root {
    --red: #E30A17;
    --red-dark: #B5060F;
    --turquoise: #00838F;
    --ink: #2B1A0B;
    --muted: #7B6552;
    --paper: rgba(255, 250, 240, 0.93);
    --paper-strong: #FFFAF0;
    --cell: rgba(255, 253, 247, 0.84);
    --cell-weekend: rgba(255, 243, 226, 0.86);
    --line: rgba(110, 66, 20, 0.16);
    --radius: 18px;
    --shadow: 0 14px 40px rgba(35, 15, 0, 0.35);
    --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    color: var(--ink);
    line-height: 1.4;
}

a {
    color: inherit;
}

.muted {
    color: var(--muted);
}

/* ---------- Кнопки, поля ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: 999px;
    font: 700 15px/1.1 var(--font);
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    background: #fff;
    color: var(--ink);
    transition: transform .12s ease, box-shadow .12s ease, background-color .12s ease;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, .15);
}

.btn:focus-visible,
.chip:focus-visible,
.event:focus-visible,
.day-add:focus-visible,
summary:focus-visible {
    outline: 3px solid #FFC94D;
    outline-offset: 2px;
}

.btn.primary {
    background: var(--red);
    color: #fff;
}

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

.btn.ghost {
    background: rgba(255, 255, 255, .6);
    border-color: var(--line);
}

.btn.danger {
    background: #fff;
    color: #B3261E;
    border-color: #E8B4B0;
}

.btn.danger:hover {
    background: #FDECEA;
}

.btn.small {
    padding: 7px 12px;
    font-size: 13px;
}

.btn.wide {
    width: 100%;
    padding: 13px 18px;
    font-size: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 18px;
    min-width: 0;
}

.label {
    font-weight: 700;
    font-size: 14px;
}

.opt {
    font-weight: 400;
    color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="time"],
select {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid rgba(110, 66, 20, .28);
    border-radius: 12px;
    background: #fff;
    font: 16px var(--font);
    color: var(--ink);
}

select {
    appearance: none;
    padding-right: 36px;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%237B6552' stroke-width='2'/%3E%3C/svg%3E") right 14px center no-repeat;
    cursor: pointer;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--turquoise);
    box-shadow: 0 0 0 3px rgba(0, 131, 143, .2);
}

input.invalid,
select.invalid,
.multiselect.invalid summary {
    border-color: #C62828;
    background: #FFF6F5;
}

.note {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.err {
    margin: 0;
    color: #B3261E;
    font-size: 13px;
    font-weight: 600;
}

.alert {
    padding: 10px 14px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-weight: 600;
    font-size: 14px;
}

.alert.error {
    background: #FDECEA;
    color: #8C1D18;
}

.alert.ok {
    background: #E6F4EA;
    color: #1E5A2B;
}

.ava {
    display: inline-grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--turquoise);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    flex: none;
}

/* ---------- Страница входа: турецкий флаг ---------- */

/* Поле флага сплошное красное, поэтому флаг масштабируется так, чтобы полумесяц
   со звездой целиком помещались слева от карточки, а остальное — тот же красный фон. */
.login-page {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 24px max(24px, 7vw);
    background: #E30A17 url("../images/turkey-flag.svg") 2vw 50% / auto min(100vh, calc(100vw - 520px)) no-repeat;
    overflow-x: hidden;
}

/* лёгкая «ткань»: медленные светлые и тёмные складки поверх флага */
.flag-waves {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(100deg,
    rgba(0, 0, 0, .10) 0, rgba(255, 255, 255, .06) 9%, rgba(0, 0, 0, .10) 18%);
    background-size: 200% 100%;
    animation: waves 14s linear infinite;
}

@keyframes waves {
    to {
        background-position: -200% 0;
    }
}

.login-card {
    position: relative;
    width: 100%;
    max-width: 400px;
    padding: 32px 30px 28px;
    border-radius: 24px;
    background: rgba(255, 252, 247, .94);
    box-shadow: 0 24px 60px rgba(70, 0, 0, .45);
    backdrop-filter: blur(6px);
}

.login-logo {
    display: block;
    margin-bottom: 12px;
    border-radius: 14px;
    box-shadow: 0 6px 14px rgba(160, 0, 10, .35);
}

.login-card h1 {
    margin: 0 0 6px;
    font-size: 30px;
    font-weight: 800;
}

.login-card > p {
    margin: 0 0 22px;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: -4px 0 20px;
    font-size: 14px;
    cursor: pointer;
}

.check input {
    width: 18px;
    height: 18px;
    accent-color: var(--red);
}

/* на телефоне эмблема сверху по центру, карточка под ней */
@media (max-width: 760px) {
    .login-page {
        justify-content: center;
        align-items: flex-start;
        padding: calc(48vw + 8px) 16px 28px;
        background-size: 110vw auto;
        background-position: 6vw -12vw;
    }
}

/* ---------- Внутренние страницы: пахлава ---------- */

.app-page {
    background-color: #4A2508;
    background-image: linear-gradient(rgba(60, 28, 4, .10), rgba(40, 18, 2, .30)),
    url("../images/baklava.svg");
    background-size: auto, 240px auto;
    background-attachment: fixed, fixed;
}

.page {
    max-width: 1640px;
    margin: 0 auto;
    padding: 18px 20px 28px;
}

.glass {
    background: var(--paper);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(4px);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    margin-bottom: 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    min-width: 0;
}

.brand img {
    border-radius: 11px;
    flex: none;
}

.brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand strong {
    font-size: 20px;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand small {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.topbar-actions form {
    margin: 0;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 16px;
    padding: 10px 16px;
    margin-bottom: 12px;
}

.stats {
    margin: 0;
    font-weight: 700;
}

.status {
    color: var(--red-dark);
}

.sep {
    color: var(--muted);
    margin: 0 4px;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px 5px 6px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .75);
    text-decoration: none;
    font-weight: 700;
    font-size: 14px;
}

.chip:first-child {
    padding-left: 12px;
}

.chip:hover {
    background: #fff;
}

.chip.active {
    background: var(--turquoise);
    border-color: var(--turquoise);
    color: #fff;
}

.chip.active .ava {
    background: #fff;
    color: var(--turquoise);
}

.toast {
    position: fixed;
    z-index: 50;
    left: 50%;
    bottom: 24px;
    width: max-content;
    max-width: calc(100vw - 32px);
    padding: 12px 20px;
    border-radius: 14px;
    background: #E6F4EA;
    color: #1E5A2B;
    font-weight: 700;
    box-shadow: var(--shadow);
    transform: translateX(-50%);
    animation: toast 4.5s ease forwards;
    pointer-events: none;
}

.toast.error {
    background: #FDECEA;
    color: #8C1D18;
}

@keyframes toast {
    0% {
        opacity: 0;
        transform: translate(-50%, 12px);
    }
    8%, 85% {
        opacity: 1;
        transform: translate(-50%, 0);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, 0);
    }
}

.foot {
    margin-top: 14px;
    text-align: center;
    color: rgba(255, 244, 222, .92);
    font-size: 14px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}

/* ---------- Календарь и бэклог рядом ---------- */

.board {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 12px;
    align-items: start;
}

.backlog {
    position: sticky;
    top: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: calc(100vh - 24px);
    padding: 14px;
    overflow: auto;
}

.backlog-head {
    display: flex;
    align-items: center;
    gap: 8px;
}

.backlog-head h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
}

.backlog-count {
    min-width: 24px;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--turquoise);
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    text-align: center;
}

.backlog-hint,
.backlog-empty {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.backlog-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* карточка идеи: цвет события — полоска слева */
.bl-card {
    --c: var(--turquoise);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px 10px 8px;
    border-radius: 12px;
    border-left: 5px solid var(--c);
    background: #fff;
    box-shadow: 0 2px 8px rgba(40, 15, 0, .15);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    transition: box-shadow .12s ease, transform .12s ease;
}

.bl-card:hover {
    box-shadow: 0 6px 16px rgba(40, 15, 0, .22);
    transform: translateY(-1px);
}

.bl-grip {
    color: #C2AE9B;
    font-size: 16px;
    line-height: 1;
}

.bl-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.bl-title {
    font-weight: 800;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.bl-title:hover {
    text-decoration: underline;
}

.bl-author {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}

.bl-author .ava {
    background: var(--c);
}

.bl-card.dragging {
    opacity: .35;
}

/* копия карточки, которая едет за курсором/пальцем */
.bl-ghost {
    position: fixed;
    z-index: 100;
    top: 0;
    left: 0;
    margin: 0;
    pointer-events: none;
    cursor: grabbing;
    box-shadow: 0 16px 36px rgba(30, 10, 0, .45);
    rotate: 2deg;
}

.dnd-active,
.dnd-active * {
    cursor: grabbing !important;
}

.day.drop-target {
    outline: 3px dashed var(--turquoise);
    outline-offset: -3px;
    background: rgba(214, 245, 243, .92);
}

.day.saving {
    opacity: .6;
}

/* ---------- Сетка календаря ---------- */

.calendar.glass {
    padding: 10px;
    background: rgba(45, 20, 2, .22);
    box-shadow: none;
    backdrop-filter: none;
}

.weekdays,
.grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 10px;
}

.weekdays {
    margin-bottom: 8px;
}

.weekdays div {
    padding: 5px 10px;
    border-radius: 10px;
    background: rgba(255, 250, 240, .9);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}

.weekdays .weekend {
    color: var(--red-dark);
}

.day {
    position: relative;
    min-height: 118px;
    padding: 6px;
    border-radius: 12px;
    background: var(--cell);
    border: 1px solid rgba(255, 255, 255, .5);
    box-shadow: 0 4px 12px rgba(40, 15, 0, .28);
    backdrop-filter: blur(3px);
    scroll-margin-top: 16px;
}

.day.weekend {
    background: var(--cell-weekend);
}

.day.past:not(.today) {
    opacity: .72;
}

.day.out {
    background: rgba(255, 250, 240, .18);
    border: 1px dashed rgba(255, 240, 210, .55);
    box-shadow: none;
    backdrop-filter: none;
    color: #FFF3DC;
}

.day.today {
    border: 2px solid var(--red);
    box-shadow: 0 0 0 3px rgba(227, 10, 23, .18);
}

.day:target {
    animation: flash-day 1.6s ease;
}

@keyframes flash-day {
    0%, 40% {
        box-shadow: 0 0 0 4px #FFC94D;
    }
}

.day-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 6px;
    min-height: 26px;
    padding: 0 30px 4px 2px;
}

.day-num {
    font-size: 18px;
    font-weight: 800;
}

.day-month {
    font-size: 13px;
    font-weight: 700;
    color: var(--red-dark);
}

.day-full {
    display: none;
}

.today-badge {
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--red);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
}

.day-add {
    position: absolute;
    top: 6px;
    right: 6px;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    text-decoration: none;
    font-size: 19px;
    font-weight: 700;
    line-height: 1;
    color: var(--turquoise);
    background: rgba(0, 131, 143, .1);
    opacity: .55;
    transition: opacity .12s ease, background-color .12s ease;
}

.day:hover .day-add,
.day-add:focus-visible {
    opacity: 1;
}

.day-add:hover {
    background: var(--turquoise);
    color: #fff;
}

.events {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* плашка события; цвет задаётся через --c (фон) и --t (текст) */
.event {
    --c: var(--turquoise);
    --t: #fff;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 5px 7px;
    border-radius: 9px;
    background: var(--c);
    color: var(--t);
    text-decoration: none;
    font-size: 13px;
    line-height: 1.25;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
    transition: transform .1s ease, filter .1s ease;
}

a.event:hover {
    transform: translateY(-1px);
    filter: brightness(1.08);
}

.event-line {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
}

.event-time {
    flex: none;
    font-weight: 800;
}

.event-title {
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.event-meta {
    flex-wrap: wrap;
    row-gap: 3px;
    font-size: 12px;
    opacity: .92;
}

.event-place {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.event-place::before {
    content: "📍";
    margin-right: 2px;
    font-size: 10px;
}

.avas {
    display: flex;
    flex: none;
    margin-left: auto;
}

.event .ava {
    width: 17px;
    height: 17px;
    margin-left: -4px;
    font-size: 10px;
    background: rgba(255, 255, 255, .92);
    color: var(--c);
    box-shadow: 0 0 0 1.5px var(--c);
}

.event .ava:first-child {
    margin-left: 0;
}

/* ---------- Форма события ---------- */

.form-card {
    max-width: 760px;
    margin: 0 auto;
    padding: 24px 26px;
}

.form-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.form-head h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 800;
}

.form-hint {
    margin: -6px 0 18px;
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(0, 131, 143, .09);
    color: #0B5A61;
    font-size: 14px;
}

.row {
    display: grid;
    grid-template-columns: 1.3fr 1fr 1fr;
    gap: 0 14px;
}

.multiselect {
    position: relative;
}

.multiselect summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 14px;
    border: 1px solid rgba(110, 66, 20, .28);
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    list-style: none;
    font-size: 16px;
}

.multiselect summary::-webkit-details-marker {
    display: none;
}

.multiselect[open] summary {
    border-color: var(--turquoise);
    box-shadow: 0 0 0 3px rgba(0, 131, 143, .2);
}

.ms-caret {
    color: var(--muted);
    transition: transform .15s ease;
}

.multiselect[open] .ms-caret {
    transform: rotate(180deg);
}

.ms-panel {
    position: absolute;
    z-index: 10;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    padding: 6px;
    border-radius: 14px;
    background: var(--paper-strong);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.ms-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
}

.ms-option:hover {
    background: rgba(0, 131, 143, .08);
}

.ms-option input {
    width: 18px;
    height: 18px;
    accent-color: var(--turquoise);
}

.ms-actions {
    display: flex;
    gap: 6px;
    padding: 8px 4px 4px;
    border-top: 1px solid var(--line);
    margin-top: 4px;
}

.ms-actions [data-ms="close"] {
    margin-left: auto;
}

.swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.swatch {
    position: relative;
    cursor: pointer;
}

.swatch input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}

.swatch-dot {
    display: block;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--c);
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .12);
    transition: transform .1s ease;
}

.swatch:hover .swatch-dot {
    transform: scale(1.08);
}

.swatch input:checked + .swatch-dot {
    box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--c);
}

.swatch input:checked + .swatch-dot::after {
    content: "✓";
    display: grid;
    place-items: center;
    height: 100%;
    color: var(--t);
    font-weight: 800;
    font-size: 18px;
}

.swatch input:focus-visible + .swatch-dot {
    outline: 3px solid #FFC94D;
    outline-offset: 5px;
}

.preview {
    max-width: 260px;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding-top: 6px;
}

.delete-form {
    margin: 0 0 0 auto;
}

.error-card {
    margin-top: 12vh;
    text-align: center;
}

.error-card h1 {
    margin-top: 0;
}

/* ---------- Средняя ширина: бэклог лентой над календарём ---------- */

@media (max-width: 1180px) {
    .board {
        grid-template-columns: minmax(0, 1fr);
    }

    .backlog {
        position: static;
        order: -1;
        max-height: none;
        overflow: visible;
    }

    .backlog-list {
        flex-direction: row;
        overflow-x: auto;
        padding-bottom: 4px;
    }

    .backlog-list li {
        flex: 0 0 230px;
    }

    .backlog > .btn.wide {
        align-self: flex-start;
        width: auto;
    }
}

/* ---------- Телефоны: календарь превращается в список дней ---------- */

@media (max-width: 760px) {
    .page {
        padding: 10px 10px 20px;
    }

    .topbar {
        padding: 10px 12px;
    }

    .brand strong {
        font-size: 17px;
    }

    .brand small {
        font-size: 12px;
    }

    .brand img {
        width: 34px;
        height: 34px;
    }

    .topbar-actions .btn {
        padding: 9px 12px;
        font-size: 14px;
    }

    .weekdays {
        display: none;
    }

    .grid {
        grid-template-columns: 1fr;
    }

    .day {
        min-height: 0;
    }

    .day.out {
        display: none;
    }

    .day-num,
    .day-month {
        display: none;
    }

    .day-full {
        display: inline-block;
        font-weight: 800;
        font-size: 15px;
    }

    .day-full::first-letter {
        text-transform: uppercase;
    }

    .day-add {
        opacity: 1;
    }

    .event {
        font-size: 14px;
        padding: 7px 10px;
    }

    .form-card {
        padding: 18px 16px;
    }

    .form-head {
        flex-direction: column-reverse;
        align-items: flex-start;
    }

    .form-head h1 {
        font-size: 22px;
    }

    .row {
        grid-template-columns: 1fr 1fr;
    }

    .row .field:first-child {
        grid-column: 1 / -1;
    }
}

@media (max-width: 420px) {
    .brand-text small,
    .btn-label {
        display: none;
    }

    .topbar-actions a.btn {
        width: 40px;
        padding: 0;
        height: 38px;
        font-size: 20px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .flag-waves,
    .day:target {
        animation: none;
    }

    .toast {
        animation-duration: 6s;
    }

    .btn,
    .event,
    .swatch-dot {
        transition: none;
    }
}
