/* Google Fonts removed for offline capability */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #6366f1;
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --bg-gradient: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
    --surface: rgba(255, 255, 255, 0.85);
    --surface-border: rgba(0, 0, 0, 0.1);
    --text-main: #1e293b;
    --text-muted: #64748b;
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);
    --glass-blur: blur(12px);
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 12px;
}

body.dark-mode {
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --surface: rgba(30, 41, 59, 0.7);
    --surface-border: rgba(255, 255, 255, 0.08);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 25px rgba(139, 92, 246, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    /* Native System Fonts */
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    overflow-x: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
    transition: all 0.5s ease;
}

#app {
    width: 100%;
    max-width: 600px;
    height: 100vh;
    position: relative;
    padding: 2rem;
    display: flex;
    flex-direction: column;
}

/* Screen Transitions */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 0;
}

.screen.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    z-index: 10;
}

/* Typography */
h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.8px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.2rem;
    text-align: center;
}

h2 {
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

h3 {
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

p {
    line-height: 1.6;
    color: var(--text-muted);
}

/* Login Screen */
#login-screen {
    justify-content: center;
    align-items: center;
}

.app-logo {
    width: 4.5rem;
    height: 4.5rem;
    margin-bottom: 0.5rem;
    object-fit: contain;
    filter: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.1));
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

#login-screen p,
#lock-screen p {
    margin-bottom: 1.25rem;
    font-size: 0.85rem;
}

.login-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.75rem;
    direction: ltr !important;
}

.icon-btn.active {
    background: var(--primary-gradient);
    color: white;
    border-color: transparent;
    box-shadow: var(--shadow-glow);
}

#passcode-pad-container,
#lock-pad-container {
    width: 100%;
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    animation: slideDown 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

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

#passcode-slots,
#lock-slots {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    width: 100%;
}

.passcode-display {
    width: 100%;
    display: flex;
    justify-content: center;
}

.passcode-slot {
    width: 2.25rem;
    height: 3rem;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
}

.passcode-slot:not(.filled)::after {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    opacity: 0.4;
}

.passcode-slot.filled {
    border-color: #8b5cf6;
    background: rgba(139, 92, 246, 0.05);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.passcode-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    width: 100%;
    max-width: 200px;
}

.pad-btn {
    width: 3rem;
    height: 3rem;
    padding: 0;
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-main);
    font-size: 1rem;
    border: 1px solid var(--surface-border);
    box-shadow: var(--shadow-sm);
}

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

.pad-btn.secondary {
    background: rgba(0, 0, 0, 0.05);
    font-size: 1rem;
}

.hidden {
    display: none !important;
}



/* Inputs & Buttons */
input {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    background: var(--surface);
    backdrop-filter: var(--glass-blur);
    color: var(--text-main);
    font-size: 16px; /* Must be at least 16px to prevent iOS auto-zoom */
    outline: none;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    text-align: center;
}

input:focus {
    border-color: #8b5cf6;
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.room-type-container {
    display: flex;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    padding: 0.3rem;
    margin-top: 1rem;
    gap: 0.3rem;
    width: 100%;
}

.room-type-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    color: var(--text-muted);
    box-shadow: none;
    margin-top: 0 !important;
}

.room-type-btn.active {
    background: var(--primary-gradient);
    color: white !important;
    box-shadow: var(--shadow-sm);
}

.room-type-btn:hover:not(.active) {
    background: rgba(0, 0, 0, 0.05);
    transform: none;
}

button {
    border: none;
    border-radius: var(--radius-md);
    padding: 0.7rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: var(--shadow-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

button.primary,
#login-btn {
    background: var(--primary-gradient);
    color: white;
    width: 100%;
    margin-top: 1rem;
}

button:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: var(--shadow-glow);
}

button:active {
    transform: translateY(-1px) scale(0.98);
}

button.danger {
    background: #FF5D5D;
    color: white;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(0.8);
    transform: none !important;
    box-shadow: none !important;
}

