/* WinClass App Styles */
:root {
    --primary: #41C8E5;
    --primary-dark: #35a8c2;
    --secondary: #4DC247;
    --danger: #e74c3c;
    --dark: #1a1a2e;
    --gray: #6c757d;
    --light-gray: #e9ecef;
    --white: #ffffff;
    --bg: #f5f7fa;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
    --radius: 12px;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--dark);
    overflow: hidden;
}

#app {
    height: 100%;
    position: relative;
}

/* Экраны */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    background: var(--bg);
}

.screen.active {
    display: flex;
}

/* Загрузка */
#loading-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
}

.loading-content {
    text-align: center;
    color: var(--white);
}

.loading-content .logo {
    font-size: 64px;
    margin-bottom: 16px;
}

.loading-content .app-name {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 24px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: var(--white);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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

/* Экран входа */
#login-screen {
    justify-content: center;
    align-items: center;
    padding: 24px;
}

.login-container {
    width: 100%;
    max-width: 360px;
    text-align: center;
}

.login-container .logo {
    font-size: 56px;
    margin-bottom: 8px;
}

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

.login-container .subtitle {
    color: var(--gray);
    margin-bottom: 32px;
}

#login-form {
    margin-bottom: 16px;
}

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

.input-group input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--light-gray);
    border-radius: var(--radius);
    font-size: 16px;
    transition: border-color 0.2s;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.checkbox-group {
    text-align: left;
    margin-bottom: 20px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--gray);
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.login-error {
    color: var(--danger);
    margin-bottom: 16px;
    min-height: 20px;
}

.login-links {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--light-gray);
}

.login-links p {
    color: var(--gray);
    margin-bottom: 12px;
}

.guest-link {
    margin-top: 16px;
}

/* Кнопки */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    width: 100%;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-primary:disabled {
    background: var(--gray);
    cursor: not-allowed;
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

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

.btn-text {
    background: transparent;
    color: var(--gray);
    padding: 8px;
}

.btn-text:hover {
    color: var(--primary);
}

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

.btn-small {
    padding: 10px 16px;
    font-size: 14px;
}

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

.icon-btn:hover {
    background: rgba(0,0,0,0.05);
}

/* Хедер */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--white);
    box-shadow: var(--shadow);
    position: relative;
    z-index: 10;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 20px;
    font-weight: 700;
}

.logo-small {
    font-size: 24px;
}

/* Чаты */
.chats-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.chats-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.chats-header h2 {
    font-size: 18px;
}

.badge {
    background: var(--danger);
    color: var(--white);
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
}

.badge.hidden {
    display: none;
}

.chats-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s;
}

.chat-item:hover {
    transform: translateY(-2px);
}

.chat-item:active {
    transform: scale(0.98);
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--white);
    flex-shrink: 0;
}

.chat-avatar.support {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
}

.chat-avatar.group {
    background: var(--secondary);
}

.chat-avatar.channel {
    background: #9b59b6;
}

.chat-content {
    flex: 1;
    min-width: 0;
}

.chat-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-item-name {
    font-weight: 600;
    font-size: 15px;
}

.chat-item-time {
    font-size: 12px;
    color: var(--gray);
}

.chat-item-preview {
    font-size: 14px;
    color: var(--gray);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-badge {
    background: var(--primary);
    color: var(--white);
    font-size: 12px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chats-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray);
}

.chats-empty.hidden {
    display: none;
}

.chats-empty p {
    margin-bottom: 16px;
}

.chats-empty .btn {
    width: auto;
}

/* Промо для гостей */
.guest-promo {
    padding: 16px;
    background: var(--white);
    text-align: center;
    border-top: 1px solid var(--light-gray);
}

.guest-promo.hidden {
    display: none;
}

.guest-promo p {
    color: var(--gray);
    margin-bottom: 12px;
    font-size: 14px;
}

.guest-promo .btn {
    width: auto;
}

/* Нижняя навигация */
.bottom-nav {
    display: flex;
    background: var(--white);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    padding: 8px 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray);
    transition: color 0.2s;
}

.nav-item.active {
    color: var(--primary);
}

.nav-icon {
    font-size: 24px;
}

