* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: #f4f5f7;
    color: #1d232a;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex; justify-content: space-between; align-items: center;
    background: #1e293b; color: #fff; padding: 10px 20px;
}
.topbar .brand { color: #fff; font-weight: 600; font-size: 18px; }
.topbar .logout { color: #cbd5e1; font-size: 14px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.whoami { color: #94a3b8; font-size: 14px; }

.page-title { font-size: 22px; margin: 4px 0 14px; }
.user-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.user-form input[type=text] { flex: 1; min-width: 160px; margin-bottom: 0; }
.check-label { display: flex; align-items: center; gap: 6px; font-size: 14px;
    color: #475569; white-space: nowrap; }
.user-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.user-actions input[type=text] { width: 140px; margin-bottom: 0; padding: 6px 10px;
    font-size: 13px; }

.container { max-width: 1000px; margin: 0 auto; padding: 20px 16px 60px; }

.card {
    background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
    padding: 16px 18px; margin-bottom: 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.card h2 { margin: 0 0 8px; font-size: 17px; }
.card h3 { margin: 12px 0 6px; font-size: 15px; }

.create-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .create-grid { grid-template-columns: 1fr; } }

.candidates { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 10px; }
.short-check { display: flex; align-items: center; gap: 6px; margin: -4px 0 10px; }
.short-check input { width: 16px; height: 16px; min-width: 0; margin: 0; flex: none; }
.lang-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    margin-top: 10px; }
.lang-row label, .lang-row .hint { margin: 0; white-space: nowrap; }
.lang-row .check-label { display: inline-flex; align-items: center; gap: 6px; }
.lang-row input[type=text] { flex: 0 1 170px; min-width: 120px; margin-bottom: 0; }
.lang-row input[type=checkbox] { width: 16px; height: 16px; min-width: 0;
    margin: 0; flex: none; }
.lang-pair { display: inline-flex; align-items: center; gap: 8px; flex: 0 1 auto; }
.lang-pair input[type=text] { flex: 0 1 170px; min-width: 110px; margin-bottom: 0; }
.mode-switch { display: flex; gap: 16px; margin-bottom: 10px; font-size: 14px; }
.mode-switch label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.search-row { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.search-row input { flex: 1; min-width: 200px; margin-bottom: 0; }
.vocalize-options { display: flex; gap: 14px; margin-bottom: 10px; flex-wrap: wrap; }
.vocalize-options label { display: flex; flex-direction: column; gap: 4px; }

.hint { color: #64748b; font-size: 13px; margin: 4px 0 10px; }
.muted { color: #64748b; font-size: 13px; }

textarea, input[type=text], input[type=password] {
    width: 100%; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 8px;
    font: inherit; margin-bottom: 10px; background: #fff;
}
textarea { resize: vertical; }

.btn {
    display: inline-block; padding: 8px 16px; border: 1px solid #cbd5e1;
    border-radius: 8px; background: #fff; color: #1d232a; font: inherit;
    cursor: pointer;
}
.btn:hover { background: #f1f5f9; }
.btn-primary { background: #2563eb; border-color: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { border-color: #dc2626; color: #dc2626; }
.btn-danger:hover { background: #fef2f2; }
.btn-small { padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.inline { display: inline; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.flash-ok { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }
.hidden { display: none !important; }

.status {
    display: flex; align-items: center; gap: 10px; padding: 10px 0;
    color: #475569; font-size: 14px;
}
.spinner {
    width: 18px; height: 18px; border: 3px solid #cbd5e1; border-top-color: #2563eb;
    border-radius: 50%; animation: spin .8s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.list-title { margin-top: 28px; }
table.songs { width: 100%; border-collapse: collapse; background: #fff;
    border: 1px solid #e2e8f0; border-radius: 10px; overflow: hidden; }
table.songs th, table.songs td { padding: 8px 12px; text-align: left;
    border-bottom: 1px solid #eef2f7; font-size: 14px; }
table.songs th { background: #f8fafc; color: #475569; font-weight: 600; }
table.songs tr:last-child td { border-bottom: none; }
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: #f8fafc; }

.badge {
    display: inline-block; padding: 2px 10px; border-radius: 999px;
    background: #e2e8f0; color: #475569; font-size: 12px;
}
.badge-ok { background: #dcfce7; color: #166534; }

.song-head h1 { margin: 0 0 6px; font-size: 24px; }
.song-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.tags-form { display: flex; gap: 6px; flex: 1; min-width: 280px; }
.tags-form input { flex: 1; margin-bottom: 0; padding: 4px 10px; font-size: 13px; color: #475569; }
.tags-form .btn { white-space: nowrap; }

.song-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; align-items: start; }
.song-grid .card:nth-child(3), .song-grid .card:nth-child(4) { grid-column: 1 / -1; }
@media (max-width: 820px) { .song-grid { grid-template-columns: 1fr; } }

pre.lyrics {
    white-space: pre-wrap; font-family: inherit; font-size: 15px; line-height: 1.55;
    background: #f8fafc; border: 1px solid #eef2f7; border-radius: 8px;
    padding: 12px 14px; margin: 0 0 12px;
}

.track { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.track audio { flex: 1; min-width: 220px; }
.track-title { font-weight: 600; font-size: 14px; min-width: 80px; }

details.version { margin-bottom: 10px; }
details.version summary { cursor: pointer; font-size: 14px; color: #475569; }
details.version pre.lyrics { margin-top: 8px; }

.delete-form { margin-top: 8px; }

.photos-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px; margin-bottom: 12px;
}
.photo-item { position: relative; }
.photo-item img, .photo-item video {
    width: 100%; aspect-ratio: 9 / 16; object-fit: cover;
    border-radius: 6px; border: 1px solid #e2e8f0; display: block;
    background: #000;
}
.photo-del {
    position: absolute; top: 4px; right: 4px; width: 22px; height: 22px;
    border: none; border-radius: 50%; background: rgba(15, 23, 42, .65);
    color: #fff; font-size: 14px; line-height: 1; cursor: pointer;
}
.photo-del:hover { background: #dc2626; }
.progress { height: 10px; background: #e2e8f0; border-radius: 999px;
    overflow: hidden; margin: 10px 0 4px; }
.progress-fill { height: 100%; width: 0; background: #2563eb; transition: width .2s; }

.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px; }
.lib-item { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 8px; }
.lib-item img, .lib-item video { width: 100%; aspect-ratio: 9 / 16; object-fit: cover;
    border-radius: 6px; background: #000; display: block; }
.lib-meta { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; font-size: 13px; }
.lib-name { font-weight: 600; overflow-wrap: anywhere; }

.stock-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px; margin-top: 12px; }
.stock-item { position: relative; border: 1px solid #e2e8f0; border-radius: 8px;
    overflow: hidden; background: #000; display: flex; flex-direction: column; }
.stock-item img { width: 100%; aspect-ratio: 9 / 16; object-fit: cover; display: block; }
.stock-item .stock-add { margin: 6px; }

details.lib-pick { margin: 4px 0 12px; }
details.lib-pick summary { cursor: pointer; font-size: 14px; color: #475569;
    margin-bottom: 8px; }
.photo-item.pick { cursor: pointer; display: block; }
.photo-item.pick input { position: absolute; top: 6px; left: 6px; width: 18px;
    height: 18px; z-index: 2; }
.photo-item.pick:has(input:checked) img { outline: 3px solid #2563eb; }

/* Монтажная шкала */
.tl-scale {
    display: flex; align-items: stretch; gap: 2px; min-height: 64px;
    background: #eef2f7; border: 1px dashed #cbd5e1; border-radius: 8px;
    padding: 4px; margin: 8px 0 4px; overflow-x: auto;
}
.tl-empty { align-self: center; margin: 0 auto; }
.tl-item {
    position: relative; min-width: 42px; border-radius: 6px; cursor: pointer;
    background: #334155 center / cover no-repeat; border: 2px solid transparent;
    flex: 0 0 auto;
}
.tl-item.tl-item-video { background: #1e293b; }
.tl-item.sel { border-color: #2563eb; }
.tl-dur {
    position: absolute; bottom: 2px; left: 4px; color: #fff; font-size: 11px;
    text-shadow: 0 1px 2px rgba(0,0,0,.8);
}
.tl-palette {
    display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 4px;
}
.tl-pal-item {
    position: relative; width: 64px; height: 96px; border-radius: 6px;
    overflow: hidden; cursor: pointer; border: 1px solid #e2e8f0; background: #000;
}
.tl-pal-item img, .tl-pal-item video {
    width: 100%; height: 100%; object-fit: cover; display: block;
}
.tl-pal-item:hover { outline: 2px solid #2563eb; }
.tl-tag {
    position: absolute; top: 2px; right: 3px; font-size: 11px; color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,.9);
}
#tl-ctl { margin: 6px 0; }

.video-box { margin-top: 16px; border-top: 1px solid #eef2f7; padding-top: 12px; }
.video-box video, .stock-video video {
    display: block; margin: 0 auto; max-width: 100%; max-height: 480px;
    aspect-ratio: 9 / 16; border-radius: 8px; background: #000;
}
select { padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 8px; font: inherit; }
.stock-video { margin-top: 14px; padding-top: 10px; border-top: 1px dashed #e2e8f0; }
.title-edit { background: none; border: none; font-size: 20px; cursor: pointer;
    vertical-align: middle; opacity: .6; }
.title-edit:hover { opacity: 1; }
.title-form { display: flex; gap: 8px; margin: 6px 0 10px; flex-wrap: wrap;
    align-items: center; }
.title-form input { flex: 1 1 260px; font-size: 18px; font-weight: 600; }
#stock-prompt { margin-top: 10px; }
.inspire-box { margin-top: 16px; border-top: 1px solid #eef2f7; padding-top: 12px; }

.login-box { max-width: 360px; margin: 60px auto; background: #fff;
    border: 1px solid #e2e8f0; border-radius: 10px; padding: 24px; }
.login-box h1 { margin: 0 0 16px; font-size: 20px; }
.login-box label { display: block; font-size: 14px; color: #475569; margin-bottom: 4px; }

/* ---- Мобильная вёрстка (все ресурсы локальные, без CDN) ---- */
@media (max-width: 720px) {
    .container { padding: 12px 10px 40px; }
    .card { padding: 14px 12px; border-radius: 12px; }
    .topbar { padding: 12px 14px; position: sticky; top: 0; z-index: 10; }
    .btn { padding: 12px 18px; border-radius: 10px; }
    .btn-small { padding: 8px 12px; }
    textarea, input[type=text], input[type=password], select {
        padding: 11px 12px; font-size: 16px; /* 16px — iOS не зумит поле */
    }
    .btn-row { gap: 8px; }
    .btn-row .btn, .btn-row form, .btn-row .inline { flex: 1 1 auto; }
    .btn-row .inline .btn { width: 100%; }
    .song-head h1 { font-size: 20px; }
    .tags-form { min-width: 100%; }
    .track { gap: 8px; }
    .track audio { min-width: 100%; }
    .photos-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .video-box video, .stock-video video { max-height: 70vh; }
    .vocalize-options { gap: 10px; }
    .vocalize-options label { flex: 1 1 45%; }
    /* Таблица песен — компактные карточки-строки */
    table.songs th:nth-child(2), table.songs td:nth-child(2),
    table.songs th:nth-child(6), table.songs td:nth-child(6) { display: none; }
    table.songs th, table.songs td { padding: 10px 8px; }
}
