:root {
    color-scheme: light;
    --bg: #f6f4ef;
    --panel: #ffffff;
    --panel-soft: #fdf9f2;
    --ink: #202329;
    --muted: #707783;
    --line: #e1ded6;
    --primary: #197d78;
    --primary-dark: #0f5f5b;
    --accent: #c55f42;
    --danger: #b53d4a;
    --admin: #1d6f9f;
    --client: #197d78;
    --shadow: 0 18px 60px rgba(35, 34, 29, 0.12);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background:
        linear-gradient(135deg, rgba(25, 125, 120, 0.08), transparent 34%),
        linear-gradient(220deg, rgba(197, 95, 66, 0.09), transparent 28%),
        var(--bg);
    color: var(--ink);
    font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
    letter-spacing: 0;
}

button,
input,
textarea {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(460px, 100%);
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(225, 222, 214, 0.9);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.login-copy h1,
.brand h1,
.chat-header h2 {
    margin: 0;
}

.login-copy h1 {
    font-size: 34px;
    line-height: 1.15;
}

.login-copy p {
    margin: 12px 0 22px;
    color: var(--muted);
    line-height: 1.7;
}

.eyebrow {
    display: block;
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.alert {
    background: #fff0ed;
    border: 1px solid #f2bbb0;
    color: #8f3427;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
}

.login-form {
    display: grid;
    gap: 16px;
}

.role-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    background: #f0eee8;
    padding: 6px;
    border-radius: 8px;
}

.role-tabs label {
    min-width: 0;
}

.role-tabs input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.role-tabs span {
    display: grid;
    place-items: center;
    min-height: 40px;
    border-radius: 6px;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.role-tabs input:checked + span {
    background: var(--panel);
    color: var(--ink);
    box-shadow: 0 8px 20px rgba(45, 45, 45, 0.08);
}

.password-field,
.settings-form label {
    display: grid;
    gap: 8px;
    color: #555b65;
    font-size: 14px;
}

input,
textarea {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 8px;
    outline: none;
}

input:focus,
textarea:focus {
    border-color: rgba(25, 125, 120, 0.7);
    box-shadow: 0 0 0 4px rgba(25, 125, 120, 0.12);
}

.password-field input,
.settings-form input,
.search-wrap input {
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
}

.primary-button,
.secondary-button,
.ghost-button,
.send-button,
.icon-button,
.switch,
.icon-link {
    border: 0;
    cursor: pointer;
    text-decoration: none;
}

.primary-button {
    min-height: 44px;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    font-weight: 700;
    padding: 0 18px;
}

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

.primary-button.wide {
    width: 100%;
}

.secondary-button,
.ghost-button {
    min-height: 36px;
    border-radius: 8px;
    padding: 0 12px;
    display: inline-grid;
    place-items: center;
}

.secondary-button {
    background: #edf7f6;
    color: var(--primary-dark);
    border: 1px solid #cce5e2;
}

.ghost-button {
    background: #f8f6f1;
    color: #4f5661;
    border: 1px solid var(--line);
}

.ghost-button.danger {
    color: var(--danger);
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.login-foot {
    margin-top: 18px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
}

.shell {
    width: min(1280px, calc(100vw - 28px));
    height: min(900px, calc(100vh - 28px));
    margin: 14px auto;
    display: grid;
    border: 1px solid rgba(225, 222, 214, 0.92);
    background: rgba(255, 255, 255, 0.78);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.admin-shell {
    grid-template-columns: 360px minmax(0, 1fr);
}

.client-shell {
    grid-template-columns: minmax(0, 1fr);
    max-width: 900px;
}

.sidebar {
    min-width: 0;
    background: rgba(255, 252, 246, 0.94);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 18px;
}

.brand,
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.brand h1 {
    font-size: 24px;
}

.icon-link {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    color: var(--accent);
    background: #fff3ed;
    border-radius: 8px;
}

.service-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.service-panel strong {
    display: block;
    margin-top: 2px;
}

.muted {
    color: var(--muted);
    font-size: 13px;
}

.switch {
    width: 54px;
    height: 30px;
    padding: 3px;
    border-radius: 999px;
    background: #d8d5cd;
}

.switch span {
    width: 24px;
    height: 24px;
    display: block;
    background: white;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
    transition: transform 0.2s ease;
}

.switch.on {
    background: var(--primary);
}

.switch.on span {
    transform: translateX(24px);
}

.tool-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.settings-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    max-height: 48vh;
    overflow: auto;
    display: grid;
    gap: 14px;
}

body.modal-open {
    overflow: hidden;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(32, 35, 41, 0.42);
    backdrop-filter: blur(5px);
}

.modal-dialog {
    width: min(780px, 100%);
    max-height: min(760px, calc(100vh - 48px));
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    background: var(--panel);
    border: 1px solid rgba(225, 222, 214, 0.95);
    border-radius: 8px;
    box-shadow: 0 24px 80px rgba(20, 22, 25, 0.28);
    overflow: hidden;
}

.modal-dialog.compact-dialog {
    width: min(620px, 100%);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.92);
}

.modal-head h2 {
    margin: 0;
    font-size: 24px;
}

.modal-body {
    min-height: 0;
    overflow: auto;
    display: grid;
    gap: 18px;
    padding: 20px;
}

.settings-section {
    display: grid;
    gap: 10px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
}

.settings-section:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.settings-section h3 {
    margin: 0;
    font-size: 14px;
    color: var(--ink);
}

.settings-form {
    display: grid;
    gap: 10px;
}

.spaced-form {
    margin-top: 10px;
}

.security-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.form-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.client-password-target {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.locked-ip-list {
    display: grid;
    gap: 8px;
}

.locked-ip-empty {
    color: var(--muted);
    font-size: 13px;
}

.locked-ip-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    background: #fbfaf7;
}

.locked-ip-item strong,
.locked-ip-item span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.locked-ip-item span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.hidden {
    display: none !important;
}

.search-wrap input {
    background: #fff;
}

.client-list {
    min-height: 0;
    overflow: auto;
    display: grid;
    gap: 4px;
    padding-right: 4px;
}

.client-item {
    width: 100%;
    text-align: left;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px 8px;
    align-items: center;
}

.client-item:hover,
.client-item.active {
    background: var(--panel);
    border-color: var(--line);
}

.client-item.active {
    box-shadow: 0 8px 24px rgba(34, 36, 40, 0.08);
}

.client-item.pinned {
    border-color: #cce5e2;
}

.client-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.client-name {
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.client-name:hover,
.editable-title:hover {
    color: var(--primary-dark);
}

.editable-title {
    cursor: text;
}

.pin-badge {
    flex: none;
    font-size: 13px;
}

.client-item-actions {
    grid-row: 1 / span 2;
    grid-column: 2;
    display: flex;
    gap: 4px;
}

.client-icon-button {
    width: 30px;
    height: 30px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--muted);
    cursor: pointer;
    display: grid;
    place-items: center;
}

.client-icon-button:hover,
.client-icon-button.active {
    color: var(--primary-dark);
    border-color: #cce5e2;
    background: #edf7f6;
}

.inline-title-input {
    width: min(420px, 100%);
    min-height: 40px;
    padding: 4px 10px;
    font-size: 22px;
    font-weight: 800;
}

.badge {
    flex: none;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11px;
    background: #edf7f6;
    color: var(--primary-dark);
}

.badge.off {
    background: #ffecee;
    color: var(--danger);
}

.client-preview,
.client-meta {
    color: var(--muted);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.client-meta {
    grid-column: 1;
}

.chat-pane {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    background: rgba(255, 255, 255, 0.7);
}

.chat-pane.full {
    grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.chat-header {
    padding: 18px 20px;
    background: rgba(255, 255, 255, 0.82);
    border-bottom: 1px solid var(--line);
}

.chat-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.chat-header h2 {
    font-size: 22px;
    line-height: 1.2;
    word-break: break-word;
}

.client-status {
    padding: 10px 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted);
    border-bottom: 1px solid var(--line);
    background: var(--panel-soft);
    font-size: 13px;
}

.client-status.warning {
    color: var(--danger);
    background: #fff0f1;
}

.messages {
    min-height: 0;
    overflow: auto;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.empty-state {
    margin: auto;
    color: var(--muted);
    text-align: center;
    line-height: 1.8;
}

.message-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.message-row.mine {
    justify-content: flex-end;
}

.bubble {
    max-width: min(620px, 78%);
    border-radius: 8px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid var(--line);
    box-shadow: 0 6px 20px rgba(40, 39, 35, 0.06);
    word-break: break-word;
}

.bubble.text-bubble {
    position: relative;
    padding-right: 42px;
}

.message-row.mine .bubble {
    background: #e7f5f3;
    border-color: #cce6e2;
}

.bubble .text {
    white-space: pre-wrap;
    line-height: 1.58;
}

.bubble .time {
    margin-top: 6px;
    color: var(--muted);
    font-size: 11px;
    text-align: right;
}

.copy-message-button {
    position: absolute;
    top: 7px;
    right: 7px;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.88);
    color: var(--muted);
    cursor: pointer;
    line-height: 1;
}

.copy-message-button:hover {
    color: var(--primary-dark);
    border-color: #cce5e2;
    background: #edf7f6;
}

.file-card {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    color: inherit;
    text-decoration: none;
}

.file-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #fff7ee;
    color: var(--accent);
    font-weight: 900;
}

.file-name {
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    color: var(--muted);
    font-size: 12px;
    margin-top: 3px;
}

.composer {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 48px;
    gap: 10px;
    padding: 14px 18px 18px;
    background: rgba(255, 255, 255, 0.9);
    border-top: 1px solid var(--line);
}

.composer textarea {
    min-height: 44px;
    max-height: 140px;
    resize: none;
    padding: 11px 13px;
    line-height: 1.45;
}

.icon-button,
.send-button {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-weight: 900;
}

.icon-button {
    background: #f7f2e9;
    color: var(--accent);
}

.send-button {
    width: 48px;
    background: var(--primary);
    color: #fff;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%) translateY(16px);
    opacity: 0;
    pointer-events: none;
    background: #202329;
    color: white;
    padding: 10px 14px;
    border-radius: 8px;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.22);
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 20;
    max-width: min(520px, calc(100vw - 32px));
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (max-width: 820px) {
    .shell {
        width: 100vw;
        height: 100vh;
        margin: 0;
        border: 0;
        border-radius: 0;
    }

    .admin-shell {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(260px, 36vh) minmax(0, 1fr);
    }

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--line);
        padding: 14px;
    }

    .brand h1 {
        font-size: 21px;
    }

    .chat-header {
        padding: 14px;
        align-items: flex-start;
        flex-direction: column;
    }

    .chat-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .security-grid,
    .form-actions {
        grid-template-columns: 1fr;
    }

    .modal-backdrop {
        padding: 10px;
    }

    .modal-dialog {
        max-height: calc(100vh - 20px);
    }

    .modal-body {
        padding: 14px;
    }

    .messages {
        padding: 14px;
    }

    .composer {
        padding: 10px;
        gap: 8px;
    }

    .bubble {
        max-width: 86%;
    }

    .login-page {
        padding: 14px;
    }

    .login-card {
        padding: 22px;
    }

    .login-copy h1 {
        font-size: 28px;
    }
}