/* Dashboard */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--surface-border);
    direction: ltr !important;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--surface);
    padding: 0.5rem 1rem 0.5rem 0.5rem;
    /* adjusted padding for avatar */
    border-radius: 99px;
    border: 1px solid var(--surface-border);
    backdrop-filter: blur(10px);
}

.my-details {
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.2;
}

.my-ip-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.8;
    display: none !important;
}

.header-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    box-shadow: var(--shadow-sm);
}

#my-username {
    font-weight: 600;
    font-size: 1.1rem;
}

#theme-toggle {
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    padding: 0.75rem;
    font-size: 1.25rem;
    color: var(--text-main);
    border-radius: 50%;
    width: 3rem;
    height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0;
    border: 1px solid var(--surface-border);
    transition: transform 0.2s, box-shadow 0.2s;
}

.header-controls {
    display: flex;
    gap: 0.75rem;
    direction: ltr !important;
}

#language-toggle {
    font-size: 0.9rem;
    font-weight: 700;
    transition: all 0.2s;
    color: var(--text-main);
}

#language-select:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

/* [dir="rtl"] .header-controls {
    flex-direction: row-reverse;
} */

[dir="rtl"] {
    direction: rtl;
    text-align: right;
}

[dir="rtl"] h2,
[dir="rtl"] h3,
[dir="rtl"] p {
    text-align: right;
}

/* Specific RTL Fixes */
[dir="rtl"] .peer-status {
    flex-direction: row-reverse;
    /* Keep online dot consistent relative to text if needed, or normal */
}

/* Actually peer-status is "dot Text", in RTL it should be "dot Text" (R to L) or "Text dot"? 
   Usually "dot Text" is fine, but dot should be on the right. 
   Flex defaults to row which is R->L in RTL direction. So "dot" will be on right. Perfect.
*/

.icon-btn {
    border: 1px solid var(--surface-border);
    background: var(--surface);
    color: var(--text-main);
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    padding: 0;
}

.icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.danger-icon {
    color: #ef4444;
}

.danger-icon:hover {
    background: #fef2f2;
    border-color: #ef4444;
}


/* Peer List */
#peer-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 3rem;
    /* Increased from 1.5rem to 3rem */
    list-style: none;
    margin-bottom: 2rem;
}

.peer-card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    /* Increased padding */
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
}


.peer-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, rgba(255, 255, 255, 0.1), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.peer-card:hover {
    transform: translateY(-10px);
    box-shadow: var(--shadow-glow);
    border-color: rgba(139, 92, 246, 0.5);
}

.peer-card:hover::before {
    opacity: 1;
}

.peer-avatar {
    width: 5rem;
    height: 5rem;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.4);
    transition: transform 0.3s ease;
}

.peer-card:hover .peer-avatar {
    transform: scale(1.1) rotate(5deg);
}


.peer-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-main);
    text-align: center;
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.peer-status-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 0.5rem;
    gap: 0.2rem;
}

.peer-status {
    font-size: 0.75rem;
    color: #22c55e;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.peer-ip {
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.8;
    word-break: break-all;
    max-width: 150px;
    line-height: 1.1;
    display: none !important;
}

.chat-input-container {
    display: flex;
    gap: 0.8rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--surface-border);
}

#chat-input {
    flex: 1;
    background: var(--background);
    border: 1px solid var(--surface-border);
    border-radius: 0.8rem;
    padding: 0.8rem 1rem;
    color: var(--text);
    font-size: 0.95rem;
}

#send-chat-btn {
    padding: 0 1.2rem;
    gap: 0.5rem;
}

.chat-message {
    padding: 0.8rem 1rem;
    border-radius: 0.8rem;
    font-size: 0.95rem;
    max-width: 85%;
    position: relative;
    line-height: 1.4;
    display: flex;
    flex-direction: column;
}

.chat-message.sent {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    text-align: right;
}

.chat-message.sent .chat-sender {
    text-align: right;
    color: rgba(255, 255, 255, 0.9);
}

.chat-message.received {
    align-self: flex-start;
    background: var(--surface-light);
    border: 1px solid var(--surface-border);
}

.chat-message.system {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-style: italic;
    max-width: 100%;
    padding: 0.5rem;
}

