/* ==========================================================================
   R17 공통 컴포넌트 — Navigator 디자인 시스템 (docs/DESIGN_SYSTEM.md)
   Loaded right after tokens.css on every console page. Additive .nv-* classes only;
   every colour/size comes from tokens (tests/test_components_css.py enforces).
   Design reference: DEFENSE AI Platform (sharp corners, tinted actions, outline = active).
   Living gallery: /static/shell/preview.html (· ?theme=light)
   ========================================================================== */

/* ----- C1+ button: sizes, ghost, warn, icon-only, toggle, loading, group ----- */
.nv-btn:focus-visible, .nv-input:focus-visible, .nv-select:focus-visible, .nv-textarea:focus-visible,
.nv-tab:focus-visible, .nv-seg__opt:focus-visible, .nv-menu__item:focus-visible, .nv-switch:focus-visible,
.nv-check:focus-visible { outline: none; box-shadow: var(--nv-focus-ring); }
.nv-btn--sm { min-height: 24px; padding: 0 var(--nv-sp-2); font-size: var(--nv-fs-xs); }
.nv-btn--lg { min-height: 36px; padding: 0 var(--nv-sp-4); font-size: var(--nv-fs-base); }
.nv-btn--ghost { background: transparent; color: var(--nv-text-2); }
.nv-btn--ghost:hover { background: color-mix(in srgb, var(--nv-text-1) 8%, transparent); color: var(--nv-text-1); }
/* 거부·중지 등 주의가 필요한 조작 — 경보 적색(critical)은 버튼에 쓰지 않는다 */
.nv-btn--warn { background: color-mix(in srgb, var(--nv-status-warning) 15%, transparent); color: var(--nv-status-warning); }
.nv-btn--warn:hover { background: color-mix(in srgb, var(--nv-status-warning) 22%, transparent); }
.nv-btn--icon { width: 30px; padding: 0; }
.nv-btn--icon.nv-btn--sm { width: 24px; }
.nv-btn[aria-pressed="true"] { background: transparent; box-shadow: inset 0 0 0 1px var(--nv-text-3); color: var(--nv-text-1); }
.nv-btn[aria-busy="true"] { position: relative; color: transparent; pointer-events: none; }
.nv-btn[aria-busy="true"]::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 12px; height: 12px;
  border: 2px solid var(--nv-text-3); border-top-color: var(--nv-accent-text); border-radius: var(--nv-radius-pill);
  animation: nv-spin 0.8s linear infinite;
}
.nv-btn-group { display: inline-flex; gap: 1px; }
.nv-btn-group > .nv-btn { flex: 0 0 auto; }
.nv-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--nv-sp-2); }

.nv-spin {
  display: inline-block; flex: 0 0 auto; width: 12px; height: 12px; box-sizing: border-box;
  border: 2px solid var(--nv-border); border-top-color: var(--nv-accent-text); border-radius: var(--nv-radius-pill);
  animation: nv-spin 0.8s linear infinite; vertical-align: middle;
}
@keyframes nv-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .nv-spin, .nv-btn[aria-busy="true"]::after { animation-duration: 2.4s; } }

