/* ═══════════════════════════════════════════════
   CineTG — главный стиль
   Тема подстраивается под Telegram (светлая/тёмная)
   ═══════════════════════════════════════════════ */

:root {
    --bg:        var(--tg-theme-bg-color, #0f0f0f);
    --bg2:       var(--tg-theme-secondary-bg-color, #1c1c1e);
    --text:      var(--tg-theme-text-color, #ffffff);
    --hint:      var(--tg-theme-hint-color, #8e8e93);
    --accent:    var(--tg-theme-button-color, #e50914);
    --accent-fg: var(--tg-theme-button-text-color, #ffffff);
    --gold:      #f5c518;
    --blue:      #4a9eff;
    --radius:    12px;
    --tab-h:     58px;
    --header-h:  52px;
    --safe-b:    env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #app {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
}

/* ─── Views ───────────────────────────────────────────────────────────── */
.view {
    display: none;
    flex-direction: column;
    height: calc(100dvh - var(--tab-h) - var(--safe-b));
    overflow: hidden;
}
.view.active { display: flex; }

.view-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 20px;
    -webkit-overflow-scrolling: touch;
}

/* ─── Header ──────────────────────────────────────────────────────────── */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: var(--header-h);
    flex-shrink: 0;
    background: var(--bg);
    border-bottom: 1px solid rgba(255,255,255,.06);
}

.logo {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -.3px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
}

/* ─── Search header ───────────────────────────────────────────────────── */
.search-header { padding: 8px 12px; }

.search-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--bg2);
    border-radius: 10px;
    padding: 0 10px;
    gap: 8px;
}

.search-ico { color: var(--hint); flex-shrink: 0; }

.search-input {
    flex: 1;
    border: none;
    background: none;
    color: var(--text);
    font-size: 15px;
    padding: 10px 0;
    outline: none;
}
.search-input::placeholder { color: var(--hint); }

.clear-btn {
    background: none;
    border: none;
    color: var(--hint);
    cursor: pointer;
    font-size: 16px;
    padding: 2px 4px;
}
.clear-btn.hidden { display: none; }

/* ─── Filter chips ────────────────────────────────────────────────────── */
.filter-chips {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }

.chip {
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,.15);
    background: none;
    color: var(--hint);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: all .15s;
}
.chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ─── Section ─────────────────────────────────────────────────────────── */
.section { margin-bottom: 8px; }

.section-title {
    font-size: 17px;
    font-weight: 700;
    padding: 14px 16px 10px;
}

/* ─── Horizontal row (trending) ───────────────────────────────────────── */
.movies-row {
    display: flex;
    gap: 10px;
    padding: 0 16px 4px;
    overflow-x: auto;
    scrollbar-width: none;
}
.movies-row::-webkit-scrollbar { display: none; }

.movies-row .movie-card {
    width: 130px;
    flex-shrink: 0;
}
.movies-row .movie-card img {
    height: 195px;
}

/* ─── Grid ────────────────────────────────────────────────────────────── */
.movies-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    padding: 0 12px;
}

/* ─── Movie card ──────────────────────────────────────────────────────── */
.movie-card {
    cursor: pointer;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg2);
    transition: transform .15s, opacity .15s;
    position: relative;
}
.movie-card:active { transform: scale(.96); opacity: .85; }

.movie-card img {
    width: 100%;
    height: 225px;
    object-fit: cover;
    display: block;
}

.card-overlay {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,.85) 60%);
    padding: 24px 8px 8px;
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

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

