:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --line: #dfe6ef;
    --line-soft: #edf1f6;
    --text: #111827;
    --muted: #667085;
    --blue: #1677ff;
    --blue-dark: #0b5bd3;
    --green: #13845f;
    --amber: #d97706;
    --red: #dc2626;
    --shadow: 0 18px 44px rgba(15, 23, 42, .08);
    --shadow-soft: 0 10px 24px rgba(15, 23, 42, .055);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(180deg, #edf4ff 0, rgba(237, 244, 255, 0) 320px),
        var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    font-size: 14px;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

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

input,
select {
    height: 40px;
    padding: 0 12px;
}

textarea {
    min-height: 88px;
    padding: 10px 12px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(22, 119, 255, .12);
}

code {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fafc;
    padding: 2px 6px;
    color: #334155;
    vertical-align: middle;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border: 0;
    border-radius: 8px;
    padding: 8px 14px;
    background: var(--blue);
    color: #fff;
    cursor: pointer;
    font-weight: 800;
    white-space: nowrap;
}

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

.btn.secondary {
    border: 1px solid var(--line);
    background: #fff;
    color: #1f2937;
}

.btn.secondary:hover {
    background: #f8fafc;
}

.btn.ghost {
    background: transparent;
    color: var(--muted);
}

.btn.ghost:hover {
    background: #eef2f7;
    color: var(--text);
}

.btn.small {
    min-height: 32px;
    padding: 5px 10px;
    font-size: 13px;
}

.subtle {
    color: var(--muted);
}

.error-box {
    border: 1px solid #fecdd3;
    border-radius: 8px;
    background: #fff1f2;
    color: var(--red);
    padding: 10px 12px;
}

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

.login-card,
.install-card {
    width: min(420px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    padding: 30px;
}

.login-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    border-radius: 8px;
    background: #eef6ff;
    color: var(--blue);
    padding: 0 10px;
    font-weight: 800;
}

.login-card h1,
.install-card h1 {
    margin: 16px 0 8px;
    font-size: 24px;
}

.field {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
}

.field label {
    color: #344054;
    font-size: 13px;
    font-weight: 800;
}

.app-shell {
    width: min(2160px, calc(100vw - 56px));
    margin: 0 auto;
    padding: 22px 0 52px;
}

.app-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 16px;
    border: 1px solid rgba(191, 219, 254, .72);
    border-radius: 8px;
    background: rgba(255, 255, 255, .86);
    box-shadow: var(--shadow-soft);
    padding: 18px 20px;
    backdrop-filter: blur(8px);
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    height: 24px;
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    background: #eff6ff;
    color: #1d4ed8;
    padding: 0 9px;
    font-size: 12px;
    font-weight: 800;
}

.app-header h1 {
    margin: 8px 0 4px;
    font-size: 30px;
    line-height: 1.15;
    letter-spacing: 0;
}

.app-header p {
    margin: 0;
    color: var(--muted);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-top: 2px;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: #475467;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.admin-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .9);
    box-shadow: var(--shadow-soft);
    padding: 12px;
}

.admin-panel summary {
    cursor: pointer;
    color: #1f2937;
    font-weight: 900;
}

.admin-panel details {
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #fff;
    padding: 12px;
}

.admin-panel details[open] {
    border-color: #bfdbfe;
    box-shadow: 0 8px 22px rgba(22, 119, 255, .08);
}

.notice {
    grid-column: 1 / -1;
    margin: 0 0 10px;
    border-radius: 8px;
    padding: 9px 11px;
    font-weight: 800;
}

.notice.ok {
    border: 1px solid #bbf7d0;
    background: #f0fdf4;
    color: #047857;
}

.notice.error {
    border: 1px solid #fecdd3;
    background: #fff1f2;
    color: var(--red);
}

.notice.warn {
    border: 1px solid #fde68a;
    background: #fffbeb;
    color: #92400e;
}

.subaccount-form {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) auto;
    gap: 10px;
    margin-top: 12px;
}

.subaccount-list {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

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

.subaccount-item b,
.subaccount-item small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.subaccount-item small {
    margin-top: 3px;
    color: var(--muted);
}

.danger-admin {
    margin-top: 0;
}

.clear-data-form {
    display: grid;
    gap: 10px;
    max-width: 420px;
    margin-top: 12px;
}

.clear-data-form p {
    margin: 0;
    color: var(--muted);
    font-weight: 700;
    line-height: 1.5;
}

.summary-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.summary-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 76px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(180deg, #fff 0, #fbfdff 100%);
    padding: 0 18px;
    box-shadow: var(--shadow-soft);
}

.summary-card span {
    color: var(--muted);
    font-weight: 800;
}

.summary-card b {
    font-size: 28px;
    letter-spacing: 0;
}

.summary-card.pending {
    border-color: #fed7aa;
}

.summary-card.pending b {
    color: var(--amber);
}

.summary-card.called b {
    color: var(--green);
}

.summary-card.ignored b {
    color: #64748b;
}

.summary-card.today b {
    color: var(--blue);
}

.phone-panel {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .96);
    box-shadow: var(--shadow);
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--line-soft);
    background: linear-gradient(180deg, #fff 0, #f8fbff 100%);
    padding: 16px;
}