/* ----- C8 form field: label + control + help/error ----- */
.nv-field { display: flex; flex-direction: column; gap: var(--nv-sp-1); min-width: 0; }
.nv-field__label { color: var(--nv-text-2); font-size: var(--nv-fs-xs); font-weight: var(--nv-fw-medium); }
.nv-field__label .nv-req { color: var(--nv-accent-text); margin-left: 2px; }
.nv-field__help { color: var(--nv-text-3); font-size: var(--nv-fs-2xs); }
.nv-field__error { color: var(--nv-status-warning); font-size: var(--nv-fs-2xs); }
.nv-input, .nv-select, .nv-textarea {
  box-sizing: border-box; width: 100%; min-width: 0; height: 30px; padding: 0 var(--nv-sp-2);
  background: var(--nv-bg-2); color: var(--nv-text-1); border: 1px solid var(--nv-border); border-radius: 0;
  font-family: var(--nv-font-ui); font-size: var(--nv-fs-sm); line-height: var(--nv-lh-tight);
  transition: border-color var(--nv-dur-fast) var(--nv-ease);
}
.nv-input::placeholder, .nv-textarea::placeholder { color: var(--nv-text-3); }
.nv-input:hover, .nv-select:hover, .nv-textarea:hover { border-color: var(--nv-text-3); }
.nv-input:focus, .nv-select:focus, .nv-textarea:focus { outline: none; border-color: var(--nv-focus); }
.nv-input:disabled, .nv-select:disabled, .nv-textarea:disabled { background: var(--nv-bg-1); color: var(--nv-text-3); cursor: not-allowed; }
.nv-input[aria-invalid="true"], .nv-select[aria-invalid="true"], .nv-textarea[aria-invalid="true"] { border-color: var(--nv-status-warning); }
.nv-textarea { height: auto; min-height: 64px; padding: var(--nv-sp-2); resize: vertical; line-height: var(--nv-lh-base); }
.nv-input--sm, .nv-select.nv-input--sm { height: 24px; font-size: var(--nv-fs-xs); }
.nv-input--num { font-family: var(--nv-font-num); font-variant-numeric: tabular-nums; text-align: right; }

/* checkbox / radio: native control, accent from tokens */
.nv-check { width: 14px; height: 14px; margin: 0; accent-color: var(--nv-accent-strong); cursor: pointer; flex: 0 0 auto; }
.nv-check-label { display: inline-flex; align-items: center; gap: var(--nv-sp-1); color: var(--nv-text-body); font-size: var(--nv-fs-sm); cursor: pointer; }

/* switch: <input type="checkbox" role="switch" class="nv-switch"> */
.nv-switch {
  appearance: none; -webkit-appearance: none; position: relative; flex: 0 0 auto; margin: 0; cursor: pointer;
  width: 28px; height: 16px; background: var(--nv-bg-3); border: 1px solid var(--nv-border); border-radius: var(--nv-radius-pill);
  transition: background-color var(--nv-dur-fast) var(--nv-ease);
}
.nv-switch::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 10px; height: 10px;
  background: var(--nv-text-2); border-radius: var(--nv-radius-pill); transition: transform var(--nv-dur-fast) var(--nv-ease);
}
.nv-switch:checked { background: color-mix(in srgb, var(--nv-accent-text) 30%, var(--nv-bg-3)); border-color: var(--nv-accent); }
.nv-switch:checked::before { transform: translateX(12px); background: var(--nv-accent-text); }
.nv-switch:disabled { opacity: 0.5; cursor: not-allowed; }

/* ----- C9 tabs (underline) & segmented control ----- */
.nv-tabs { display: flex; gap: var(--nv-sp-3); min-width: 0; border-bottom: 1px solid var(--nv-divider); overflow-x: auto; scrollbar-width: none; }
.nv-tab {
  display: inline-flex; align-items: center; gap: var(--nv-sp-1); flex: 0 0 auto; height: 32px; padding: 0 2px;
  background: transparent; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer;
  color: var(--nv-text-2); font-family: var(--nv-font-ui); font-size: var(--nv-fs-sm); font-weight: var(--nv-fw-medium); white-space: nowrap;
}
.nv-tab:hover { color: var(--nv-text-1); }
.nv-tab[aria-selected="true"], .nv-tab.is-active { color: var(--nv-text-1); font-weight: var(--nv-fw-semibold); border-bottom-color: var(--nv-accent-strong); }
.nv-tab__n { min-width: 16px; padding: 0 4px; background: var(--nv-bg-3); color: var(--nv-text-2); font-size: var(--nv-fs-2xs);
  font-variant-numeric: tabular-nums; text-align: center; line-height: 16px; border-radius: var(--nv-radius-pill); }