.badge {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 6px;
    line-height: 1.4;
}
.badge-tmdb  { background: var(--gold); color: #000; }
.badge-cine  { background: var(--accent); color: #fff; }
.badge-type  { background: rgba(255,255,255,.2); color: #fff; }

/* ─── Skeleton ────────────────────────────────────────────────────────── */
.skeleton-card {
    width: 130px;
    height: 195px;
    border-radius: var(--radius);
    background: linear-gradient(90deg, var(--bg2) 25%, #2a2a2e 50%, var(--bg2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    flex-shrink: 0;
}
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ─── Load more ───────────────────────────────────────────────────────── */
.load-more-btn {
    display: block;
    margin: 16px auto 4px;
    padding: 10px 32px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,.2);
    background: none;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
}

/* ─── Placeholder ─────────────────────────────────────────────────────── */
.placeholder-msg {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 300px;
    color: var(--hint);
}
.placeholder-msg span { font-size: 40px; }
.placeholder-msg p { font-size: 15px; }

/* ─── Tab bar ─────────────────────────────────────────────────────────── */
.tab-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--tab-h) + var(--safe-b));
    padding-bottom: var(--safe-b);
    display: flex;
    background: var(--bg);
    border-top: 1px solid rgba(255,255,255,.08);
    z-index: 100;
}

.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: none;
    background: none;
    color: var(--hint);
    font-size: 10px;
    cursor: pointer;
    transition: color .15s;
}
.tab-btn.active { color: var(--accent); }
.tab-btn svg { transition: stroke .15s; }

/* ─── Detail overlay ──────────────────────────────────────────────────── */
.detail-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform .3s cubic-bezier(.32,0,.67,0);
}
.detail-overlay.visible { transform: translateY(0); }
.detail-overlay.hidden  { transform: translateY(100%); }

.detail-close {
    position: absolute;
    top: 12px;
    right: 14px;
    z-index: 10;
    width: 32px; height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,.5);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.detail-scroll {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(80px + var(--safe-b));
}

/* Backdrop hero */
.detail-backdrop {
    width: 100%;
    height: 220px;
    object-fit: cover;
    display: block;
    position: relative;
}
.detail-backdrop-wrap {
    position: relative;
    overflow: hidden;
}
.detail-backdrop-wrap::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 80px;
    background: linear-gradient(transparent, var(--bg));
}

/* Detail content */
.detail-content { padding: 0 16px 16px; }

.detail-title {
    font-size: 22px;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 6px;
}

.detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-bottom: 10px;
    color: var(--hint);
    font-size: 13px;
}

.detail-ratings {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.rating-pill {
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--bg2);
    border-radius: 10px;
    padding: 6px 12px;
}
.rating-pill .label { font-size: 11px; color: var(--hint); }
.rating-pill .score { font-size: 20px; font-weight: 800; }
.rating-pill .count { font-size: 11px; color: var(--hint); }
.rating-pill.tmdb  .score { color: var(--gold); }
.rating-pill.cine  .score { color: var(--accent); }
.rating-pill.mine  .score { color: var(--blue); }

/* Genres */
.genres {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.genre-tag {
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,.15);
    font-size: 12px;
    color: var(--hint);
}

/* Action buttons */
.detail-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.btn-rate {
    flex: 1;
    min-width: 120px;
    padding: 11px;
    border-radius: var(--radius);
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
.btn-share {
    padding: 11px 16px;
    border-radius: var(--radius);
    border: 1px solid rgba(255,255,255,.2);
    background: none;
    color: var(--text);
    font-size: 15px;
    cursor: pointer;
}

/* Overview */
.detail-section-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 8px;
    margin-top: 18px;
}
.overview-text {
    font-size: 14px;
    line-height: 1.6;
    color: var(--hint);
}
.overview-text.collapsed {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.expand-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 13px;
    cursor: pointer;
    padding: 4px 0;
}

/* Cast */
.cast-row {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
}
.cast-row::-webkit-scrollbar { display: none; }

