:root {
    --bg: #0b141a;
    --panel: #111b21;
    --panel-2: #182229;
    --bubble-me: #005c4b;
    --bubble-them: #202c33;
    --text: #e9edef;
    --muted: #8696a0;
    --accent: #00a884;
    --danger: #f15c6d;
    --line: #222e35;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overscroll-behavior: none;
}

body { height: 100dvh; overflow: hidden; }

.hidden { display: none !important; }

.screen {
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ─── Belépés / identitás kártyák ─── */
#screen-login, #screen-pick, #screen-setpw {
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 32px 28px;
    width: 100%;
    max-width: 340px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.card h1 { margin: 0; font-size: 22px; font-weight: 600; }
.lock { font-size: 40px; }

.card input[type=password] {
    background: var(--panel-2);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 14px 16px;
    border-radius: 10px;
    font-size: 16px;
    outline: none;
}
.card input[type=password]:focus { border-color: var(--accent); }

.card button, .upload-btn span {
    background: var(--accent);
    color: #08120f;
    border: none;
    padding: 13px 16px;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}
.card button:active { opacity: .85; }

.error { color: var(--danger); min-height: 18px; margin: 0; font-size: 14px; }

.pick-buttons { display: flex; gap: 14px; }
.pick-buttons button {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 22px 10px;
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
}
.pick-buttons button .letter { font-size: 34px; font-weight: 700; color: var(--accent); }
.pick-buttons button .name { font-size: 15px; color: var(--muted); }

/* ─── App váz ─── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top));
}
.tabs { display: flex; gap: 6px; }
.tab {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 15px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 18px;
    cursor: pointer;
}
.tab.active { background: var(--panel-2); color: var(--text); }
.tab { position: relative; }
.tab-badge {
    display: inline-block;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    padding: 0 5px;
    margin-left: 6px;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    text-align: center;
    vertical-align: middle;
}
.tab-badge.orange { background: #f59e0b; }
.tab-badge.blue   { background: #3b82f6; }

.back-link { color: var(--muted); font-size: 13px; text-decoration: none; margin-top: 4px; }
.back-link:hover { color: var(--text); }

.new-tag {
    position: absolute;
    top: 6px; left: 6px;
    z-index: 1;
    background: #3b82f6;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 6px;
    letter-spacing: .5px;
}
.me { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.me button {
    background: transparent; border: none; color: var(--muted);
    font-size: 18px; cursor: pointer; padding: 4px 6px;
}
.me #ping-btn.on { color: var(--accent); }

.topbar { position: relative; }
.menu {
    position: absolute;
    top: 100%;
    right: 8px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 20;
    box-shadow: 0 10px 30px rgba(0,0,0,.4);
    min-width: 220px;
}
.menu button {
    background: transparent;
    border: none;
    color: var(--text);
    text-align: left;
    padding: 11px 12px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
}
.menu button:hover { background: var(--panel-2); }
.menu button.danger { color: var(--danger); }
.menu button.on { color: var(--accent); }

#toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 200;
    opacity: 0;
    transition: opacity .25s;
    pointer-events: none;
}
#toast.show { opacity: 1; }

.tabpane { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ─── Chat ─── */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.msg {
    max-width: 78%;
    padding: 7px 10px 5px;
    border-radius: 10px;
    position: relative;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 15px;
    line-height: 1.35;
}
.msg.them { align-self: flex-start; background: var(--bubble-them); border-top-left-radius: 3px; }
.msg.me   { align-self: flex-end;  background: var(--bubble-me);  border-top-right-radius: 3px; }
.msg.deleted { font-style: italic; color: var(--muted); }

.msg .meta {
    display: flex;
    gap: 5px;
    justify-content: flex-end;
    align-items: center;
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}
.msg.me .meta { color: #aacbc0; }
.msg .tick.seen { color: #53bdeb; }
.msg .edited { font-style: italic; }

.msg .actions {
    position: absolute;
    top: -10px;
    right: 6px;
    display: none;
    gap: 4px;
}
.msg.me:hover .actions { display: flex; }
.msg .actions button {
    background: var(--panel-2);
    border: 1px solid var(--line);
    color: var(--muted);
    border-radius: 6px;
    font-size: 11px;
    padding: 2px 6px;
    cursor: pointer;
}

.typing { padding: 0 16px 6px; color: var(--muted); font-size: 13px; font-style: italic; }

.composer {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    background: var(--panel);
    border-top: 1px solid var(--line);
    align-items: flex-end;
}
.composer textarea {
    flex: 1;
    resize: none;
    background: var(--panel-2);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 20px;
    padding: 11px 14px;
    font-size: 15px;
    font-family: inherit;
    max-height: 120px;
    outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.composer #send-btn {
    background: var(--accent);
    border: none;
    color: #08120f;
    width: 44px; height: 44px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    flex: 0 0 auto;
}
.composer .emoji-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    width: 40px; height: 44px;
    cursor: pointer;
    flex: 0 0 auto;
    line-height: 1;
    opacity: .85;
}
.composer .emoji-btn:active { opacity: 1; }

/* ─── Emoji panel ─── */
.emoji-panel {
    background: var(--panel);
    border-top: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    max-height: 260px;
}
.emoji-tabs {
    display: flex;
    gap: 2px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
}
.emoji-tabs button {
    background: transparent;
    border: none;
    font-size: 20px;
    padding: 4px 8px;
    border-radius: 8px;
    cursor: pointer;
    opacity: .6;
    flex: 0 0 auto;
}
.emoji-tabs button.active { opacity: 1; background: var(--panel-2); }
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 2px;
    overflow-y: auto;
    padding: 8px;
}
.emoji-grid button {
    background: transparent;
    border: none;
    font-size: 24px;
    padding: 4px;
    border-radius: 8px;
    cursor: pointer;
    line-height: 1.2;
}
.emoji-grid button:hover { background: var(--panel-2); }

/* ─── Fájlok ─── */
.files-toolbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
}
.upload-btn { cursor: pointer; }
.upload-progress { display: flex; align-items: center; gap: 8px; flex: 1; }
.bar { flex: 1; height: 6px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.upload-progress span { font-size: 13px; color: var(--muted); min-width: 38px; }

.files-grid {
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    padding: 12px;
    align-content: start;
}

.file-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    position: relative;
}
.file-thumb {
    height: 110px;
    background: var(--panel-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 42px;
    overflow: hidden;
}
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-info { padding: 8px 10px; }
.file-name { font-size: 13px; word-break: break-word; }
.file-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.file-del {
    position: absolute;
    top: 6px; right: 6px;
    background: rgba(0,0,0,.55);
    border: none;
    color: #fff;
    border-radius: 50%;
    width: 26px; height: 26px;
    cursor: pointer;
    font-size: 13px;
}

/* ─── Médianéző ─── */
.viewer {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.92);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.viewer-close {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top)); right: 16px;
    background: rgba(255,255,255,.12);
    border: none;
    color: #fff;
    width: 40px; height: 40px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    z-index: 2;
}
.viewer-content { max-width: 100%; max-height: 100%; display: flex; }
.viewer-content img,
.viewer-content video { max-width: 100%; max-height: 90dvh; border-radius: 8px; }
.viewer-content audio { width: min(90vw, 500px); }
.viewer-content .txt {
    background: var(--panel);
    color: var(--text);
    padding: 20px;
    border-radius: 10px;
    max-width: 800px;
    max-height: 85dvh;
    overflow: auto;
    white-space: pre-wrap;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 14px;
    line-height: 1.5;
}

/* görgetősáv diszkrét */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: #2a3942; border-radius: 4px; }

/* jobbklikk-mentés nehezítése médián */
.viewer-content img, .file-thumb img {
    -webkit-user-drag: none;
    user-select: none;
    pointer-events: auto;
}
