/* ========================================
   iOS 17 iMessage Clone - Main Styles
   ======================================== */

/* CSS Variables - iOS 17 Color System */
:root {
    /* iOS System Colors */
    --ios-blue: #007AFF;
    --ios-green: #34C759;
    --ios-red: #FF3B30;
    --ios-orange: #FF9500;
    --ios-yellow: #FFCC00;
    --ios-purple: #AF52DE;
    --ios-pink: #FF2D55;
    --ios-teal: #5AC8FA;

    /* iMessage Specific */
    --imessage-blue: #007AFF;
    --imessage-green: #34C759;
    --imessage-bubble-sent: #007AFF;
    --imessage-bubble-received: #E9E9EB;
    --imessage-text-sent: #FFFFFF;
    --imessage-text-received: #000000;

    /* iOS Backgrounds */
    --ios-bg-primary: #FFFFFF;
    --ios-bg-secondary: #F2F2F7;
    --ios-bg-tertiary: #FFFFFF;
    --ios-separator: rgba(60, 60, 67, 0.12);
    --ios-separator-opaque: #C6C6C8;

    /* Text Colors */
    --ios-label: #000000;
    --ios-label-secondary: #3C3C43;
    --ios-label-tertiary: rgba(60, 60, 67, 0.6);
    --ios-label-quaternary: rgba(60, 60, 67, 0.18);

    /* Typography */
    --font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif;
    --font-size-title: 17px;
    --font-size-body: 17px;
    --font-size-caption: 12px;
    --font-size-footnote: 13px;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 20px;
    --spacing-xl: 24px;

    /* Safe Areas */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);

    /* Layout */
    --max-width: 375px;
    --status-bar-height: 54px;
    --header-height: 96px;
    --input-area-height: 52px;
    --home-indicator-height: 34px;
}

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Navigation - Desktop Only */
.main-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 12px 30px;
    display: flex;
    justify-content: center;
    gap: 20px;
    z-index: 1000;
    border-bottom: 0.5px solid var(--ios-separator);
}

.nav-link {
    color: var(--ios-blue);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    padding: 8px 20px;
    border-radius: 20px;
    transition: all 0.2s ease;
}

.nav-link:hover {
    background: rgba(0, 122, 255, 0.1);
}

.nav-link.active {
    background: var(--ios-blue);
    color: white;
}

/* iPhone Frame - Desktop */
.iphone-frame {
    width: 100%;
    max-width: var(--max-width);
    height: calc(100vh - 100px);
    max-height: 812px;
    min-height: 600px;
    background: #1C1C1E;
    border-radius: 50px;
    padding: 10px;
    box-shadow:
        0 50px 100px -20px rgba(0, 0, 0, 0.5),
        0 30px 60px -30px rgba(0, 0, 0, 0.5),
        inset 0 0 0 2px #3A3A3C;
    position: relative;
}

.iphone-frame::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 32px;
    background: #1C1C1E;
    border-radius: 18px;
    z-index: 10;
}