.cast-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    min-width: 68px;
    text-align: center;
}
.cast-photo {
    width: 60px; height: 60px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg2);
}
.cast-name {
    font-size: 11px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Reviews */
.review-card {
    background: var(--bg2);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 10px;
}
.review-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.review-author { font-size: 13px; font-weight: 600; }
.review-rating  { font-size: 13px; color: var(--gold); font-weight: 700; }
.review-text { font-size: 13px; color: var(--hint); line-height: 1.5; }

/* Similar */
.similar-row {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 4px;
}
.similar-row::-webkit-scrollbar { display: none; }
.similar-row .movie-card { width: 110px; flex-shrink: 0; }
.similar-row .movie-card img { height: 165px; }

/* ─── Rating modal ────────────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: var(--safe-b);
    backdrop-filter: blur(6px);
}
.modal-backdrop.hidden { display: none; }

.modal-box {
    background: var(--bg2);
    border-radius: 20px 20px 0 0;
    padding: 24px 20px calc(24px + var(--safe-b));
    width: 100%;
    max-width: 480px;
}

.modal-title {
    font-size: 17px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 16px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.rating-big {
    text-align: center;
    margin-bottom: 10px;
}
.rating-big #rating-number {
    font-size: 52px;
    font-weight: 800;
    color: var(--gold);
    line-height: 1;
}
.rating-max { font-size: 22px; color: var(--hint); }

/* Slider */
.slider {
    width: 100%;
    accent-color: var(--gold);
    margin-bottom: 4px;
    cursor: pointer;
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--hint);
    margin-bottom: 14px;
}

.comment-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    padding: 10px 12px;
    resize: none;
    font-family: inherit;
    outline: none;
    margin-bottom: 16px;
}
.comment-input::placeholder { color: var(--hint); }

.modal-actions {
    display: flex;
    gap: 10px;
}
.btn-cancel {
    flex: 1;
    padding: 12px;
    border-radius: var(--radius);
    border: 1px solid rgba(255,255,255,.2);
    background: none;
    color: var(--text);
    font-size: 15px;
    cursor: pointer;
}
.btn-submit {
    flex: 2;
    padding: 12px;
    border-radius: var(--radius);
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

/* ─── Toast ───────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: calc(var(--tab-h) + 16px + var(--safe-b));
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #333;
    color: #fff;
    font-size: 14px;
    padding: 10px 20px;
    border-radius: 20px;
    z-index: 500;
    opacity: 0;
    transition: opacity .2s, transform .2s;
    white-space: nowrap;
    max-width: 80vw;
    text-align: center;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast.hidden { display: none; }

/* ─── Profile ─────────────────────────────────────────────────────────── */
.profile-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px 16px;
    gap: 10px;
}
.avatar {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    color: #fff;
}
.profile-name { font-size: 18px; font-weight: 700; }
.profile-username { font-size: 14px; color: var(--hint); }

.stats-row {
    display: flex;
    justify-content: center;
    gap: 24px;
    padding: 12px 16px;
    background: var(--bg2);
    margin: 0 12px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.stat-item { text-align: center; }
.stat-num  { font-size: 22px; font-weight: 700; }
.stat-lbl  { font-size: 12px; color: var(--hint); }

.profile-section-title {
    font-size: 15px;
    font-weight: 700;
    padding: 4px 16px 10px;
}

.review-list-item {
    display: flex;
    gap: 12px;
    padding: 10px 16px;
    align-items: center;
    cursor: pointer;
}
.review-list-item:active { background: var(--bg2); }
.review-poster {
    width: 46px; height: 69px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--bg2);
    flex-shrink: 0;
}
.review-meta { flex: 1; min-width: 0; }
.review-meta-title {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.review-meta-score {
    font-size: 13px;
    color: var(--gold);
    margin-top: 3px;
}
.review-meta-comment {
    font-size: 12px;
    color: var(--hint);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── No-auth notice ──────────────────────────────────────────────────── */
.auth-notice {
    padding: 32px 24px;
    text-align: center;
    color: var(--hint);
    line-height: 1.6;
}
.auth-notice span { font-size: 40px; display: block; margin-bottom: 12px; }

/* ─── Utility ─────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
