:root {
    --bg: #0b1220;
    --bg-2: #121a2b;
    --bg-3: #182238;
    --border: #24314d;
    --text: #e6ecf8;
    --text-dim: #94a3b8;
    --accent: #6366f1;
    --accent-2: #818cf8;
    --red: #ef4444;
    --green: #22c55e;
    --radius: 12px;
}

* { box-sizing: border-box; }

/* Атрибут hidden не работает, если у элемента задан display (grid/flex).
   Без этого правила форма входа остаётся висеть поверх приложения. */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Ubuntu, sans-serif;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 12px; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
h2 { font-size: 21px; }
h3 { font-size: 17px; }
a { color: var(--accent-2); }

/* ---------- кнопки / поля ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 14px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--bg-3);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { background: #1e2a44; border-color: #33416a; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #4f52e0; border-color: #4f52e0; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-3); }
.btn-danger { background: transparent; border-color: #7f1d1d; color: #fca5a5; }
.btn-danger:hover { background: #2a1414; }
.btn-block { width: 100%; }
.btn-mini { padding: 3px 9px; font-size: 16px; line-height: 1; }
.file-btn { position: relative; overflow: hidden; }

.input, .search, .select {
    padding: 9px 12px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--bg-2);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
}
.input:focus, .search:focus, .select:focus { border-color: var(--accent); }
.search { min-width: 190px; }

.msg { margin-top: 12px; padding: 10px 12px; border-radius: 9px; font-size: 13.5px; }
.msg-err { background: #2a1416; color: #fca5a5; border: 1px solid #7f1d1d; }
.msg-ok { background: #10281a; color: #86efac; border: 1px solid #166534; }
.msg-info { background: #14203a; color: #a5b4fc; border: 1px solid #33416a; }
.hint { color: var(--text-dim); font-size: 13px; line-height: 1.5; margin: 12px 0; }
.hint-inline { color: var(--text-dim); font-size: 12.5px; font-weight: 400; }

/* ---------- вход ---------- */
.auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: radial-gradient(circle at 50% 0%, #17233d 0%, var(--bg) 55%);
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.brand-icon { width: 34px; height: 34px; fill: var(--red); }
.brand-icon.small { width: 22px; height: 22px; }
.brand h1 { font-size: 22px; margin: 0; }
.auth-sub { color: var(--text-dim); font-size: 13.5px; margin: 0 0 22px; }
.auth-card label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--text-dim); }
.auth-card label input {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 11px 13px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    outline: none;
}
.auth-card label input:focus { border-color: var(--accent); }