.iphone-screen {
    width: 100%;
    height: 100%;
    background: var(--ios-bg-primary);
    border-radius: 42px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* iOS Status Bar */
.ios-status-bar {
    height: var(--status-bar-height);
    padding: 14px 28px 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background: var(--ios-bg-secondary);
    position: relative;
    z-index: 5;
}

.status-left .time {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.dynamic-island {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 30px;
    background: #000;
    border-radius: 20px;
}

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

.cellular, .wifi {
    opacity: 0.9;
}

.battery-icon {
    display: flex;
    align-items: center;
    margin-left: 2px;
}

.battery-body {
    width: 25px;
    height: 12px;
    border: 1.5px solid rgba(0, 0, 0, 0.4);
    border-radius: 3px;
    padding: 1.5px;
    position: relative;
}

.battery-level {
    height: 100%;
    background: #000;
    border-radius: 1px;
}

.battery-cap {
    width: 2px;
    height: 5px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 0 1px 1px 0;
    margin-left: 1px;
}

/* iMessage Header */
.imessage-header {
    height: var(--header-height);
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--ios-bg-secondary);
    border-bottom: 0.5px solid var(--ios-separator);
}

.header-left {
    width: 80px;
}

.back-button {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    margin-left: -8px;
}

.back-count {
    font-size: 17px;
    color: var(--ios-blue);
    font-weight: 400;
}

.header-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.avatar-letter {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.contact-name {
    font-size: 11px;
    color: var(--ios-label);
    font-weight: 400;
}

.header-right {
    width: 80px;
    display: flex;
    justify-content: flex-end;
}

.header-btn {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.header-btn:active {
    background: rgba(0, 0, 0, 0.05);
}

/* Messages Area */
.messages-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--ios-bg-primary);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.messages-container {
    min-height: 100%;
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Date Separator */
.date-separator {
    text-align: center;
    padding: 8px 0 16px;
}

.date-separator span {
    font-size: 12px;
    color: var(--ios-label-tertiary);
    font-weight: 400;
}

/* iMessage Input Area */
.imessage-input-area {
    padding: 8px 8px;
    background: var(--ios-bg-secondary);
    border-top: 0.5px solid var(--ios-separator);
}

.input-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, opacity 0.15s;
}

.input-btn:active {
    transform: scale(0.92);
    opacity: 0.7;
}

.plus-btn {
    width: 32px;
    height: 32px;
}

.send-btn {
    width: 32px;
    height: 32px;
    opacity: 0.4;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.15s;
}

.send-btn.active {
    opacity: 1;
    pointer-events: auto;
}

.message-input-container {
    flex: 1;
    background: var(--ios-bg-primary);
    border-radius: 20px;
    border: 0.5px solid var(--ios-separator-opaque);
    overflow: hidden;
}

.message-input-container input {
    width: 100%;
    padding: 9px 16px;
    border: none;
    background: transparent;
    font-size: 17px;
    font-family: var(--font-family);
    outline: none;
    line-height: 1.4;
}

.message-input-container input::placeholder {
    color: var(--ios-label-tertiary);
}

/* Home Indicator */
.home-indicator {
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ios-bg-secondary);
    padding-bottom: 8px;
}

.home-indicator::after {
    content: '';
    width: 134px;
    height: 5px;
    background: #000;
    border-radius: 3px;
    opacity: 0.2;
}

/* Plus Menu */
.plus-menu {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.plus-menu.active {
    opacity: 1;
    visibility: visible;
}

.plus-menu-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--ios-bg-secondary);
    border-radius: 20px 20px 0 0;
    padding: 20px;
    padding-bottom: calc(20px + var(--safe-area-bottom));
    display: flex;
    gap: 16px;
    justify-content: center;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.plus-menu.active .plus-menu-content {
    transform: translateY(0);
}

.plus-menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 12px 20px;
}

.plus-menu-icon {
    width: 60px;
    height: 60px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.plus-menu-icon.camera {
    background: #8E8E93;
}

.plus-menu-icon.photos {
    background: linear-gradient(135deg, #FF9500, #FF2D55);
}

.plus-menu-item span {
    font-size: 12px;
    color: var(--ios-blue);
    font-weight: 500;
}

/* Share Modal - iOS Style Sheet */
.share-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.share-modal.active {
    opacity: 1;
    visibility: visible;
}

.share-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
}

.share-sheet {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--ios-bg-secondary);
    border-radius: 20px 20px 0 0;
    max-height: 85vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

.share-modal.active .share-sheet {
    transform: translateY(0);
}

.share-sheet-handle {
    width: 36px;
    height: 5px;
    background: rgba(60, 60, 67, 0.3);
    border-radius: 3px;
    margin: 8px auto 16px;
}

.share-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px 16px;
    border-bottom: 0.5px solid var(--ios-separator);
}

.share-sheet-header h2 {
    font-size: 17px;
    font-weight: 600;
}

.share-close {
    background: none;
    border: none;
    color: var(--ios-blue);
    font-size: 17px;
    font-weight: 400;
    cursor: pointer;
    padding: 8px;
}

.share-sheet-content {
    padding: 20px;
    padding-bottom: calc(20px + var(--safe-area-bottom));
}

.share-preview {
    margin-bottom: 20px;
}

.preview-bubble {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--ios-bg-primary);
    border-radius: 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.preview-icon {
    font-size: 36px;
}

.preview-title {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 2px;
}

.preview-subtitle {
    font-size: 14px;
    color: var(--ios-label-tertiary);
}

