/* 한우 개체 관리 — 웹(모바일 우선). 색은 WPF와 같은 토큰(Hw.*)을 CSS 변수로 옮겨 씁니다. */
:root {
    color-scheme: light dark;
    --bg: #f3f3f3;
    --surface: #ffffff;
    --surface-2: #fafafa;
    --text: #1b1b1b;
    --text-2: #5c5c5c;
    --border: #e0e0e0;
    --accent: #005fb8;
    --accent-hover: #0067c0;
    --accent-text: #ffffff;
    --ok-fg: #0e6b0e;
    --ok-bg: #dff6dd;
    --warn-fg: #7a4200;
    --warn-bg: #fff1cc;
    --danger-fg: #b3261e;
    --danger-bg: #fde7e9;
    --info-fg: #004c99;
    --info-bg: #e1edf8;
    --grade-low-bg: #eaeaea;
    --grade-low-fg: #5c5c5c;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 1px 1px rgba(0, 0, 0, .04);
    --font: "Segoe UI Variable Text", "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
    --tabbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1c1c1c;
        --surface: #2b2b2b;
        --surface-2: #323232;
        --text: #f2f2f2;
        --text-2: #b4b4b4;
        --border: #3a3a3a;
        --accent: #60cdff;
        --accent-hover: #7ad6ff;
        --accent-text: #002339;
        --ok-fg: #8fdc84;
        --ok-bg: #23361f;
        --warn-fg: #ffd66b;
        --warn-bg: #3d3218;
        --danger-fg: #ff9ea6;
        --danger-bg: #48252a;
        --info-fg: #9cd7ff;
        --info-bg: #1d3a4f;
        --grade-low-bg: #383838;
        --grade-low-fg: #c2c2c2;
        --shadow: none;
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h1:focus { outline: none; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 틀: 윗줄 · 본문 · (모바일) 아래 탭 ---------- */
.app-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.app-bar .farm { font-weight: 600; font-size: 1.05rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-bar .farm small { display: block; font-weight: 400; font-size: .75rem; color: var(--text-2); }
.app-bar .spacer { flex: 1; }
.app-bar .top-nav { display: none; gap: 4px; }
.app-bar .top-nav a { padding: 6px 12px; border-radius: 6px; color: var(--text); }
.app-bar .top-nav a.active { background: var(--info-bg); color: var(--info-fg); font-weight: 600; }
.app-bar .top-nav a:hover { text-decoration: none; background: var(--surface-2); }

.content {
    max-width: 960px;
    margin: 0 auto;
    padding: 16px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom, 0px));
}

.tab-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(5, 1fr);   /* 홈 · 개체 · 번식 · 분만 등록 · 구입 입식 (조회자는 MainLayout이 3칸) */
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.tab-bar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-2);
    font-size: .75rem;
}
.tab-bar a:hover { text-decoration: none; }
.tab-bar a.active { color: var(--accent); font-weight: 600; }
.tab-bar svg { width: 24px; height: 24px; }

@media (min-width: 768px) {
    .tab-bar { display: none; }
    .app-bar .top-nav { display: flex; }
    .content { padding-bottom: 32px; }
}

/* ---------- 카드 · 목록 ---------- */
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head .grow { flex: 1; min-width: 0; }
/* 단추가 많은 머리(웹 개체 상세): 제목 칸이 이 폭보다 좁아지면 단추 묶음이 다음 줄로 (번호 제목이 단추 밑으로 겹치지 않게) */
.page-head.wrap-actions > .grow { flex-basis: 12rem; }
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 16px;
    margin-bottom: 12px;
}
.card > h2 { margin-bottom: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .label { color: var(--text-2); font-size: .85rem; }
.stat .value { font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: .9rem; font-weight: 400; margin-left: 2px; }
.stat.warn { background: var(--warn-bg); border-color: transparent; }
.stat.warn .label, .stat.warn .value { color: var(--warn-fg); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--border); }
.item {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 11px 2px;
    color: var(--text);
}
a.item:hover { text-decoration: none; background: var(--surface-2); }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.item .title .sub { font-weight: 400; color: var(--text-2); font-variant-numeric: tabular-nums; }
.item .meta { display: block; color: var(--text-2); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .side { text-align: right; font-size: .85rem; color: var(--text-2); white-space: nowrap; }
.item .chev { color: var(--text-2); display: flex; }
.item .chev svg { width: 18px; height: 18px; }
.btn-reset { width: 100%; background: none; border: none; font: inherit; text-align: left; cursor: pointer; }
.btn-reset:hover { background: var(--surface-2); }

.badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
}
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge.danger { background: var(--danger-bg); color: var(--danger-fg); }
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge.info { background: var(--info-bg); color: var(--info-fg); }
.badge.plain { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

/* 등급 배지 (WPF GradeBadge와 같은 구분: 1++ 강조색 · 1+ 테두리 · 1 연한 · 2/3 회색 · 등외 빨강 · 판정 대기 주황) */
.badge.grade-top { background: var(--accent); color: var(--accent-text); }
.badge.grade-high { background: var(--info-bg); color: var(--info-fg); box-shadow: inset 0 0 0 1px var(--accent); }
.badge.grade-mid { background: var(--info-bg); color: var(--info-fg); }
.badge.grade-low { background: var(--grade-low-bg); color: var(--grade-low-fg); }
.badge.grade-sub { background: var(--danger-bg); color: var(--danger-fg); }
.badge.grade-wait { background: var(--warn-bg); color: var(--warn-fg); }
.badge.big { font-size: .95rem; padding: 2px 12px; }

.empty { text-align: center; color: var(--text-2); padding: 28px 8px; }

/* 상세: 이름표 목록 */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--text-2); }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (min-width: 768px) {
    .facts.two { grid-template-columns: max-content 1fr max-content 1fr; }
}

