:root {
    --ink: #16211e;
    --paper: #f6f7f5;
    --panel: #ffffff;
    --line: #e2e5e1;
    --muted: #6c7570;
    --accent: #0f6e5c;      /* signal teal — communication/connectivity */
    --accent-soft: #e4f2ee;
    --outbound: #0f6e5c;
    --outbound-text: #ffffff;
    --inbound: #eef0ed;
    --inbound-text: #16211e;
    --danger: #b3432b;
    --radius: 10px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-size: 14px;
}

a { color: var(--accent); }

/* ---------- App shell (3 columns) ---------- */
.app {
    display: grid;
    grid-template-columns: 220px 280px 1fr;
    height: 100vh;
}

.col {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--line);
    overflow: hidden;
}

.col-thread { border-right: none; }

.col-header {
    padding: 16px;
    font-weight: 600;
    letter-spacing: 0.01em;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.col-footer {
    padding: 12px 16px;
    font-size: 12px;
    color: var(--muted);
    border-top: 1px solid var(--line);
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--muted);
    text-decoration: none;
}
.icon-btn:hover { color: var(--accent); }

/* ---------- Numbers column ---------- */
.col-numbers { background: var(--panel); }

.number-list {
    list-style: none;
    margin: 0;
    padding: 6px;
    overflow-y: auto;
    flex: 1;
}

.number-item {
    padding: 10px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    margin-bottom: 2px;
}

.number-item:hover { background: var(--accent-soft); }
.number-item.active { background: var(--accent); }
.number-item.active .number-name,
.number-item.active .number-phone { color: #fff; }

.number-name { font-weight: 600; font-size: 13px; }
.number-phone { font-size: 12px; color: var(--muted); margin-top: 2px; }

.empty-hint { padding: 12px 10px; color: var(--muted); font-size: 13px; }

/* ---------- Conversations column ---------- */
.col-conversations { background: #fbfbfa; }

.conversation-list {
    list-style: none;
    margin: 0;
    padding: 6px;
    overflow-y: auto;
    flex: 1;
}

.conversation-item {
    padding: 10px;
    border-radius: var(--radius);
    cursor: pointer;
    margin-bottom: 2px;
    position: relative;
}

.conversation-item:hover { background: var(--accent-soft); }
.conversation-item.active { background: var(--accent); }
.conversation-item.active .contact-name,
.conversation-item.active .preview,
.conversation-item.active .time { color: #fff; }

.contact-name { font-weight: 600; font-size: 13px; }
.preview {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.time { font-size: 11px; color: var(--muted); position: absolute; top: 10px; right: 10px; }

.unread-badge {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    border-radius: 10px;
    padding: 1px 7px;
    margin-top: 4px;
}

/* ---------- Thread column ---------- */
.col-thread { background: var(--paper); }

.thread-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.msg-row { display: flex; }
.msg-row.outbound { justify-content: flex-end; }
.msg-row.inbound { justify-content: flex-start; }

.bubble {
    max-width: 60%;
    padding: 10px 13px;
    border-radius: 16px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.msg-row.outbound .bubble { background: var(--outbound); color: var(--outbound-text); border-bottom-right-radius: 4px; }
.msg-row.inbound .bubble { background: var(--inbound); color: var(--inbound-text); border-bottom-left-radius: 4px; }

.bubble .meta { font-size: 10px; opacity: 0.7; margin-top: 4px; }
.bubble img, .bubble video { max-width: 100%; border-radius: 8px; margin-top: 6px; display: block; }
.bubble a.file-link { display: block; margin-top: 6px; font-size: 12px; }

.send-form {
    border-top: 1px solid var(--line);
    background: var(--panel);
    padding: 12px 16px;
    flex-shrink: 0;
}

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

.send-row textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 14px;
    max-height: 120px;
}

.send-row button[type="submit"] {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 10px 18px;
    font-weight: 600;
    cursor: pointer;
}
.send-row button[type="submit"]:disabled { opacity: 0.5; cursor: default; }

.attach-preview {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 12px;
    color: var(--muted);
}
.attach-preview.visible { display: flex; }
.attach-preview button { border: none; background: none; color: var(--danger); cursor: pointer; font-size: 12px; }

.placeholder-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
}

/* ---------- Login ---------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(160deg, #0f6e5c 0%, #0a4d40 100%);
}

.login-card {
    background: var(--panel);
    padding: 36px 32px;
    border-radius: 14px;
    width: 320px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.subtitle { margin: 0 0 20px; color: var(--muted); font-size: 13px; }

.login-card label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.login-card input {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 14px;
}

.login-card button {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 6px;
}

.alert { padding: 8px 10px; border-radius: 8px; font-size: 12px; margin-bottom: 14px; }
.alert-error { background: #fbe9e5; color: var(--danger); }
.alert-success { background: var(--accent-soft); color: var(--accent); }

/* ---------- Settings ---------- */
.settings-body { background: var(--paper); }
.settings-wrap { max-width: 720px; margin: 0 auto; padding: 32px 20px 60px; }
.back-link { font-size: 13px; text-decoration: none; }
.settings-wrap h1 { margin: 12px 0 24px; }
.settings-section { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 20px; }
.settings-section h2 { margin-top: 0; font-size: 15px; }
.webhook-url { display: block; background: var(--accent-soft); padding: 10px 12px; border-radius: 8px; font-size: 13px; margin: 10px 0; word-break: break-all; }
.hint { color: var(--muted); font-size: 12px; }

.inline-form { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.inline-form input[type="text"] {
    padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; flex: 1; min-width: 140px;
}
.inline-form button {
    padding: 9px 16px; border: none; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; font-size: 13px;
}
.inline-form button.secondary { background: var(--inbound); color: var(--ink); }

.numbers-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.numbers-table th, .numbers-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); font-size: 13px; }
.link-btn { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 12px; padding: 0; }

@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .col-numbers, .col-conversations { display: none; }
}
