/* ============================================================================
   保险测试 UI - 统一样式表
   ============================================================================ */

:root {
    /* 配色系统 */
    --bg: #f5f7fb;
    --card: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;

    --primary: #2563eb;
    --primary-2: #4f46e5;

    --danger: #dc2626;
    --success: #22c55e;
    --warning: #f59e0b;
    --info: #3b82f6;

    /* 阴影 */
    --shadow-soft: 0 1px 2px rgba(0, 0, 0, .05);
    --shadow: 0 10px 24px rgba(0, 0, 0, .08);

    /* 圆角 */
    --radius: 12px;
    --radius-sm: 10px;

    /* 字体 */
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial;
}

/* ===== Reset ===== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Layout ===== */
.app {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: 64px 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
}

/* ===== Sidebar ===== */
.sidebar {
    grid-area: sidebar;
    padding: 18px 14px;
    background: linear-gradient(180deg, #0f172a, #020617);
    color: #e5e7eb;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
}
.sidebar h2 {
    font-size: 12px;
    margin: 0 0 14px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: .12em;
}
.nav { display: flex; flex-direction: column; gap: 8px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 12px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    color: #cbd5f5;
    user-select: none;
    transition: .18s ease;
}
.nav-item:hover { background: rgba(148, 163, 184, .12); }
.nav-item.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    box-shadow: 0 10px 22px rgba(37, 99, 235, .25);
}

/* ===== Topbar ===== */
.topbar {
    grid-area: topbar;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-badge {
    width: 36px; height: 36px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 800;
    box-shadow: 0 10px 18px rgba(37, 99, 235, .25);
}
.brand-title { display: flex; flex-direction: column; line-height: 1.1; }
.brand-title strong { font-size: 14px; }
.brand-title span { font-size: 12px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 10px; }

/* ===== Main ===== */
.main {
    grid-area: main;
    padding: 18px;
    max-width: 1900px;
}
.page-title { margin: 8px 0 16px; }
.page-title h1 { font-size: 18px; margin: 0; }

/* ===== Cards ===== */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    padding: 18px;
    margin-bottom: 14px;
}
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.card-title {
    font-size: 15px;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.hint { font-size: 12px; color: var(--muted); }

/* ===== Controls ===== */
.controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.field { display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.field label { font-size: 12px; color: var(--muted); }
.input-row { display: flex; gap: 6px; flex-wrap: nowrap; align-items: center; }
.input {
    height: 38px;
    min-width: 240px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    outline: none;
    background: #fff;
    color: var(--text);
    transition: .15s ease;
}
.input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

/* ===== Buttons ===== */
/* Action tag buttons (phone number row) */
.action-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    margin-top: 8px;
    align-items: center;
}
.tag-group {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding-right: 16px;
    border-right: 1px solid var(--border);
}
.tag-group:last-child {
    border-right: none;
    padding-right: 0;
}
.tag-group-danger {
    margin-left: auto;
}
.tag-btn {
    height: 32px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #f8fafc;
    color: #334155;
    cursor: pointer;
    transition: all .18s ease;
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.tag-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(37, 99, 235, .25);
    transform: translateY(-1px);
}
.tag-btn:active {
    transform: translateY(0);
}
.tag-danger {
    color: #fff;
    border-color: #dc2626;
    background: #dc2626;
    font-weight: 700;
}
.tag-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    box-shadow: 0 2px 12px rgba(220, 38, 38, .35);
    transform: translateY(-1px);
}
.tag-primary {
    color: var(--primary);
    border-color: #93c5fd;
    background: #eff6ff;
}
.tag-primary:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(37, 99, 235, .25);
}

/* ===== Query Panel ===== */
.query-panel {
    padding: 20px;
    background: linear-gradient(180deg, #fff 0%, #f8fafc 100%);
}
.query-sections {
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 20px;
    align-items: stretch;
}
.query-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}
.query-section:first-child {
    max-width: 360px;
    width: 100%;
}
.query-section-title {
    font-size: 13px;
    font-weight: 800;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 6px;
}
.query-divider {
    width: 1px;
    background: var(--border);
    margin: 4px 0;
}
.query-input-row {
    display: flex;
    gap: 10px;
    align-items: center;
}
.query-input-row .input {
    flex: 1;
    min-width: 0;
}
.query-input-row #phoneNumber {
    max-width: 260px;
}
.query-input-row .btn {
    height: 42px;
    padding: 0 20px;
    border-radius: 10px;
    font-size: 14px;
}
.input-lg {
    height: 42px;
    padding: 0 14px;
    border-radius: 10px;
    font-size: 14px;
}

