/* Стили для редактора категорий и проектов */

/* Ensure flex containers wrap content properly */
:where([style*="display"][style*="flex"]) {
    flex-wrap: wrap;
}

/* Keep header padding and force toggle to sit to the right without auto margins on small screens */
@media (max-width: 480px) {
    .subscription-item {
        padding: 0 !important;
    }
    .subscription-item-header {
        padding: 8px !important;
    }
    .subscription-item-header .toggle-switch {
        margin-left: 8px !important;
    }
}

/* Модальное окно */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--tg-theme-bg-color);
    border-radius: 16px;
    padding: 20px;
    max-width: 500px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
}

@media (max-width: 480px) {
    .modal {
        padding: 16px;
        max-height: 90vh;
        width: 95%;
    }
}

.modal-overlay.show .modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--tg-theme-secondary-bg-color);
    gap: 8px;
}

.modal-title {
    font-size: clamp(16px, 4vw, 20px);
    font-weight: 600;
    color: var(--tg-theme-text-color);
}

.modal-close {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--tg-theme-hint-color);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.modal-close:hover {
    background: var(--danger-color);
    color: white;
    transform: rotate(90deg);
}

.modal-body {
    margin-bottom: 16px;
}

.modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

@media (max-width: 480px) {
    .modal-header {
        margin-bottom: 12px;
        padding-bottom: 10px;
    }
    .modal-title {
        font-size: 16px;
    }
    .modal-close {
        width: 24px;
        height: 24px;
        font-size: 14px;
    }
    .modal-body {
        margin-bottom: 12px;
    }
}

/* Форма */
.form-group {
    margin-bottom: 14px;
}

.form-label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--tg-theme-text-color);
    font-size: clamp(12px, 3vw, 14px);
}

.form-label .required {
    color: var(--danger-color);
    margin-left: 4px;
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--tg-theme-secondary-bg-color);
    border-radius: 8px;
    font-size: clamp(12px, 3vw, 14px);
    background-color: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    transition: border-color 0.2s ease;
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-textarea {
    min-height: 70px;
    resize: vertical;
}

.form-hint {
    font-size: clamp(10px, 2.5vw, 12px);
    color: var(--tg-theme-hint-color);
    margin-top: 4px;
}

@media (max-width: 480px) {
    .form-group {
        margin-bottom: 12px;
    }
    .form-label {
        font-size: 12px;
        margin-bottom: 4px;
    }
    .form-input,
    .form-textarea {
        padding: 8px;
        font-size: 12px;
    }
    .form-textarea {
        min-height: 60px;
    }
}

/* Категории */
.category-card {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.category-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.1);
}

@media (max-width: 480px) {
    .category-card {
        padding: 12px;
        margin-bottom: 10px;
        border-radius: 10px;
    }
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 14px;
    gap: 8px;
}

.category-info {
    flex: 1;
    min-width: 0;
}

.category-name {
    font-size: clamp(16px, 4vw, 18px);
    font-weight: 600;
    color: var(--tg-theme-text-color);
    margin-bottom: 4px;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.category-meta {
    font-size: clamp(10px, 2.5vw, 12px);
    color: var(--tg-theme-hint-color);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
    align-items: center;
}

.category-meta span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: 12px;
    font-size: clamp(10px, 2vw, 11px);
    font-weight: 500;
    margin-left: 4px;
}

@media (max-width: 480px) {
    .category-header {
        margin-bottom: 12px;
    }
    .category-name {
        font-size: 16px;
    }
    .category-meta {
        font-size: 10px;
        gap: 6px;
    }
}

.badge-hidden {
    background: rgba(225, 112, 85, 0.1);
    color: var(--danger-color);
}

.badge-deleted {
    background: rgba(214, 48, 49, 0.1);
    color: #d63031;
}

.badge-url {
    background: rgba(9, 132, 227, 0.1);
    color: #0984e3;
}

.category-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    width: 100%;
}

.icon-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(10px, 2.5vw, 12px);
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-btn-edit {
    background: rgba(108, 92, 231, 0.1);
    color: var(--primary-color);
}

.icon-btn-edit:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-1px);
}

.icon-btn-hide {
    background: rgba(225, 112, 85, 0.1);
    color: var(--danger-color);
}

.icon-btn-hide:hover {
    background: var(--danger-color);
    color: white;
    transform: translateY(-1px);
}

.icon-btn-show {
    background: rgba(0, 184, 148, 0.1);
    color: var(--success-color);
}

.icon-btn-show:hover {
    background: var(--success-color);
    color: white;
    transform: translateY(-1px);
}

.icon-btn-delete {
    background: rgba(214, 48, 49, 0.1);
    color: #d63031;
}

.icon-btn-delete:hover {
    background: #d63031;
    color: white;
    transform: translateY(-1px);
}

@media (max-width: 480px) {
    .category-actions {
        gap: 4px;
    }
    .icon-btn {
        min-width: 28px;
        height: 28px;
        padding: 0 6px;
        font-size: 10px;
        border-radius: 5px;
    }
}

/* Проекты */
.projects-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.projects-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 8px;
}

.projects-title {
    font-size: clamp(12px, 3vw, 14px);
    font-weight: 600;
    color: var(--tg-theme-text-color);
}

.projects-count {
    font-size: clamp(10px, 2.5vw, 12px);
    color: var(--tg-theme-hint-color);
    background: var(--tg-theme-bg-color);
    padding: 2px 6px;
    border-radius: 12px;
    flex-shrink: 0;
}

