/* ============================================================
   ISO 13485:2016 의료기기 사후관리 실습 시스템 — 전체 스타일
   ============================================================ */

:root {
  --primary: #1e5aa8;
  --primary-dark: #174a8a;
  --primary-light: #e8f0fb;
  --accent: #0f9d6e;
  --danger: #d64545;
  --warn: #d99a1b;
  --bg: #f1f4f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #22303f;
  --muted: #64748b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 42, 84, .08), 0 8px 24px rgba(16, 42, 84, .06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
               "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

body.modal-open { overflow: hidden; }

.hidden { display: none !important; }
.ta-c { text-align: center; }

button { font-family: inherit; cursor: pointer; }

/* ============================================================
   버튼
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14px; font-weight: 600;
  background: var(--primary); color: #fff;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline { background: #fff; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b83535; }

.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 10px; font-size: 13px; }

.btn-mini {
  padding: 3px 8px; font-size: 12px;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--primary);
}
.btn-mini:hover { background: var(--primary-light); }
.btn-mini-danger { color: var(--danger); }
.btn-mini-danger:hover { background: #fdeaea; }

/* ============================================================
   로그인 / 회원가입
   ============================================================ */
.auth-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(30, 90, 168, .35), transparent 60%),
    radial-gradient(900px 500px at 90% 110%, rgba(15, 157, 110, .25), transparent 55%),
    linear-gradient(160deg, #0f2c55, #174a8a);
  padding: 20px;
}

.auth-card {
  width: 460px; max-width: 100%;
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
  padding: 30px 32px 26px;
}

.auth-brand { text-align: center; margin-bottom: 22px; }

.auth-logo {
  display: inline-block;
  font-weight: 800; letter-spacing: 1px; font-size: 15px;
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: 10px;
  padding: 5px 12px;
  margin-bottom: 10px;
}

.auth-brand h1 { font-size: 19px; color: var(--text); }
.auth-brand p { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

.auth-tabs {
  display: flex; gap: 6px;
  background: var(--bg);
  border-radius: 10px; padding: 4px;
  margin-bottom: 20px;
}
.auth-tabs button {
  flex: 1; padding: 9px 0;
  border: none; border-radius: 8px;
  background: transparent; font-size: 14px; font-weight: 600;
  color: var(--muted);
}
.auth-tabs button.active { background: var(--card); color: var(--primary); box-shadow: var(--shadow); }

.auth-form { display: flex; flex-direction: column; gap: 12px; }

.auth-note {
  margin-top: 14px; font-size: 12px; color: var(--muted);
  text-align: center;
}

.serial-input {
  font-family: "SFMono-Regular", Consolas, Menlo, monospace !important;
  letter-spacing: 2px; text-transform: uppercase;
}

/* ============================================================
   레이아웃 (사이드바 + 메인)
   ============================================================ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px; flex-shrink: 0;
  background: linear-gradient(180deg, #123157, #0f2c55);
  color: #dbe6f5;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

.side-brand { padding: 22px 20px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.side-logo { font-size: 15px; font-weight: 800; letter-spacing: 1px; color: #fff; }
.side-title { font-size: 12px; color: #9db4d8; margin-top: 2px; }

.side-nav { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 11px 12px;
  border: none; border-radius: 9px;
  background: transparent; color: #c7d6ef; font-size: 13.5px; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 700; }
.nav-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.side-foot {
  padding: 12px 20px; font-size: 11px; color: #6f87ac;
  border-top: 1px solid rgba(255,255,255,.08);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.page-title { font-size: 17px; font-weight: 700; flex: 1; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  display: none;
  width: 36px; height: 36px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font-size: 18px; color: var(--text);
}

.user-chip {
  display: flex; flex-direction: column; align-items: flex-end;
  font-size: 13px;
}
.user-chip strong { color: var(--text); }
.user-chip .chip-sub { font-size: 11px; color: var(--muted); }

.conn-chip {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  white-space: nowrap;
}
.conn-chip.on { color: #1a7f37; border-color: #9ed3ac; background: #f0fbf2; }
.conn-chip.sync { color: #9a6700; border-color: #e6c97d; background: #fff8e5; }
.conn-chip.off { color: #9d3535; border-color: #e4b5b5; background: #fdf1f1; }

.content { padding: 24px; max-width: 1200px; width: 100%; margin: 0 auto; }

/* ============================================================
   카드 / 테이블
   ============================================================ */
.page-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 20px;
}

