:root {
    --wa-green: #25D366;
    --wa-green-dark: #128C7E;
    --bg-1: #075E54;
    --bg-2: #128C7E;
    --text-dark: #1a1a1a;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: linear-gradient(135deg, var(--bg-1), var(--bg-2));
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    color: var(--text-dark);
}

.app {
    width: 100%;
    max-width: 460px;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.app-header {
    padding: 28px 28px 20px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.app-header h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

.app-header p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

.view {
    padding: 28px;
    display: none;
}

.view.active {
    display: block;
}

.login-copy {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    margin: 4px 0 24px;
}

.btn-fb-login {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px 20px;
    background: #1877F2;
    color: #fff;
    border-radius: 12px;
    text-decoration: none;
    font-weight: 600;
    font-size: 15px;
    transition: transform .15s ease, box-shadow .15s ease;
}

.btn-fb-login:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(24, 119, 242, .35);
}

.btn-fb-login img {
    width: 20px;
    height: 20px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--wa-green-dark);
    font-size: 13px;
    font-weight: 600;
    background: none;
    border: none;
    padding: 0;
    margin-bottom: 16px;
    cursor: pointer;
}

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

.view-title {
    font-size: 16px;
    font-weight: 700;
    margin: 0 0 4px;
}

.view-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0 0 18px;
    min-height: 16px;
}

.list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 420px;
    overflow-y: auto;
}

.card-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fafafa;
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: inherit;
    transition: border-color .15s ease, background .15s ease;
}

.card-item:hover {
    border-color: var(--wa-green);
    background: #f0fdf6;
}

.card-item.disabled {
    opacity: .5;
    cursor: not-allowed;
}

.card-item.disabled:hover {
    border-color: var(--border);
    background: #fafafa;
}

.card-item .title {
    font-weight: 600;
    font-size: 14px;
    text-transform: capitalize;
}

.card-item .subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: .3px;
    white-space: nowrap;
    flex-shrink: 0;
}

.badge.green { background: #dcfce7; color: #15803d; }
.badge.yellow { background: #fef9c3; color: #a16207; }
.badge.red { background: #fee2e2; color: #b91c1c; }
.badge.gray { background: #f1f5f9; color: #475569; }

.selected-template {
    background: #f0fdf6;
    border: 1px solid #bbf7d0;
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 18px;
}

.selected-template .label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #15803d;
    font-weight: 700;
}

.selected-template .name {
    font-size: 15px;
    font-weight: 700;
    margin-top: 2px;
    text-transform: capitalize;
}

label.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
}

input[type="text"] {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    margin-bottom: 16px;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--wa-green);
    box-shadow: 0 0 0 3px rgba(37, 211, 102, .15);
}

.btn-primary {
    width: 100%;
    padding: 14px 20px;
    background: var(--wa-green);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    transition: background .15s ease;
}

.btn-primary:hover {
    background: var(--wa-green-dark);
}

.btn-primary:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.state-msg {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    padding: 30px 0;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #e5e7eb;
    border-top-color: var(--wa-green);
    border-radius: 50%;
    margin: 0 auto 12px;
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.result-box {
    text-align: center;
    padding: 10px 0;
}

.result-icon {
    font-size: 40px;
    margin-bottom: 10px;
}

.result-box.success .result-icon { color: var(--wa-green); }
.result-box.error .result-icon { color: var(--danger); }

.result-title {
    font-weight: 700;
    font-size: 16px;
    margin-bottom: 6px;
}

.result-detail {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
    word-break: break-word;
}

.error-banner {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13px;
    margin-bottom: 16px;
}

#view-chat {
    padding: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--wa-green-dark);
    color: #fff;
}

.chat-back {
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.chat-title {
    font-weight: 700;
    font-size: 15px;
}

.chat-body {
    background: #e5ddd5;
    padding: 16px;
    height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-empty {
    margin: auto;
    text-align: center;
    color: #6b7280;
    font-size: 13px;
}

.bubble {
    max-width: 78%;
    padding: 8px 10px 6px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.35;
    box-shadow: 0 1px 1px rgba(0, 0, 0, .1);
}

.bubble.out {
    align-self: flex-end;
    background: #dcf8c6;
    border-top-right-radius: 2px;
}

.bubble.in {
    align-self: flex-start;
    background: #ffffff;
    border-top-left-radius: 2px;
}

.bubble-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.bubble-time {
    display: block;
    text-align: right;
    font-size: 10px;
    color: #94a3b8;
    margin-top: 4px;
}

.ticks {
    margin-left: 4px;
    font-size: 11px;
    color: #94a3b8;
}

.ticks.read {
    color: #34b7f1;
}

.chat-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #f0f0f0;
    border-top: 1px solid var(--border);
}

.chat-footer input[type="text"] {
    flex: 1;
    margin-bottom: 0;
    border-radius: 999px;
    padding: 10px 16px;
}

.chat-send-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--wa-green);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease;
}

.chat-send-btn:hover {
    background: var(--wa-green-dark);
}

.chat-send-btn:disabled {
    opacity: .6;
    cursor: not-allowed;
}
