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

:root {
    --bg: #f5f5f5;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

#app {
    width: 100%;
    max-width: 480px;
    padding: 20px;
}

.screen {
    display: none;
}

.screen.active {
    display: block;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
    margin-bottom: 16px;
}

.card h3 {
    font-size: 18px;
    margin-bottom: 8px;
}

.card p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
}

.logo {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
    color: var(--primary);
}

h1 {
    text-align: center;
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 28px;
    font-size: 15px;
}

.google-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 12px 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    transition: background 0.2s, box-shadow 0.2s;
}

.google-btn:hover {
    background: #f9fafb;
    box-shadow: var(--shadow);
}

.google-btn:active {
    background: #f3f4f6;
}

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

.privacy-link {
    display: block;
    text-align: center;
    margin-top: 16px;
    color: var(--text-secondary);
    font-size: 13px;
    text-decoration: none;
    transition: color 0.2s;
}

.privacy-link:hover {
    color: var(--primary);
}

header {
    margin-bottom: 24px;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-content h1 {
    font-size: 20px;
    margin: 0;
}

.logout-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    transition: background 0.2s;
}

.logout-btn:hover {
    background: #f3f4f6;
}

.profile-card {
    padding: 24px;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 16px;
}

.avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
}

.profile-info h2 {
    font-size: 20px;
    margin-bottom: 4px;
}

.profile-info p {
    font-size: 14px;
}

.danger-card {
    border: 1px solid var(--danger-border);
    background: var(--danger-bg);
}

.danger-card h3 {
    color: var(--danger);
}

.danger-card p {
    margin-bottom: 16px;
}

.delete-btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--danger);
    color: white;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
}

.delete-btn:hover:not(:disabled) {
    background: var(--danger-hover);
}

.delete-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 32px;
    width: 100%;
    max-width: 420px;
}

.modal-content h3 {
    margin-bottom: 8px;
}

.modal-content > p {
    margin-bottom: 16px;
}

.modal-content input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.modal-content input:focus {
    border-color: var(--primary);
}

.error-text {
    color: var(--danger);
    font-size: 13px;
    margin-top: 8px;
    min-height: 20px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
}

.btn-secondary {
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #f3f4f6;
}

.toast {
    display: none;
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    z-index: 200;
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s ease;
}

.toast.show {
    display: block;
}

.toast.error {
    background: var(--danger);
}

.toast.success {
    background: #059669;
}

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

.lang-toggle {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 50;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: background 0.2s;
}

.lang-toggle:hover {
    background: #f3f4f6;
}

@media (max-width: 480px) {
    #app {
        padding: 12px;
    }

    .card {
        padding: 20px;
    }

    .modal-content {
        padding: 24px;
    }

    .chat-sidebar {
        display: none;
    }

    .chat-layout {
        flex-direction: column;
    }

    .chat-sidebar.mobile-open {
        display: flex;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
        background: var(--card-bg);
    }
}

.support-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    color: var(--primary);
    transition: background 0.2s, box-shadow 0.2s;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.support-btn:hover {
    background: #f0f0ff;
    box-shadow: var(--shadow-lg);
}

.support-btn svg {
    flex-shrink: 0;
}

.chat-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.chat-sidebar {
    width: 240px;
    min-width: 240px;
    border-right: 1px solid var(--border);
    background: #fafafa;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.chat-list {
    flex: 1;
    padding: 8px;
}

.chat-list-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

.chat-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    gap: 8px;
}

.chat-list-item:hover {
    background: #e8e8ff;
}

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

.chat-list-item.active .chat-list-item-delete {
    color: rgba(255,255,255,0.7);
}

.chat-list-item-title {
    flex: 1;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-list-item-delete {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0 2px;
    flex-shrink: 0;
    transition: color 0.15s;
}

.chat-list-item-delete:hover {
    color: var(--danger);
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

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

.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-secondary);
    text-align: center;
    gap: 12px;
}

.chat-welcome-icon {
    font-size: 48px;
}

.chat-welcome p {
    font-size: 15px;
    max-width: 300px;
    line-height: 1.5;
}

.chat-msg {
    display: flex;
    max-width: 80%;
}

.chat-msg-user {
    align-self: flex-end;
    justify-content: flex-end;
}

.chat-msg-assistant {
    align-self: flex-start;
    justify-content: flex-start;
}

.chat-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-msg-user .chat-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-msg-assistant .chat-bubble {
    background: #f0f0f0;
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.chat-typing {
    display: flex;
    gap: 4px;
    padding: 12px 18px;
    align-items: center;
}

.chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #999;
    animation: typing-dot 1.4s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-dot {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--card-bg);
}

.chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    max-height: 120px;
    line-height: 1.4;
}

.chat-input:focus {
    border-color: var(--primary);
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#chat-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    display: none;
    flex-direction: column;
    z-index: 90;
}

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

#chat-screen header {
    margin-bottom: 0;
    flex-shrink: 0;
}