.filters {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) 160px auto;
    gap: 12px;
    width: min(880px, 100%);
}

.status-tabs {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--line-soft);
    padding: 12px 16px;
    overflow-x: auto;
}

.status-tabs a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0 12px;
    color: #475467;
    font-weight: 800;
    white-space: nowrap;
}

.status-tabs a b {
    color: var(--muted);
    font-size: 12px;
}

.status-tabs a:hover,
.status-tabs a.active {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: #0b5bd3;
}

.list-title {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--line-soft);
    background: #fff;
    padding: 18px 16px;
}

.list-title h2 {
    margin: 0 0 3px;
    font-size: 20px;
}

.list-title p {
    margin: 0;
    color: var(--muted);
}

.list-tools {
    display: grid;
    justify-items: end;
    gap: 8px;
    max-width: 460px;
}

.api-info,
.blocked-sources {
    max-width: 430px;
    text-align: right;
    color: var(--muted);
}

.api-info summary,
.blocked-sources summary {
    cursor: pointer;
    color: #475467;
    font-weight: 800;
}

.api-info p,
.blocked-sources p {
    margin-top: 8px;
}

.blocked-source-list {
    display: grid;
    gap: 8px;
    min-width: min(380px, calc(100vw - 48px));
    margin-top: 10px;
}

.blocked-source-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #fff;
    padding: 10px;
    text-align: left;
}

.blocked-source-item span {
    min-width: 0;
}

.blocked-source-item b,
.blocked-source-item small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.blocked-source-item small {
    margin-top: 3px;
    color: #98a2b3;
}

.tiny-link {
    min-height: 28px;
    border: 0;
    border-radius: 999px;
    background: #eff6ff;
    color: #0b5bd3;
    padding: 0 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.tiny-link:hover {
    background: #dbeafe;
}

.tiny-link.danger {
    background: #fff1f2;
    color: #b91c1c;
}

.tiny-link.danger:hover {
    background: #ffe4e6;
}

.phone-list {
    display: grid;
}

.phone-item {
    border-bottom: 1px solid var(--line-soft);
    background: #fff;
}

.phone-item:last-child {
    border-bottom: 0;
}

.phone-item[open] {
    background: #fcfdff;
    box-shadow: inset 4px 0 0 #bfdbfe;
}

.phone-item summary {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr) auto;
    align-items: center;
    gap: 18px;
    min-height: 84px;
    padding: 12px 18px;
    cursor: pointer;
    list-style: none;
}

.phone-item summary::-webkit-details-marker {
    display: none;
}

.phone-item summary:hover {
    background: #f8fbff;
}

