:root {
    --bg-color: var(--tg-theme-bg-color, #0f172a);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #1e293b);
    --text-color: var(--tg-theme-text-color, #f8fafc);
    --hint-color: var(--tg-theme-hint-color, #94a3b8);
    --link-color: var(--tg-theme-link-color, #38bdf8);
    --button-color: var(--tg-theme-button-color, #0284c7);
    --button-text-color: var(--tg-theme-button-text-color, #ffffff);

    --card-bg: var(--secondary-bg);
    --border-color: rgba(255, 255, 255, 0.1);
    --accent-color: #38bdf8;
    --danger-color: #ef4444;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    padding: 16px;
    font-size: 14px;
    line-height: 1.5;
}

#app {
    max-width: 680px;
    margin: 0 auto;
}

/* --- Header --- */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0284c7, #38bdf8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 15px;
}

.user-role {
    font-size: 12px;
    color: var(--hint-color);
}

/* --- Buttons --- */
.btn {
    padding: 8px 16px;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background-color: var(--button-color);
    color: var(--button-text-color);
}

.btn-primary:active {
    transform: scale(0.97);
    opacity: 0.9;
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-color);
}

.btn-danger {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--danger-color);
}

/* --- Controls Section --- */
.controls-section {
    margin-bottom: 16px;
}

.search-box {
    display: flex;
    align-items: center;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 14px;
    gap: 10px;
}

.search-box input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-color);
    width: 100%;
    font-size: 14px;
}

/* --- Filters Grid --- */
.filters-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.filter-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 16px;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.filter-card:hover {
    border-color: rgba(56, 189, 248, 0.4);
}

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

.filter-title {
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.owner-badge {
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--hint-color);
}

/* Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255, 255, 255, 0.2);
    transition: .3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--success-color);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Card Sections */
.card-section {
    margin-top: 10px;
}

.section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--hint-color);
    margin-bottom: 4px;
}

.chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    font-size: 12px;
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-color);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.chip-any {
    background: rgba(56, 189, 248, 0.15);
    color: #7dd3fc;
}

.chip-all {
    background: rgba(34, 197, 94, 0.15);
    color: #86efac;
}

.chip-not {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}

.chip-chat {
    background: rgba(245, 158, 11, 0.15);
    color: #fcd34d;
}

.card-actions {
    margin-top: 14px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.modal-content {
    background-color: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.close-btn {
    background: none;
    border: none;
    color: var(--hint-color);
    font-size: 24px;
    cursor: pointer;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
}

.form-hint {
    font-size: 11px;
    color: var(--hint-color);
    margin-bottom: 8px;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    outline: none;
}

/* Tags Input */
.tags-input-container {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.tags-input-container.danger-border {
    border-color: rgba(239, 68, 68, 0.3);
}

.tags-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.editable-tag {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.12);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.remove-tag-btn {
    cursor: pointer;
    font-weight: bold;
    color: var(--hint-color);
}

.remove-tag-btn:hover {
    color: var(--danger-color);
}

.tags-input-container input {
    flex: 1;
    min-width: 120px;
    border: none !important;
    background: transparent !important;
    padding: 4px 0 !important;
    outline: none !important;
}

.modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
    gap: 10px;
}

.modal-footer-right {
    display: flex;
    gap: 10px;
    margin-left: auto;
}

/* States */
.state-container {
    text-align: center;
    padding: 40px 20px;
    color: var(--hint-color);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--button-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

.hidden {
    display: none !important;
}
