:root {
    --primary: #07c160;
    --primary-dark: #06ad56;
    --primary-light: rgba(7, 193, 96, 0.12);
    --bg: #ededed;
    --card: #ffffff;
    --text: #1a1a1a;
    --text-secondary: #888888;
    --border: #d8d8d8;
    --bubble-other: #ffffff;
    --bubble-self: #95ec69;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --danger: #ff4d4f;
    --warning: #faad14;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.app {
    max-width: 768px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.view.hidden {
    display: none;
}

.view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ---------- join view ---------- */

.join-card {
    margin: auto 24px;
    background: var(--card);
    border-radius: 16px;
    padding: 32px 24px;
    box-shadow: var(--shadow);
    text-align: center;
}

.join-card h1 {
    font-size: 22px;
    margin-bottom: 8px;
}

.join-card p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 24px;
}

.join-card input {
    width: 100%;
    font-size: 40px;
    letter-spacing: 16px;
    text-align: center;
    font-weight: 700;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 20px;
    font-family: "SF Mono", Monaco, "Courier New", monospace;
    outline: none;
}

.join-card input:focus {
    border-color: var(--primary);
}

.primary-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

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

.primary-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* ---------- chat header ---------- */

.chat-header {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    flex-shrink: 0;
}

.chat-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.chat-title {
    font-size: 17px;
    font-weight: 600;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.storage-link {
    font-size: 13px;
    color: var(--primary);
    text-decoration: none;
    padding: 4px 10px;
    background: var(--primary-light);
    border-radius: 12px;
}

.storage-link:hover {
    background: rgba(7, 193, 96, 0.2);
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
}

.status-dot.connected {
    background: var(--primary);
}

.status-dot.connecting {
    background: var(--warning);
}

.status-dot.disconnected {
    background: var(--danger);
}

.chat-header-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
}

.session-code strong {
    color: var(--primary);
    font-size: 14px;
    letter-spacing: 2px;
}

/* ---------- messages ---------- */

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.system-msg {
    text-align: center;
    color: var(--text-secondary);
    font-size: 12px;
    padding: 8px 0;
}

.message {
    display: flex;
    max-width: 78%;
}

.message.self {
    align-self: flex-end;
    justify-content: flex-end;
}

.message.other {
    align-self: flex-start;
    justify-content: flex-start;
}

.bubble {
    padding: 10px 14px;
    border-radius: 6px;
    box-shadow: var(--shadow);
    word-break: break-word;
    font-size: 15px;
}

.message.self .bubble {
    background: var(--bubble-self);
    color: #000;
}

.message.other .bubble {
    background: var(--bubble-other);
    color: #000;
}

.message-text {
    white-space: pre-wrap;
}

.message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 180px;
}

.file-icon {
    font-size: 28px;
    flex-shrink: 0;
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-weight: 500;
    font-size: 14px;
    word-break: break-all;
}

.file-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.message-image {
    margin-bottom: 6px;
}

.chat-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 4px;
    cursor: pointer;
    display: block;
}

.image-file-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    cursor: zoom-out;
}

.lightbox img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
}

.lightbox.hidden {
    display: none;
}

.download-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 4px;
    font-size: 13px;
    color: var(--text);
    text-decoration: none;
}

.message.self .download-btn {
    background: rgba(0, 0, 0, 0.08);
}

/* ---------- input bar ---------- */

.input-bar {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    background: #f7f7f7;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.attach-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    font-size: 22px;
    cursor: pointer;
    border-radius: 50%;
    flex-shrink: 0;
}

.attach-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

#text-input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 10px 12px;
    border: none;
    border-radius: 6px;
    background: var(--card);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    line-height: 1.4;
}

.send-btn {
    height: 40px;
    padding: 0 18px;
    border: none;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    flex-shrink: 0;
}

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

.send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* ---------- drop overlay ---------- */

.drop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.drop-overlay.hidden {
    display: none;
}

.drop-overlay-box {
    width: 220px;
    height: 220px;
    border: 3px dashed #fff;
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    text-align: center;
}

.drop-overlay-icon {
    font-size: 64px;
    margin-bottom: 12px;
}

.drop-overlay-text {
    font-size: 18px;
    font-weight: 500;
}

/* ---------- toast ---------- */

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 300;
    transition: opacity 0.3s;
    max-width: 90%;
    text-align: center;
}

.toast.hidden {
    opacity: 0;
    pointer-events: none;
}

.hidden {
    display: none !important;
}

/* ---------- desktop tweaks ---------- */

@media (min-width: 769px) {
    body {
        background: #e5e5e5;
    }

    .app {
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }
}

@media (max-width: 480px) {
    .chat-title {
        font-size: 16px;
    }

    .message {
        max-width: 85%;
    }
}