/* 상세: 도축성적 카드 (핵심 숫자 3개 · 전체 항목 펼치기) */
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 10px 0 6px; }
.kpis .label { color: var(--text-2); font-size: .78rem; }
.kpis .value { font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
details.all > summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 4px 0; }
details.all h3 { font-size: .9rem; color: var(--text-2); margin: 12px 0 4px; }

.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 16px 0; }

/* ---------- 입력 ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span, .field-label { display: block; font-size: .85rem; color: var(--text-2); margin-bottom: 4px; }
.field .hint { font-size: .8rem; color: var(--text-2); margin-top: 3px; }
.field .error, .validation-message { font-size: .82rem; color: var(--danger-fg); margin-top: 3px; }

input:not([type]), input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=search], input[type=tel], select, textarea {
    width: 100%;
    min-height: 44px;
    padding: 9px 12px;
    font: inherit;
    font-size: 16px;   /* iOS가 입력할 때 화면을 확대하지 않도록 16px 이상 */
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom: 2px solid var(--border);
    border-radius: 8px;
    outline: none;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input.invalid, select.invalid, textarea.invalid, .invalid > input { border-color: var(--danger-fg); }
/* 검증번호가 틀린 이력번호(옛 번호일 수 있음 — 2026-10-07): 번호 칸 글자만 빨간색. 입력칸 글자색 규칙(input[type=text])보다 뒤에 */
.trace-bad, input.trace-bad { color: var(--danger-fg); }
input:disabled, select:disabled { opacity: .6; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }
.row > .field { min-width: 0; }
@media (max-width: 380px) { .row.three { grid-template-columns: 1fr 1fr; } }

.check { display: flex; align-items: center; gap: 8px; min-height: 36px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* 암 · 수 같은 한 가지 고르기 단추 */
.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.segmented label { flex: 1; min-width: 64px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
    user-select: none;
}
.segmented input:checked + span { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-fg); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
/* 글자가 긴 단추 여럿(번식 보기 5개): 단추 폭은 글자만큼, 넘치면 다음 줄로 — 한 단추 안에서 글자가 꺾이지 않게 */
.segmented.wrap label { flex: 1 1 auto; }
.segmented.wrap span { white-space: nowrap; }

.input-with-button { display: flex; gap: 8px; }
.input-with-button > input { flex: 1; min-width: 0; }

/* ---------- 단추 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 16px;
    font: inherit;
    font-weight: 600;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger-fg); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .88rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.link { background: none; border: none; color: var(--accent); padding: 0 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions.end { justify-content: flex-end; }
.actions.sticky {
    position: sticky;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    background: var(--bg);
    padding: 10px 0;
    margin-top: 8px;
    border-top: 1px solid var(--border);
}
@media (min-width: 768px) { .actions.sticky { bottom: 0; } }
/* 고정 단추 줄 안의 안내 띠(편집 폼 자손 질문): 한 줄 전체를 차지하고 단추는 그 아래 줄로 */
.actions.sticky > .alert { flex-basis: 100%; margin-bottom: 0; }

/* ---------- 안내 ---------- */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.alert.danger { background: var(--danger-bg); color: var(--danger-fg); }
.alert.warn { background: var(--warn-bg); color: var(--warn-fg); }
.alert.ok { background: var(--ok-bg); color: var(--ok-fg); }
.alert.info { background: var(--info-bg); color: var(--info-fg); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- 로그인 화면 ---------- */
.auth {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px 22px;
    box-shadow: var(--shadow);
}
.auth-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.auth-card .brand svg { width: 34px; height: 34px; color: var(--accent); }
.auth-links { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; font-size: .9rem; }

/* ---------- 검색 ---------- */
.search-bar { display: flex; gap: 8px; margin-bottom: 10px; }
.search-bar input[type=search] { flex: 1; min-width: 0; }
.search-bar select { width: auto; }
details.more { margin-bottom: 12px; }
details.more > summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 4px 0; list-style: none; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "▸ "; }
details.more[open] > summary::before { content: "▾ "; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }

/* ---------- 입력 화면(WebAssembly) ---------- */
.loading { display: flex; align-items: center; gap: 10px; color: var(--text-2); padding: 24px 4px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.suggest { list-style: none; margin: 4px 0 0; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); max-height: 260px; overflow-y: auto; }
.suggest li button { display: block; width: 100%; text-align: left; padding: 10px 12px; background: none; border: none; font: inherit; color: var(--text); cursor: pointer; }
.suggest li + li { border-top: 1px solid var(--border); }
.suggest li button:hover { background: var(--surface-2); }
.picked { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--info-fg); background: var(--info-bg); color: var(--info-fg); border-radius: 8px; }
.picked .grow { flex: 1; min-width: 0; }
.trace-box { margin: -4px 0 12px; }

/* ---------- 번식 화면(휴대폰) ---------- */
/* 이력번호: 귀표에 굵게 보이는 네 자리(TraceNoText Emphasis의 <b>)만 굵고 크게, 나머지는 보통 글자 — 목록 줄 제목의 굵은 글씨를 풀어 줌.
   검증번호가 틀린 번호의 빨강(.trace-bad)은 그대로 */
.trace-em { font-weight: 400; color: var(--text-2); font-variant-numeric: tabular-nums; }
.trace-em b { font-weight: 700; font-size: 1.12em; }
.trace-em b:not(.trace-bad) { color: var(--text); }
/* 목록 카드 안 우방 묶음 머리글("구축사2 › 2 · 5두") */
.card > .group-head { margin: 0; padding: 10px 2px 4px; font-size: .85rem; font-weight: 600; color: var(--text-2); border-top: 1px solid var(--border); }
.card > .group-head:first-child { border-top: none; }
/* 기록 화면: 소 카드 제목(이력번호), 개체 메모 줄바꿈 그대로 */
.cow-title { margin-bottom: 0; overflow-wrap: anywhere; }
.facts dd.memo { white-space: pre-line; }
/* 입력 칸 카드: 지난 기록 줄을 눌러 편집으로 스크롤할 때 위 고정 줄(.app-bar)에 가리지 않게 */
.breeding-form { scroll-margin-top: 72px; }
/* 잠긴 단추 묶음(편집 중인 기록 종류): 고른 단추는 그대로, 나머지는 흐리게 */
.segmented input:disabled + span { cursor: default; }
.segmented input:disabled:not(:checked) + span { opacity: .5; }
/* 지난 기록 줄: 요약 · 메모는 줄을 바꿔 다 보임 (.meta처럼 자르지 않음) */
.item .record-summary { display: block; overflow-wrap: anywhere; }
.item .record-memo { display: block; color: var(--text-2); font-size: .85rem; white-space: pre-line; overflow-wrap: anywhere; }
/* 기록 화면 [저장]: 아래 고정 줄의 남은 폭을 다 씀(한 손으로 누르기 쉽게) */
.actions .btn.grow { flex: 1; }
/* 결과 띠 안 단추(지웠습니다 [되살리기]) */
.alert.with-action { display: flex; align-items: center; gap: 10px; }
.alert.with-action > span { flex: 1; min-width: 0; }

/* Blazor 오류 표시 */
#blazor-error-ui {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    padding: 10px 16px;
    background: var(--warn-bg);
    color: var(--warn-fg);
    box-shadow: 0 -1px 2px rgba(0, 0, 0, .2);
}
#blazor-error-ui .dismiss { float: right; cursor: pointer; }
.blazor-error-boundary { background: var(--danger-bg); color: var(--danger-fg); padding: 12px 16px; border-radius: 8px; }
.blazor-error-boundary::after { content: "화면을 그리는 중 오류가 났습니다. 새로 고쳐 보세요."; }
