/**
 * chats.krd - Mobile-First Styles
 * White background with brand colors: #2B9148 (green), #F9BD1E (yellow), #E62B27 (red)
 */

/* CSS Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-green: #2B9148;
    --color-yellow: #F9BD1E;
    --color-red: #E62B27;
    --color-white: #ffffff;
    --color-gray-light: #f5f5f5;
    --color-gray: #e0e0e0;
    --color-gray-dark: #666666;
    --color-text: #333333;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--color-white);
    color: var(--color-text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* Screen Management */
.screen {
    display: none;
    min-height: 100vh;
    width: 100%;
    opacity: 0;
    transform: translateY(20px);
    transition: var(--transition);
}

.screen.active {
    display: flex;
    flex-direction: column;
    opacity: 1;
    transform: translateY(0);
    animation: fadeIn 0.4s ease-out;
}

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

/* Container */
.container {
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

/* Logo */
.logo-container {
    text-align: center;
    margin-bottom: 40px;
}

.logo {
    max-width: 120px;
    height: auto;
    animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

.logo-container-small {
    text-align: center;
    margin-bottom: 20px;
}

.logo-small {
    max-width: 60px;
    height: auto;
}

/* Typography */
.title {
    font-size: 28px;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 12px;
    text-align: center;
}

.subtitle {
    font-size: 16px;
    color: var(--color-gray-dark);
    margin-bottom: 32px;
    text-align: center;
}

/* Buttons */
.btn {
    width: 100%;
    padding: 16px 24px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: var(--shadow);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--color-green);
    color: white;
}

.btn-primary:hover {
    background-color: #248a3d;
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background-color: var(--color-gray-light);
    color: var(--color-text);
}

.btn-secondary:hover {
    background-color: var(--color-gray);
}

.btn-admin {
    background-color: var(--color-yellow);
    color: var(--color-text);
}

.btn-admin:hover {
    background-color: #e0ad1a;
}

.btn-icon {
    font-size: 20px;
}

.btn-back {
    background: none;
    border: none;
    color: var(--color-green);
    font-size: 16px;
    cursor: pointer;
    padding: 10px;
    margin-bottom: 20px;
    align-self: flex-start;
    -webkit-tap-highlight-color: transparent;
}

.btn-icon-only {
    background: none;
    border: none;
    color: var(--color-gray-dark);
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    -webkit-tap-highlight-color: transparent;
}

.button-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

/* Info Text */
.info-text {
    text-align: center;
    color: var(--color-gray-dark);
    font-size: 14px;
    margin-top: 20px;
}

.info-text p {
    margin: 6px 0;
}

/* Instagram Link */
.instagram-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--color-text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    margin-top: 24px;
    padding: 10px 20px;
    border-radius: 20px;
    background-color: var(--color-gray-light);
    transition: var(--transition);
}

.instagram-link:hover {
    background-color: var(--color-gray);
    transform: translateY(-2px);
}

.instagram-link svg {
    width: 24px;
    height: 24px;
}

/* Loading Spinner */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--color-gray);
    border-top-color: var(--color-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Auth Screen */
.auth-tabs {
    display: flex;
    width: 100%;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--color-gray);
}

.auth-tab {
    flex: 1;
    padding: 12px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--color-gray-dark);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.auth-tab.active {
    color: var(--color-green);
    border-bottom-color: var(--color-green);
}

.auth-form {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 16px;
}

.auth-form.active {
    display: flex;
}

.form-group {
    width: 100%;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    border: 2px solid var(--color-gray);
    border-radius: 8px;
    transition: var(--transition);
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-green);
    box-shadow: 0 0 0 3px rgba(43, 145, 72, 0.1);
}

.error-message {
    color: var(--color-red);
    font-size: 14px;
    text-align: center;
    margin-top: 8px;
    display: none;
}

.error-message.show {
    display: block;
}

.success-message {
    color: var(--color-green);
    font-size: 14px;
    text-align: center;
    margin-top: 8px;
    display: none;
}

