/* ========================================
   Knowledge Base Mini App - Styles
   ======================================== */

:root {
    --primary: #10b981;
    --primary-light: #d1fae5;
    --primary-dark: #059669;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--tg-theme-bg-color, var(--bg));
    color: var(--tg-theme-text-color, var(--text));
    line-height: 1.5;
    min-height: 100vh;
    padding-bottom: 20px;
}

#app {
    max-width: 100%;
    overflow-x: hidden;
}

/* ========================================
   Header
   ======================================== */

.header {
    padding: 20px 16px 32px;
    text-align: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.header p {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* ========================================
   Search
   ======================================== */

.search-container {
    padding: 0 16px;
    margin-top: -20px;
    position: relative;
    z-index: 10;
}

.search-box {
    display: flex;
    align-items: center;
    background: var(--tg-theme-bg-color, var(--bg-card));
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0 16px;
    gap: 12px;
}

.search-icon {
    font-size: 1.1rem;
    opacity: 0.5;
}

.search-box input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 14px 0;
    font-size: 1rem;
    color: var(--tg-theme-text-color, var(--text));
    outline: none;
}

.search-box input::placeholder {
    color: var(--tg-theme-hint-color, var(--text-light));
}

.search-clear {
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
}

/* ========================================
   Content
   ======================================== */

.content {
    padding: 20px 16px;
}

/* ========================================
   Categories List (Accordion)
   ======================================== */

.categories-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.category-item {
    background: var(--tg-theme-bg-color, var(--bg-card));
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.category-header {
    display: flex;
    align-items: center;
    padding: 16px;
    cursor: pointer;
    transition: background 0.2s;
    gap: 12px;
}

.category-header:hover {
    background: var(--tg-theme-secondary-bg-color, #f1f5f9);
}

.category-header:active {
    background: var(--tg-theme-secondary-bg-color, #e2e8f0);
}

.category-icon {
    font-size: 1.5rem;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

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

.category-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--tg-theme-text-color, var(--text));
}

.category-count {
    font-size: 0.85rem;
    color: var(--tg-theme-hint-color, var(--text-muted));
}

.category-toggle {
    font-size: 1rem;
    color: var(--text-muted);
    transition: transform 0.3s;
}

.category-item.open .category-toggle {
    transform: rotate(180deg);
}

/* Articles List */
.articles-list {
    display: none;
    border-top: 1px solid var(--border);
}

.category-item.open .articles-list {
    display: block;
}

.article-item {
    display: flex;
    align-items: center;
    padding: 14px 16px 14px 72px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
    gap: 12px;
}

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

.article-item:hover {
    background: var(--tg-theme-secondary-bg-color, #f8fafc);
}

.article-item:active {
    background: var(--tg-theme-secondary-bg-color, #f1f5f9);
}

.article-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

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

.article-title {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--tg-theme-text-color, var(--text));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.article-description {
    font-size: 0.8rem;
    color: var(--tg-theme-hint-color, var(--text-muted));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.article-arrow {
    color: var(--text-light);
    font-size: 1rem;
}

/* ========================================
   Search Results
   ======================================== */

.search-results {
    margin-top: -8px;
}

.search-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.9rem;
    cursor: pointer;
}

#search-results-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#search-results-list .article-item {
    padding-left: 16px;
    background: var(--tg-theme-bg-color, var(--bg-card));
    border-radius: var(--radius-sm);
    border: none;
    box-shadow: var(--shadow);
}

/* ========================================
   Empty State
   ======================================== */

.empty-state {
    text-align: center;
    padding: 40px 20px;
}

.empty-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state p {
    color: var(--text-muted);
}

/* ========================================
   Loading
   ======================================== */

.loading {
    text-align: center;
    padding: 40px 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 12px;
}

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

/* ========================================
   Modal
   ======================================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    align-items: flex-end;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.2s;
}

.modal-content {
    position: relative;
    width: 100%;
    max-height: 85vh;
    background: var(--tg-theme-bg-color, var(--bg-card));
    border-radius: var(--radius) var(--radius) 0 0;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.modal-icon {
    font-size: 1.5rem;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
}

.modal-header h2 {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--tg-theme-text-color, var(--text));
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: 60px;
    line-height: 1.7;
    font-size: 0.95rem;
}

.modal-body p {
    margin-bottom: 12px;
}

.modal-body a {
    color: var(--primary);
    text-decoration: none;
}

.modal-body a:hover {
    text-decoration: underline;
}

.modal-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.modal-footer:empty {
    display: none;
}

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

/* ========================================
   Utilities
   ======================================== */

.hidden {
    display: none !important;
}

/* Telegram theme adaptations */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1a1a2e;
        --bg-card: #16213e;
        --text: #e4e4e7;
        --text-muted: #a1a1aa;
        --text-light: #71717a;
        --border: #27272a;
        --primary-light: rgba(16, 185, 129, 0.2);
    }
}