.btn {
    height: 34px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #fff;
    color: #334155;
    cursor: pointer;
    transition: .18s ease;
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}
.btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #0f172a;
    transform: translateY(-1px);
}
.btn:active { transform: translateY(0); }

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    border: none;
    color: #fff;
    box-shadow: 0 6px 14px rgba(37, 99, 235, .25);
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    border: none;
    color: #fff !important;
    box-shadow: 0 10px 20px rgba(37, 99, 235, .35);
    filter: brightness(1.02);
}
.btn-danger {
    background: var(--danger);
    border: none;
    color: #fff;
    box-shadow: 0 6px 14px rgba(220, 38, 38, .18);
}
.btn-danger:hover {
    background: #b91c1c;
    border: none;
    color: #fff !important;
    box-shadow: 0 10px 20px rgba(220, 38, 38, .22);
}
.btn-ghost { background: transparent; border: 1px solid var(--border); }

/* 小按钮（多保单表格用） */
.btn-xs {
    height: 30px;
    padding: 0 10px;
    font-size: 12px;
    border-radius: 999px;
}

/* ===== Split ===== */
.split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    align-items: stretch;
}
.split .card {
    height: 100%;
    display: flex;
    flex-direction: column;
}
.split .table-wrap {
    flex: 1;
}