.success-message.show {
    display: block;
}

/* Rooms List */
.rooms-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.room-card {
    background: var(--color-gray-light);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow);
}

.room-card:active {
    transform: scale(0.98);
}

.room-card h3 {
    color: var(--color-green);
    margin-bottom: 8px;
    font-size: 18px;
}

.room-card p {
    color: var(--color-gray-dark);
    font-size: 14px;
}

.room-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    margin-top: 8px;
    background-color: var(--color-green);
    color: white;
}

/* Admin Panel */
.admin-tabs {
    display: flex;
    width: 100%;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--color-gray);
    gap: 0;
}

.admin-tab {
    flex: 1;
    padding: 12px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--color-gray-dark);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.admin-tab.active {
    color: var(--color-green);
    border-bottom-color: var(--color-green);
}

.admin-tab-content {
    display: none;
    width: 100%;
}

.admin-tab-content.active {
    display: block;
}

.requests-list,
.ads-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.request-card {
    background: var(--color-gray-light);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.request-card h3 {
    color: var(--color-text);
    margin-bottom: 8px;
    font-size: 16px;
}

.request-card p {
    color: var(--color-gray-dark);
    font-size: 14px;
    margin-bottom: 12px;
}

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

.btn-approve {
    flex: 1;
    padding: 10px;
    background-color: var(--color-green);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
}

.btn-reject {
    flex: 1;
    padding: 10px;
    background-color: var(--color-red);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
}

/* Ad Management */
.ad-form {
    background: var(--color-gray-light);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 24px;
}

.ad-form h3 {
    margin-bottom: 16px;
    color: var(--color-text);
}

.ad-form small {
    display: block;
    font-size: 12px;
    color: var(--color-gray-dark);
    margin-top: 4px;
}

.ad-form select {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    border: 2px solid var(--color-gray);
    border-radius: 8px;
    transition: var(--transition);
    font-family: inherit;
    background-color: white;
}

.ad-form select:focus {
    outline: none;
    border-color: var(--color-green);
    box-shadow: 0 0 0 3px rgba(43, 145, 72, 0.1);
}

.ad-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.ad-card h4 {
    color: var(--color-green);
    margin-bottom: 8px;
    font-size: 16px;
}

.ad-card p {
    color: var(--color-gray-dark);
    font-size: 14px;
    margin-bottom: 8px;
}

.ad-card .ad-meta {
    font-size: 12px;
    color: var(--color-gray-dark);
    margin-bottom: 12px;
}

.ad-card .ad-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    font-size: 13px;
}

.ad-card .ad-stats span {
    color: var(--color-text);
    font-weight: 600;
}

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

.btn-delete {
    flex: 1;
    padding: 10px;
    background-color: var(--color-red);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
}

.ad-status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 8px;
}

.ad-status-badge.active {
    background-color: var(--color-green);
    color: white;
}

.ad-status-badge.inactive {
    background-color: var(--color-gray);
    color: var(--color-text);
}

.ad-status-badge.expired {
    background-color: var(--color-red);
    color: white;
}

/* Matching Screen */
.matching-animation {
    position: relative;
    width: 150px;
    height: 150px;
    margin: 40px auto;
}

.pulse-circle {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 4px solid var(--color-green);
    border-radius: 50%;
    opacity: 0;
    animation: pulse 2s ease-out infinite;
}

.pulse-circle.delay-1 {
    animation-delay: 0.5s;
}

.pulse-circle.delay-2 {
    animation-delay: 1s;
}

@keyframes pulse {
    0% {
        transform: scale(0.5);
        opacity: 0.8;
    }
    100% {
        transform: scale(1.2);
        opacity: 0;
    }
}

/* Chat Screen */
#chat-screen {
    display: none;
}

#chat-screen.active {
    display: flex;
}

.chat-header {
    background-color: var(--color-green);
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
}

.chat-header-left {
    display: flex;
    gap: 8px;
}

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

.chat-header .btn-icon-only {
    color: white;
}

