/* ===== 디자인 토큰 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --brand: #1d4ed8;
  --brand-soft: #3b82f6;
  --brand-bg: #eaf1fe;
  --down: #c76a00;        /* 내림 (CVD 검증 완료) */
  --down-bg: #fbf0e1;
  --up: #178f45;          /* 올림 (CVD 검증 완료) */
  --up-bg: #e6f6ec;
  --danger: #d43333;
  --bg: #eef1f6;
  --card: #ffffff;
  --text: #17202b;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(23, 32, 43, .04), 0 4px 16px rgba(23, 32, 43, .06);
}

html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
body {
  font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
.view { max-width: 640px; margin: 0 auto; padding: 0 16px 72px; }
h2 { font-size: 13px; letter-spacing: .04em; margin: 24px 2px 10px; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; }
.ok-msg { color: var(--up); font-size: 14px; margin-top: 10px; }

/* ===== 버튼 ===== */
.btn {
  border: none; border-radius: 12px; cursor: pointer; font-family: inherit;
  font-size: 16px; padding: 14px 18px; background: #e8edf4; color: var(--text);
  transition: transform .06s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--brand-soft), var(--brand));
  color: #fff; width: 100%; font-weight: 700;
  box-shadow: 0 4px 14px rgba(29, 78, 216, .3);
}
.btn.tiny { font-size: 12px; padding: 7px 12px; border-radius: 9px; background: rgba(255,255,255,.16); color: inherit; }
.admin-section .btn.tiny { background: var(--brand-bg); color: var(--brand); font-weight: 700; }
.btn.danger { background: #fdecec; color: var(--danger); font-size: 13px; padding: 7px 14px; font-weight: 600; }
.btn:disabled { opacity: .55; }

input, select {
  font-size: 16px; padding: 13px 14px; border: 1.5px solid var(--border); border-radius: 12px;
  background: #fff; width: 100%; font-family: inherit; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--brand-soft); box-shadow: 0 0 0 3px var(--brand-bg); }

/* ===== 로그인 ===== */
#login-view { display: flex; min-height: 100dvh; align-items: center; justify-content: center; padding: 16px; }
.login-box {
  width: 100%; max-width: 360px; background: var(--card); border-radius: 24px;
  padding: 36px 26px 30px; box-shadow: var(--shadow); text-align: center;
}
.login-logo {
  width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 22px;
  background: linear-gradient(135deg, var(--brand-soft), var(--brand));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 20px rgba(29, 78, 216, .35);
}
.login-logo img { width: 46px; height: 46px; }
.login-box h1 { font-size: 21px; font-weight: 800; letter-spacing: -.01em; }
.login-box .muted { margin-top: 4px; }
.login-box form { margin-top: 22px; display: flex; flex-direction: column; gap: 10px; }

/* ===== 상단 헤더 ===== */
.topbar {
  background: linear-gradient(135deg, #1e3a8a, var(--brand) 60%, var(--brand-soft));
  color: #fff; margin: 0 -16px 16px; padding: 18px 18px 16px;
  border-radius: 0 0 22px 22px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  box-shadow: 0 6px 18px rgba(29, 78, 216, .25);
}
.topbar .app-title { font-size: 12px; opacity: .75; display: block; letter-spacing: .05em; }
.topbar strong { font-size: 17px; font-weight: 800; }
.topbar .muted { color: rgba(255,255,255,.75); }
.topbar-right { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.year-select {
  width: auto; padding: 7px 10px; font-size: 14px; font-weight: 700;
  border: none; border-radius: 9px; background: rgba(255,255,255,.92); color: var(--text);
}

/* ===== 스탯 카드 ===== */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.cards.three { grid-template-columns: 1fr 1fr 1fr; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px 14px;
  display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow);
  border-top: 3px solid transparent;
}
.card-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.card-num { font-size: 30px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.card-num::after { content: '대'; font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.card.down { border-top-color: var(--down); }
.card.up { border-top-color: var(--up); }
.card.down .card-num { color: var(--down); }
.card.up .card-num { color: var(--up); }

/* ===== 기록 폼 ===== */
.record-form {
  background: var(--card); border-radius: var(--radius); padding: 18px 16px;
  margin-top: 16px; box-shadow: var(--shadow);
}
.record-form h2 { margin: 0 0 12px; color: var(--text); font-size: 16px; text-transform: none; letter-spacing: 0; }
.row { display: flex; gap: 8px; margin-bottom: 10px; }
.type-toggle { display: flex; gap: 8px; margin-bottom: 10px; }
.type-toggle label { flex: 1; cursor: pointer; }
.type-toggle input { display: none; }
.type-toggle span {
  display: block; text-align: center; padding: 14px 4px; border-radius: 12px;
  border: 1.5px solid var(--border); font-size: 14px; font-weight: 700;
  color: var(--muted); background: #fff; transition: all .15s;
}
.type-toggle input[value="down"]:checked + span { border-color: var(--down); color: #fff; background: var(--down); box-shadow: 0 4px 12px rgba(199,106,0,.3); }
.type-toggle input[value="up"]:checked + span { border-color: var(--up); color: #fff; background: var(--up); box-shadow: 0 4px 12px rgba(23,143,69,.3); }
.photo-btn {
  display: block; text-align: center; padding: 14px; border: 2px dashed #c8d2df;
  border-radius: 12px; color: var(--muted); font-size: 15px; font-weight: 600;
  margin-bottom: 10px; cursor: pointer; background: #fafbfd;
}
.photo-btn:active { background: var(--brand-bg); }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.thumbs img {
  width: 68px; height: 68px; object-fit: cover; border-radius: 12px;
  border: 1px solid var(--border);
}

/* ===== 날짜별 기록 ===== */
.record-list { display: flex; flex-direction: column; gap: 12px; }
.date-group { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.date-head {
  font-weight: 800; font-size: 15px; margin-bottom: 4px;
  display: flex; justify-content: space-between; align-items: center;
}
.date-head .date-sums { font-size: 12.5px; font-weight: 700; }
.date-sums .d { color: var(--down); margin-right: 10px; }
.date-sums .u { color: var(--up); }
.entry { border-top: 1px solid var(--border); padding: 10px 0 8px; }
.entry:first-of-type { border-top: none; }
.entry-head { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.entry-head .who { color: var(--muted); font-size: 13px; }
.entry-head .spacer { flex: 1; }
.badge { font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 20px; }
.badge.down { background: var(--down-bg); color: var(--down); }
.badge.up { background: var(--up-bg); color: var(--up); }
.entry .thumbs { margin: 10px 0 0; }
.entry .thumbs img { cursor: pointer; }

/* ===== 진척률 (검토자) ===== */
.progress-box {
  background: var(--card); border-radius: var(--radius); padding: 22px 20px;
  margin: 12px 0; box-shadow: var(--shadow); text-align: center;
}
.progress-title { font-size: 13px; color: var(--muted); font-weight: 700; }
.progress-pct {
  font-size: 52px; font-weight: 800; letter-spacing: -.03em;
  color: var(--down); margin: 2px 0 14px; font-variant-numeric: tabular-nums;
}
.bar { height: 10px; background: #e8edf4; border-radius: 10px; overflow: hidden; }
.bar-fill {
  height: 100%; width: 0; border-radius: 10px;
  background: linear-gradient(90deg, #e08b2a, var(--down));
  transition: width .6s cubic-bezier(.22,1,.36,1);
}
.bar.secondary { height: 6px; margin-top: 10px; }
.bar.secondary .bar-fill { background: linear-gradient(90deg, #2fb267, var(--up)); }
.progress-sub {
  font-size: 13px; color: var(--muted); margin-top: 8px;
  display: flex; justify-content: space-between;
}
.progress-sub .up-label { color: var(--up); font-weight: 700; }

/* ===== 병원별 표 ===== */
.hosp-table {
  width: 100%; background: var(--card); border-radius: var(--radius);
  border-collapse: separate; border-spacing: 0; overflow: hidden; box-shadow: var(--shadow);
}
.hosp-table th, .hosp-table td { padding: 12px 10px; text-align: center; font-size: 15px; border-bottom: 1px solid var(--border); }
.hosp-table thead th { font-size: 12px; color: var(--muted); background: #f8fafc; font-weight: 700; }
.hosp-table th.col-down { color: var(--down); }
.hosp-table th.col-up { color: var(--up); }
.hosp-table td { font-variant-numeric: tabular-nums; font-weight: 600; }
.hosp-table td:first-child { font-weight: 800; }
.hosp-table tr:last-child td { border-bottom: none; }

/* ===== 라이트박스 ===== */
.lightbox {
  position: fixed; inset: 0; background: rgba(10, 14, 20, .92); z-index: 100;
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px;
}.lightbox img { max-width: 100vw; max-height: 92vh; object-fit: contain; border-radius: 4px; }
.lightbox::after { content: '탭하면 닫힙니다'; color: rgba(255,255,255,.6); font-size: 13px; }

/* ===== 관리자 페이지 ===== */
.admin-section {
  background: var(--card); border-radius: var(--radius); padding: 20px 18px;
  margin-top: 16px; box-shadow: var(--shadow);
}
.admin-section h2 { margin-top: 0; color: var(--text); font-size: 16px; text-transform: none; letter-spacing: 0; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th { font-size: 12px; color: var(--muted); text-align: left; padding: 8px; border-bottom: 1.5px solid var(--border); }
.admin-table td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.admin-form-row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.admin-form-row input, .admin-form-row select { width: auto; flex: 1; min-width: 110px; padding: 11px 12px; }
.admin-form-row .btn { white-space: nowrap; width: auto; }

/* 관리자 사진 삭제 */
.photo-wrap { position: relative; display: inline-block; }
.photo-x {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px;
  border: none; border-radius: 50%; background: var(--danger); color: #fff;
  font-size: 13px; line-height: 22px; cursor: pointer; padding: 0;
}
.photo-add {
  display: inline-block; font-size: 12px; color: var(--brand); font-weight: 700;
  cursor: pointer; padding: 4px 8px; background: var(--brand-bg); border-radius: 8px;
}

@media (min-width: 480px) {
  .thumbs img { width: 84px; height: 84px; }
}