/* ===== Table ===== */
.table-wrap {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: auto;
    background: #fff;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
    text-align: left;
    padding: 10px 12px;
    background: #f9fafb;
    color: #6b7280;
    font-size: 12px;
    font-weight: 800;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1;
    white-space: nowrap;
}
tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    white-space: nowrap;
}
tbody tr:hover { background: #f8fafc; }
.op-cell { white-space: nowrap; text-align: right; }

/* ===== Badge ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 800;
    color: #fff;
    white-space: nowrap;
}
.b-success { background: var(--success); }
.b-warning { background: var(--warning); }
.b-danger { background: var(--danger); }
.b-info { background: var(--info); }
.b-default { background: #64748b; }

/* ===== 保单列表：基础/升级标记 ===== */
.policy-name-cell {
    white-space: normal;
    min-width: 140px;
    line-height: 1.35;
    vertical-align: middle;
}
.policy-ver-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-right: 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    color: #fff;
    vertical-align: -3px;
    flex-shrink: 0;
}
.policy-ver-base { background: #0ea5e9; }
.policy-ver-upgrade { background: #f59e0b; }
.policy-name { font-weight: 600; color: #0f172a; }
tr.policy-row-linked td:first-child {
    box-shadow: inset 3px 0 0 #94a3b8;
}
tr.policy-row-upgrade td:first-child {
    box-shadow: inset 3px 0 0 #f59e0b;
}
tr.policy-row-linked:not(.policy-row-upgrade) td:first-child {
    box-shadow: inset 3px 0 0 #0ea5e9;
}

/* ===== 基础单/升级单 配对：升级单作为缩进子行 ===== */
/* 树形连接线：从基础单保单号左侧连到升级单的 └ 拐角 */
tr.policy-group-head .policy-no-cell { position: relative; }
tr.policy-group-head .policy-no-cell::after {
    content: '';
    position: absolute;
    left: 14px;
    top: 50%;
    bottom: -1px;
    border-left: 2px solid #cbd5e1;
}
tr.policy-child .policy-no-cell { position: relative; padding-left: 38px; }
tr.policy-child .policy-no-cell::before {
    content: '';
    position: absolute;
    left: 14px;
    top: -1px;
    height: 50%;
    width: 12px;
    border-left: 2px solid #cbd5e1;
    border-bottom: 2px solid #cbd5e1;
    border-bottom-left-radius: 6px;
}
/* 子行内容缩进 + 弱化颜色，层级更清晰 */
tr.policy-child .policy-name-cell { padding-left: 38px; }
tr.policy-child td { color: #475569; }
tr.policy-child .policy-no-cell strong { color: #64748b; font-weight: 600; }
tr.policy-child .policy-name { color: #475569; font-weight: 500; }

/* ===== Empty / Loading ===== */
.empty {
    padding: 40px 24px;
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border);
    background: #fff;
    color: var(--muted);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.empty::before {
    content: '📭';
    font-size: 32px;
    line-height: 1;
    opacity: .6;
}
.state-loading {
    padding: 40px 24px;
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--muted);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
}
.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #e2e8f0;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.alert {
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    background: #fffbeb;
    border: 1px solid #fcd34d;
    color: #92400e;
    font-size: 13px;
    line-height: 1.5;
}
.alert-warning {
    background: #fff7ed;
    border-color: #fdba74;
    color: #9a3412;
}

/* ===== Modal ===== */
.mask {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 16px;
}
.modal {
    width: min(720px, 100%);
    background: #fff;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: #f9fafb;
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 900; }
.modal-body { padding: 14px 16px; max-height: 70vh; overflow: auto; }
.modal-foot {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: #fff;
}

/* ===== User Location floating panel（不挤占主内容，可拖动） ===== */
.user-loc-fab {
    position: fixed;
    right: 16px;
    bottom: 72px;
    left: auto;
    top: auto;
    z-index: 900;
    display: none;
    max-width: min(360px, calc(100vw - 32px));
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
    box-shadow: var(--shadow);
    cursor: grab;
    text-align: left;
    touch-action: none;
    user-select: none;
}
.user-loc-fab.is-visible { display: block; }
.user-loc-fab.is-dragging { cursor: grabbing; box-shadow: 0 12px 28px rgba(15, 23, 42, .18); }
.user-loc-fab:hover { border-color: #bfdbfe; }
.user-loc-fab-title {
    font-size: 12px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 6px;
}
.user-loc-fab-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.user-loc-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 999px;
    background: #f1f5f9;
    color: #334155;
    font-size: 12px;
    line-height: 1.4;
}
.user-loc-chip b { font-weight: 700; color: var(--muted); }
.user-loc-fab-hint {
    margin-top: 6px;
    font-size: 11px;
    color: var(--muted);
}

/* ===== Toast ===== */
.toast-wrap {
    position: fixed;
    right: 14px;
    bottom: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1200;
}
.toast {
    min-width: 240px;
    max-width: 360px;
    border-radius: 12px;
    padding: 10px 12px;
    background: #111827;
    color: rgba(255, 255, 255, .92);
    box-shadow: var(--shadow-soft);
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: 12px;
}
.toast .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 4px;
    background: var(--info);
}
.toast.success .dot { background: var(--success); }
.toast.warn .dot { background: var(--warning); }
.toast.danger .dot { background: var(--danger); }
.toast .t-title { font-weight: 900; margin-bottom: 2px; }
.toast .t-msg { color: rgba(255, 255, 255, .72); }

/* ===== Multi-Policy Grid ===== */
.multi-policy-grid {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 450px;
    gap: 12px;
    overflow-x: auto;
    overflow-y: visible;
    padding-bottom: 10px;
}
.multi-policy-card {
    padding: 14px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    z-index: 0;
}
.multi-policy-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
}
.multi-policy-meta { margin-bottom: 10px; }
.multi-policy-meta table td { padding: 8px 10px; }
.multi-policy-meta td:first-child { width: 72px; color: var(--muted); }

.plans-title {
    margin-top: 10px;
    font-weight: 900;
    font-size: 13px;
}

/* Plans Wrap */
.plans-wrap {
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    overflow: visible;
    position: relative;
}
.plans-wrap table {
    width: 100%;
    table-layout: fixed;
}
.plans-wrap th,
.plans-wrap td {
    padding: 8px 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.plans-wrap col.op-col { width: 240px; }
.plans-wrap th.op-cell,
.plans-wrap td.op-cell {
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: nowrap !important;
    text-align: right;
}
.plans-wrap td.op-cell .btn {
    width: 100%;
    justify-content: center;
}

/* ===== Responsive ===== */
@media (max-width: 1100px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-areas: "topbar" "main";
        grid-template-rows: 64px 1fr;
    }
    .sidebar { display: none; }
    .controls { grid-template-columns: 1fr; }
    .split { grid-template-columns: 1fr; }
    .query-sections { grid-template-columns: 1fr; }
    .query-divider {
        width: 100%;
        height: 1px;
        margin: 0;
    }
    .multi-policy-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    }
    .plans-wrap col.op-col { width: 220px; }
    .btn-xs { height: 26px; }
    .tag-group-danger { margin-left: 0; }
}
@media (max-width: 640px) {
    .query-input-row {
        flex-direction: column;
        align-items: stretch;
    }
    .query-input-row .btn { width: 100%; justify-content: center; }
    .action-tags { flex-direction: column; align-items: stretch; }
    .tag-group {
        flex-direction: column;
        align-items: stretch;
        padding-right: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding-bottom: 8px;
        width: 100%;
    }
    .tag-group .tag-btn {
        width: 100%;
        justify-content: center;
    }
    .tag-group:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }
}

/* ===== Utility ===== */
.reason-cell {
    max-width: 260px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.product-cell {
    max-width: 320px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
