/* ==================== VARIABLES ==================== */
:root {
    --primary: #7C3AED;
    --primary-dark: #5B21B6;
    --primary-light: #DDD6FE;
    --primary-gradient: linear-gradient(135deg, #7C3AED 0%, #3B82F6 100%);
    --secondary: #6366F1;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    
    --bg-primary: #FFFFFF;
    --bg-secondary: #F8FAFC;
    --bg-tertiary: #F1F5F9;
    
    --text-primary: #1E293B;
    --text-secondary: #64748B;
    --text-hint: #94A3B8;
    
    --border-color: #E2E8F0;
    --shadow: 0 2px 8px rgba(124, 58, 237, 0.1);
    --shadow-lg: 0 4px 16px rgba(124, 58, 237, 0.15);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 50%;
    
    --header-height: 56px;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #0F172A;
        --bg-secondary: #1E293B;
        --bg-tertiary: #334155;
        
        --text-primary: #F8FAFC;
        --text-secondary: #CBD5E1;
        --text-hint: #94A3B8;
        
        --border-color: #475569;
        --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.5);
        
        --primary-light: #4C1D95;
    }
}

/* ==================== RESET ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-secondary);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

#app {
    min-height: 100%;
    padding-top: calc(var(--header-height) + var(--safe-area-top));
    padding-bottom: calc(80px + var(--safe-area-bottom));
}

/* ==================== HEADER ==================== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--header-height) + var(--safe-area-top));
    padding-top: var(--safe-area-top);
    background: var(--primary-gradient);
    color: white;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.3);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 16px;
}

.header-title {
    font-size: 20px;
    font-weight: 600;
}

.btn-add {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-full);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-add:active {
    background: rgba(255, 255, 255, 0.3);
}

/* ==================== SEARCH ==================== */
.search-container {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.search-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-hint);
    pointer-events: none;
}