.nv-seg { display: inline-flex; gap: 2px; padding: 2px; background: var(--nv-bg-2); border: 1px solid var(--nv-border); }
.nv-seg__opt {
  height: 24px; padding: 0 var(--nv-sp-2); background: transparent; border: 0; border-radius: 0; cursor: pointer;
  color: var(--nv-text-2); font-family: var(--nv-font-ui); font-size: var(--nv-fs-xs); font-weight: var(--nv-fw-medium); white-space: nowrap;
}
.nv-seg__opt:hover { color: var(--nv-text-1); }
.nv-seg__opt[aria-pressed="true"], .nv-seg__opt[aria-checked="true"] { background: var(--nv-bg-3); color: var(--nv-text-1); font-weight: var(--nv-fw-semibold); }

/* ----- C10 card / section — 면책 문구는 head 의 __note 에 1회 ----- */
.nv-card { display: flex; flex-direction: column; min-width: 0; background: var(--nv-bg-1); border: 1px solid var(--nv-divider); }
.nv-card__head { display: flex; align-items: center; gap: var(--nv-sp-2); min-width: 0; padding: var(--nv-sp-2) var(--nv-sp-3); border-bottom: 1px solid var(--nv-divider); }
.nv-card__title { flex: 1 1 auto; min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--nv-text-1); font-size: var(--nv-fs-md); font-weight: var(--nv-fw-semibold); }
.nv-card__note { padding: var(--nv-sp-1) var(--nv-sp-3); color: var(--nv-text-3); font-size: var(--nv-fs-2xs); border-bottom: 1px solid var(--nv-divider); }
.nv-card__body { display: flex; flex-direction: column; gap: var(--nv-sp-2); min-width: 0; padding: var(--nv-sp-3); }
.nv-card__foot { display: flex; justify-content: flex-end; gap: var(--nv-sp-2); padding: var(--nv-sp-2) var(--nv-sp-3); border-top: 1px solid var(--nv-divider); }
.nv-card.is-selected { border-color: var(--nv-accent); }

/* ----- C11 table: dense, one line per cell, numbers right-aligned ----- */
.nv-table-wrap { min-width: 0; overflow: auto; }
.nv-table { width: 100%; border-collapse: collapse; font-size: var(--nv-fs-sm); color: var(--nv-text-body); }
.nv-table th, .nv-table td { height: 32px; padding: 0 var(--nv-sp-2); text-align: left; white-space: nowrap; border-bottom: 1px solid var(--nv-divider); }
.nv-table th { position: sticky; top: 0; z-index: 1; height: 28px; background: var(--nv-bg-1);
  color: var(--nv-text-2); font-size: var(--nv-fs-xs); font-weight: var(--nv-fw-medium); }
.nv-table .num, .nv-table td.num, .nv-table th.num { text-align: right; font-family: var(--nv-font-num); font-variant-numeric: tabular-nums; }
.nv-table .wrap { white-space: normal; overflow-wrap: anywhere; }
.nv-table tbody tr:hover { background: color-mix(in srgb, var(--nv-text-1) 4%, transparent); }
.nv-table tbody tr.is-selected { background: color-mix(in srgb, var(--nv-accent-text) 10%, transparent); }
.nv-table tbody tr.is-top td:first-child { box-shadow: inset 2px 0 0 var(--nv-accent-strong); }
.nv-table tbody tr[data-href], .nv-table tbody tr.is-clickable { cursor: pointer; }

/* ----- C12 key–value list ----- */
.nv-kv { display: grid; grid-template-columns: auto 1fr; gap: var(--nv-sp-1) var(--nv-sp-3); margin: 0; font-size: var(--nv-fs-sm); }
.nv-kv dt { color: var(--nv-text-3); white-space: nowrap; }
.nv-kv dd { margin: 0; min-width: 0; color: var(--nv-text-1); overflow-wrap: anywhere; }
.nv-kv--cols2 { grid-template-columns: auto 1fr auto 1fr; }