.phone-primary {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.phone-number {
    color: #075ec8;
    font-size: 22px;
    font-weight: 900;
    letter-spacing: 0;
}

.phone-count {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.phone-summary-meta {
    display: grid;
    grid-template-columns: minmax(140px, .8fr) minmax(240px, 1.2fr) minmax(180px, .9fr) 180px;
    gap: 16px;
    min-width: 0;
}

.phone-summary-meta.no-sender {
    grid-template-columns: minmax(140px, .8fr) minmax(260px, 1.3fr) 180px;
}

.phone-summary-meta span {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.phone-summary-meta em {
    color: #98a2b3;
    font-size: 12px;
    font-style: normal;
    font-weight: 800;
}

.phone-summary-meta b,
.phone-summary-meta small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.phone-summary-meta b {
    color: #334155;
    font-size: 13px;
}

.phone-summary-meta small {
    color: var(--muted);
    font-size: 12px;
}

.location-missing {
    color: #98a2b3 !important;
}

.phone-row-actions {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.detail-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    height: 30px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #475467;
    font-size: 13px;
    font-weight: 800;
}

.phone-item[open] .detail-chip {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: #0b5bd3;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 12px;
    font-weight: 800;
}

.badge.warn {
    background: #fff7ed;
    color: #b45309;
}

.badge.ok {
    background: #ecfdf5;
    color: #047857;
}

.badge.muted {
    background: #eef2f7;
    color: #64748b;
}

.phone-detail {
    border-top: 1px solid var(--line-soft);
    padding: 16px 18px 18px;
}

.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 16px;
    align-items: start;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.detail-grid div {
    min-width: 0;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #fff;
    padding: 10px;
}

.detail-grid span,
.message-card > span,
.action-box label > span {
    display: block;
    margin-bottom: 5px;
    color: #667085;
    font-size: 12px;
    font-weight: 800;
}

.detail-grid b,
.detail-grid small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.detail-grid small {
    margin-top: 3px;
    color: #98a2b3;
}

.message-card p {
    max-height: 170px;
    overflow: auto;
    margin: 0;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #fff;
    padding: 12px;
    color: #334155;
    line-height: 1.65;
    word-break: break-word;
}

.message-card .message-excerpt {
    max-height: none;
    border-color: #bfdbfe;
    background: #f8fbff;
    color: #1f2937;
    font-weight: 700;
}

.quote-card {
    display: grid;
    gap: 5px;
    margin-top: 10px;
    border-left: 3px solid #bfdbfe;
    border-radius: 8px;
    background: #f8fafc;
    padding: 9px 11px;
}

.quote-card.compact {
    margin-top: 8px;
}

.quote-card span {
    color: #667085;
    font-size: 12px;
    font-weight: 800;
}

.quote-card p {
    max-height: none;
    margin: 0;
    border: 0;
    background: transparent;
    padding: 0;
    color: #334155;
    font-weight: 800;
    line-height: 1.45;
}

.raw-message {
    margin-top: 10px;
}

.raw-message summary {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 10px;
    color: #475467;
    cursor: pointer;
    font-size: 13px;
    font-weight: 800;
}

.raw-message summary:hover {
    border-color: #bfdbfe;
    color: #0b5bd3;
}

.raw-message p {
    margin-top: 8px;
}

.occurrence-card {
    margin-top: 12px;
}

.occurrence-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.occurrence-head span {
    color: #667085;
    font-size: 12px;
    font-weight: 800;
}

.occurrence-head b {
    color: #0b5bd3;
    font-size: 13px;
}

.occurrence-list {
    display: grid;
    gap: 10px;
}

.occurrence-item {
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #fff;
    padding: 10px;
}

.occurrence-meta {
    display: grid;
    grid-template-columns: 130px minmax(0, 1fr) minmax(120px, .8fr);
    gap: 10px;
    margin-bottom: 8px;
}

.occurrence-meta.no-sender {
    grid-template-columns: 130px minmax(0, 1fr);
}

.occurrence-meta span {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.occurrence-meta em {
    color: #98a2b3;
    font-size: 12px;
    font-style: normal;
    font-weight: 800;
}

.occurrence-meta b,
.occurrence-meta small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.occurrence-meta b {
    color: #334155;
    font-size: 13px;
}

.occurrence-meta small {
    color: var(--muted);
    font-size: 12px;
}

.occurrence-item > p,
.empty-occurrence {
    margin: 0;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #f8fafc;
    padding: 10px;
    color: #334155;
    line-height: 1.55;
    word-break: break-word;
}

.empty-occurrence {
    color: var(--muted);
}

.action-box {
    display: grid;
    gap: 10px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #fff;
    padding: 12px;
}

.action-box label {
    display: grid;
    gap: 4px;
}

.action-stack {
    display: grid;
    gap: 10px;
}

.source-block-box {
    border: 1px solid #fee2e2;
    border-radius: 8px;
    background: #fff7f7;
    padding: 10px;
}

.danger-soft-btn {
    width: 100%;
    min-height: 38px;
    border: 1px solid #fecaca;
    border-radius: 8px;
    background: #fff;
    color: #b91c1c;
    cursor: pointer;
    font-weight: 800;
}

.danger-soft-btn:hover {
    border-color: #fca5a5;
    background: #fef2f2;
}

.danger-soft-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.copy-btn {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: #475467;
    padding: 0 12px;
    cursor: pointer;
    font-weight: 800;
}

.copy-btn:hover {
    border-color: #bfdbfe;
    color: #0b5bd3;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-top: 1px solid var(--line-soft);
    background: #fbfdff;
    padding: 14px 18px;
    color: var(--muted);
}

.empty-state {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 10px;
    min-height: 320px;
    margin: 18px;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    background:
        linear-gradient(135deg, rgba(22, 119, 255, .08), rgba(19, 132, 95, .05)),
        #fbfdff;
    color: var(--muted);
    text-align: center;
}

.empty-state::before {
    content: "回访";
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border: 1px solid #bfdbfe;
    border-radius: 18px;
    background: #eff6ff;
    color: #0b5bd3;
    font-size: 14px;
    font-weight: 900;
}

.empty-state strong {
    color: var(--text);
    font-size: 20px;
}

@media (max-width: 900px) {
    .summary-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .admin-panel {
        grid-template-columns: 1fr;
    }
    .toolbar,
    .list-title,
    .app-header {
        display: grid;
    }
    .header-actions {
        justify-content: start;
    }
    .detail-layout,
    .detail-grid,
    .occurrence-meta,
    .phone-summary-meta,
    .phone-summary-meta.no-sender {
        grid-template-columns: 1fr;
    }
    .list-tools,
    .api-info,
    .blocked-sources {
        max-width: none;
        justify-items: start;
        text-align: left;
    }
}

@media (max-width: 640px) {
    .app-shell {
        width: min(2160px, calc(100vw - 24px));
        padding-top: 14px;
    }
    .summary-strip,
    .filters,
    .phone-item summary {
        grid-template-columns: 1fr;
    }
    .app-header,
    .admin-panel,
    .phone-panel {
        box-shadow: none;
    }
    .app-header {
        padding: 14px;
    }
    .summary-card {
        min-height: 62px;
    }
    .empty-state {
        min-height: 240px;
        margin: 12px;
    }
    .toolbar {
        gap: 10px;
    }
    .toolbar > .btn,
    .filters .btn {
        width: 100%;
    }
    .phone-row-actions {
        justify-content: space-between;
    }
    .app-header h1 {
        font-size: 24px;
    }
}
