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

:root {
    --bg-gradient-start: #667eea;
    --bg-gradient-end: #764ba2;
    --card-bg: rgba(255, 255, 255, 0.97);
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --border-focus: #667eea;
    --accent: #667eea;
    --accent-hover: #5a6fd6;
    --success-bg: #d1fae5;
    --success-text: #065f46;
    --error-bg: #fee2e2;
    --error-text: #dc2626;
    --admin-bubble: #eef2ff;
    --admin-bubble-text: #312e81;
    --user-bubble: linear-gradient(135deg, #667eea, #764ba2);
    --user-bubble-text: #ffffff;
    --chat-bg: #e9ecf3;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    --radius: 16px;
    --radius-sm: 10px;
}

[hidden] {
    display: none !important;
}

html,
body {
    height: 100%;
}

body {
    font-family: 'Vazirmatn', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    min-height: 100%;
    color: var(--text-primary);
    line-height: 1.6;
}

.page-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 24px 16px;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 620px;
    max-height: calc(100vh - 48px);
    padding: 32px 28px;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.card-header {
    text-align: center;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.logo-icon {
    width: 52px;
    height: 52px;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    color: white;
}

.logo-icon svg {
    width: 26px;
    height: 26px;
}

.card-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.app-alert {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    flex-shrink: 0;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success-text);
}

.alert-error {
    background: var(--error-bg);
    color: var(--error-text);
}

.auth-section,
.ticket-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.auth-form {
    flex-shrink: 0;
}

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

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.optional {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fafafa;
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
    background: white;
}

.auth-hint {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 18px;
}

.chat-app {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: white;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    color: white;
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.chat-header-title {
    font-size: 0.95rem;
    font-weight: 600;
}

.user-badge {
    font-weight: 600;
    font-size: 0.82rem;
    color: white;
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.12);
    color: white;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

.icon-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.22);
}

.icon-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.icon-btn-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.logout-btn {
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.12);
    color: white;
    padding: 8px 12px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.logout-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.22);
}

.chat-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--chat-bg);
    padding: 16px 12px;
    scroll-behavior: smooth;
}

.chat-body::-webkit-scrollbar {
    width: 6px;
}

.chat-body::-webkit-scrollbar-thumb {
    background: #c7d2fe;
    border-radius: 999px;
}

.messages-empty {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 32px 12px;
}

.chat-message-row {
    display: flex;
    margin-bottom: 12px;
    width: 100%;
}

.chat-message-row:last-child {
    margin-bottom: 0;
}

.chat-row-user {
    justify-content: flex-start;
}

.chat-row-admin {
    justify-content: flex-end;
}

.chat-bubble {
    max-width: 82%;
    padding: 10px 12px;
    border-radius: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

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

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

.chat-bubble-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 0.75rem;
    opacity: 0.9;
}

.chat-bubble-author {
    font-weight: 700;
}

.chat-bubble-time {
    font-size: 0.72rem;
    opacity: 0.85;
}

.chat-bubble-text {
    font-size: 0.92rem;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
}

.chat-bubble-attachment {
    margin-top: 8px;
}

.chat-attachment-image {
    display: block;
    max-width: 100%;
    max-height: 220px;
    border-radius: 10px;
    object-fit: cover;
}

.chat-attachment-video {
    display: block;
    max-width: 100%;
    max-height: 220px;
    border-radius: 10px;
}

.chat-attachment-link {
    display: inline-block;
    font-size: 0.82rem;
    font-weight: 600;
    color: inherit;
    text-decoration: underline;
}

.chat-composer {
    flex-shrink: 0;
    border-top: 1px solid var(--border-color);
    background: white;
    padding: 10px 12px;
}

.composer-attachment-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px 10px;
    background: #f3f4f6;
    border-radius: 8px;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.composer-clear-file {
    border: none;
    background: transparent;
    color: var(--error-text);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}

.composer-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.composer-attach-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #f3f4f6;
    color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
}

.composer-attach-btn:hover {
    background: #e5e7eb;
}

.composer-attach-btn svg {
    width: 20px;
    height: 20px;
}

.composer-input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.92rem;
    resize: none;
    min-height: 40px;
    max-height: 120px;
    line-height: 1.4;
    background: #fafafa;
}

.composer-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
    background: white;
}

.composer-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    color: white;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.composer-send-btn svg {
    width: 18px;
    height: 18px;
}

.composer-send-btn:hover:not(:disabled) {
    opacity: 0.92;
}

.composer-send-btn.is-loading,
.composer-send-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.submit-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 13px 24px;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.submit-btn svg {
    width: 18px;
    height: 18px;
}

.submit-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.submit-btn.is-loading,
.submit-btn:disabled {
    cursor: not-allowed;
    opacity: 0.85;
    transform: none;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.submit-btn-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

.is-submitting .composer-input,
.is-submitting .composer-attach-btn,
.is-submitting .composer-send-btn {
    pointer-events: none;
    opacity: 0.65;
    cursor: not-allowed;
}

@media (max-width: 480px) {
    .card {
        padding: 24px 18px;
        max-height: calc(100vh - 32px);
    }

    .card-header h1 {
        font-size: 1.35rem;
    }

    .chat-bubble {
        max-width: 90%;
    }
}
