* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-card: #242424;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #333;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    padding-bottom: 80px;
}

.hidden { display: none !important; }

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    gap: 20px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error Screen */
.error-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 40px;
    text-align: center;
    gap: 20px;
}

.error-screen h2 { color: var(--warning); }
.error-screen button {
    padding: 12px 24px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 16px;
    cursor: pointer;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 48px;
    height: 48px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.user-name {
    font-weight: 600;
    font-size: 16px;
}

.user-id {
    font-size: 12px;
    color: var(--text-secondary);
}

.status {
    padding: 6px 12px;
    background: var(--danger);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status.active {
    background: var(--success);
}

/* Cards */
.card {
    margin: 16px;
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.status-badge {
    padding: 4px 10px;
    background: var(--danger);
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.status-badge.active {
    background: var(--success);
}

.card-body {
    padding: 16px;
}

.stat-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.stat {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-value {
    display: block;
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
}

.empty-text {
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
}

/* Keys */
.key-item {
    background: var(--bg-secondary);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 12px;
}

.key-item:last-child { margin-bottom: 0; }

.key-server {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.key-server-name {
    font-weight: 600;
}

.key-server-status {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
}

.key-code {
    background: var(--bg-primary);
    padding: 8px;
    border-radius: 6px;
    font-family: monospace;
    font-size: 11px;
    word-break: break-all;
    margin-bottom: 8px;
}

.key-actions {
    display: flex;
    gap: 8px;
}

.key-actions button {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}

.btn-copy {
    background: var(--bg-card);
    color: var(--text-primary);
}

.btn-connect {
    background: var(--accent);
    color: white;
}

/* Actions */
.actions {
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn {
    padding: 14px 20px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-full {
    width: 100%;
}

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 8px 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 8px;
}

.nav-item.active {
    color: var(--accent);
}

.nav-icon {
    font-size: 20px;
}

.nav-label {
    font-size: 11px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: flex-end;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
}

/* Tariff Grid */
.tariff-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.tariff-card {
    background: var(--bg-secondary);
    padding: 16px 12px;
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    border: 2px solid transparent;
    position: relative;
}

.tariff-card.selected {
    border-color: var(--accent);
}

.tariff-card .tariff-badge {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--success);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
}

.tariff-days {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.tariff-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}

/* Device Select */
.device-select {
    margin-bottom: 20px;
}

.device-select label,
.payment-methods label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.device-select select {
    width: 100%;
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
}

/* Payment Options */
.payment-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.payment-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    cursor: pointer;
}

.payment-option input {
    width: 18px;
    height: 18px;
}

/* App List */
.app-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.app-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--bg-secondary);
    border-radius: 10px;
    text-decoration: none;
    color: var(--text-primary);
}

.app-icon {
    font-size: 24px;
}

.app-name {
    flex: 1;
    font-weight: 500;
}

.app-action {
    color: var(--text-secondary);
}

/* Setup Instruction */
.setup-instruction {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: 10px;
}

.setup-instruction h4 {
    margin-bottom: 12px;
}

.setup-instruction ol {
    padding-left: 20px;
}

.setup-instruction li {
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 14px;
}