/* onedesk 客户端 —— 微信/QQ 式左右气泡布局。
   所有颜色走 CSS 变量，改主题只需要动 :root 这一块。 */

:root {
    --bg: #ededed;
    --panel: #f7f7f7;
    --surface: #ffffff;
    --text: #1a1a1a;
    --text-dim: #8b8b8b;
    --border: #e0e0e0;
    --bubble-them: #ffffff;
    --bubble-them-text: #1a1a1a;
    --bubble-mine: #95ec69;
    --bubble-mine-text: #14351a;
    --accent: #07c160;
    --accent-text: #ffffff;
    --danger: #e64545;
    --divider-bg: rgba(0, 0, 0, .06);
    --shadow: 0 1px 2px rgba(0, 0, 0, .06);
    --radius: 8px;
    --header-h: 56px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111113;
        --panel: #1c1c1f;
        --surface: #232327;
        --text: #e8e8ea;
        --text-dim: #85858c;
        --border: #303036;
        --bubble-them: #2a2a30;
        --bubble-them-text: #e8e8ea;
        /* 深浅两套保持同一色相，只压明度 —— 换主题时观感才连续 */
        --bubble-mine: #4c9e58;
        --bubble-mine-text: #f2fff4;
        --accent: #3fae63;
        --divider-bg: rgba(255, 255, 255, .08);
        --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    }
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
          "Helvetica Neue", Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}

.hidden { display: none !important; }

/* ---------- 登录 ---------- */

#login {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border-radius: 14px;
    padding: 36px 28px 28px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, .08);
}

.login-card h1 {
    margin: 0 0 4px;
    font-size: 21px;
    font-weight: 600;
    text-align: center;
}

.login-card .sub {
    margin: 0 0 28px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
}

.field { margin-bottom: 14px; }

.field input {
    width: 100%;
    padding: 12px 14px;
    font-size: 16px; /* 16px 以下 iOS Safari 会在聚焦时自动放大页面 */
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color .15s;
}

.field input:focus { border-color: var(--accent); }

.btn {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    font-weight: 500;
    color: var(--accent-text);
    background: var(--accent);
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
    transition: opacity .15s;
}

.btn:hover { opacity: .9; }
.btn:disabled { opacity: .5; cursor: default; }

.error {
    min-height: 20px;
    margin: 10px 0 0;
    color: var(--danger);
    font-size: 13px;
    text-align: center;
}

/* ---------- 聊天 ---------- */

#chat {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
}

header {
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    padding-top: env(safe-area-inset-top);
    height: calc(var(--header-h) + env(safe-area-inset-top));
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

header .title {
    flex: 1;
    min-width: 0;
    font-size: 16px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

header .icon-btn {
    flex: none;
    padding: 6px 10px;
    font-size: 13px;
    color: var(--text-dim);
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}

header .icon-btn:hover { color: var(--text); }

/* 状态条：只在断线或有提示时出现，正常时不占位 */
#status {
    flex: none;
    padding: 6px 16px;
    font-size: 13px;
    text-align: center;
    color: #8a6d00;
    background: #fff4d1;
}

@media (prefers-color-scheme: dark) {
    #status { color: #ffd66b; background: #3a2f10; }
}

#messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 12px 8px;
}

/* 时间分隔条：只在间隔超过 5 分钟时出现，替代每条消息都挂时间戳 */
.day {
    margin: 18px 0 12px;
    text-align: center;
}

.day span {
    padding: 3px 9px;
    font-size: 12px;
    color: var(--text-dim);
    background: var(--divider-bg);
    border-radius: 4px;
}

/* 一行消息：头像 + 气泡。自己发的整行反向排列，气泡就到了右边。 */
.row {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    margin-bottom: 10px;
}

.row.mine { flex-direction: row-reverse; }

/* 同一人连发：头像不重复画，但仍占位以保持气泡对齐；行距收紧成一组 */
.row.grouped { margin-top: -6px; }
.row.grouped .avatar { visibility: hidden; }

.avatar {
    flex: none;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: #7a8ba6;
    border-radius: 6px;
    user-select: none;
}

.row.mine .avatar { background: var(--accent); }

.bubble-wrap {
    max-width: min(78%, 560px);
    display: flex;
    flex-direction: column;
}

.row.mine .bubble-wrap { align-items: flex-end; }

.bubble {
    position: relative;
    padding: 9px 13px;
    color: var(--bubble-them-text);
    background: var(--bubble-them);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-wrap: anywhere;   /* 长英文/URL 不撑破气泡 */
    white-space: pre-wrap;
}

.row.mine .bubble {
    color: var(--bubble-mine-text);
    background: var(--bubble-mine);
}

/* 气泡小尖角。分组内的后续气泡不画尖角，视觉上更像一整块。 */
.bubble::before {
    content: "";
    position: absolute;
    top: 11px;
    left: -5px;
    width: 10px;
    height: 10px;
    background: inherit;
    transform: rotate(45deg);
}

.row.mine .bubble::before { left: auto; right: -5px; }
.row.grouped .bubble::before { display: none; }

/* ---------- 图片气泡 ---------- */

.bubble.img {
    padding: 0;
    overflow: hidden;
    background: var(--divider-bg);
    line-height: 0;
    white-space: normal;
}

.bubble.img::before { display: none; }   /* 图片不带尖角，避免边缘出现色块 */

.bubble.img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    cursor: zoom-in;
}

.bubble.img.broken {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 72px !important;
    padding: 0 14px;
    font-size: 13px;
    line-height: 1.4;
    color: var(--text-dim);
}

.bubble.img.broken img { display: none; }

/* ---------- 大图查看 ---------- */

#lightbox {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, .92);
    cursor: zoom-out;
}

#lightbox img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* ---------- 输入区 ---------- */

#composer {
    flex: none;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    background: var(--panel);
    border-top: 1px solid var(--border);
}

.tool {
    flex: none;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    background: none;
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
    transition: color .15s, background .15s;
}

.tool:hover { color: var(--accent); background: var(--divider-bg); }

#input {
    flex: 1;
    max-height: 120px;
    min-height: 40px;
    padding: 9px 12px;
    font: inherit;
    font-size: 16px;
    line-height: 1.4;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    resize: none;
}

#input:focus { border-color: var(--accent); }

#send {
    flex: none;
    height: 40px;
    padding: 0 18px;
    font-size: 15px;
    color: var(--accent-text);
    background: var(--accent);
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
}

#send:disabled { opacity: .45; cursor: default; }

/* ---------- 拖拽提示 ---------- */

.drop-hint {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    font-weight: 500;
    color: var(--accent);
    background: rgba(7, 193, 96, .08);
    border: 2px dashed var(--accent);
    border-radius: 10px;
    pointer-events: none;
    z-index: 20;
}

#chat.dragging .drop-hint { display: flex; }

.empty {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-dim);
    font-size: 14px;
}
