/* ============ CSS Variables ============ */
:root {
    /* Dark Theme (Default) */
    --bg-primary: #0f1419;
    --bg-secondary: #1a1f26;
    --bg-tertiary: #242b33;
    --bg-card: #1e252d;
    --text-primary: #ffffff;
    --text-secondary: #8b98a5;
    --text-muted: #6e7681;
    --border-color: #2f363d;
    --accent-green: #25D366;
    --accent-green-dark: #128C7E;
    --accent-blue: #3b82f6;
    --accent-purple: #8b5cf6;
    --accent-orange: #f59e0b;
    --accent-red: #ef4444;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --transition: all 0.2s ease;
}

/* Light Theme */
[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* ============ Reset & Base ============ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

/* ============ Layout ============ */
.app {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 18px;
    font-weight: 700;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: linear-gradient(135deg, var(--accent-green), var(--accent-green-dark));
    color: white;
}

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

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-red);
}

.status-dot.connected {
    background: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    padding: 20px 32px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

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

.api-key-display {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-tertiary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
}

.api-key-display input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 200px;
    font-family: monospace;
    font-size: 13px;
}

.page-container {
    flex: 1;
    padding: 32px;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

/* ============ Stats Grid ============ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon.green {
    background: rgba(37, 211, 102, 0.15);
    color: var(--accent-green);
}

.stat-icon.blue {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
}

.stat-icon.purple {
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-purple);
}

.stat-icon.orange {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-orange);
}

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

.stat-value {
    font-size: 28px;
    font-weight: 700;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ============ Cards ============ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

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

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 24px;
}

/* ============ Devices Grid ============ */
.page-header {
    margin-bottom: 24px;
}

.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.device-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 24px;
    transition: var(--transition);
}

.device-card:hover {
    border-color: var(--accent-green);
    transform: translateY(-2px);
}

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

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

.device-status {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.device-status.connected {
    background: rgba(37, 211, 102, 0.15);
    color: var(--accent-green);
}

.device-status.disconnected {
    background: rgba(107, 114, 128, 0.15);
    color: var(--text-secondary);
}

.device-status.connecting {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-orange);
}

.device-info {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 16px;
}

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

/* ============ Messaging ============ */
.messaging-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

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

.message-list {
    max-height: 500px;
    overflow-y: auto;
}

.message-item {
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.message-item .to {
    font-weight: 500;
    margin-bottom: 4px;
}

.message-item .content {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 8px;
}

.message-item .meta {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
}

.message-status {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
}

.message-status.sent {
    background: rgba(37, 211, 102, 0.15);
    color: var(--accent-green);
}

.message-status.pending {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-orange);
}

.message-status.failed {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ============ Buttons ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-green), var(--accent-green-dark));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

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

.btn-sm {
    padding: 8px 12px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

/* ============ Modals ============ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow: auto;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

.modal-body {
    padding: 24px;
}

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

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

.qr-container {
    background: white;
    padding: 20px;
    border-radius: var(--radius);
    display: inline-block;
    margin-bottom: 16px;
}

.qr-container img {
    width: 256px;
    height: 256px;
}

.qr-instructions {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Connection Tabs */
.connection-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    justify-content: center;
}

.tab-btn {
    padding: 10px 24px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn.active {
    background: var(--accent-green);
    border-color: var(--accent-green);
    color: white;
}

.connection-tab {
    display: none;
}

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

.pairing-code-container {
    text-align: center;
    padding: 20px;
}

.pairing-code {
    font-size: 32px;
    font-weight: 700;
    font-family: monospace;
    letter-spacing: 4px;
    color: var(--accent-green);
    background: var(--bg-tertiary);
    padding: 20px 40px;
    border-radius: var(--radius);
    margin: 20px 0;
    display: inline-block;
}

/* ============ Toast ============ */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    min-width: 300px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: toastIn 0.3s ease;
}

.toast.success {
    border-left: 3px solid var(--accent-green);
}

.toast.error {
    border-left: 3px solid var(--accent-red);
}

.toast.info {
    border-left: 3px solid var(--accent-blue);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

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

.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
}

.api-keys-list .api-key-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.api-key-item code {
    font-family: monospace;
    font-size: 13px;
    color: var(--accent-green);
}

/* ============ Activity List ============ */
.activity-list .activity-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.activity-item .icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
}

.activity-item .details {
    flex: 1;
}

.activity-item .time {
    color: var(--text-muted);
    font-size: 12px;
}

/* ============ Responsive ============ */
@media (max-width: 1024px) {
    .messaging-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .main-content {
        margin-left: 0;
    }
}

/* ============ Proxy Table ============ */
.proxy-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.proxy-table th,
.proxy-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.proxy-table th {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.proxy-table tr:hover {
    background: var(--bg-tertiary);
}

/* Health Status Indicators */
.health-healthy {
    color: var(--accent-green);
    background: rgba(37, 211, 102, 0.15);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.health-slow {
    color: var(--accent-orange);
    background: rgba(245, 158, 11, 0.15);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.health-failed {
    color: var(--accent-red);
    background: rgba(239, 68, 68, 0.15);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
}

/* Badge */
.badge {
    display: inline-block;
    padding: 4px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* ============ Settings Page ============ */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 24px;
}

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

.settings-info .info-row:last-child {
    border-bottom: none;
}

.settings-info .info-label {
    color: var(--text-secondary);
}

.settings-info .info-value {
    font-weight: 500;
    color: var(--text-primary);
}

/* API Key Display */
.api-key-box {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
}

.api-key-box code {
    flex: 1;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    color: var(--accent-green);
    word-break: break-all;
}

/* Code Block */
.code-block {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px;
    overflow-x: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: pre-wrap;
}

/* ============ Toast Notifications ============ */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    animation: slideIn 0.3s ease;
    min-width: 280px;
}

.toast.success {
    border-left: 4px solid var(--accent-green);
}

.toast.error {
    border-left: 4px solid var(--accent-red);
}

.toast.info {
    border-left: 4px solid var(--accent-blue);
}

.toast-message {
    flex: 1;
    font-size: 14px;
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ============ Password Strength ============ */
.password-strength {
    margin-top: 8px;
}

.strength-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 4px;
}

.strength-fill {
    height: 100%;
    width: 0%;
    transition: all 0.3s;
    border-radius: 2px;
}

.strength-fill.weak {
    width: 33%;
    background: var(--accent-red);
}

.strength-fill.medium {
    width: 66%;
    background: var(--accent-orange);
}

.strength-fill.strong {
    width: 100%;
    background: var(--accent-green);
}

.strength-text {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ============ Skeleton Loading ============ */
.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-secondary) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
}

.skeleton-stat {
    height: 48px;
}