* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: #f2f2f7;
    color: #111;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    width: 100%;
    max-width: 720px;
    overflow: hidden;
}
@media (min-width: 721px) {
    body { box-shadow: 0 0 42px rgba(0, 0, 0, 0.18); border-left: 1px solid rgba(0,0,0,0.06); border-right: 1px solid rgba(0,0,0,0.06); }
}
header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top));
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    z-index: 5;
}
header h2 { margin: 0; font-size: 17px; font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 10px; }
.status-wrap { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #6e6e73; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #c7c7cc; }
.dot.connected { background: #34c759; box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.18); }
.dot.connecting { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18); }
.dot.error { background: #ff3b30; box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.18); }
.icon-btn {
    border: none;
    background: #f2f2f7;
    border-radius: 22px;
    padding: 10px 18px;
    min-height: 44px;
    font-size: 14px;
    font-weight: 600;
    color: #0a84ff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:active { background: #e5e5ea; transform: scale(0.97); }
main {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px 12px;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}
.empty-tip {
    text-align: center;
    color: #aeaeb2;
    font-size: 14px;
    margin-top: 44px;
    line-height: 1.7;
}
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.msg {
    max-width: 82%;
    align-self: flex-end;
    background: #0a84ff;
    color: #fff;
    border-radius: 18px 18px 5px 18px;
    padding: 10px 14px;
    font-size: 16px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    animation: msg-in 160ms ease-out;
}
@keyframes msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}
.msg .time {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.72);
    text-align: right;
}
.msg.long { font-size: 15px; }
#inputPanel {
    flex: 0 0 auto;
    background: rgba(255, 255, 255, 0.95);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.input-row { display: flex; align-items: center; gap: 8px; }
#textInput {
    flex: 1;
    border: none;
    outline: none;
    background: #f2f2f7;
    border-radius: 24px;
    padding: 14px 18px;
    min-height: 48px;
    font-size: 17px;
    color: #111;
}
#textInput:focus { background: #fff; box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.35); }
#sendBtn {
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    min-width: 48px;
    background: #0a84ff;
    color: #fff;
    cursor: pointer;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(10, 132, 255, 0.3);
    transition: transform 120ms ease, opacity 120ms ease;
}
#sendBtn svg { width: 22px; height: 22px; }
#sendBtn:active { transform: scale(0.92); }
#sendBtn:disabled { background: #c7c7cc; box-shadow: none; }
#overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.42);
    display: none;
    align-items: flex-end;
    z-index: 20;
}
#overlay.show { display: flex; }
.sheet {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    background: #fff;
    border-radius: 20px 20px 0 0;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
    max-height: 88%;
    overflow-y: auto;
    animation: sheet-in 200ms ease-out;
}
@keyframes sheet-in {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: none; opacity: 1; }
}
.sheet h3 { margin: 0 0 16px; font-size: 17px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: #6e6e73; margin-bottom: 6px; font-weight: 600; }
.field input[type="text"], .field input[type="password"], .field input[type="number"] {
    width: 100%;
    border: 1px solid #e5e5ea;
    border-radius: 12px;
    padding: 13px 14px;
    min-height: 48px;
    font-size: 16px;
    outline: none;
    background: #f9f9fb;
}
.field input:focus { border-color: #0a84ff; background: #fff; box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.15); }
.row { display: flex; gap: 10px; }
.row .field { flex: 1; }
.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 15px;
    margin-bottom: 16px;
    min-height: 44px;
}
.switch-row input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 50px;
    height: 30px;
    border-radius: 15px;
    background: #e5e5ea;
    position: relative;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background 160ms ease;
}
.switch-row input[type="checkbox"]::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 160ms ease;
}
.switch-row input[type="checkbox"]:checked { background: #34c759; }
.switch-row input[type="checkbox"]:checked::after { transform: translateX(20px); }
.btn {
    width: 100%;
    border: none;
    border-radius: 14px;
    padding: 15px;
    min-height: 48px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}
.btn.primary { background: #0a84ff; color: #fff; box-shadow: 0 4px 12px rgba(10, 132, 255, 0.25); }
.btn.secondary { background: #f2f2f7; color: #333; margin-top: 8px; }
.btn:active { opacity: 0.88; transform: scale(0.98); }
.hint { font-size: 11px; color: #aeaeb2; margin-top: 12px; line-height: 1.5; }
@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