.chat-sender {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-bottom: 0.2rem;
    display: block;
}

.peer-status::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 8px #22c55e;
}

.peers-section {
    margin-bottom: 3rem;
}

.peers-section h3 {
    margin-bottom: 1.5rem;
    font-size: 1.4rem;
    color: var(--text-main);
    opacity: 0.8;
}

#no-peers {
    display: none !important;
}


/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(16px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: var(--shadow-md);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal:not(.hidden) .modal-content {
    transform: scale(1);
}

.file-details {
    background: rgba(139, 92, 246, 0.1);
    padding: 1rem;
    border-radius: var(--radius-sm);
    margin: 1.5rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    border: 1px dashed rgba(139, 92, 246, 0.3);
    overflow: hidden;
}

#incoming-filename {
    word-break: break-all;
    line-height: 1.4;
    display: block;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* Progress Bar */
.progress-bar-container {
    height: 0.75rem;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 99px;
    margin: 1.5rem 0 0.5rem 0;
    overflow: hidden;
    position: relative;
}

.progress-bar {
    height: 100%;
    background: var(--primary-gradient);
    width: 0%;
    transition: width 0.2s linear;
    border-radius: 99px;
    position: relative;
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transform: translateX(-100%);
    animation: shimmer 1.5s infinite;
}

#progress-title {
    word-break: break-all;
    line-height: 1.4;
    display: block;
    width: 100%;
}

#progress-status {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    width: 100%;
}

@keyframes shimmer {
    100% {
        transform: translateX(100%);
    }
}

/* Transfer Log */
.transfer-log_section {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 1rem;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#transfer-log {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.log-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.4);
    border-radius: var(--radius-md);
    border: 1px solid var(--surface-border);
    transition: transform 0.2s;
}

.log-item:hover {
    transform: translateX(4px);
    background: rgba(255, 255, 255, 0.6);
}

.log-avatar {
    font-size: 1.2rem;
    width: 2.5rem;
    height: 2.5rem;
    background: var(--surface);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    filter: grayscale(0.2);
}

.log-details {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    overflow: hidden;
    min-width: 0;
}

.log-filename {
    font-weight: 600;
    color: var(--text);
    word-break: break-all;
    line-height: 1.3;
}

.log-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}


/* Drag Overlay */
body.drag-over::after {
    content: 'Drop to Share 🚀';
    background: rgba(99, 102, 241, 0.9);
    backdrop-filter: blur(8px);
    font-size: 3rem;
    font-weight: 800;
    color: white;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

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

::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.5);
    border-radius: 3px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

/* Robust hidden state for iOS clickable inputs */
#file-input {
    position: absolute;
    width: 0.1px;
    height: 0.1px;
    opacity: 0;
    z-index: -1;
}

/* Developer Info Styles */
.info-btn {
    font-family: serif;
    font-style: italic;
    font-weight: bold;
    font-size: 1.4rem !important;
}

.devLink {
    text-decoration: none;
    display: block;
    transition: opacity 0.2s;
}

.devLink:hover {
    opacity: 0.8;
}

.devOverlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.devOverlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.devModal {
    background-color: var(--surface);
    color: var(--text-main);
    padding: 40px;
    border-radius: 24px;
    border: 1px solid var(--surface-border);
    text-align: center;
    box-shadow: var(--shadow-md);
    min-width: 320px;
    max-width: 95vw;
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.devOverlay:not(.hidden) .devModal {
    transform: scale(1);
}

.devLogo {
    width: 110px;
    height: auto;
    margin-bottom: 24px;
    border-radius: 12px;
}

.devModal h3 {
    margin: 0 0 12px 0;
    color: var(--text-main);
    font-size: 24px;
    font-weight: 800;
}

.devModal p {
    margin: 0 0 28px 0;
    color: var(--text-muted);
    font-size: 20px;
    letter-spacing: 0.8px;
    font-weight: 500;
}

.devModal button {
    background-color: #2196f3;
    color: #fff;
    border: none;
    padding: 16px 40px;
    border-radius: 14px;
    font-weight: 800;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.devModal button:hover {
    background-color: #1976d2;
}