/* ---------- каркас ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-2);
    position: sticky;
    top: 0;
    z-index: 40;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 14px; }
.logo-text { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.tabs { display: flex; gap: 4px; }
.tab {
    padding: 8px 13px;
    border-radius: 9px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}
.tab:hover { background: var(--bg-3); color: var(--text); }
.tab.active { background: var(--accent); color: #fff; }
.user-name { color: var(--text-dim); font-size: 13.5px; }

.layout { display: flex; align-items: flex-start; min-height: calc(100vh - 61px); }

/* ---------- сайдбар ---------- */
.sidebar {
    width: 260px;
    flex: 0 0 260px;
    border-right: 1px solid var(--border);
    padding: 16px 12px;
    position: sticky;
    top: 61px;
    max-height: calc(100vh - 61px);
    overflow-y: auto;
}
.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 6px 10px;
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-dim);
}
.playlist-list { display: flex; flex-direction: column; gap: 2px; }
.pl-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 10px;
    border-radius: 9px;
    cursor: pointer;
    color: var(--text);
    font-size: 14px;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: inherit;
}
.pl-item:hover { background: var(--bg-3); }
.pl-item.active { background: var(--accent); color: #fff; }
.pl-item .pl-count {
    font-size: 11.5px;
    padding: 1px 7px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .1);
    color: inherit;
    flex: 0 0 auto;
}
.pl-item .pl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- контент ---------- */
.content { flex: 1 1 auto; padding: 22px 24px 60px; min-width: 0; }
.feed-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.feed-meta { color: var(--text-dim); font-size: 13px; margin-top: 4px; }
.feed-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- видео ---------- */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(258px, 1fr));
    gap: 18px;
}
.vcard {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: border-color .15s, transform .15s;
    display: flex;
    flex-direction: column;
}
.vcard:hover { border-color: #3b4a6f; transform: translateY(-2px); }
.vcard.watched { opacity: .52; }
.vthumb { position: relative; aspect-ratio: 16 / 9; background: #000; }
.vthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vthumb .vdate {
    position: absolute;
    right: 6px;
    bottom: 6px;
    background: rgba(0, 0, 0, .82);
    color: #fff;
    font-size: 11.5px;
    padding: 2px 6px;
    border-radius: 5px;
}
.vthumb .vnew {
    position: absolute;
    left: 6px;
    top: 6px;
    background: var(--red);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .04em;
    padding: 2px 7px;
    border-radius: 5px;
    text-transform: uppercase;
}
.vbody { padding: 11px 12px 13px; display: flex; gap: 9px; }
.vavatar { width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto; background: var(--bg-3); object-fit: cover; }
.vtext { min-width: 0; }
.vtitle {
    font-size: 13.8px;
    line-height: 1.38;
    font-weight: 550;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.vchannel { font-size: 12.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vchannel:hover { color: var(--accent-2); }

/* ---------- каналы ---------- */
.add-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.add-row .input { flex: 1 1 320px; min-width: 0; }
.subs-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(272px, 1fr)); gap: 12px; margin-top: 18px; }
.sub-card {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 12px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.sub-card img.avatar { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; background: var(--bg-3); flex: 0 0 auto; }
.sub-info { min-width: 0; flex: 1 1 auto; }
.sub-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-stat { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.icon-btn {
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 15px;
    padding: 5px 7px;
    border-radius: 7px;
    line-height: 1;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.icon-btn.danger:hover { background: #2a1414; color: #fca5a5; }

/* ---------- редактор плейлистов ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.pl-editor-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px 16px;
    margin-bottom: 12px;
}
.pl-editor-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pl-editor-title { font-size: 16px; font-weight: 650; }
.pl-editor-desc { color: var(--text-dim); font-size: 13px; margin-top: 5px; }
.pl-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--bg-3);
    border: 1px solid var(--border);
    color: var(--text);
}
.chip img { width: 16px; height: 16px; border-radius: 50%; object-fit: cover; }
.chip.muted { color: var(--text-dim); }

/* ---------- модалки ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(4, 8, 16, .82);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.modal-inner {
    position: relative;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 22px;
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
}
.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    border: none;
    background: var(--bg-3);
    color: var(--text);
    width: 30px;
    height: 30px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}
.modal-close:hover { background: #26344f; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.modal-actions .spacer { flex: 1 1 auto; }

.player-inner { max-width: 1020px; padding: 14px; }
.player-frame { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; }
.player-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player-info { padding: 14px 6px 4px; }
.player-meta { color: var(--text-dim); font-size: 13px; margin-bottom: 12px; }
.player-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { font-size: 13px; color: var(--text-dim); }
.form-grid input[type="text"], .form-grid input[type="date"] { display: block; width: 100%; margin-top: 6px; }
.form-grid .check { display: flex; align-items: center; gap: 8px; grid-column: 1 / -1; color: var(--text); }
.pl-channels-head { display: flex; align-items: baseline; gap: 10px; margin: 18px 0 10px; flex-wrap: wrap; }
.pl-channels { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px; max-height: 320px; overflow-y: auto; }
.pl-chan {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 9px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--bg);
    cursor: pointer;
    font-size: 13.5px;
}
.pl-chan:hover { background: var(--bg-3); }
.pl-chan.on { border-color: var(--accent); background: #1a1f3d; }
.pl-chan input { accent-color: var(--accent); }
.pl-chan img { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; background: var(--bg-3); }
.pl-chan span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- прочее ---------- */
.empty { text-align: center; color: var(--text-dim); padding: 60px 20px; font-size: 14.5px; line-height: 1.6; }
.toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%);
    background: var(--bg-3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 11px 18px;
    border-radius: 10px;
    font-size: 13.5px;
    z-index: 200;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
    max-width: min(90vw, 560px);
}
.toast[hidden] { display: none; }
.toast.err { border-color: #7f1d1d; background: #241216; color: #fca5a5; }

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, .25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-card .stat-value { font-size: 25px; font-weight: 700; }
.stat-card .stat-label { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.admin-table th, .admin-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.admin-table th { color: var(--text-dim); font-weight: 500; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }

@media (max-width: 900px) {
    .sidebar { display: none; }
    .content { padding: 16px 14px 60px; }
    .topbar { padding: 10px 12px; }
    .logo-text { display: none; }
    .form-grid { grid-template-columns: 1fr; }
}
