:root {
    --green: #075E54;
    --green-2: #128C7E;
    --green-3: #25D366;
    --ink: #111B21;
    --muted: #667781;
    --line: #e9edef;
    --bg: #efeae2;
    --mine: #d9fdd3;
    --theirs: #fff;
    --header: 56px;
    color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #111B21; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

#app {
    height: 100%;
    height: 100dvh;
    max-width: 520px;
    margin: 0 auto;
    background: #fff;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.screen { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.top {
    background: var(--green);
    color: #fff;
    min-height: calc(var(--header) + env(safe-area-inset-top));
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}
.top h1 { font-size: 20px; font-weight: 600; margin: 0; flex: 1; }
.top p { margin: 1px 0 0; font-size: 12px; opacity: .85; }
.icon-btn {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #fff;
    font-size: 22px;
    line-height: 40px;
    padding: 0;
}
.icon-btn:active { background: rgba(255,255,255,.12); }

.login {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 28px 22px calc(24px + env(safe-area-inset-bottom));
    background: #f0f2f5;
}
.brand {
    width: 84px;
    height: 84px;
    border-radius: 22px;
    background: var(--green);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 40px;
    margin: 0 auto 16px;
    box-shadow: 0 10px 24px rgba(7,94,84,.25);
}
.login h2 { text-align: center; margin: 0 0 6px; font-size: 26px; }
.login .sub { text-align: center; color: var(--muted); margin: 0 0 22px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field span { font-size: 13px; color: var(--muted); }
.field input {
    height: 48px;
    border: 1px solid #d1d7db;
    border-radius: 10px;
    padding: 0 14px;
    background: #fff;
    font-size: 16px;
}
.primary {
    width: 100%;
    height: 48px;
    border: 0;
    border-radius: 10px;
    background: var(--green-2);
    color: #fff;
    font-weight: 700;
    margin-top: 6px;
}
.primary:disabled { opacity: .6; }
.error {
    background: #fde8e8;
    color: #9b1c1c;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
    font-size: 14px;
}
.hint {
    margin-top: 22px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}
.install {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 28px 22px calc(24px + env(safe-area-inset-bottom));
    background: #f0f2f5;
    text-align: center;
}
.install-logo {
    width: 96px;
    height: 96px;
    border-radius: 22px;
    margin: 0 auto 16px;
    box-shadow: 0 10px 24px rgba(7,94,84,.25);
}
.install h2 { margin: 0 0 8px; font-size: 26px; }
.install p { margin: 0 0 18px; color: var(--muted); }
.install ol { text-align: left; margin: 0 0 18px; padding-left: 22px; line-height: 1.55; }
.ghost {
    width: 100%;
    height: 48px;
    border: 0;
    background: transparent;
    color: var(--green);
    font-weight: 700;
    margin-top: 8px;
}
.hint strong { color: var(--ink); }

.tabs {
    display: flex;
    gap: 8px;
    padding: 10px 12px 0;
    background: #fff;
}
.tabs button {
    flex: 1;
    height: 36px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
}
.tabs button.on { background: #e7f6f3; color: var(--green); border-color: #b7e0da; font-weight: 700; }

.search-wrap { padding: 10px 12px; background: #fff; }
.search-wrap input {
    width: 100%;
    height: 40px;
    border: 0;
    border-radius: 10px;
    background: #f0f2f5;
    padding: 0 14px;
    font-size: 16px;
}

.list { flex: 1; overflow-y: auto; background: #fff; -webkit-overflow-scrolling: touch; }
.person {
    width: 100%;
    border: 0;
    background: #fff;
    display: flex;
    gap: 12px;
    align-items: center;
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid #f3f4f5;
}
.person:active { background: #f5f6f6; }
.avatar, .bubble-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    background: #dfe5e7;
    flex: 0 0 50px;
}
.person-main { flex: 1; min-width: 0; }
.person-main strong, .person-main span { display: block; }
.person-main strong { font-size: 16px; }
.person-main .role { color: var(--green-2); font-size: 12px; margin-top: 1px; }
.person-main .preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.meta { text-align: right; min-width: 64px; color: var(--muted); font-size: 12px; }
.badge {
    display: inline-block;
    min-width: 20px;
    height: 20px;
    line-height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--green-3);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    margin-top: 6px;
}
.empty { color: var(--muted); text-align: center; padding: 40px 20px; }

.thread {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 10px 8px;
    background: var(--bg);
    background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px);
    background-size: 14px 14px;
    -webkit-overflow-scrolling: touch;
}
.row { display: flex; margin: 6px 0; }
.row.mine { justify-content: flex-end; }
.bubble {
    max-width: 82%;
    background: var(--theirs);
    border-radius: 8px;
    padding: 7px 9px 5px;
    box-shadow: 0 1px 0.5px rgba(0,0,0,.13);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.35;
}
.row.mine .bubble { background: var(--mine); }
.subject { display: block; color: var(--green); font-size: 12px; font-weight: 700; margin-bottom: 3px; }
.time { display: block; text-align: right; color: #667781; font-size: 11px; margin-top: 3px; }
.file-card {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    color: #027eb5;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
}
.shot { display: block; max-width: 240px; border-radius: 6px; margin-top: 4px; }

.compose {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: #f0f2f5;
    flex: 0 0 auto;
}
.compose textarea {
    flex: 1;
    min-height: 42px;
    max-height: 120px;
    border: 0;
    border-radius: 21px;
    padding: 11px 14px;
    resize: none;
    font-size: 16px;
    line-height: 1.3;
    background: #fff;
}
.attach, .send {
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    flex: 0 0 42px;
}
.attach { background: #fff; color: #54656f; font-size: 20px; }
.send { background: var(--green-2); color: #fff; font-size: 18px; }
.send:disabled, .attach:disabled { opacity: .5; }
.pending {
    font-size: 12px;
    color: var(--green);
    padding: 0 16px 6px;
    background: #f0f2f5;
}
.file-pill {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
    margin: 0 8px;
    padding: 8px 10px;
    background: #fff;
    border-radius: 10px 10px 0 0;
    font-size: 13px;
}
.file-pill button { border: 0; background: transparent; color: #c00; }

.menu {
    position: absolute;
    top: calc(48px + env(safe-area-inset-top));
    right: 8px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.18);
    z-index: 5;
    min-width: 160px;
    overflow: hidden;
}
.menu button {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: #fff;
    padding: 12px 14px;
}
.menu button:active { background: #f5f6f6; }
