:root {
    --bg: #0f1117;
    --bg2: #1a1d27;
    --bg3: #22263a;
    --bg4: #2a2f45;
    --border: #2e3350;
    --text: #e2e8f0;
    --text2: #8892a4;
    --accent: #4f8ef7;
    --green: #34d399;
    --yellow: #fbbf24;
    --red: #f87171;
    --purple: #a78bfa;
    --radius: 8px;
}

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

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

/* ── Login ──────────────────────────────────── */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--bg);
}

.login-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem;
    width: 100%;
    max-width: 380px;
}

.login-card h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.login-subtitle {
    color: var(--text2);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text2);
    margin-bottom: 0.3rem;
}

.form-group input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
}

.form-group input:focus {
    border-color: var(--accent);
}

.btn-primary {
    width: 100%;
    padding: 0.7rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    cursor: pointer;
    margin-top: 0.5rem;
}

.btn-primary:hover { opacity: 0.9; }

.flash-error {
    background: var(--red);
    color: white;
    padding: 0.5rem 0.8rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.85rem;
}

/* ── App Layout ─────────────────────────────── */

.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    height: 52px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.1rem;
    font-weight: 600;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-badge {
    font-size: 0.85rem;
    color: var(--text2);
}

.btn-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.85rem;
}

.btn-link:hover { text-decoration: underline; }

.app-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebar ────────────────────────────────── */

.sidebar {
    width: 320px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--bg2);
    flex-shrink: 0;
}

.sidebar-header {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.search-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
    margin-bottom: 0.5rem;
}

.search-input:focus { border-color: var(--accent); }

.filter-row {
    display: flex;
    gap: 0.25rem;
}

.filter-btn {
    flex: 1;
    padding: 0.3rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text2);
    font-size: 0.75rem;
    cursor: pointer;
}

.filter-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
}

.conv-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.conv-item:hover { background: var(--bg3); }
.conv-item.active { background: var(--bg4); }

.conv-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--bg4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--accent);
    flex-shrink: 0;
}

.conv-info {
    flex: 1;
    min-width: 0;
}

.conv-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.conv-name {
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-time {
    font-size: 0.7rem;
    color: var(--text2);
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.conv-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.15rem;
}

.conv-preview {
    font-size: 0.8rem;
    color: var(--text2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-unread {
    background: var(--accent);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 10px;
    padding: 0.1rem 0.4rem;
    margin-left: 0.5rem;
    flex-shrink: 0;
}

.conv-tags {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.3rem;
    flex-wrap: wrap;
}

.tag-chip {
    font-size: 0.65rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
}

.tag-removable .tag-remove {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0;
    line-height: 1;
}

.empty-state {
    padding: 2rem;
    text-align: center;
    color: var(--text2);
    font-size: 0.9rem;
}

/* ── Chat Panel ─────────────────────────────── */

.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    min-width: 0;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text2);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-header-info strong { font-size: 0.95rem; }

.chat-phone {
    font-size: 0.8rem;
    color: var(--text2);
    margin-left: 0.5rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.message-bubble {
    max-width: 65%;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.msg-in {
    align-self: flex-start;
    background: var(--bg2);
    border-bottom-left-radius: 2px;
}

.msg-out {
    align-self: flex-end;
    background: rgba(79, 142, 247, 0.15);
    border-bottom-right-radius: 2px;
}

.msg-leonela {
    align-self: flex-end;
    background: rgba(167, 139, 250, 0.15);
    border-bottom-right-radius: 2px;
}

.msg-sender {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--purple);
    margin-bottom: 0.15rem;
}

.msg-out .msg-sender { color: var(--accent); }

.msg-content {
    white-space: pre-wrap;
}

.msg-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.2rem;
}

.msg-time {
    font-size: 0.65rem;
    color: var(--text2);
}

.msg-status {
    font-size: 0.7rem;
}

/* ── Chat Input ─────────────────────────────── */

.chat-input-area {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    padding: 0.6rem 0.8rem;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    resize: none;
    max-height: 120px;
}

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

.btn-send {
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    align-self: flex-end;
}

.btn-send:disabled { opacity: 0.5; cursor: default; }
.btn-send:hover:not(:disabled) { opacity: 0.9; }

/* ── Contact Panel ──────────────────────────── */

.contact-panel {
    width: 300px;
    border-left: 1px solid var(--border);
    background: var(--bg2);
    overflow-y: auto;
    flex-shrink: 0;
}

.panel-section {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.panel-section h3 {
    font-size: 0.8rem;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.panel-field {
    margin-bottom: 0.4rem;
}

.panel-field label {
    font-size: 0.75rem;
    color: var(--text2);
    display: block;
}

.panel-field span {
    font-size: 0.9rem;
}

.select-sm, .select-full {
    padding: 0.35rem 0.5rem;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.8rem;
    outline: none;
}

.select-full { width: 100%; }

.tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.5rem;
}

/* ── Settings ───────────────────────────────── */

.settings-page {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.settings-content {
    padding: 2rem;
    color: var(--text2);
}

/* ── Scrollbar ──────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }
