/**
 * 宝贝回家寻人嵌入页样式（独立于主站与其他工具页，自包含，无需构建）
 * 主要供外部站点经 iframe 嵌入：缺省随 iframe 大小自适应（容器查询切换横/竖排版、cqmin 流式字号），
 * 亦可经 width/height 参数固定展示尺寸（.is-fixed）。
 * 主题经 <html data-theme> 切换（auto 跟随系统 prefers-color-scheme，light/dark 强制），
 * 强调色经内联 --accent 覆盖（明暗两主题通用，故暗色块不重定义 --accent）。
 */

:root {
    color-scheme: light dark;
    --bg: #f4f6fb;
    --panel: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --accent: #ef4444;
    --accent-text: #ffffff;
    --shadow: 0 12px 32px rgba(31, 41, 55, 0.10);
}

@media (prefers-color-scheme: dark) {
    :root[data-theme="auto"] {
        --bg: #0f172a;
        --panel: #1e293b;
        --text: #e5e7eb;
        --muted: #94a3b8;
        --border: #334155;
        --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0f172a;
    --panel: #1e293b;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #334155;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
    color-scheme: light;
}

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

body {
    display: flex;
    background: var(--bg);
    color: var(--text);
    font-family: 'Figtree', -apple-system, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

/* 外层：缺省撑满 iframe 自适应；is-fixed（width/height 参数）时固定尺寸并居中 */
.wrap {
    box-sizing: border-box;
    flex: 1;
    display: flex;
    padding: 8px;
    /* 尺寸容器：供卡片的容器查询（横/竖排版）与 cqmin 流式字号按展示区域取尺寸 */
    container-type: size;
}

.wrap.is-fixed {
    flex: none;
    width: 100%;
    height: 100%;
    margin: auto;
    padding: 0;
    /* 内联 width/height（参数指定）覆盖 100%：仅指定其一时另一维仍撑满 */
}

/* 卡片：font-size 兜底 px 后再用 cqmin 流式字号（不支持容器查询单位的浏览器回落兜底值） */
.card {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
    container-type: size;
    font-size: 14px;
    font-size: clamp(12px, 3.4cqmin, 15px);
}

/* 标题栏 */
.head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5em;
    padding: 0.55em 0.9em;
    border-bottom: 1px solid var(--border);
}

.head-title {
    font-size: 0.95em;
    font-weight: 600;
}

.head-brand {
    font-size: 0.8em;
    color: var(--muted);
}

/* 失败态（拉取失败且缓存池为空） */
.state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.8em;
    padding: 1em;
}

.state-text {
    color: var(--muted);
    font-size: 0.9em;
}

/* 主体：单列（容器宽高比 < 4/5）照片在上占剩余空间、文字贴底；
   宽高比 ≥ 4/5 转图片文字两列（见下方容器查询） */
.content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* 照片：占文字上方全部剩余空间，contain 按照片原始比例完整显示（不裁剪）。
   宝贝回家照片基本为竖向，原比例显示即竖版、不出现横版比例照片；
   min-height 保底与 .info 的 max-height 对应，大窗口下照片随窗口增大充分利用空间 */
.photo {
    position: relative;
    flex: 1 1 auto;
    min-height: 38%;
    overflow: hidden;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.photo img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.photo-empty {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.8em;
}

.photo.no-photo img {
    display: none;
}

.photo.no-photo .photo-empty {
    display: flex;
}

.info {
    /* 单列：自然高度贴底，内容超高（> 62%）时滚动，保证照片始终占剩余空间 */
    flex: 0 1 auto;
    min-height: 0;
    min-width: 0;
    max-height: 62%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.3em;
    padding: 0.6em 0.9em 0.7em;
}

/* 姓名 + 性别 */
.name-row {
    display: flex;
    align-items: center;
    gap: 0.5em;
}

.name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.1em;
    font-weight: 600;
}

.sex {
    flex-shrink: 0;
    padding: 0.1em 0.7em;
    border-radius: 9999px;
    font-size: 0.8em;
    color: var(--accent);
    background: transparent;
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* 寻子信息行 */
.row {
    display: flex;
    align-items: baseline;
    gap: 0.35em;
    font-size: 0.85em;
}

.row-label {
    flex-shrink: 0;
    color: var(--muted);
}

.row-value {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 叙述字段：标签独占一行 + 正文 */
.block {
    display: flex;
    flex-direction: column;
    gap: 0.25em;
    padding-top: 0.15em;
}

.block-label {
    font-size: 0.8em;
    color: var(--muted);
}

.block-text {
    margin: 0;
    font-size: 0.85em;
    line-height: 1.6;
    word-break: break-word;
}

/* 操作：换一个 / 查看详情 */
.actions {
    display: flex;
    gap: 0.5em;
    padding: 0.55em 0.9em;
    border-top: 1px solid var(--border);
}

.btn {
    flex: 1;
    padding: 0.5em 0.8em;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 0.85em;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.btn:hover {
    background: color-mix(in srgb, var(--text) 6%, transparent);
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-primary {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-text);
}

.btn-primary:hover {
    background: var(--accent);
    filter: brightness(1.08);
}

/* 底部：线索联系方式 */
.contact {
    padding: 0.55em 0.9em;
    border-top: 1px solid var(--border);
    font-size: 0.8em;
    color: var(--muted);
}

.contact p {
    margin: 0;
}

.contact-value {
    margin-top: 0.2em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 宽高比 ≥ 4/5：图片文字两列并排。图片列高撑满、列宽按照片原始比例撑开（contain 不裁剪），
   照片加载前以 min-width 25% 占位防塌缩、max-width 70% 保文字列空间；文字列占剩余宽度滚动 */
@container (min-aspect-ratio: 4/5) {
    .content {
        flex-direction: row;
    }

    .photo {
        flex: 0 0 auto;
        min-height: 0;
        min-width: 25%;
        max-width: 70%;
        border-bottom: none;
        border-right: 1px solid var(--border);
    }

    .photo img {
        /* 高撑满列、宽度按照片内在比例推导：照片完整显示不裁剪，竖版照片列宽自动贴合 */
        width: auto;
        max-width: 100%;
        height: 100%;
    }

    .info {
        flex: 1;
        max-height: none;
    }
}