.card-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; margin-bottom: 16px;
}
.card-head h2 { font-size: 17px; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card-actions.right { justify-content: flex-end; }

.iso-badge {
  display: inline-block;
  background: var(--primary-light); color: var(--primary);
  font-size: 12px; font-weight: 700;
  padding: 3px 10px; border-radius: 20px;
  margin-top: 6px;
}
.card-desc { font-size: 13px; color: var(--muted); margin-top: 8px; }

.table-wrap { overflow-x: auto; }

.grid {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.grid th, .grid td {
  padding: 10px 12px; text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.grid th { background: #f8fafc; font-weight: 700; color: #3b4a5c; white-space: nowrap; }
.grid tr:hover td { background: #fafcff; }
.grid td { word-break: break-word; }
.grid .empty { text-align: center; color: var(--muted); padding: 28px 12px; }

.info-table th { width: 110px; background: #f8fafc; }
.info-table th, .info-table td { border: 1px solid var(--line); }

.sep { border: none; border-top: 1px solid var(--line); margin: 20px 0; }

/* ============================================================
   폼
   ============================================================ */
.form-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
.form-item { display: flex; flex-direction: column; gap: 5px; }
.form-item-wide { grid-column: 1 / -1; }

.form-item label { font-size: 12.5px; font-weight: 600; color: #3b4a5c; }
.req { color: var(--danger); }

.form-item input, .form-item select, .form-item textarea {
  padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; font-family: inherit; color: var(--text);
  background: #fff;
  width: 100%;
}
.form-item input:focus, .form-item select:focus, .form-item textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 90, 168, .12);
}
.form-item input[readonly] { background: #f4f6f9; color: var(--muted); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

.gen-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.gen-row label { font-weight: 600; font-size: 14px; }
.gen-row input[type="number"] {
  width: 120px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
}

.hint { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }

/* ============================================================
   대시보드
   ============================================================ */
.hero-card {
  display: flex; justify-content: space-between; align-items: center; gap: 18px;
  background: linear-gradient(120deg, #123157, #1e5aa8);
  color: #fff; border: none;
}
.hero-text h2 { font-size: 20px; margin-bottom: 6px; }
.hero-text p { font-size: 13.5px; color: #c7d6ef; }
.exp-note { margin-top: 10px; font-size: 13px; color: #ffe9a8; }
.hero-badge {
  text-align: right; flex-shrink: 0;
  background: rgba(255,255,255,.1);
  border: 1px dashed rgba(255,255,255,.4);
  border-radius: 10px; padding: 12px 16px;
}
.hero-badge span { display: block; font-size: 11px; color: #c7d6ef; }
.hero-badge b { font-size: 14px; letter-spacing: 1px; }

.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 14px; margin-bottom: 20px;
}
.stat-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; text-align: left;
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(16,42,84,.12); }
.stat-icon { font-size: 22px; }
.stat-num { font-size: 26px; font-weight: 800; color: var(--primary); margin: 4px 0 0; }
.stat-label { font-size: 13px; font-weight: 600; }
.stat-iso { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.quick-links { display: flex; flex-wrap: wrap; gap: 10px; }
.quick-link {
  padding: 10px 16px; font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--text);
}
.quick-link:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

.iso-map td { font-size: 13px; }

/* ============================================================
   상태 배지 / 기타
   ============================================================ */
.pill {
  display: inline-block; padding: 2px 10px;
  border-radius: 20px; font-size: 11.5px; font-weight: 700;
  white-space: nowrap;
}
.pill-fresh { background: #e8f7ef; color: #0f7a52; }
.pill-used { background: #fdeaea; color: #b83535; }
.pill-warn { background: #fdf3e0; color: #a06a08; }
.pill-ok { background: #e3f1fd; color: #1a6bb5; }
.pill-danger { background: #fbe3e3; color: #b01818; }

.deadline-over { color: var(--danger); font-weight: 700; }

/* ============================================================
   모달
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15, 30, 55, .55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}
.modal-card {
  background: var(--card); border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.3);
  width: 680px; max-width: 100%;
  margin: auto 0;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 16px; }
.modal-close {
  width: 30px; height: 30px; font-size: 20px; line-height: 1;
  border: none; background: transparent; color: var(--muted);
  border-radius: 6px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 20px 22px; max-height: 62vh; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: #fafbfd; border-radius: 0 0 14px 14px;
}
.confirm-msg { font-size: 14px; line-height: 1.7; }

/* ============================================================
   토스트
   ============================================================ */
.toasts {
  position: fixed; top: 16px; right: 16px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: #1c2b3d; color: #fff;
  padding: 11px 16px; border-radius: 10px;
  font-size: 13.5px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  opacity: 0; transform: translateX(20px);
  transition: opacity .25s, transform .25s;
  max-width: 340px;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast.ok { background: var(--accent); }
.toast.warn { background: #c97e10; }

/* ============================================================
   인쇄 (A4 보고서)
   ============================================================ */
#printArea { display: none; }

@media print {
  #authOverlay, #app, #toasts, #modalOverlay { display: none !important; }
  #printArea { display: block !important; }
  body { background: #fff; }
  .report-page {
    width: 210mm; min-height: 297mm;
    margin: 0 auto; padding: 18mm 16mm;
    background: #fff; color: #111;
    font-size: 12px;
  }
}

.report-title { font-size: 20px; font-weight: 800; text-align: center; margin-bottom: 14px; }

.report-meta { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.report-meta th, .report-meta td { border: 1px solid #bbb; padding: 6px 10px; text-align: left; }
.report-meta th { width: 130px; background: #f2f4f8; }
.report-serial { font-weight: 800; letter-spacing: 1.5px; }

.report-section { font-size: 13.5px; margin: 18px 0 8px; padding-bottom: 4px; border-bottom: 2px solid #333; }

.report-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.report-table th, .report-table td { border: 1px solid #bbb; padding: 6px 8px; text-align: left; vertical-align: top; font-size: 12px; }
.report-table th { background: #f2f4f8; }

.report-par { white-space: pre-line; font-size: 12.5px; line-height: 1.8; margin-bottom: 8px; }
.report-empty { text-align: center; color: #888; }

.report-signatures {
  display: flex; justify-content: space-between; gap: 40px;
  margin-top: 46px; padding: 0 20px;
}
.sig { text-align: center; flex: 1; }
.sig-label { font-size: 11px; color: #555; }
.sig-name { font-size: 16px; font-weight: 700; margin-top: 34px; border-bottom: 1px solid #333; padding-bottom: 6px; }
.sig-serial { font-size: 11px; color: #555; margin-top: 6px; letter-spacing: 1px; }

/* ============================================================
   반응형
   ============================================================ */
@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid, .form-row { grid-template-columns: 1fr; }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }

  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 90;
    transform: translateX(-100%); transition: transform .25s;
    box-shadow: 0 0 40px rgba(0,0,0,.3);
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 16px; }
  .hero-card { flex-direction: column; align-items: flex-start; }
  .hero-badge { text-align: left; }
}

@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card-head { flex-direction: column; }
  .topbar-right .user-chip .chip-sub { display: none; }
}
