:root {
    --primary-color: #25D366;
    --primary-dark: #128C7E;
    --bg-color: #E5DDD5;
    --white: #FFFFFF;
    --text-primary: #000000;
    --text-secondary: #667781;
    --sent-bg: #DCF8C6;
    --received-bg: #FFFFFF;
    --online: #25D366;
    --container-bg: #FFFFFF;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Cairo', 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    direction: rtl;
}

#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 600px;
    margin: 0 auto;
    background: var(--bg-color);
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-color);
}

.hidden {
    display: none !important;
}

/* Login Screen */
.login-screen {
    display: flex;
    flex-direction: column;
}

.login-header {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    left: 10px;
    right: 10px;
    display: flex;
    justify-content: flex-end;
    z-index: 10;
}

.login-header .header-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: var(--white);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-family: 'Cairo', sans-serif;
    display: none;
}

#install-btn-login {
    display: none;
}

.header-btn:active {
    background: rgba(255,255,255,0.3);
}

.login-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    background: linear-gradient(180deg, #128C7E 0%, #25D366 100%);
}

.logo {
    margin-bottom: 20px;
}

.logo img {
    border-radius: 20px;
}

.login-container h1 {
    color: var(--white);
    font-size: 28px;
    font-weight: 500;
    margin-bottom: 8px;
}

.subtitle {
    color: rgba(255,255,255,0.8);
    font-size: 16px;
    margin-bottom: 40px;
}

.form-group {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#phone-input {
    width: 100%;
    padding: 16px;
    font-size: 18px;
    border: none;
    border-radius: 8px;
    text-align: center;
    background: var(--white);
    font-family: 'Cairo', sans-serif;
}

#phone-input:focus {
    outline: 2px solid #fff;
}

#phone-input::placeholder {
    color: #999;
}

.btn-primary {
    padding: 16px 32px;
    font-size: 18px;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    background: var(--white);
    color: var(--primary-dark);
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
    font-family: 'Cairo', sans-serif;
}

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

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.hint {
    color: rgba(255,255,255,0.7);
    font-size: 14px;
    margin-top: 20px;
}

/* Teachers List Screen */
#teachers-screen {
    background: var(--bg-color);
}

.app-header {
    background: var(--primary-dark);
    padding: 16px 20px;
    padding-top: max(16px, env(safe-area-inset-top));
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h1 {
    color: var(--white);
    font-size: 22px;
    font-weight: 500;
}

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

.header-btn {
    background: rgba(255,255,255,0.25);
    border: none;
    color: var(--white);
    padding: 8px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-family: 'Cairo', sans-serif;
    white-space: nowrap;
}

.header-btn:active {
    background: rgba(255,255,255,0.4);
    transform: scale(0.98);
}

.install-btn {
    display: none;
}

.install-btn.visible,
.visible {
    display: inline-block !important;
}

.list-container {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-color);
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-secondary);
}

.teacher-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--white);
    margin-bottom: 2px;
    cursor: pointer;
    transition: background 0.2s;
}

.teacher-item:active {
    background: #f0f0f0;
}

.teacher-item .avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    margin-left: 16px;
}

.teacher-item .info {
    flex: 1;
}

.teacher-item .name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.teacher-item .subject {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Chat Screen */
#chat-screen {
    background: var(--bg-color);
}

.chat-header {
    background: var(--primary-dark);
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.back-btn, .info-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--white);
    cursor: pointer;
    padding: 8px;
}

.chat-header-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-info .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    margin-left: 12px;
}

.chat-header-info h2 {
    color: var(--white);
    font-size: 16px;
    font-weight: 500;
}

.chat-header-info .status {
    color: rgba(255,255,255,0.8);
    font-size: 12px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 8px;
    position: relative;
}

.message.sent {
    align-self: flex-end;
    background: var(--sent-bg);
}

.message.received {
    align-self: flex-start;
    background: var(--received-bg);
}

.message .text {
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message .time {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: left;
    margin-top: 4px;
}

.message.sent .time {
    color: rgba(0,0,0,0.5);
}

/* Date Header */
.date-header {
    text-align: center;
    margin: 16px 0 8px;
    font-size: 13px;
    color: var(--text-secondary);
    background: #E5DDD5;
    padding: 4px 12px;
    border-radius: 12px;
    display: inline-block;
    align-self: center;
}

.typing-area {
    padding: 12px 16px;
    background: var(--white);
    border-top: 1px solid #eee;
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.typing-hint {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--white);
    width: 90%;
    max-width: 400px;
    border-radius: 12px;
    padding: 24px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 12px;
    left: 12px;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
}

.about-header {
    text-align: center;
    margin-bottom: 24px;
}

.about-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 16px;
}

.about-header h2 {
    font-size: 22px;
    margin-bottom: 8px;
}

.about-header .subject {
    color: var(--text-secondary);
    font-size: 14px;
}

.about-details .detail-item {
    margin-bottom: 20px;
}

.about-details h3 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.about-details p {
    font-size: 15px;
    line-height: 1.5;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Responsive */
@media (min-width: 600px) {
    #app {
        border-left: 1px solid rgba(0,0,0,0.1);
        border-right: 1px solid rgba(0,0,0,0.1);
    }
}

/* Toast Notification */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.85);
    color: var(--white);
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    z-index: 2000;
    animation: toastFadeIn 0.3s ease;
    max-width: 90%;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

@keyframes toastFadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}