:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg: #f0f2f5;
    --card: #ffffff;
    --text: #1a1a1a;
    --text-secondary: #555;
    --border: #d0d5dd;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --danger: #b91c1c;
    --danger-light: #fef2f2;
    --danger-border: #fecaca;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 16px;
    line-height: 1.5;
}

.container {
    width: 100%;
    max-width: 480px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px 24px;
}

h1 {
    font-size: 1.4rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 24px;
}

.field { margin-bottom: 18px; }

label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="date"] {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    font-family: inherit;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

input[type="file"] { width: 100%; font-size: 14px; padding: 8px 0; }

.hint {
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.field-error {
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--danger);
    animation: fadeIn 0.15s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-2px); }
    to   { opacity: 1; transform: translateY(0); }
}

input.invalid {
    border-color: var(--danger-border);
    background: var(--danger-light);
}

input.invalid:focus {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

.preview-card {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    background: #fafafa;
    display: flex;
    gap: 14px;
    align-items: center;
}

.preview-thumb {
    flex: 0 0 96px;
    width: 96px;
    height: 96px;
    border-radius: 8px;
    overflow: hidden;
    background: #eef0f4;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.04);
}

.preview-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.preview-info { flex: 1 1 auto; min-width: 0; }

.preview-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.preview-size { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 8px; }

.preview-remove {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger-border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    width: auto;
    margin: 0;
    transition: background 0.2s, border-color 0.2s;
}

.preview-remove:hover { background: var(--danger-light); border-color: #fca5a5; }

button[type="submit"] {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
    transition: background 0.2s;
    font-family: inherit;
}

button[type="submit"]:hover { background: var(--primary-hover); }
button[type="submit"]:disabled { background: #a5b4fc; cursor: not-allowed; }

.message {
    margin-bottom: 20px;
    padding: 14px 16px;
    border-radius: 8px;
    font-size: 0.95rem;
    line-height: 1.45;
}

.success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.error   { background: var(--danger-light); border: 1px solid var(--danger-border); color: #991b1b; }

.error-list { margin: 6px 0 0 18px; padding: 0; }
.error-list li { margin-bottom: 2px; }

.link {
    display: block;
    text-align: center;
    margin-top: 16px;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9rem;
}

.link:hover { text-decoration: underline; }

.profile-photo {
    width: 100%;
    max-width: 200px;
    border-radius: 8px;
    margin: 10px auto;
    display: block;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.hidden { display: none !important; }

.chat-body { align-items: stretch !important; padding: 0 !important; }

.chat-container {
    width: 100%;
    max-width: 1100px;
    height: 100vh;
    background: var(--card);
    display: flex;
    flex-direction: column;
    margin: 0 auto;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--card);
}

.chat-back { color: var(--primary); text-decoration: none; font-size: 0.9rem; background: none; border: none; cursor: pointer; padding: 0; font-family: inherit; }
.chat-back:hover { text-decoration: underline; }
.chat-title { font-weight: 600; font-size: 1rem; }
.chat-user { font-size: 0.85rem; color: var(--text-secondary); }

.chat-main { flex: 1 1 auto; display: flex; min-height: 0; }

.chat-sidebar {
    width: 280px;
    flex: 0 0 280px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-sidebar-title {
    padding: 12px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}

.chat-users { flex: 1 1 auto; overflow-y: auto; }

.chat-user-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.15s;
}

.chat-user-item:hover { background: #f7f7f9; }
.chat-user-item.active { background: #eef2ff; }

.chat-user-name { font-weight: 500; font-size: 0.95rem; color: var(--text); margin-bottom: 2px; }
.chat-user-email { font-size: 0.8rem; color: var(--text-secondary); }

.chat-content { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }

.chat-content-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    background: var(--card);
}

.chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 20px;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-msg {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    font-size: 0.95rem;
    line-height: 1.4;
}

.chat-msg.own {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.other {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.chat-msg-text { margin-bottom: 4px; }
.chat-msg-time { font-size: 0.7rem; opacity: 0.7; text-align: right; }

.chat-empty { padding: 20px; text-align: center; color: var(--text-secondary); font-size: 0.9rem; }

.chat-input {
    display: flex;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--card);
}

.chat-input input {
    flex: 1 1 auto;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
}

.chat-input input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.chat-input button {
    padding: 12px 24px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    font-family: inherit;
}

.chat-input button:hover:not(:disabled) { background: var(--primary-hover); }
.chat-input button:disabled,
.chat-input input:disabled { opacity: 0.5; cursor: not-allowed; }

.online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

.online-dot.online {
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

.online-dot.offline { background: #d1d5db; }

.unread-badge {
    display: inline-block;
    background: #ef4444;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 6px;
    vertical-align: middle;
}

@media (min-width: 600px) {
    body { padding: 40px 20px; }
    .container { padding: 36px 32px; }
    h1 { font-size: 1.55rem; }
}

@media (max-width: 700px) {
    .chat-sidebar { width: 200px; flex: 0 0 200px; }
    .chat-msg { max-width: 85%; }
}

@media (max-width: 500px) {
    .chat-main { flex-direction: column; }
    .chat-sidebar {
        width: 100%; flex: 0 0 150px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
}

@media (max-width: 360px) {
    .container { padding: 20px 16px; }
    h1 { font-size: 1.25rem; }
    input[type="text"], input[type="email"], input[type="tel"], input[type="password"], input[type="date"] { padding: 11px 12px; }
    .preview-thumb { flex-basis: 72px; width: 72px; height: 72px; }
    .preview-name { font-size: 0.85rem; }
}

@media (display-mode: standalone) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}