.search-input {
    width: 100%;
    height: 44px;
    padding: 0 40px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    font-size: 16px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.search-input::placeholder {
    color: var(--text-hint);
}

.btn-clear-search {
    position: absolute;
    right: 8px;
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--text-hint);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-filter {
    width: 44px;
    height: 44px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-filter.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ==================== ACTIVE FILTERS ==================== */
.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 16px 12px;
    background: var(--bg-primary);
}

.filter-tag {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 500;
}

.filter-tag button {
    width: 18px;
    height: 18px;
    border: none;
    background: none;
    color: var(--primary-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* ==================== SEARCH HINT ==================== */
.search-hint {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.search-hint p {
    margin-bottom: 8px;
}

.hint-example {
    font-size: 14px;
    color: var(--text-hint);
}

/* ==================== CATALOG LIST ==================== */
.catalog-list {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ==================== CATALOG CARD ==================== */
.catalog-card {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.catalog-card:active {
    transform: scale(0.98);
}

.card-avatar {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.card-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-type {
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.card-type.chat { background: #E3F2FD; color: #1565C0; }
.card-type.channel { background: #F3E5F5; color: #7B1FA2; }
.card-type.bot { background: #E8F5E9; color: #2E7D32; }

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-description {
    font-size: 14px;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-stats {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-hint);
    margin-top: auto;
}

/* ==================== LOADING ==================== */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px;
    color: var(--text-secondary);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    background: conic-gradient(from 0deg, #7C3AED, #3B82F6, transparent);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==================== EMPTY STATE ==================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 60px 20px;
    color: var(--text-hint);
    text-align: center;
}

.empty-state p {
    font-size: 18px;
    color: var(--text-secondary);
}

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

/* ==================== LOAD MORE ==================== */
.load-more {
    padding: 16px;
    text-align: center;
}

.btn-load-more {
    padding: 12px 32px;
    border: 1px solid var(--primary);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--primary);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-load-more:active {
    background: var(--primary);
    color: white;
}

/* ==================== MODAL ==================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    width: 100%;
    max-height: 85vh;
    background: var(--bg-primary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-large {
    max-height: 95vh;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.btn-close-modal,
.btn-back {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.modal-footer {
    display: flex;
    gap: 12px;
    padding: 16px;
    border-top: 1px solid var(--border-color);
    padding-bottom: calc(16px + var(--safe-area-bottom));
    flex-shrink: 0;
}

.modal-footer button {
    flex: 1;
}

/* ==================== BUTTONS ==================== */
.btn-primary {
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--primary-gradient);
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
}

.btn-primary:active {
    transform: scale(0.98);
    box-shadow: 0 2px 10px rgba(124, 58, 237, 0.2);
}

.btn-secondary {
    padding: 14px 24px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
}

/* ==================== FILTER SECTION ==================== */
.filter-section {
    margin-bottom: 24px;
}

.filter-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 12px;
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.categories-list {
    max-height: 200px;
    overflow-y: auto;
}

.chip {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ==================== ITEM DETAIL ==================== */
.item-detail {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.item-avatar {
    width: 100px;
    height: 100px;
    border-radius: var(--radius-lg);
    background: var(--bg-tertiary);
    overflow: hidden;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
}

.item-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.item-name {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.item-type-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 16px;
}

.item-type-badge.chat { background: #E3F2FD; color: #1565C0; }
.item-type-badge.channel { background: #F3E5F5; color: #7B1FA2; }
.item-type-badge.bot { background: #E8F5E9; color: #2E7D32; }

.item-description {
    font-size: 16px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 16px;
    text-align: left;
    width: 100%;
}

.item-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 16px;
}

.item-category {
    padding: 4px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
}

.item-meta {
    width: 100%;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
}

.item-meta-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.item-meta-row:last-child {
    border-bottom: none;
}

.item-meta-label {
    color: var(--text-hint);
    font-size: 14px;
}

.item-meta-value {
    font-weight: 500;
    font-size: 14px;
}

.btn-join {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--primary-gradient);
    color: white;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-join.bot {
    background: var(--primary-gradient);
}

.btn-join:active {
    transform: scale(0.98);
    box-shadow: 0 2px 10px rgba(124, 58, 237, 0.2);
}

/* ==================== ADD FORM ==================== */
.add-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-group input,
.form-group textarea {
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    font-size: 16px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s;
}

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

.form-group textarea {
    resize: none;
    font-family: inherit;
}

.char-counter {
    font-size: 12px;
    color: var(--text-hint);
    text-align: right;
}

.type-selector {
    display: flex;
    gap: 8px;
}

.type-option {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.type-option input {
    display: none;
}

.type-option span {
    font-size: 14px;
    font-weight: 500;
}

.type-option:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
}

.avatar-upload {
    display: flex;
    align-items: center;
    gap: 16px;
}

.avatar-preview {
    width: 72px;
    height: 72px;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: var(--text-hint);
}

.avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.btn-upload {
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
}

.selected-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 32px;
}

.selected-category {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: var(--radius-lg);
    font-size: 14px;
}

.selected-category button {
    width: 18px;
    height: 18px;
    border: none;
    background: none;
    color: var(--primary-dark);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-select-categories {
    padding: 12px;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    background: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    width: 100%;
}

/* ==================== CATEGORY SELECTOR ==================== */
.category-hint {
    font-size: 14px;
    color: var(--text-hint);
    margin-bottom: 16px;
}

.category-selector-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.category-selector-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.category-selector-item.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.category-selector-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.category-checkbox {
    width: 22px;
    height: 22px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.category-selector-item.selected .category-checkbox {
    background: var(--primary);
    border-color: var(--primary);
}

.category-checkbox svg {
    display: none;
}

.category-selector-item.selected .category-checkbox svg {
    display: block;
    color: white;
}

.category-name {
    font-size: 15px;
}

/* ==================== UPLOAD MODAL ==================== */
.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 24px;
    text-align: center;
}

.upload-icon {
    margin-bottom: 24px;
    animation: uploadBounce 2s ease-in-out infinite;
}

@keyframes uploadBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.upload-status {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 24px;
}

.progress-container {
    width: 100%;
    max-width: 280px;
}

.progress-bar {
    width: 100%;
    height: 12px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-fill {
    height: 100%;
    background: var(--primary-gradient);
    border-radius: 6px;
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 24px;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.upload-hint {
    font-size: 14px;
    color: var(--text-hint);
    margin-top: 20px;
}

/* ==================== TOAST ==================== */
.toast {
    position: fixed;
    bottom: calc(20px + var(--safe-area-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    background: var(--primary-gradient);
    color: white;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    z-index: 300;
    opacity: 0;
    transition: transform 0.3s, opacity 0.3s;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.toast.error {
    background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}
