:root {
    --green: #1b8354;
    --green-dark: #14693f;
    --brown: #7a5230;
    --brown-dark: #5f3f24;
    --bg: #f4f4f5;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #9ca3af;
    --border: #e5e7eb;
    --bubble-visitor: #e9e9eb;
    --danger: #dc2626;
}

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

html, body {
    height: 100%;
    background: #e8e8ea;
    font-family: 'Poppins', 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
    color: var(--text);
}



.widget {
    position: relative;
    width: 100%;
    height: 100vh;
    margin: 0 auto;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 30px rgba(0,0,0,.12);
    overflow: hidden;
}

/* ---------- header ---------- */
.app-header {
    background: linear-gradient(180deg, var(--brown) 0%, var(--brown-dark) 100%);
    color: #fff;
    padding: 18px 18px 14px;
    flex: 0 0 auto;
}
.header-inner { display: flex; align-items: baseline; justify-content: space-between; }
.header-brand { display: flex; align-items: baseline; gap: 8px; }
.header-logo { display: none; font-size: 20px; }
.header-title { font-size: 22px; font-weight: 800; letter-spacing: .3px; }
.header-link {
    background: none; border: none; color: #f3e8dd;
    font-size: 12.5px; cursor: pointer; font-family: inherit;
}
.header-link:hover { text-decoration: underline; }