/* ----- C13 notice strip (정직 라벨·안내). critical 은 실제 경보에만 ----- */
.nv-notice {
  --nv-notice-c: var(--nv-status-info);
  display: flex; align-items: flex-start; gap: var(--nv-sp-2); min-width: 0; padding: var(--nv-sp-2) var(--nv-sp-3);
  background: color-mix(in srgb, var(--nv-notice-c) 10%, var(--nv-bg-1)); border-left: 2px solid var(--nv-notice-c);
  color: var(--nv-text-1); font-size: var(--nv-fs-sm); line-height: var(--nv-lh-base);
}
.nv-notice > .nv-icon { color: var(--nv-notice-c); margin-top: 1px; }
.nv-notice__text { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.nv-notice--warn { --nv-notice-c: var(--nv-status-warning); }
.nv-notice--good { --nv-notice-c: var(--nv-status-good); }
.nv-notice--simulated { --nv-notice-c: var(--nv-label-simulated); border-left-style: dashed; }
.nv-notice--critical { --nv-notice-c: var(--nv-status-critical); }

/* ----- C14 popover + menu ----- */
.nv-popover {
  position: fixed; z-index: var(--nv-z-popover); max-width: calc(100vw - 16px); min-width: 160px;
  display: flex; flex-direction: column; gap: var(--nv-sp-1); padding: var(--nv-sp-2) var(--nv-sp-3);
  background: var(--nv-bg-1); color: var(--nv-text-1); border: 1px solid var(--nv-border); box-shadow: var(--nv-shadow-2);
  font-size: var(--nv-fs-xs);
}
.nv-popover.hidden, .nv-popover[hidden] { display: none; }
.nv-menu { display: flex; flex-direction: column; width: max-content; max-width: 100%; min-width: 160px; padding: var(--nv-sp-1) 0; margin: 0; list-style: none;
  background: var(--nv-bg-1); border: 1px solid var(--nv-border); box-shadow: var(--nv-shadow-2); }
.nv-menu__item {
  display: flex; align-items: center; gap: var(--nv-sp-2); width: 100%; height: 30px; padding: 0 var(--nv-sp-3);
  background: transparent; border: 0; text-align: left; cursor: pointer;
  color: var(--nv-text-body); font-family: var(--nv-font-ui); font-size: var(--nv-fs-sm); white-space: nowrap;
}
.nv-menu__item:hover, .nv-menu__item[aria-current="true"] { background: var(--nv-bg-2); color: var(--nv-text-1); }
.nv-menu__item:disabled { color: var(--nv-text-3); cursor: default; background: transparent; }
.nv-menu__sep { height: 1px; margin: var(--nv-sp-1) 0; background: var(--nv-divider); }
.nv-menu__hint { margin-left: auto; color: var(--nv-text-3); font-size: var(--nv-fs-2xs); }

/* ----- C15 modal: HITL 승인 등 한 번에 하나 ----- */
.nv-modal-scrim { position: fixed; inset: 0; z-index: var(--nv-z-modal); display: flex; align-items: center; justify-content: center;
  padding: var(--nv-sp-5); background: var(--nv-overlay-scrim); }
.nv-modal-scrim.hidden, .nv-modal-scrim[hidden] { display: none; }
.nv-modal { display: flex; flex-direction: column; width: min(560px, 100%); max-height: 82vh; min-width: 0;
  background: var(--nv-bg-1); border: 1px solid var(--nv-border); box-shadow: var(--nv-shadow-2); }
.nv-modal--wide { width: min(800px, 100%); }
.nv-modal__head { display: flex; align-items: center; gap: var(--nv-sp-2); padding: var(--nv-sp-3) var(--nv-sp-4); border-bottom: 1px solid var(--nv-divider); }
.nv-modal__title { flex: 1 1 auto; min-width: 0; margin: 0; color: var(--nv-text-1); font-size: var(--nv-fs-lg); font-weight: var(--nv-fw-semibold); }
.nv-modal__body { display: flex; flex-direction: column; gap: var(--nv-sp-3); min-height: 0; padding: var(--nv-sp-4); overflow: auto; color: var(--nv-text-body); font-size: var(--nv-fs-sm); }
.nv-modal__foot { display: flex; justify-content: flex-end; gap: var(--nv-sp-2); padding: var(--nv-sp-3) var(--nv-sp-4); border-top: 1px solid var(--nv-divider); }

/* ----- C16 empty / loading state ----- */
.nv-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--nv-sp-2);
  min-height: 96px; padding: var(--nv-sp-4); color: var(--nv-text-3); font-size: var(--nv-fs-sm); text-align: center; }
