:root {
    --bg: #e5ddd5;
    --panel: #ffffff;
    --header: #f0f2f5;
    --border: #e9edef;
    --text: #111b21;
    --muted: #667781;
    --accent: #00a884;
    --out: #d9fdd3;
    --in: #ffffff;
    --chip: #ffffff;
    --danger: #e54b4b;
    --hover: #f5f6f6;
    --active: #f0f2f5;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 15px;
}

a { color: inherit; }

.login-body { min-height: 100%; overflow: auto; }
.app-body { height: 100%; overflow: hidden; }

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(1200px 400px at 50% -10%, rgba(0, 168, 132, 0.12), transparent 60%),
        #f0f2f5;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 32px 32px;
    box-shadow: 0 12px 32px rgba(17, 27, 33, 0.08);
}

.login-logo {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--accent);
    display: grid;
    place-items: center;
    margin: 0 auto 16px;
}

.login-card h1 {
    margin: 0 0 8px;
    text-align: center;
    font-size: 22px;
    font-weight: 600;
}

.login-sub {
    margin: 0 0 24px;
    text-align: center;
    color: var(--muted);
    line-height: 1.45;
}

.login-form { display: flex; flex-direction: column; gap: 8px; }

.login-form label {
    margin-top: 8px;
    font-size: 13px;
    color: var(--muted);
}

.login-form input {
    background: #ffffff;
    border: 1px solid #d1d7db;
    border-radius: 8px;
    color: var(--text);
    padding: 11px 12px;
    font-size: 15px;
}

.login-form input:focus {
    outline: 2px solid var(--accent);
    border-color: transparent;
}

.login-form button,
.ghost-btn {
    margin-top: 16px;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #ffffff;
    font-weight: 600;
    padding: 11px 16px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

.login-error, .field-error { color: var(--danger); font-size: 13px; }
.login-error ul { margin: 0; padding-left: 18px; }

.wa {
    height: 100%;
    min-height: 0;
    display: flex;
    overflow: hidden;
    background: var(--bg);
}

.sidebar {
    width: min(420px, 38vw);
    min-width: 300px;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--panel);
    border-right: 1px solid var(--border);
}

.sidebar-header,
.thread-header {
    min-height: 60px;
    padding: 0 16px;
    background: var(--header);
    display: flex;
    align-items: center;
    gap: 12px;
}

.thread-header .ghost-btn { margin-left: auto; }

.contact-form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: end;
    padding: 10px 16px 12px;
    background: var(--header);
    border-bottom: 1px solid var(--border);
}

.contact-form[hidden] { display: none; }

.contact-form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
    min-width: 180px;
    flex: 1;
}

.contact-form input {
    border: 1px solid #d1d7db;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 14px;
    color: var(--text);
    background: #fff;
}

.contact-form button {
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    padding: 8px 16px;
    cursor: pointer;
    height: 36px;
}

.sidebar-header { justify-content: space-between; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand small, .thread-title small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #ffffff;
    display: grid;
    place-items: center;
    font-weight: 700;
}

.ghost-btn {
    margin: 0;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    padding: 6px 10px;
    font-size: 13px;
}

.ghost-btn:hover { color: var(--text); border-color: var(--muted); }

.search-form { padding: 8px 12px 10px; background: var(--panel); }
.search-form input {
    width: 100%;
    border: 0;
    border-radius: 8px;
    background: var(--header);
    color: var(--text);
    padding: 9px 12px;
}

.search-form input:focus { outline: 1px solid var(--accent); }

.chat-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
.empty-list { padding: 32px 16px; text-align: center; color: var(--muted); }

.chat-item {
    display: flex;
    gap: 12px;
    padding: 11px 16px;
    text-decoration: none;
    border-bottom: 1px solid var(--border);
}

.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); }

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
}

.avatar.sm { width: 40px; height: 40px; font-size: 13px; }

.chat-meta { min-width: 0; flex: 1; }
.chat-top { display: flex; justify-content: space-between; gap: 8px; }
.chat-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.chat-preview {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

.thread-empty {
    margin: auto;
    text-align: center;
    color: var(--muted);
    padding: 24px;
}

.thread-empty h2 { color: var(--text); font-weight: 400; margin: 8px 0; }
.empty-icon { font-size: 42px; }

.thread-title { min-width: 0; }
.thread-title strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phone-link { color: inherit; text-decoration: none; }
.phone-link:hover { text-decoration: underline; color: var(--accent); }

.back-btn {
    display: none;
    width: 32px;
    font-size: 28px;
    text-decoration: none;
    color: var(--muted);
}

.messages {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 16px 6%;
    background-color: #efeae2;
    background-image:
        radial-gradient(circle at 1px 1px, rgba(0,0,0,0.04) 1px, transparent 0);
    background-size: 22px 22px;
}

.date-chip, .system-msg { display: flex; justify-content: center; margin: 10px 0; }
.date-chip span, .system-msg span {
    background: var(--chip);
    color: var(--muted);
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 8px;
    max-width: 80%;
    text-align: center;
}

.row { display: flex; margin: 2px 0; }
.row.out { justify-content: flex-end; }
.row.in { justify-content: flex-start; }

.bubble {
    max-width: min(72%, 680px);
    padding: 6px 8px 4px 9px;
    border-radius: 8px;
    box-shadow: 0 1px 1px rgba(11, 20, 26, 0.13);
}

.bubble.out { background: var(--out); border-top-right-radius: 0; }
.bubble.in { background: var(--in); border-top-left-radius: 0; }

.sender { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.forwarded { font-size: 12px; color: var(--muted); font-style: italic; margin-bottom: 4px; }

.quote {
    background: rgba(11, 20, 26, 0.05);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    padding: 6px 8px;
    margin-bottom: 6px;
    font-size: 13px;
    color: #3b4a54;
}

.quote strong { display: block; color: var(--accent); font-size: 12px; }

.media {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(11, 20, 26, 0.05);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 4px;
    font-size: 13px;
}

.deleted { font-style: italic; color: var(--muted); }

.text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.4;
}

.bubble a {
    color: #027eb5;
    text-decoration: underline;
}

.bubble a:hover { color: #015f89; }

.bubble time {
    display: block;
    text-align: right;
    font-size: 11px;
    color: #667781;
    margin-top: 4px;
}

@media (max-width: 800px) {
    .sidebar {
        width: 100%;
        min-width: 0;
    }

    .thread { display: none; }
    .wa.is-open .sidebar { display: none; }
    .wa.is-open .thread { display: flex; }
    .back-btn { display: grid; place-items: center; }
    .messages { padding: 12px 4%; }
    .bubble { max-width: 88%; }
}
