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

:root {
    --bg-dark: #0a0a1a;
    --bg-card: rgba(255, 255, 255, 0.06);
    --bg-card-hover: rgba(255, 255, 255, 0.1);
    --glass: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.12);
    --text-primary: #f0f0f5;
    --text-secondary: rgba(255, 255, 255, 0.55);
    --accent-1: #6c5ce7;
    --accent-2: #a29bfe;
    --accent-gradient: linear-gradient(135deg, #6c5ce7, #a29bfe, #fd79a8);
    --danger: #ff4757;
    --danger-gradient: linear-gradient(135deg, #ff4757, #ff6b81);
    --success: #00b894;
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 32px rgba(0,0,0,0.4);
    --shadow-lg: 0 16px 64px rgba(0,0,0,0.5);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body {
    width: 100%;
    height: 100%;
    font-family: var(--font);
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* =================== SCROLLBAR =================== */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* =================== SCREENS =================== */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    z-index: 1;
}

.screen.active {
    opacity: 1;
    visibility: visible;
    z-index: 10;
}

/* =================== LOGIN SCREEN =================== */
#login-screen {
    background: #1a1d2e;
    justify-content: center;
    align-items: center;
    padding: 24px;
}

.login-container {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 360px;
    animation: slideUp 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(40px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Avatar */
.login-avatar {
    text-align: center;
    margin-bottom: 32px;
}

.avatar-circle {
    width: 96px;
    height: 96px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.06);
    border: 2px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.avatar-circle:hover {
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 24px rgba(79, 195, 247, 0.15);
}

.avatar-circle svg {
    width: 56px;
    height: 56px;
}

/* Form */
.login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-label {
    font-size: 14px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.75);
    padding-left: 2px;
}

.input-group {
    position: relative;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    display: flex;
    align-items: center;
    transition: all 0.3s ease;
}

.input-group:focus-within {
    border-color: rgba(79, 195, 247, 0.5);
    background: rgba(79, 195, 247, 0.04);
    box-shadow: 0 0 0 3px rgba(79, 195, 247, 0.1);
}

.input-icon {
    width: 46px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.35);
    flex-shrink: 0;
    transition: color 0.3s ease;
}

.input-group:focus-within .input-icon {
    color: rgba(79, 195, 247, 0.8);
}

.input-icon svg {
    width: 18px;
    height: 18px;
}

.input-group input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font);
    padding: 13px 14px 13px 0;
    font-weight: 400;
}

.input-group input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

/* Remember Me Checkbox */
.remember-me {
    margin-top: -4px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
    padding-left: 2px;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.custom-checkbox {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
    background: rgba(255, 255, 255, 0.04);
    flex-shrink: 0;
}

.custom-checkbox svg {
    width: 14px;
    height: 14px;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    color: white;
}

.checkbox-label input[type="checkbox"]:checked + .custom-checkbox {
    background: #4caf50;
    border-color: #4caf50;
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.checkbox-label input[type="checkbox"]:checked + .custom-checkbox svg {
    opacity: 1;
    transform: scale(1);
}

/* Login Button */
.login-btn {
    position: relative;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #43a047, #66bb6a);
    color: white;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    margin-top: 4px;
    overflow: hidden;
    transition: all 0.3s ease;
    box-shadow: 0 4px 16px rgba(76, 175, 80, 0.3);
    letter-spacing: 0.3px;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(76, 175, 80, 0.4);
    background: linear-gradient(135deg, #388e3c, #4caf50);
}

.login-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.login-btn.loading .btn-text {
    opacity: 0;
}

.login-btn.loading .btn-loader {
    opacity: 1;
}

.btn-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 22px;
    height: 22px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.3s;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* =================== HOME SCREEN =================== */
#home-screen {
    background: linear-gradient(170deg, #0f0c29 0%, #1a1a3e 50%, #24243e 100%);
    padding-bottom: 0;
}

.phone-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px 8px;
    font-size: 13px;
    font-weight: 600;
}

.status-icons {
    display: flex;
    gap: 6px;
    align-items: center;
}

.status-icon {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

.logout-btn {
    cursor: pointer;
    opacity: 0.7;
    margin-left: 10px;
    transition: opacity 0.2s ease, color 0.2s ease;
    display: flex;
    align-items: center;
}

.logout-btn:hover {
    opacity: 1;
    color: var(--danger);
}

.home-header {
    padding: 8px 24px 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 16px;
    position: relative;
    z-index: 150;
}

.header-titles {
    display: flex;
    flex-direction: column;
}

.home-greeting {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #fff 0%, rgba(255,255,255,0.7) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.home-date {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 400;
}

.target-device {
    font-size: 13px;
    color: #4cd137;
    margin-top: 2px;
    font-weight: 500;
}

.header-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    background: rgba(255, 255, 255, 0.05);
    padding: 6px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-label {
    font-size: 10px;
    color: rgba(255,255,255,0.6);
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-number {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.5px;
}

.live-dot {
    width: 6px;
    height: 6px;
    background-color: #ff4757;
    border-radius: 50%;
    display: inline-block;
    animation: blink 1.5s infinite ease-in-out;
}

@keyframes blink {
    0% { opacity: 1; box-shadow: 0 0 4px #ff4757; }
    50% { opacity: 0.3; box-shadow: 0 0 0 transparent; }
    100% { opacity: 1; box-shadow: 0 0 4px #ff4757; }
}

/* =================== APP GRID =================== */
.apps-grid {
    flex: 1;
    overflow-y: auto;
    padding: 8px 20px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    align-content: start;
    -webkit-overflow-scrolling: touch;
}

.app-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    animation: appPop 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.app-item:nth-child(1) { animation-delay: 0.05s; }
.app-item:nth-child(2) { animation-delay: 0.1s; }
.app-item:nth-child(3) { animation-delay: 0.15s; }
.app-item:nth-child(4) { animation-delay: 0.2s; }
.app-item:nth-child(5) { animation-delay: 0.25s; }
.app-item:nth-child(6) { animation-delay: 0.3s; }
.app-item:nth-child(7) { animation-delay: 0.35s; }
.app-item:nth-child(8) { animation-delay: 0.4s; }
.app-item:nth-child(9) { animation-delay: 0.45s; }
.app-item:nth-child(10) { animation-delay: 0.5s; }
.app-item:nth-child(11) { animation-delay: 0.55s; }
.app-item:nth-child(12) { animation-delay: 0.6s; }

@keyframes appPop {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.app-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px; /* iOS squircle approximation */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.app-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%);
    border-radius: inherit;
}

.app-item:active .app-icon {
    transform: scale(0.88);
}

.app-icon svg {
    width: 20px;
    height: 20px;
    position: relative;
    z-index: 1;
}

.app-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    overflow: hidden;
}

.app-name {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.app-sub {
    font-size: 10px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

/* =================== DOCK =================== */
.home-dock {
    display: flex;
    justify-content: center;
    gap: 20px;
    padding: 12px 24px;
    margin: 0 20px 16px;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.dock-item {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.dock-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px; /* iOS squircle approximation */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.dock-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%);
    border-radius: inherit;
}

.dock-item:active .dock-icon {
    transform: scale(0.88);
}

.dock-icon svg {
    width: 24px;
    height: 24px;
    position: relative;
    z-index: 1;
}

/* =================== LOADING OVERLAY =================== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 240px 24px 24px;
    overflow: hidden;
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-modal {
    width: 100%;
    max-width: 340px;
    background: linear-gradient(165deg, rgba(30, 30, 60, 0.95), rgba(20, 20, 40, 0.98));
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-lg);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: calc(100vh - 270px);
    overflow-y: auto;
}

.loading-overlay.active .loading-modal {
    transform: scale(1);
}

.loading-modal-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
}

.loading-app-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.loading-title {
    font-size: 16px;
    font-weight: 600;
}

.loading-subtitle-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.loading-progress-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}

.loading-progress-bar {
    flex: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    overflow: hidden;
}

.loading-progress-fill {
    width: 0%;
    height: 100%;
    background: var(--accent-gradient);
    border-radius: 10px;
    transition: width 0.3s ease;
    position: relative;
}

.loading-progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 20px;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3));
    animation: shimmer 1.5s ease-in-out infinite;
}

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

.loading-percent {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent-2);
    min-width: 40px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.loading-files {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.loading-file-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.3s ease;
}

.loading-file-item.done {
    border-color: rgba(0, 184, 148, 0.2);
    background: rgba(0, 184, 148, 0.06);
}

.loading-file-item.done .file-status {
    color: var(--success);
}

.loading-file-item svg {
    flex-shrink: 0;
    opacity: 0.5;
}

.loading-file-item span:nth-child(2) {
    flex: 1;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

.file-status {
    font-size: 14px;
}

/* =================== ERROR OVERLAY =================== */
.error-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 240px 24px 24px;
    overflow: hidden;
}

.error-overlay.active {
    opacity: 1;
    visibility: visible;
}

.error-modal {
    width: 100%;
    max-width: 340px;
    background: linear-gradient(165deg, rgba(40, 15, 20, 0.97), rgba(25, 10, 15, 0.99));
    border: 1px solid rgba(255, 71, 87, 0.25);
    border-radius: var(--radius-lg);
    padding: 28px 24px;
    box-shadow: 0 16px 64px rgba(255, 71, 87, 0.2);
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    animation: errorShake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) 0.3s both;
    max-height: calc(100vh - 270px);
    overflow-y: auto;
}

.error-overlay.active .error-modal {
    transform: scale(1);
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0) scale(1); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px) scale(1); }
    20%, 40%, 60%, 80% { transform: translateX(4px) scale(1); }
}

.error-icon-container {
    margin-bottom: 18px;
}

.error-icon-bg {
    width: 72px;
    height: 72px;
    margin: 0 auto;
    background: var(--danger-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px rgba(255, 71, 87, 0.4);
    animation: errorPulse 2s ease-in-out infinite;
}

@keyframes errorPulse {
    0%, 100% { box-shadow: 0 8px 32px rgba(255, 71, 87, 0.4); }
    50% { box-shadow: 0 8px 48px rgba(255, 71, 87, 0.6); }
}

.error-title {
    font-size: 20px;
    font-weight: 700;
    color: #ff6b81;
    margin-bottom: 6px;
}

.error-code {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: 'Courier New', monospace;
    margin-bottom: 18px;
}

.error-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    text-align: left;
    padding: 14px;
    background: rgba(255, 71, 87, 0.08);
    border: 1px solid rgba(255, 71, 87, 0.15);
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
}

.error-message svg {
    flex-shrink: 0;
    color: #ff6b81;
    margin-top: 2px;
}

.error-message p {
    font-size: 13px;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.8);
}