.share-form {
    margin-bottom: 20px;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--ios-label-secondary);
    margin-bottom: 8px;
    padding-right: 4px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 14px 16px;
    background: var(--ios-bg-primary);
    border: none;
    border-radius: 12px;
    font-size: 17px;
    font-family: var(--font-family);
    outline: none;
    transition: box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.2);
}

.form-group textarea {
    resize: none;
    min-height: 60px;
}

.generate-btn {
    width: 100%;
    padding: 16px;
    background: var(--ios-blue);
    color: white;
    border: none;
    border-radius: 14px;
    font-size: 17px;
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.generate-btn:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.share-url-section {
    margin-bottom: 20px;
}

.url-display {
    display: flex;
    align-items: center;
    background: var(--ios-bg-primary);
    border-radius: 12px;
    overflow: hidden;
}

.url-display input {
    flex: 1;
    padding: 14px 16px;
    border: none;
    background: transparent;
    font-size: 14px;
    font-family: monospace;
    color: var(--ios-label-secondary);
    outline: none;
    direction: ltr;
    text-align: left;
}

.copy-inline {
    padding: 14px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--ios-blue);
}

.share-actions {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 4px 0;
    -webkit-overflow-scrolling: touch;
}

.share-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px 12px;
    min-width: 70px;
    flex-shrink: 0;
}

.share-action-btn:active {
    opacity: 0.7;
}

.action-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--ios-bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.action-icon.whatsapp {
    background: #25D366;
}

.action-icon.telegram {
    background: #0088cc;
}

.share-action-btn span {
    font-size: 11px;
    color: var(--ios-label);
    font-weight: 400;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 25px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 500;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 4000;
    backdrop-filter: blur(10px);
}

.toast.active {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.toast svg {
    color: var(--ios-green);
}

/* ========================================
   Mobile Responsive - Full Screen Mode
   ======================================== */
@media (max-width: 480px) {
    body {
        padding: 0;
        background: var(--ios-bg-secondary);
    }

    .main-nav {
        display: none;
    }

    .iphone-frame {
        max-width: none;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        min-height: auto;
        border-radius: 0;
        padding: 0;
        background: none;
        box-shadow: none;
    }

    .iphone-frame::before {
        display: none;
    }

    .iphone-screen {
        border-radius: 0;
    }

    .ios-status-bar {
        height: calc(var(--status-bar-height) + var(--safe-area-top));
        padding-top: calc(14px + var(--safe-area-top));
    }

    .dynamic-island {
        display: none;
    }

    .imessage-input-area {
        padding-bottom: calc(8px + var(--safe-area-bottom));
    }

    .home-indicator {
        display: none;
    }
}

/* Tablet */
@media (min-width: 481px) and (max-width: 768px) {
    .iphone-frame {
        max-width: 375px;
    }
}

/* Large Desktop */
@media (min-width: 1200px) {
    .iphone-frame {
        max-height: 900px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --ios-bg-primary: #000000;
        --ios-bg-secondary: #1C1C1E;
        --ios-bg-tertiary: #2C2C2E;
        --ios-separator: rgba(84, 84, 88, 0.65);
        --ios-separator-opaque: #38383A;
        --ios-label: #FFFFFF;
        --ios-label-secondary: #EBEBF5;
        --ios-label-tertiary: rgba(235, 235, 245, 0.6);
        --imessage-bubble-received: #26252A;
        --imessage-text-received: #FFFFFF;
    }

    .dynamic-island {
        background: #000;
    }

    .battery-body {
        border-color: rgba(255, 255, 255, 0.4);
    }

    .battery-level {
        background: #fff;
    }

    .battery-cap {
        background: rgba(255, 255, 255, 0.4);
    }

    .home-indicator::after {
        background: #fff;
    }

    .status-left .time,
    .cellular, .wifi {
        color: #fff;
    }

    /* Fix input text color in dark mode */
    .message-input-container {
        background: #1C1C1E;
        border-color: #38383A;
    }

    .message-input-container input {
        color: #FFFFFF;
    }

    .message-input-container input::placeholder {
        color: rgba(235, 235, 245, 0.6);
    }

    /* Fix form inputs in dark mode */
    .form-group input,
    .form-group textarea {
        background: #1C1C1E;
        color: #FFFFFF;
    }

    .url-display input {
        color: #EBEBF5;
    }

    /* Fix avatar letter in dark mode */
    .avatar-letter {
        color: #333;
    }
}
