:root {
    --bg: #0f141a;
    --panel: #18212b;
    --surface: #253241;
    --surface-2: #32465d;
    --text: #e6edf4;
    --muted: #9db0c4;
    --accent: #66c2a6;
    --danger: #ff6b6b;
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at top, #1b2735, var(--bg));
    color: var(--text);
}

.view { min-height: 100vh; }
.hidden { display: none !important; }

#loginView {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.card {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid #33485e;
    border-radius: 14px;
    padding: 20px;
}

label { display: block; margin-top: 12px; margin-bottom: 4px; }
input {
    width: 100%;
    border-radius: 10px;
    border: 1px solid #3a536d;
    background: #0f1a24;
    color: var(--text);
    padding: 10px;
}
button {
    border: 0;
    border-radius: 10px;
    padding: 10px 14px;
    background: var(--accent);
    color: #072217;
    font-weight: 700;
    cursor: pointer;
}
button.secondary {
    background: var(--surface-2);
    color: var(--text);
}
button:disabled { opacity: 0.7; cursor: not-allowed; }

.error { color: var(--danger); min-height: 20px; }
.muted { color: var(--muted); }

#appView {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr auto;
}

.appHeader {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: rgba(15, 20, 26, 0.92);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid #2e4155;
}

.stream {
    overflow-y: auto;
    padding: 10px;
    scroll-behavior: smooth;
}

.msg {
    background: var(--panel);
    border: 1px solid #2e4155;
    border-radius: 10px;
    margin: 8px 0;
    padding: 8px 10px;
}
.msgHead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
    position: relative;
}
.msgHeadMeta {
    flex: 1;
}
.msgMenuBtn {
    padding: 4px 8px;
    border-radius: 8px;
    line-height: 1;
}
.msgMenu {
    position: absolute;
    right: 0;
    top: 22px;
    display: flex;
    gap: 6px;
    padding: 6px;
    border-radius: 8px;
    border: 1px solid #3a536d;
    background: #162330;
    z-index: 5;
}
.dangerBtn {
    background: #7d2f3a !important;
}
.msgBody {
    word-wrap: break-word;
}
.msgBody img {
    max-width: 50%;
    width: auto;
    height: auto;
    border-radius: 8px;
    margin: 6px 0;
}
body.ios .msgBody img {
    max-width: 100%;
}
.msg.editing .msgBody {
    border: 1px dashed #4e6781;
    border-radius: 8px;
    padding: 8px;
}
.editControls {
    margin-top: 8px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.editImgWrap {
    display: inline-block;
    position: relative;
    margin: 4px 0;
}
.editImgWrap img {
    display: block;
}
.imgRemoveBtn {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 24px;
    min-height: 24px;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(125, 47, 58, 0.95);
    color: #fff;
}

.jump {
    position: fixed;
    right: 12px;
    bottom: calc(100px + env(safe-area-inset-bottom));
    z-index: 12;
}

.composerWrap {
    border-top: 1px solid #2e4155;
    background: rgba(15, 20, 26, 0.95);
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

.composer {
    min-height: 90px;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid #3a536d;
    border-radius: 10px;
    background: #0f1a24;
    padding: 10px;
}
.composer:empty:before {
    content: attr(data-placeholder);
    color: #7088a1;
}

.composerActions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.stagedAttachment {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: min(20vw, 110px);
    height: min(20vw, 110px);
    min-width: 58px;
    min-height: 58px;
    border: 1px solid #3a536d;
    border-radius: 10px;
    background: #111c27;
    overflow: hidden;
    margin: 4px 6px 4px 0;
    vertical-align: top;
}

.stagedAttachment img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.stagedRemoveBtn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
    padding: 0;
    border-radius: 999px;
    background: rgba(125, 47, 58, 0.95);
    color: #fff;
    line-height: 1;
}