.btn-next {
    opacity: 0.9;
}

.btn-next:hover {
    opacity: 1;
}

#chat-title {
    text-align: center;
    font-weight: 600;
    font-size: 16px;
}

.chat-stats {
    display: flex;
    gap: 8px;
    font-size: 11px;
}

.stat-badge {
    background-color: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
}

/* Connection Status Toast */
.connection-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background-color: white;
    padding: 12px 20px;
    border-radius: 24px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1000;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    max-width: 90%;
}

.connection-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

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

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

.connection-toast.info {
    border-left: 4px solid var(--color-yellow);
}

.connection-toast-icon {
    font-size: 20px;
    line-height: 1;
}

.connection-toast-message {
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text);
}

.connection-toast-close {
    background: none;
    border: none;
    color: var(--color-gray-dark);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    margin-left: 8px;
}



.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: var(--color-gray-light);
}

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    word-wrap: break-word;
    animation: messageSlideIn 0.3s ease-out;
}

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

.message.sent {
    align-self: flex-end;
    background-color: var(--color-green);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background-color: white;
    color: var(--color-text);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow);
}

.message.system {
    align-self: center;
    background-color: var(--color-yellow);
    color: var(--color-text);
    font-size: 14px;
    padding: 8px 12px;
    border-radius: 12px;
}

.message-sender {
    font-size: 11px;
    font-weight: 600;
    opacity: 0.8;
    margin-bottom: 4px;
}

.message.received .message-sender {
    color: var(--color-green);
}

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

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
}

.chat-input-form {
    display: flex;
    gap: 12px;
    padding: 16px;
    background-color: white;
    border-top: 1px solid var(--color-gray);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

#chat-input {
    flex: 1;
    padding: 14px 18px;
    font-size: 16px;
    border: 2px solid var(--color-gray);
    border-radius: 28px;
    font-family: inherit;
    transition: var(--transition);
    background-color: var(--color-gray-light);
}

#chat-input:focus {
    outline: none;
    border-color: var(--color-green);
    background-color: white;
    box-shadow: 0 0 0 4px rgba(43, 145, 72, 0.1);
    transform: scale(1.01);
}

.btn-send {
    width: 52px;
    height: 52px;
    min-width: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-green) 0%, #248a3d 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    transition: var(--transition);
    box-shadow: 0 4px 12px rgba(43, 145, 72, 0.3);
    position: relative;
    overflow: hidden;
}

.btn-send:hover {
    box-shadow: 0 6px 16px rgba(43, 145, 72, 0.4);
    transform: translateY(-2px);
}

.btn-send:active {
    transform: scale(0.95) translateY(0);
    box-shadow: 0 2px 8px rgba(43, 145, 72, 0.3);
}

.btn-send.sending {
    opacity: 0.6;
    pointer-events: none;
}

/* Ripple effect for send button */
.btn-send::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn-send:active::before {
    width: 100px;
    height: 100px;
}

/* Responsive adjustments for larger screens */
@media (min-width: 768px) {
    .title {
        font-size: 32px;
    }

    .subtitle {
        font-size: 18px;
    }

    .btn {
        font-size: 18px;
    }
}

/* Ad Banner */
.ad-banner-container {
    background-color: var(--color-gray-light);
    border-bottom: 1px solid var(--color-gray);
    display: none;
    overflow: hidden;
}

.ad-banner-container.show {
    display: block;
}

.ad-banner {
    padding: 12px 16px;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background-color 0.2s;
}

.ad-banner:active {
    background-color: rgba(0, 0, 0, 0.05);
}

.ad-banner-image {
    max-width: 80px;
    max-height: 60px;
    object-fit: contain;
    border-radius: 8px;
}

.ad-banner-content {
    flex: 1;
}

.ad-banner-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 4px;
}

.ad-banner-text {
    font-size: 12px;
    color: var(--color-gray-dark);
}

.ad-banner-close {
    background: none;
    border: none;
    color: var(--color-gray-dark);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    .chat-messages {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .chat-input-form {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
}
