:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary-color: #64748b;
    --secondary-dark: #475569;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --bg-color: #1a1a1a;
    --card-bg: #2a2a2a;
    --text-color: #e5e5e5;
    --text-muted: #888;
    --border-color: #3a3a3a;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --transition: all 0.3s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    font-size: 15px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header Styles */
.header {
    background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
    border-bottom: 1px solid var(--border-color);
    padding: 15px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 15px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-dot.healthy {
    background: var(--success-color);
    box-shadow: 0 0 8px var(--success-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--success-color);
    letter-spacing: 0.5px;
}

.server-info {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    font-size: 0.95rem;
}

.server-time, .server-uptime {
    display: flex;
    gap: 8px;
    align-items: center;
}

.label {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Buttons */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: nowrap;
    justify-content: flex-end;
    min-width: 0;
}

.btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

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

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

.btn-secondary {
    background: var(--secondary-color);
}

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

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-block {
    width: 100%;
}

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

.btn-mode {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

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

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

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

/* Auto-refresh container */
.auto-refresh-container {
    background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
    border-top: 1px solid var(--border-color);
    padding: 15px 0;
    margin-top: 30px;
    box-shadow: var(--shadow);
}

.auto-refresh-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 15px;
}

.refresh-interval {
    display: flex;
    align-items: center;
    gap: 10px;
}

.refresh-interval label {
    color: var(--text-muted);
    font-size: 0.9rem;
    white-space: nowrap;
}

.refresh-countdown {
    color: var(--text-muted);
    font-size: 0.9rem;
    min-width: 180px;
    text-align: right;
}

.refresh-countdown span {
    color: var(--primary-color);
    font-weight: 600;
    font-size: 1.1rem;
}

/* Traffic Section */
.traffic-section {
    padding: 25px 0;
}

.section-title {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: var(--text-color);
    font-weight: 600;
}

.traffic-period {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
    font-size: 0.95rem;
}

.period-mode {
    display: flex;
    gap: 8px;
}

.period-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 300px;
}

.period-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.period-selects {
    display: flex;
    gap: 10px;
    flex: 1;
    min-width: 280px;
    max-width: 400px;
}

.period-selects select {
    flex: 1;
}

.period-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 40px;
}

.btn-reset {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 6px;
    display: none;
}

.btn-reset:hover {
    background: var(--danger-color);
    color: white;
    border-color: var(--danger-color);
    transform: none;
}

.btn-reset svg {
    stroke-width: 2;
}

.select-period {
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    width: 100%;
}

.select-period:focus {
    outline: 2px solid var(--primary-color);
}

.period-display {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Traffic Stats */
.traffic-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 18px;
    margin-bottom: 25px;
}

.traffic-card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.traffic-card h3 {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    font-weight: 500;
}

.traffic-value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 12px;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.traffic-unit {
    font-size: 1rem;
    color: var(--text-muted);
}

.traffic-bar {
    height: 10px;
    background: #3a3a3a;
    border-radius: 5px;
    overflow: hidden;
    position: relative;
}

.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--primary-dark));
    border-radius: 5px;
    transition: width 0.5s ease;
}

.bar-limit {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(to bottom, var(--danger-color), #ff6b6b);
    box-shadow: 0 0 12px var(--danger-color), 0 0 24px var(--danger-color);
    z-index: 10;
}

/* Connections Grid */
.connections-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 18px;
    margin-top: 20px;
}

.connection-card {
    background: var(--card-bg);
    padding: 14px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.connection-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
    border-color: var(--primary-color);
}

.connection-card h3 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 500;
}

.connection-count {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 800px;
}

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

.modal-header h3 {
    font-size: 1.2rem;
    color: var(--text-color);
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.8rem;
    cursor: pointer;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

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

.modal-body {
    padding: 20px;
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-color);
    font-weight: 500;
    font-size: 0.95rem;
}

.input-field {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-color);
    font-size: 0.95rem;
    transition: var(--transition);
}