.nav-label {
    font-size: 12px;
    font-weight: 500;
}

/* Экран чата */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--white);
    box-shadow: var(--shadow);
}

.chat-info {
    flex: 1;
}

.chat-name {
    font-weight: 600;
    font-size: 16px;
}

.chat-status {
    font-size: 12px;
    color: var(--gray);
}

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

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: auto;
}

.message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    position: relative;
}

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

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

.message.admin {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: var(--white);
}

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

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

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

/* Ввод сообщения */
.message-input-container {
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: var(--white);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

.message-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg);
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
}

#message-input {
    flex: 1;
    border: none;
    background: none;
    font-size: 16px;
    resize: none;
    max-height: 120px;
    padding: 8px 0;
    font-family: inherit;
}

#message-input:focus {
    outline: none;
}

.send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:disabled {
    background: var(--light-gray);
    color: var(--gray);
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

/* Настройки */
.settings-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.settings-section {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.settings-section h3 {
    font-size: 14px;
    color: var(--gray);
    text-transform: uppercase;
    margin-bottom: 16px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--light-gray);
}

.setting-item:last-child {
    border-bottom: none;
}

/* Switch */
.switch {
    position: relative;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--light-gray);
    transition: 0.3s;
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: var(--white);
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider {
    background: var(--primary);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

.user-info {
    padding: 12px 0;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--light-gray);
}

.user-info p {
    margin-bottom: 4px;
}

.user-info .user-name {
    font-weight: 600;
    font-size: 18px;
}

.user-info .user-role {
    color: var(--gray);
    font-size: 14px;
}

.settings-section .btn {
    margin-bottom: 12px;
}

.settings-section .btn:last-child {
    margin-bottom: 0;
}

.app-version {
    color: var(--gray);
    font-size: 14px;
}

/* Адаптация для iOS */
@supports (padding-top: env(safe-area-inset-top)) {
    .app-header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }
    
    .chat-header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }
}

/* Скрытие скроллбара на мобильных */
.chats-container::-webkit-scrollbar,
.messages-container::-webkit-scrollbar,
.settings-container::-webkit-scrollbar {
    display: none;
}

.chats-container,
.messages-container,
.settings-container {
    -ms-overflow-style: none;
    scrollbar-width: none;
}



/* Дополнительные стили для админки - добавить в конец app.css */

/* Информация о клиенте в списке чатов */
.chat-client-info {
    font-size: 12px;
    color: var(--secondary);
    margin-bottom: 2px;
}

/* Подсветка чатов с непрочитанными */
.chat-item.has-unread {
    background: linear-gradient(135deg, rgba(65, 200, 229, 0.1) 0%, rgba(77, 194, 71, 0.1) 100%);
    border-left: 3px solid var(--primary);
}

/* Панель шаблонов */
.templates-panel {
    position: absolute;
    bottom: 70px;
    left: 0;
    right: 0;
    background: var(--white);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    max-height: 60%;
    display: none;
    flex-direction: column;
    z-index: 100;
}

.templates-panel.active {
    display: flex;
}

.templates-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--light-gray);
    font-weight: 600;
}

.templates-header button {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.templates-header button:hover {
    background: var(--light-gray);
}

.templates-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.templates-category {
    font-size: 12px;
    color: var(--gray);
    text-transform: uppercase;
    padding: 8px 12px 4px;
    font-weight: 600;
}

.template-item {
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 4px;
}

.template-item:hover {
    background: var(--light-gray);
}

.template-item:active {
    background: var(--primary);
    color: var(--white);
}

.template-item:active .template-preview {
    color: rgba(255,255,255,0.8);
}

.template-title {
    font-weight: 500;
    margin-bottom: 2px;
}

.template-preview {
    font-size: 13px;
    color: var(--gray);
}

.templates-empty {
    text-align: center;
    color: var(--gray);
    padding: 24px;
}

/* Админский режим - другой цвет хедера */
.admin-mode .app-header,
.admin-mode .chat-header {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: var(--white);
}

.admin-mode .app-header .icon-btn,
.admin-mode .chat-header .icon-btn {
    color: var(--white);
}

.admin-mode .chat-status {
    color: rgba(255,255,255,0.7);
}