@media (max-width: 480px) {
    .projects-section {
        margin-top: 10px;
        padding-top: 10px;
    }
    .projects-header {
        margin-bottom: 8px;
    }
}

.project-item {
    background: var(--tg-theme-bg-color);
    border-radius: 8px;
    margin-bottom: 8px;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    overflow: hidden;
}

.project-item:hover {
    border-color: var(--primary-color);
}

.project-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    cursor: pointer;
    transition: background 0.2s ease;
    flex-wrap: wrap;
    gap: 8px;
}

.project-item-header:hover {
    background: rgba(108, 92, 231, 0.05);
}

.project-item.expanded .project-item-header {
    background: rgba(108, 92, 231, 0.08);
}

.project-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0 12px;
    background: rgba(0, 0, 0, 0.02);
}

.project-item.expanded .project-details {
    max-height: 500px;
    padding: 16px 12px;
    border-top: 1px solid var(--tg-theme-secondary-bg-color);
}

.project-detail-row {
    margin-bottom: 12px;
}

.project-detail-row:last-child {
    margin-bottom: 0;
}

.project-detail-label {
    font-size: 11px;
    color: var(--tg-theme-hint-color);
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.project-detail-value {
    font-size: 13px;
    color: var(--tg-theme-text-color);
    line-height: 1.4;
}

.project-image {
    width: 100%;
    max-width: 200px;
    height: auto;
    border-radius: 8px;
    margin-top: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.project-readers {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.reader-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    background: var(--primary-color);
    color: white;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
}

.reader-badge:hover {
    background: var(--success-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 184, 148, 0.3);
}

.project-info {
    flex: 1;
}

.project-name {
    font-weight: 500;
    font-size: 14px;
    color: var(--tg-theme-text-color);
    margin-bottom: 4px;
}

.project-meta {
    font-size: 11px;
    color: var(--tg-theme-hint-color);
}

.project-actions {
    display: flex;
    gap: 6px;
}

.icon-btn-sm {
    min-width: 28px;
    height: 28px;
    padding: 0 10px;
    font-size: 11px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--tg-theme-hint-color);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 14px;
}

/* Кнопки */
.btn-add {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-add:hover {
    background: #5f4fd1;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.3);
}

.btn-add-sm {
    padding: 6px 12px;
    font-size: 12px;
}

/* Заголовок страницы */
.manage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding: 20px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
}

.manage-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--tg-theme-text-color);
}

/* Анимации */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.category-card {
    animation: slideIn 0.3s ease;
}

/* Адаптивность */
@media (max-width: 480px) {
    .modal {
        width: 95%;
        padding: 20px;
    }
    
    .category-actions {
        flex-wrap: wrap;
    }
    
    .manage-header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }
    
    .project-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .project-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* Subscription list layout fixes: ensure progress bar fills the row and title is left-aligned */
.subscription-list {
    width: 100%;
}

.subscription-item {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 12px !important;
    width: 100% !important;
}

/* Header should behave like simple item: title left, toggle right */
.subscription-item-header {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 12px;
    padding: 10px !important; /* match padding of simple items */
    box-sizing: border-box;
}

.subscription-item-header .subscription-info {
    flex: 1 1 0;
    min-width: 0;
}

.subscription-item-header {
    justify-content: space-between;
}

.subscription-item-header .toggle-switch {
    flex: 0 0 auto;
    margin-left: auto;
    margin-right: 0 !important; /* keep fixed distance from header edge */
}

/* When a subscription is expanded, show details below (column) */
.subscription-item.expanded {
    flex-direction: column !important;
    align-items: flex-start !important;
}

.subscription-item.expanded .subscription-item-header {
    width: 100%;
}

.subscription-item.expanded + .subscription-details {
    width: 100%;
    margin-top: 8px;
    max-height: 1000px !important;
    padding: 12px !important;
    opacity: 1;
    visibility: visible;
}

/* Ensure collapsed details don't reserve horizontal space in row layout */
.subscription-details {
    width: auto !important;
    flex: 0 0 auto;
    max-height: 0;
    overflow: hidden;
    transition: max-height 420ms cubic-bezier(.22,.9,.14,1), padding 320ms ease, opacity 260ms ease 60ms, margin 320ms ease;
    padding: 0 12px !important;
    opacity: 0;
    visibility: hidden;
    margin-top: 0;
    will-change: max-height, opacity, margin;
}

.subscription-item.expanded + .subscription-details {
    width: 100% !important;
    flex: 0 0 auto;
    max-height: 1000px !important;
    padding: 12px !important;
    opacity: 1;
    visibility: visible;
}

.subscription-item > div:first-child {
    flex: 1 1 auto;
    min-width: 0; /* allow flex child to shrink so progress bar can grow */
}

/* Allow subscription title to wrap instead of truncating */
.subscription-item-header .subscription-info {
    flex: 1 1 auto;
    min-width: 0;
}

.subscription-item .subscription-name {
    text-align: left !important;
    overflow: visible;
    text-overflow: unset;
    white-space: normal;
    word-break: break-word;
    max-width: 100%;
}

.subscription-item .subscription-bar {
    width: 100% !important;
    min-width: 0;
}

.subscription-item .subscription-progress {
    width: 100%;
    display: block;
}

/* Collapse details horizontally when not expanded so header gets full width */
.subscription-item:not(.expanded) + .subscription-details {
    width: 0 !important;
    flex: 0 0 0 !important;
    padding: 0 !important;
    border: none !important;
    overflow: hidden !important;
}
