:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f4f6f9;
    --border: #e2e5ea;
    --text: #1f2937;
    --text-muted: #6b7280;
    --bubble-in: #eef1f5;
    --success: #16a34a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
    margin: 0; height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #fff; color: var(--text);
    overscroll-behavior: none;
}

/* ---------- Auth ---------- */
.auth-screen {
    height: 100%; display: flex; align-items: center; justify-content: center;
    background: var(--bg); padding: 20px; position: relative;
}
.back-to-site {
    position: absolute; top: 16px; left: 16px;
    font-size: 13px; color: var(--text-muted); text-decoration: none;
}
.back-to-site:hover { color: var(--primary); }
.auth-box { width: 100%; max-width: 340px; }
.auth-box h1 { font-size: 26px; margin: 0 0 4px; text-align: center; }
.auth-box .subtitle { text-align: center; color: var(--text-muted); margin: 0 0 28px; }
.auth-form input {
    width: 100%; padding: 13px 14px; margin-bottom: 12px; font-size: 15px;
    border: 1px solid var(--border); border-radius: 10px; background: #fff;
}
.auth-form button {
    width: 100%; padding: 13px; background: var(--primary); color: #fff; border: none;
    border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.auth-form button:active { background: var(--primary-dark); }
.switch { text-align: center; font-size: 13px; color: var(--text-muted); margin-top: 14px; }
.switch a { color: var(--primary); font-weight: 600; text-decoration: none; }
.error { color: #dc2626; font-size: 13px; text-align: center; margin-top: 10px; min-height: 16px; }

/* ---------- Selección de departamento ---------- */
.department-screen {
    height: 100%; display: flex; align-items: center; justify-content: center;
    background: var(--bg); padding: 20px; position: relative;
}
.department-box { width: 100%; max-width: 340px; }
.department-box h1 { font-size: 22px; margin: 0 0 24px; text-align: center; }
.department-btn {
    width: 100%; display: flex; align-items: center; gap: 14px;
    padding: 18px 20px; margin-bottom: 14px; background: #fff;
    border: 1px solid var(--border); border-radius: 14px; cursor: pointer;
    font-size: 16px; font-weight: 600; color: var(--text); text-align: left;
}
.department-btn:active { background: var(--bg); }
.dept-icon { font-size: 26px; }

.back-btn {
    background: none; border: none; font-size: 20px; cursor: pointer;
    padding: 4px 8px 4px 0; color: var(--text);
}

/* ---------- Chat ---------- */
.chat-screen {
    height: 100%; display: flex; flex-direction: column;
}
.chat-header {
    display: flex; align-items: center; gap: 10px; padding: 14px 16px;
    padding-top: calc(14px + env(safe-area-inset-top));
    border-bottom: 1px solid var(--border); background: #fff;
    position: sticky; top: 0; z-index: 5;
}
.chat-header h3 { margin: 0; font-size: 16px; }
.status-text { font-size: 12px; color: var(--success); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--success); flex-shrink: 0; }

.messages {
    flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px;
    background: var(--bg); -webkit-overflow-scrolling: touch;
}
.bubble {
    max-width: 78%; padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.4;
    word-wrap: break-word;
}
.bubble.in { background: var(--bubble-in); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.out { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble img, .bubble video { max-width: 100%; border-radius: 10px; display: block; margin-bottom: 4px; }
.bubble .meta { font-size: 10px; opacity: 0.7; margin-top: 4px; display: block; }
.bubble a.file-link { color: inherit; text-decoration: underline; }

.message-form {
    display: flex; align-items: center; gap: 8px; padding: 10px 14px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border); background: #fff;
    position: sticky; bottom: 0;
}
.attach-btn { font-size: 22px; cursor: pointer; padding: 4px; }
#messageInput {
    flex: 1; padding: 11px 16px; border: 1px solid var(--border); border-radius: 22px; font-size: 15px;
}
.message-form button[type="submit"] {
    width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: #fff;
    border: none; cursor: pointer; font-size: 16px; flex-shrink: 0;
}