/* ---------- views ---------- */
.view {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.view.hidden { display: none; }

/* ---------- cards ---------- */
.card {
    background: var(--card);
    border-radius: 14px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    flex: 0 0 auto;
}

.hero-card { text-align: left; }
.hero-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.hero-name { font-weight: 700; font-size: 15px; }
.hero-status { font-size: 12px; color: var(--muted); }
.hero-greeting {
    font-size: 14px; line-height: 1.55; white-space: pre-wrap;
    margin-bottom: 16px; color: #374151;
}
.hero-backat {
    margin-top: 10px; text-align: center;
    font-size: 12.5px; color: #6b7280;
}
.clock { font-size: 12px; }

.method-card { display: flex; align-items: center; justify-content: space-between; }
.method-label { font-size: 13.5px; color: #6b7280; }
.method-icon {
    width: 36px; height: 36px; border-radius: 50%;
    background: #e8f0fe; display: flex; align-items: center; justify-content: center;
    text-decoration: none; font-size: 16px;
}

.powered { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* ---------- buttons ---------- */
.btn {
    border: none; border-radius: 10px; cursor: pointer;
    font-family: inherit; font-weight: 700; font-size: 14px;
    padding: 12px 18px;
}
.btn-block { width: 100%; display: block; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:disabled { background: #a7cbb8; cursor: default; }
.btn-danger { background: #fff; color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover { background: #fef2f2; }

/* ---------- avatars ---------- */
.avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: #e7f3ec; border: 1px solid #d3e8dc;
    display: flex; align-items: center; justify-content: center;
    font-size: 19px; flex: 0 0 auto;
}
.avatar-lg { width: 46px; height: 46px; font-size: 22px; }
.avatar-sm { width: 32px; height: 32px; font-size: 15px; }
.avatar-agent { background: #eef2ff; border-color: #dfe4ff; }

/* ---------- subheader (inner pages) ---------- */
.subheader {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 2px 10px;
    flex: 0 0 auto;
}
.icon-btn {
    background: none; border: none; font-size: 26px; line-height: 1;
    color: var(--green); cursor: pointer; padding: 2px 6px; font-family: inherit;
}
.icon-spacer { width: 30px; }
.subheader-title { font-weight: 700; font-size: 16px; }
.subheader-id { flex: 1 1 auto; }
.subheader-name { font-weight: 700; font-size: 14.5px; }
.subheader-status { font-size: 11.5px; color: var(--muted); }

/* ---------- chat ---------- */
#viewChat { padding: 10px 12px 8px; gap: 0; }
.messages {
    flex: 1 1 auto;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 6px 2px 10px;
}

.msg { display: flex; flex-direction: column; max-width: 88%; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.in { align-self: flex-start; align-items: flex-start; }

.msg-with-avatar { display: flex; gap: 8px; align-items: flex-start; max-width: 100%; }

.bubble {
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.msg.in .bubble { background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.msg.out .bubble { background: var(--bubble-visitor); }
.bubble a { color: #2563eb; text-decoration: underline; }
.bubble strong { font-weight: 700; }

.msg.pending .bubble, .msg.pending .msg-image { opacity: .55; }

.typing { margin-top: 2px; }
.typing.hidden { display: none; }
.typing-bubble { color: #6b7280; font-size: 12.5px; }
.tdots span { animation: tblink 1.2s infinite; }
.tdots span:nth-child(2) { animation-delay: .2s; }
.tdots span:nth-child(3) { animation-delay: .4s; }
@keyframes tblink {
    0%, 80%, 100% { opacity: .2; }
    40% { opacity: 1; }
}

.msg-meta {
    font-size: 10.5px; color: var(--muted);
    margin: 3px 0 0 48px;
}
.msg.out .msg-meta { margin: 3px 4px 0 0; }

.msg-chip {
    background: var(--bubble-visitor);
    border-radius: 16px;
    padding: 9px 14px;
    font-size: 13.5px;
    font-weight: 600;
}

.options { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 2px; align-self: flex-end; }
.chip {
    background: #fff; border: 1px solid var(--border);
    border-radius: 18px; padding: 8px 14px;
    font-size: 13px; font-weight: 600; font-family: inherit;
    cursor: pointer; color: var(--text);
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.chip:hover { border-color: var(--green); color: var(--green); }
.chip:disabled { opacity: .45; cursor: default; }
.chip:disabled:hover { border-color: var(--border); color: var(--text); }

.form-block {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 12px; padding: 12px; margin-top: 4px;
    width: 100%; max-width: 320px;
    align-self: flex-start;
}
.form-title { font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.form-row { display: flex; gap: 8px; }
.text-input, .composer-input {
    border: 1px solid var(--border); border-radius: 9px;
    padding: 10px 12px; font-size: 13.5px; font-family: inherit;
    outline: none; background: #fff; color: var(--text);
    flex: 1 1 auto; min-width: 0;
}
.text-input:focus, .composer-input:focus { border-color: var(--green); }
.form-row .btn { padding: 10px 20px; }
.form-block.done .text-input, .form-block.done .btn { display: none; }
.form-done { color: var(--green); font-weight: 700; font-size: 13px; }

.system-msg {
    align-self: center;
    font-size: 11.5px; color: var(--muted);
    background: #ececee; border-radius: 12px;
    padding: 4px 12px;
    text-align: center;
}

/* ---------- banner ---------- */
.banner {
    flex: 0 0 auto;
    background: #ecfdf3; border: 1px solid #bbe7cc;
    border-radius: 12px; padding: 12px; margin-bottom: 8px;
}
.banner.hidden { display: none; }
.banner-text { font-size: 13px; color: #14532d; margin-bottom: 10px; font-weight: 600; text-align: center; }
.banner .btn { padding: 10px; }

/* ---------- composer ---------- */
.composer {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 8px;
    background: #f0f0f1; border-radius: 14px;
    padding: 6px 6px 6px 8px;
}
.composer-input { background: transparent; border: none; padding: 10px 0; }
.composer-clip {
    background: none; border: none; cursor: pointer;
    font-size: 17px; padding: 6px; flex: 0 0 auto;
    border-radius: 8px;
}
.composer-clip:hover { background: #e2e2e5; }
.composer-send {
    width: 38px; height: 38px; border-radius: 10px;
    border: none; background: #bcd9c9; color: #fff;
    font-size: 15px; cursor: pointer; flex: 0 0 auto;
}
.composer-send.active { background: var(--green); }
.composer-send:disabled { cursor: default; }

.upload-preview {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 8px;
    background: #eef7f1; border: 1px dashed #bcd9c9;
    border-radius: 10px; padding: 6px 10px; margin-bottom: 8px;
}
.upload-preview.hidden { display: none; }
.upload-thumb img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; display: block; }
.upload-name {
    flex: 1 1 auto; font-size: 12px; color: #374151;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.upload-cancel {
    background: none; border: none; cursor: pointer;
    font-size: 14px; color: var(--muted); padding: 2px 6px;
}
.upload-cancel:hover { color: var(--danger); }
.upload-progress { font-size: 11px; color: var(--muted); }

/* ---------- images in messages ---------- */
.msg-image {
    max-width: 220px; max-height: 220px;
    border-radius: 10px; display: block; cursor: zoom-in;
    border: 1px solid var(--border);
}

/* ---------- forms ---------- */
.form-fields { display: flex; flex-direction: column; gap: 8px; }
.form-field label {
    display: block; font-size: 11.5px; color: #6b7280;
    margin-bottom: 3px; font-weight: 600;
}
.form-field input {
    width: 100%;
    border: 1px solid var(--border); border-radius: 8px;
    padding: 9px 10px; font-size: 13px; font-family: inherit;
    outline: none; background: #fff;
}
.form-field input:focus { border-color: var(--green); }

/* ---------- business hours ---------- */
.hours-now { font-size: 20px; font-weight: 800; }
.hours-tz { font-size: 12px; color: var(--muted); margin-top: 4px; }
.hours-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.hours-table td { padding: 7px 4px; border-bottom: 1px solid #f1f1f3; }
.hours-table tr:last-child td { border-bottom: none; }
.hours-table td:first-child { font-weight: 600; width: 40%; }
.hours-table tr.today td { color: var(--green); font-weight: 700; }
.hours-closed { color: var(--muted); }

/* ---------- settings ---------- */
.settings-row-title { font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.settings-hint { font-size: 12.5px; color: #6b7280; line-height: 1.5; margin-bottom: 10px; }
.settings-line { font-size: 13px; margin-bottom: 10px; }
.settings-note { font-size: 12px; color: var(--green); margin-top: 8px; font-weight: 600; }
.settings-note.hidden { display: none; }
#viewSettings .card .btn { margin-top: 4px; }
#aboutEmail { word-break: break-all; }

/* ---------- tabs ---------- */
.tabs {
    flex: 0 0 auto;
    display: flex;
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 6px 0 max(6px, env(safe-area-inset-bottom));
}
.tab {
    flex: 1; background: none; border: none; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-family: inherit; color: var(--muted); padding: 4px 0;
}
.tab-icon { font-size: 18px; }
.tab-label { font-size: 11px; }
.tab.active { color: var(--green); font-weight: 700; }

/* ---------- toast ---------- */
.toast {
    position: absolute; left: 50%; bottom: 76px; transform: translateX(-50%);
    background: #111827; color: #fff; font-size: 12.5px;
    border-radius: 10px; padding: 9px 16px;
    max-width: 85%; text-align: center;
    z-index: 50; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.toast.hidden { display: none; }

/* ---------- desktop: floating box (kept last so base rules can't override it) ---------- */
@media (min-width: 700px) {
    body {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 28px;
        box-sizing: border-box;
    }
    .widget {
        width: min(720px, calc(100vw - 56px));
        height: calc(100vh - 88px);
        border-radius: 22px;
        box-shadow: 0 16px 48px rgba(0,0,0,.22);
    }
    #viewHome .card, #viewHours .card, #viewSettings .card {
        max-width: 560px;
        width: 100%;
        margin-left: auto;
        margin-right: auto;
    }
    .msg { max-width: 72%; }
    .options { max-width: 72%; }
    .bubble { font-size: 14px; }
}