.input-field:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 5px;
}

.checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.form-error {
    color: var(--danger-color);
    font-size: 0.85rem;
    margin-bottom: 8px;
    min-height: 18px;
}

/* Connections List */
.connections-list {
    max-height: 60vh;
    overflow-y: auto;
}

.connections-list table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.connections-list th,
.connections-list td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.connections-list th {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-color);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
}

.connections-list tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.no-connections {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-style: italic;
}

.connections-footer {
    margin-top: 15px;
    padding: 12px;
    background: rgba(37, 99, 235, 0.05);
    border-radius: 6px;
    text-align: center;
    font-size: 0.9rem;
    color: var(--primary-color);
    font-weight: 500;
}

/* Devices Management Modal */
.devices-list {
    max-height: 60vh;
    overflow-y: auto;
}

.device-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.device-item.current {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.1);
}

.device-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.device-info {
    flex: 1;
}

.device-id {
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 4px;
}

.device-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.device-meta span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.device-meta svg {
    width: 14px;
    height: 14px;
    stroke: var(--text-muted);
}

.device-current {
    background: var(--success-color);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

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

.devices-info {
    margin-top: 15px;
    padding: 12px;
    background: rgba(37, 99, 235, 0.05);
    border-radius: 6px;
    border-left: 3px solid var(--primary-color);
}

.devices-info p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--primary-color);
}

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

.btn-danger:hover {
    background: #dc2626;
}

.no-devices {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-style: italic;
}

.loading {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
}

.error {
    text-align: center;
    padding: 20px;
    color: var(--danger-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        font-size: 14px;
    }
    
    .header {
        padding: 12px 0;
    }
    
    .status-text {
        font-size: 1.3rem;
    }
    
    .server-info {
        gap: 12px;
        font-size: 0.9rem;
    }
    
    .section-title {
        font-size: 1.4rem;
        margin-bottom: 18px;
    }
    
    .traffic-period {
        flex-direction: column;
        align-items: stretch;
    }
    
    .period-mode {
        width: 100%;
        justify-content: center;
    }
    
    .period-controls {
        width: 100%;
        min-width: auto;
    }
    
    .period-nav {
        width: 100%;
        justify-content: space-between;
    }
    
    .period-selects {
        width: 100%;
        min-width: auto;
        max-width: none;
        flex-direction: row;
        gap: 8px;
    }
    
    .period-selects select {
        width: auto;
        flex: 1;
        min-width: 80px;
    }
    
    .select-period {
        font-size: 1.1rem;
        padding: 12px 15px;
    }
    
    .period-actions {
        justify-content: center;
        width: 100%;
    }
    
    .period-display {
        text-align: center;
        width: 100%;
        padding: 8px 0;
    }
    
    .traffic-stats {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .traffic-card {
        padding: 18px;
    }
    
    .traffic-value {
        font-size: 1.8rem;
    }
    
    .connections-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .connection-card {
        padding: 12px;
    }
    
    .connection-card h3 {
        font-size: 0.8rem;
    }
    
    .connection-count {
        font-size: 1.4rem;
    }
    
    /* Кнопки авторизации на мобильных - в колонку */
    .header-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    
    .header-actions .btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Auto-refresh controls на мобильных */
    .auto-refresh-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .refresh-interval {
        width: 100%;
        justify-content: center;
    }
    
    .refresh-countdown {
        width: 100%;
        text-align: center;
        padding-top: 10px;
    }
}

@media (max-width: 480px) {
    .connections-grid {
        grid-template-columns: 1fr;
    }
    
    .modal-content {
        width: 95%;
        margin: 15px;
    }
    
    .traffic-value {
        font-size: 1.6rem;
    }
    
    .connection-count {
        font-size: 1.3rem;
    }
    
    .period-selects {
        flex-wrap: wrap;
    }
    
    .period-selects select {
        min-width: 70px;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* Loading indicator */
.loading {
    color: var(--text-muted);
    font-style: italic;
}