.nv-empty > .nv-icon { width: var(--nv-icon-lg); height: var(--nv-icon-lg); }
.nv-empty__title { color: var(--nv-text-2); font-weight: var(--nv-fw-medium); }
.nv-skeleton { display: block; height: 12px; background: var(--nv-bg-3); animation: nv-pulse 1.4s ease-in-out infinite; }
@keyframes nv-pulse { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .nv-skeleton { animation: none; } }

/* ----- C17 tooltip (title 대체용, CSS only): <span class="nv-tip" data-tip="설명"> ----- */
.nv-tip { position: relative; }
.nv-tip[data-tip]:hover::after, .nv-tip[data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%);
  z-index: var(--nv-z-popover); max-width: 260px; width: max-content; padding: var(--nv-sp-1) var(--nv-sp-2);
  background: var(--nv-bg-3); color: var(--nv-text-1); border: 1px solid var(--nv-border); box-shadow: var(--nv-shadow-1);
  font-size: var(--nv-fs-2xs); font-weight: var(--nv-fw-regular); line-height: var(--nv-lh-base); white-space: normal; pointer-events: none;
}

/* ----- C18 함정 도감 리치 카드(navy_ship_card) — 사진+제원+출처. 토큰만, 경보색 미사용 ----- */
.nv-ship-card { flex-direction: row; gap: var(--nv-sp-3); margin: var(--nv-sp-2) 0; padding: var(--nv-sp-2); }
.nv-ship-photo { flex: 0 0 132px; width: 132px; margin: 0; display: flex; flex-direction: column; gap: var(--nv-sp-1); }
.nv-ship-photo img, .nv-ship-photo > svg {
  width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--nv-bg-2); border: 1px solid var(--nv-divider); display: block; }
.nv-ship-photo.is-fallback { color: var(--nv-text-3); }
.nv-ship-photo figcaption { font-size: var(--nv-fs-2xs); color: var(--nv-text-3); overflow-wrap: anywhere; }
.nv-ship-photo figcaption a { color: var(--nv-accent-text, var(--nv-accent)); }
.nv-ship-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: var(--nv-sp-1); }
.nv-ship-head { display: flex; align-items: center; gap: var(--nv-sp-1); flex-wrap: wrap; font-size: var(--nv-fs-sm); }
.nv-ship-head > .nv-icon { width: var(--nv-icon-sm); height: var(--nv-icon-sm); color: var(--nv-text-3); }
.nv-ship-body .nv-kv { margin-top: var(--nv-sp-1); }
.nv-ship-conflict { color: var(--nv-status-warn); font-size: var(--nv-fs-2xs); }
.nv-ship-none, .nv-ship-more { font-size: var(--nv-fs-xs); color: var(--nv-text-3); margin: var(--nv-sp-1) 0 0; }
.nv-ship-srcs { margin: var(--nv-sp-1) 0 0 var(--nv-sp-3); padding: 0; font-size: var(--nv-fs-xs); color: var(--nv-text-2); }
.nv-ship-srcs li { margin: 2px 0; overflow-wrap: anywhere; }
.nv-ship-note { font-size: var(--nv-fs-2xs); color: var(--nv-text-3); margin: var(--nv-sp-1) 0 0; }
@media (max-width: 420px) { .nv-ship-card { flex-direction: column; } .nv-ship-photo { flex-basis: auto; width: 100%; } }
