:root {
    --tg-theme-bg-color: #ffffff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #999999;
    --tg-theme-link-color: #2481cc;
    --tg-theme-button-color: #2481cc;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f1f1f1;
    --primary-color: #2481cc;
    --success-color: #4CAF50;
    --danger-color: #f44336;
    --warning-color: #ff9800;
    --border-radius: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
}

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

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

#app {
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
}

.header {
    background: var(--tg-theme-bg-color);
    border-bottom: 1px solid rgba(0,0,0,0.08);
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary-color), #1565c0);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.header-icon svg {
    width: 18px;
    height: 18px;
    color: white;
}

.header h1 {
    font-size: 17px;
    font-weight: 600;
    color: var(--tg-theme-text-color);
    margin: 0;
}

.status {
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-hint-color);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.main {
    padding: 0;
}

/* Tabs */
.tabs {
    display: flex;
    background: var(--tg-theme-secondary-bg-color);
    border-bottom: 1px solid #e0e0e0;
    position: sticky;
    top: 57px;
    z-index: 99;
}

.tab-button {
    flex: 1;
    padding: 12px 8px;
    border: none;
    background: transparent;
    color: var(--tg-theme-hint-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 2px solid transparent;
}

.tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: var(--tg-theme-bg-color);
}

.tab-content {
    display: none;
    padding: 16px;
    min-height: calc(100vh - 160px);
}

.tab-content.active {
    display: block;
}

/* Filter Chips */
.filter-chips {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.filter-chips::-webkit-scrollbar {
    display: none;
}

.filter-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    background: var(--tg-theme-bg-color);
    color: var(--tg-theme-hint-color);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.filter-chip:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

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

.filter-chip[data-filter="blocked"].active {
    background: var(--danger-color);
    border-color: var(--danger-color);
}

.filter-chip[data-filter="allowed"].active {
    background: var(--success-color);
    border-color: var(--success-color);
}

.filter-chip[data-filter="temp-access"].active {
    background: var(--warning-color);
    border-color: var(--warning-color);
}

.chip-count {
    background: rgba(255,255,255,0.3);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 11px;
    min-width: 20px;
    text-align: center;
}

.filter-chip:not(.active) .chip-count {
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-hint-color);
}

/* Search */
.search-section {
    margin-bottom: 12px;
}

.search-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    border-radius: var(--border-radius);
    font-size: 16px;
    background: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(36, 129, 204, 0.2);
}

/* Devices List */
.devices-list {
    margin-bottom: 16px;
}

.device-item {
    background: var(--tg-theme-bg-color);
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    margin-bottom: 8px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: all 0.2s ease;
}

.device-item:active {
    transform: scale(0.98);
    background: var(--tg-theme-secondary-bg-color);
}

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

.device-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--tg-theme-text-color);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 8px;
}

.device-status {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}

.device-status.blocked {
    background: var(--danger-color);
    color: white;
}

.device-status.allowed {
    background: var(--success-color);
    color: white;
}

.device-status.temp-access {
    background: var(--warning-color);
    color: white;
}

.device-info {
    color: var(--tg-theme-hint-color);
    font-size: 12px;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

/* Buttons */
.action-btn {
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
    min-width: 0;
}

.action-btn.primary {
    background: var(--primary-color);
    color: white;
}

.action-btn.success {
    background: var(--success-color);
    color: white;
}

.action-btn.danger {
    background: var(--danger-color);
    color: white;
}

.action-btn.secondary {
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    border: 1px solid #e0e0e0;
}

.action-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.action-btn:active {
    transform: translateY(0);
}

.action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 12px;
    padding: 16px 0;
    border-top: 1px solid #e0e0e0;
}

/* Groups */
.groups-list {
    margin-top: 16px;
}

.group-item {
    background: var(--tg-theme-bg-color);
    border: 1px solid #e0e0e0;
    border-radius: var(--border-radius);
    margin-bottom: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
}

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

.group-name {
    font-weight: 600;
    font-size: 16px;
}

.group-devices {
    color: var(--tg-theme-hint-color);
    font-size: 14px;
    margin-bottom: 12px;
}

/* Schedule */
.schedule-list {
    margin-bottom: 16px;
}

.schedule-item {
    background: var(--tg-theme-bg-color);
    border: 1px solid #e0e0e0;
    border-radius: var(--border-radius);
    margin-bottom: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--tg-theme-bg-color);
    border-radius: var(--border-radius);
    padding: 24px;
    margin: 16px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.modal-content h3 {
    margin-bottom: 16px;
    color: var(--tg-theme-text-color);
}

.time-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 20px 0;
}

.time-btn {
    padding: 12px;
    border: 2px solid var(--primary-color);
    border-radius: var(--border-radius);
    background: transparent;
    color: var(--primary-color);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.time-btn:hover {
    background: var(--primary-color);
    color: white;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

/* Loading */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1001;
}

.loading.hidden {
    display: none;
}

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

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 480px) {
    .header {
        padding: 16px 12px;
    }

    .tab-content {
        padding: 12px;
    }

    .device-actions {
        flex-direction: column;
    }

    .quick-actions {
        flex-direction: column;
    }

    .time-buttons {
        grid-template-columns: 1fr;
    }
}

/* Dark theme support */
.dark {
    --tg-theme-bg-color: #212121;
    --tg-theme-text-color: #ffffff;
    --tg-theme-hint-color: #aaaaaa;
    --tg-theme-secondary-bg-color: #424242;
}

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

.text-center {
    text-align: center;
}

.mt-16 {
    margin-top: 16px;
}

.mb-16 {
    margin-bottom: 16px;
}