.error-message strong {
    color: #ff6b81;
    font-weight: 700;
}

.error-details {
    text-align: left;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}

.error-details p {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    line-height: 1.6;
}

.error-details p:last-child {
    margin-bottom: 0;
}

.error-details code {
    color: #ff6b81;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    background: rgba(255, 71, 87, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
}

.error-close-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--danger-gradient);
    color: white;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 16px rgba(255, 71, 87, 0.3);
}

.error-close-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(255, 71, 87, 0.4);
}

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

/* =================== SCROLLBAR =================== */
.apps-grid::-webkit-scrollbar {
    width: 0;
}

/* =================== RESPONSIVE =================== */

/* Small phones */
@media (max-width: 380px) {
    .apps-grid {
        gap: 16px 8px;
    }
    .app-icon {
        width: 54px;
        height: 54px;
        border-radius: 14px;
    }
    .app-icon svg {
        width: 24px;
        height: 24px;
    }
    .app-name {
        font-size: 10px;
    }
    .login-container {
        max-width: 300px;
    }
    .avatar-circle {
        width: 80px;
        height: 80px;
    }
    .avatar-circle svg {
        width: 46px;
        height: 46px;
    }
}

/* Tablets & Desktop */
@media (min-width: 500px) {
    .apps-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 16px;
        padding: 24px 40px;
    }
    
    .home-header {
        padding: 24px 40px 20px;
    }

    .home-dock {
        margin: 0 40px 24px;
        padding: 16px 32px;
        gap: 32px;
    }
    
    .phone-status-bar {
        padding: 16px 40px;
    }
    
    .loading-overlay, .error-overlay {
        padding: 24px;
        align-items: center;
    }
    
    .loading-modal, .error-modal {
        max-height: none;
        overflow-y: visible;
    }
}

