/* pokestock 웹 UI 스타일 — 시스템 폰트, CSS 변수, 다크/라이트 자동 */

:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #d9dde3;
  --text: #1c1f24;
  --muted: #646b76;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --badge-restock-bg: #dcfce7;  --badge-restock-fg: #166534;
  --badge-soldout-bg: #e5e7eb;  --badge-soldout-fg: #374151;
  --badge-new-bg: #dbeafe;      --badge-new-fg: #1e40af;
  --badge-notice-bg: #fef3c7;   --badge-notice-fg: #92400e;
  /* 역할 배지: admin 보라 · member 초록 · pending 노랑 · blocked 회색 */
  --role-admin-bg: #ede9fe;     --role-admin-fg: #5b21b6;
  --role-member-bg: #dcfce7;    --role-member-fg: #166534;
  --role-pending-bg: #fef3c7;   --role-pending-fg: #92400e;
  --role-blocked-bg: #e5e7eb;   --role-blocked-fg: #4b5563;
  --shadow: 0 1px 2px rgba(0,0,0,.06);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Segoe UI", Roboto, "Noto Sans KR", "Malgun Gothic", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2c333d;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --accent: #60a5fa;
    --accent-text: #0b1220;
    --ok: #4ade80;
    --warn: #fbbf24;
    --danger: #f87171;
    --badge-restock-bg: #14532d;  --badge-restock-fg: #bbf7d0;
    --badge-soldout-bg: #374151;  --badge-soldout-fg: #e5e7eb;
    --badge-new-bg: #1e3a8a;      --badge-new-fg: #bfdbfe;
    --badge-notice-bg: #78350f;   --badge-notice-fg: #fde68a;
    --role-admin-bg: #4c1d95;     --role-admin-fg: #ddd6fe;
    --role-member-bg: #14532d;    --role-member-fg: #bbf7d0;
    --role-pending-bg: #78350f;   --role-pending-fg: #fde68a;
    --role-blocked-bg: #374151;   --role-blocked-fg: #d1d5db;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--accent); }
h2, h3 { margin: 0; font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; margin: 12px 0 6px; }
small, .hint { color: var(--muted); font-size: 12px; }
[hidden] { display: none !important; }

/* 헤더 */
.app-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px 0;
}
.brand { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.version { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.monitor-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.monitor-dot .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.monitor-dot[data-state="running"] .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.monitor-dot[data-state="paused"] .dot { background: var(--warn); }
.monitor-dot[data-state="none"] .dot { background: var(--muted); }
/* 언어 토글(KO | EN): 헤더 오른쪽 끝, seg 버튼 재사용 */
.lang-toggle { margin-left: auto; }
.lang-toggle .seg-btn { padding: 3px 9px; font-size: 12px; font-weight: 600; letter-spacing: .02em; }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin-top: 8px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: 0 0 auto;
  padding: 8px 12px;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* 본문 */
main { padding: 16px; max-width: 1200px; margin: 0 auto; }
.view { display: flex; flex-direction: column; gap: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.section-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { color: var(--muted); text-align: center; padding: 16px 8px; margin: 0; }
.note { background: var(--surface-2); border-radius: var(--radius); padding: 8px 12px; margin: 0; color: var(--muted); }

/* 버튼 */
.btn {
  font: inherit;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 3px 8px; font-size: 12px; }

/* 상태 카드 */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px;
}
.card-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 600; }
.card-meta { color: var(--muted); font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.card-error { color: var(--danger); font-size: 12px; word-break: break-all; }
.card-actions { display: flex; justify-content: flex-end; }

/* 표 */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; min-width: 480px; }
.table th, .table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.empty { text-align: center; }
.table .mono { font-family: var(--mono); font-size: 12px; }
.table .muted { color: var(--muted); }
.table .ellipsis { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-instock td:first-child { border-left: 3px solid var(--ok); }
.row-oos td:first-child { border-left: 3px solid var(--border); }

/* 배지 */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; line-height: 18px; white-space: nowrap; }
.badge-restock { background: var(--badge-restock-bg); color: var(--badge-restock-fg); }
.badge-sold_out { background: var(--badge-soldout-bg); color: var(--badge-soldout-fg); }
.badge-new_product { background: var(--badge-new-bg); color: var(--badge-new-fg); }
.badge-notice { background: var(--badge-notice-bg); color: var(--badge-notice-fg); }
.badge-other { background: var(--surface-2); color: var(--muted); }
.badge-source { background: var(--surface-2); color: var(--muted); font-weight: 500; }

/* 토글 스위치 */
.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch .slider::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: var(--surface); border-radius: 50%; transition: .15s; }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 타임라인 */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.timeline li.event {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}
.event-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.event-title { font-weight: 600; flex: 1 1 200px; word-break: break-word; }
.event-time { color: var(--muted); font-size: 12px; }
.event-desc { color: var(--muted); font-size: 13px; margin-top: 4px; white-space: pre-line; word-break: break-word; }
.event-points { margin: 6px 0 0; padding-left: 16px; font-size: 13px; }
.event-points li { color: var(--text); }
.event-more { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* 폼 */
.form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow); }
.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); min-width: 120px; flex: 1 1 140px; }
.form label.grow { flex: 2 1 220px; }
.form input, .form select {
  font: inherit; font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0; width: 100%;
}
.form input:focus, .form select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.lotte-lookup { display: flex; gap: 8px; align-items: flex-end; flex: 1 1 240px; }
.lotte-lookup label { flex: 1 1 120px; }
.store-results { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.store-results .store-row { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border); cursor: pointer; }
.store-results .store-row:hover { background: var(--surface-2); }
.store-results .store-row:last-child { border-bottom: 0; }

/* 주문서 결과 */
.buy-result { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.buy-result img { max-width: 100%; border-radius: 8px; border: 1px solid var(--border); margin-top: 8px; display: block; }
.buy-result .ok { color: var(--ok); font-weight: 600; }
.buy-result .fail { color: var(--danger); font-weight: 600; }

/* 토스트 */
.toast-stack { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 100; width: min(92vw, 420px); }
.toast {
  background: var(--text); color: var(--bg);
  padding: 10px 14px; border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  font-size: 13px; word-break: break-word;
  animation: toast-in .15s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--ok); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* 로딩 */
.loading { opacity: .6; pointer-events: none; }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 모바일 */
@media (max-width: 480px) {
  body { font-size: 13px; }
  main { padding: 12px; }
  .app-header { padding: 8px 12px 0; }
  .brand-name { font-size: 16px; }
  .card-grid { grid-template-columns: 1fr; }
  .table { min-width: 360px; }
  .table th, .table td { padding: 6px 8px; }
  .table .ellipsis { max-width: 180px; }
  .form label { flex: 1 1 100%; }
  .form label.grow { flex: 1 1 100%; }
}

/* 자동 추가 배지·체크박스 */
.badge-auto { margin-left: 0.35rem; background: color-mix(in srgb, var(--accent, #2563eb) 15%, transparent); color: var(--accent, #2563eb); }
label.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; }
label.check input { width: 1rem; height: 1rem; }

/* ===== 대시보드: 필터 바 ===== */
.filter-bar {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: 12px; display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer; white-space: nowrap;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.chip[aria-pressed="true"] .chip-count { background: rgba(255,255,255,.25); color: inherit; }
.chip-count { font-size: 11px; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 0 6px; line-height: 16px; font-variant-numeric: tabular-nums; }
.dot-src { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; vertical-align: 0; margin-right: 4px; }
.chip .dot-src, .legend-item .dot-src { margin-right: 0; }
.chip[aria-pressed="true"] .dot-src { box-shadow: 0 0 0 1.5px rgba(255,255,255,.8); }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.filter-field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); flex: 1 1 140px; min-width: 120px; }
.filter-field.grow { flex: 3 1 220px; }
.filter-field select, .filter-field input {
  font: inherit; font-size: 14px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0;
}
.filter-field select:disabled { opacity: .6; cursor: not-allowed; }
.filter-field select:focus, .filter-field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
#btn-my-location { flex: 0 0 auto; align-self: flex-end; }
#btn-my-location[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.filter-summary { margin: 0; font-size: 13px; color: var(--text); font-weight: 500; }

/* ===== 대시보드: 지도/목록 패널 ===== */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.panel .table-wrap { border: 0; border-radius: 0; box-shadow: none; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-btn {
  font: inherit; font-size: 13px; padding: 5px 12px; border: 0; background: var(--surface); color: var(--muted); cursor: pointer;
  border-right: 1px solid var(--border);
}
.seg-btn:last-child { border-right: 0; }
.seg-btn:hover { background: var(--surface-2); }
.seg-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.seg-btn:disabled { opacity: .45; cursor: not-allowed; }
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.table td.actions { display: flex; gap: 4px; flex-wrap: wrap; }
.table td.actions .btn { text-decoration: none; }

/* ===== 지도 ===== */
.map-wrap { position: relative; background: var(--surface-2); }
#stock-map { height: 60vh; min-height: 320px; width: 100%; background: var(--surface-2); outline: none; }
#stock-map:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
/* 팝업(Leaflet 지도 pane 위)을 가리지 않도록 지도 위에 띄우지 않고 지도 상단의 띠로 둔다. */
.map-note {
  background: var(--surface-2); color: var(--muted); border-bottom: 1px solid var(--border);
  padding: 4px 12px; font-size: 12px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.map-legend {
  position: absolute; left: 10px; bottom: 10px; z-index: 500; display: flex; flex-wrap: wrap; gap: 4px 10px;
  background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 8px; font-size: 11px; color: var(--text); max-width: calc(100% - 20px); pointer-events: none;
}
.legend-item { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.leaflet-container { font-family: var(--font); font-size: 13px; background: var(--surface-2); }
.leaflet-container a { color: var(--accent); }
.stock-pin { background: transparent; border: 0; }
.stock-pin-dot {
  display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%;
  color: #fff; font-size: 11px; font-weight: 700; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); box-sizing: border-box;
}
.leaflet-marker-icon.stock-pin:focus-visible .stock-pin-dot { outline: 3px solid var(--accent); }
.user-pin { filter: drop-shadow(0 1px 3px rgba(0,0,0,.4)); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); box-shadow: 0 3px 14px rgba(0,0,0,.3); }
.leaflet-popup-content { margin: 12px 14px; line-height: 1.45; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.stock-popup { display: flex; flex-direction: column; gap: 6px; min-width: 200px; }
.pp-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pp-head strong { font-size: 14px; }
.pp-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; max-height: 160px; overflow: auto; }
.pp-list li { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; border-bottom: 1px dashed var(--border); padding: 2px 0; }
.pp-list li:last-child { border-bottom: 0; }
.pp-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.pp-qty { flex: 0 0 auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.pp-meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.pp-addr { font-size: 12px; color: var(--muted); word-break: keep-all; }
.pp-route { align-self: flex-start; text-decoration: none; }
.leaflet-container a.pp-route.btn-primary { color: var(--accent-text); }
.leaflet-control-zoom a, .leaflet-control-attribution { background: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-bar { border-color: var(--border) !important; }

/* ===== 접을 수 있는 소스 상태 ===== */
details.collapsible { margin-top: 4px; }
details.collapsible > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 6px 0; user-select: none;
}
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary::before { content: "▸"; color: var(--muted); font-size: 12px; transition: transform .15s; display: inline-block; }
details.collapsible[open] > summary::before { transform: rotate(90deg); }
details.collapsible > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.collapsible-body { display: flex; flex-direction: column; gap: 10px; }
.collapsible-body .section-actions { justify-content: flex-end; }

/* ===== 다크 모드: 지도 타일·컨트롤 ===== */
@media (prefers-color-scheme: dark) {
  .leaflet-layer { filter: brightness(.72) invert(1) contrast(2.6) hue-rotate(195deg) saturate(.35) brightness(.78); }
  .stock-pin-dot { border-color: #e6e8eb; }
  .leaflet-control-attribution a { color: var(--accent) !important; }
}

/* ===== 모바일: 지도 높이·필터 ===== */
@media (max-width: 768px) {
  #stock-map { height: 50vh; min-height: 260px; }
  .map-legend { font-size: 10px; gap: 3px 8px; }
}
@media (max-width: 480px) {
  .filter-field, .filter-field.grow { flex: 1 1 100%; }
  #btn-my-location { width: 100%; }
  .panel-head { padding: 6px 8px; }
  .seg-btn { padding: 5px 9px; font-size: 12px; }
  .table .ellipsis { max-width: 160px; }
}

/* ===== 사용자 탭 ===== */
.badge-role.role-admin { background: var(--role-admin-bg); color: var(--role-admin-fg); }
.badge-role.role-member { background: var(--role-member-bg); color: var(--role-member-fg); }
.badge-role.role-pending { background: var(--role-pending-bg); color: var(--role-pending-fg); }
.badge-role.role-blocked { background: var(--role-blocked-bg); color: var(--role-blocked-fg); }
.badge-action { background: var(--surface-2); color: var(--text); font-weight: 500; }

/* 승인 대기 강조 섹션 */
.pending-box {
  background: color-mix(in srgb, var(--warn) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--border));
  border-left: 4px solid var(--warn);
  border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.pending-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.pending-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.pending-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.pending-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 240px; }
.pending-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pending-meta { display: flex; gap: 4px 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.pending-meta .mono { font-family: var(--mono); }
.pending-note { word-break: break-word; }
.pending-actions { display: flex; gap: 6px; flex: 0 0 auto; }

/* 표 안의 역할 select·메모 입력 */
.role-cell { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.table .role-select, .table .note-input {
  font: inherit; font-size: 12px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px; min-width: 0;
}
.table .role-select { width: auto; }
.table .note-input { width: 100%; min-width: 140px; }
.table .role-select:focus, .table .note-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.table .role-select:disabled, .table .note-input:disabled { opacity: .6; cursor: progress; }
.row-role-pending td:first-child { border-left: 3px solid var(--warn); }
.row-role-blocked td { color: var(--muted); }
.row-role-blocked td .note-input, .row-role-blocked td .role-select { color: var(--text); }

/* 섹션 머리의 인라인 필터(역할) */
.inline-field { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.inline-field select {
  font: inherit; font-size: 13px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px;
}
.inline-field select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

@media (max-width: 480px) {
  .pending-actions { width: 100%; justify-content: flex-end; }
  .table .note-input { min-width: 110px; }
}

/* ===== 로그인·세션: 헤더 사용자 칩 ===== */
.user-chip { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.user-avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--surface-2); object-fit: cover; }
.user-name { font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== 로그인 첫 화면 ===== */
.login-view { align-items: center; padding: 24px 16px; }
.login-card {
  width: min(560px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px 24px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}
.login-brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.login-brand .brand-name { font-size: 24px; }
.login-desc { margin: 0; line-height: 1.6; color: var(--text); }
.login-plans { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.login-plans li { background: var(--surface-2); border-radius: 999px; padding: 4px 12px; font-size: 13px; font-variant-numeric: tabular-nums; }
.login-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-lg { padding: 10px 18px; font-size: 15px; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; }
.login-noaccess { background: color-mix(in srgb, var(--warn) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--border)); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.login-noaccess p { margin: 0; }
.legal-links { margin: 0; font-size: 12px; color: var(--muted); }
.legal-links a { color: var(--muted); }

/* ===== 구독 탭 ===== */
.sub-status { gap: 10px; }
.sub-status .sub-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sub-status .sub-head strong { font-size: 16px; }
.sub-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: 13px; }
.sub-meta b { color: var(--text); font-weight: 600; }
.plan-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.plan-card .plan-days { font-size: 15px; font-weight: 700; }
.plan-card .plan-price { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.plan-card .plan-price s { color: var(--muted); font-size: 14px; font-weight: 400; margin-right: 6px; }
.plan-card .plan-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.plan-card .plan-actions .btn { width: 100%; }
.bank-box { gap: 8px; border-left: 4px solid var(--accent); }
.bank-box h3 { margin: 0; }
.bank-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.bank-row:last-of-type { border-bottom: 0; }
.bank-row .bank-label { flex: 0 0 110px; color: var(--muted); font-size: 12px; }
.bank-row .bank-value { font-family: var(--mono); font-size: 15px; font-weight: 600; word-break: break-all; }
.bank-row .bank-value.big { font-size: 18px; }
.bank-row .hint { flex-basis: 100%; }
.bank-done { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

/* ===== 관리 탭: 요약 카드 ===== */
.summary-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.summary-card {
  font: inherit; text-align: left; cursor: pointer; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; color: var(--text);
}
.summary-card:hover { background: var(--surface-2); }
.summary-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.summary-label { font-size: 12px; color: var(--muted); }
.summary-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.summary-sub { font-size: 12px; color: var(--muted); }
.summary-card.warn .summary-value { color: var(--warn); }
.summary-card.danger .summary-value { color: var(--danger); }
.summary-card.ok .summary-value { color: var(--ok); }
.summary-card.accent .summary-value { color: var(--accent); }
.pending-box.danger { background: color-mix(in srgb, var(--danger) 8%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); border-left-color: var(--danger); }
.pending-box h3 { margin: 0; font-size: 15px; }
.pending-amount { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ===== 구독·결제 배지 ===== */
.badge-lifetime { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.badge-active { background: var(--badge-restock-bg); color: var(--badge-restock-fg); }
.badge-expiring { background: var(--badge-notice-bg); color: var(--badge-notice-fg); }
.badge-expired { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.badge-none { background: var(--surface-2); color: var(--muted); }
.badge-pay-pending { background: var(--badge-notice-bg); color: var(--badge-notice-fg); }
.badge-pay-confirmed, .badge-pay-done { background: var(--badge-restock-bg); color: var(--badge-restock-fg); }
.badge-pay-rejected, .badge-pay-failed { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.badge-pay-expired, .badge-pay-canceled, .badge-pay-unknown { background: var(--surface-2); color: var(--muted); }
.badge-kind { background: var(--surface-2); color: var(--text); font-weight: 500; }

/* ===== 표 안의 동작 묶음·인라인 입력 ===== */
.sub-cell { display: flex; flex-direction: column; gap: 2px; }
.sub-cell .hint { white-space: nowrap; }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.row-actions .btn { text-decoration: none; }
.table .coupon-select { font: inherit; font-size: 12px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px; max-width: 150px; }
.inline-input {
  font: inherit; font-size: 13px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px; min-width: 0; width: 170px;
}
.inline-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.inline-field input.inline-input { width: 140px; }
.input-with-btn { display: flex; gap: 6px; align-items: center; }
.input-with-btn input { flex: 1 1 auto; }
.copy-btn { font-size: 12px; padding: 2px 8px; }
.row-highlight td { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.coupon-redemptions td { background: var(--surface-2); }
.coupon-redemptions ul { margin: 0; padding-left: 16px; font-size: 13px; }
.kv { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); font-size: 12px; align-self: center; }
.kv dd { margin: 0; font-size: 13px; word-break: break-all; }
details.collapsible > summary h3 { margin: 0; }
.cp-expired { color: var(--danger); }

/* ===== 모바일(≤768px): 표를 카드로 쌓는다(.table-wrap.stack). td 의 data-label 이 머리글 역할 ===== */
@media (max-width: 768px) {
  .table-wrap.stack { overflow: visible; background: transparent; border: 0; box-shadow: none; }
  .table-wrap.stack .table { min-width: 0; border-collapse: separate; border-spacing: 0 8px; }
  .table-wrap.stack thead { display: none; }
  .table-wrap.stack tbody, .table-wrap.stack tr, .table-wrap.stack td { display: block; width: 100%; }
  .table-wrap.stack tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px 10px; }
  .table-wrap.stack td { border-bottom: 1px dashed var(--border); padding: 6px 0; display: flex; gap: 10px; align-items: flex-start; text-align: left; }
  .table-wrap.stack td:last-child { border-bottom: 0; }
  .table-wrap.stack td.empty { display: block; }
  .table-wrap.stack td[data-label]::before { content: attr(data-label); flex: 0 0 84px; color: var(--muted); font-size: 12px; padding-top: 2px; }
  .table-wrap.stack td.num { text-align: left; }
  .table-wrap.stack .ellipsis { max-width: none; white-space: normal; }
  .table-wrap.stack .row-highlight { outline: 2px solid var(--accent); }
  .table-wrap.stack .row-role-pending td:first-child, .table-wrap.stack .row-instock td:first-child { border-left: 0; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .bank-row .bank-label { flex-basis: 100%; }
  .section-actions .inline-input { width: 100%; }
}

/* ===== 모니터링 탭 ===== */
/* 색은 모두 기존 토큰(--ok --warn --danger --accent --badge-* --surface-2)으로 정해 다크 모드가 자동으로 맞는다. 애니메이션은 ping 하나뿐. */

/* 머리글: 눈썹 + 제목 | 실시간 배지 · 기준 시각 · 일시중지/재개 · 새로고침 */
.mon-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.eyebrow { margin: 0; font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.mon-title { font-size: 24px; font-weight: 700; letter-spacing: -.01em; margin: 0; line-height: 1.2; }
.mon-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.live-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; line-height: 20px;
  padding: 0 10px 0 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.live-badge .ping { position: relative; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.live-badge[data-state="live"] { background: var(--badge-restock-bg); color: var(--badge-restock-fg); }
.live-badge[data-state="live"] .ping { background: var(--ok); }
.live-badge[data-state="live"] .ping::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--ok);
  animation: ping 1.6s cubic-bezier(0, 0, .2, 1) infinite;
}
.live-badge[data-state="stale"] { background: var(--badge-notice-bg); color: var(--badge-notice-fg); }
.live-badge[data-state="stale"] .ping { background: var(--warn); }
@keyframes ping { 75%, 100% { transform: scale(2.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .live-badge .ping::after { animation: none; display: none; }
}

/* 본문 묶음(잠금 때 통째로 숨긴다) · 오류 상자 · 권한 없음 */
.mon-body { display: flex; flex-direction: column; gap: 12px; }
.mon-error {
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border));
  border-left: 4px solid var(--danger);
  border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.lock-empty {
  text-align: center; color: var(--muted); padding: 40px 16px; font-size: 15px;
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}
.lock-empty .lock-icon { display: block; font-size: 28px; margin-bottom: 6px; }

/* KPI 카드 4장(≤768 2열) */
.kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.summary-card.kpi .summary-value { font-size: 26px; }

/* 상태 배지 5종: 연한 배경 + 진한 글자, 20px·11px */
.badge-state { height: 20px; line-height: 20px; padding: 0 6px; font-size: 11px; }
.badge-state.success { background: var(--badge-restock-bg); color: var(--badge-restock-fg); }
.badge-state.warning { background: var(--badge-notice-bg); color: var(--badge-notice-fg); }
.badge-state.danger { background: color-mix(in srgb, var(--danger) 16%, var(--surface)); color: var(--danger); }
.badge-state.info { background: var(--badge-new-bg); color: var(--badge-new-fg); }
.badge-state.neutral { background: var(--surface-2); color: var(--muted); }

/* 두 열: 최근 실행 3fr | 진단 2fr (≤900 1열) */
.mon-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 12px; align-items: start; }
.mon-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0;
}
.mon-card .section-head { margin-top: 0; }
.mon-card .table-wrap { border: 0; border-radius: 0; box-shadow: none; background: transparent; }
.table-compact { min-width: 520px; }
.table-compact th, .table-compact td { padding: 5px 8px; font-size: 12px; }
.table-compact td.num, .table-compact td.mono { font-variant-numeric: tabular-nums; }

/* 상태 행(health row): 왼쪽 제목+설명, 오른쪽 배지, 옅은 구분선 */
.health-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.health-list .empty { padding: 10px 0; }
.health-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.health-row:last-child { border-bottom: 0; }
.health-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.health-title { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.health-caption { font-size: 12px; color: var(--muted); word-break: break-word; }
.health-row .badge { flex: 0 0 auto; margin-top: 1px; }

/* 소요 막대(최근 20회): 실패는 빨강 */
.mini-bars { display: flex; align-items: flex-end; gap: 3px; height: 44px; padding: 2px 0; }
.mini-bar { flex: 1 1 0; min-width: 4px; background: color-mix(in srgb, var(--accent) 65%, transparent); border-radius: 2px 2px 0 0; }
.mini-bar.fail { background: var(--danger); }

/* 진행 중(스피너 + "진행 중 · i/n · 소요", 1초 틱) */
.progress-inline { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.progress-inline .spinner { margin-right: 0; }

/* 갱신 끊김: 값은 남기고 살짝 흐리게 */
.mon-stale .mon-body { opacity: .75; }

/* 표 보조 */
.row-muted td { color: var(--muted); }
.row-fail td:first-child { border-left: 3px solid var(--danger); }
.err, .table .err { color: var(--danger); }
.warn-text { color: var(--warn); }
.src-name { display: inline-flex; align-items: center; gap: 2px; white-space: nowrap; }
#view-monitor .table td { font-variant-numeric: tabular-nums; }
.inline-select {
  font: inherit; font-size: 13px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px; min-width: 0;
}
.inline-select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

/* 헤더 점의 라벨은 모니터링 탭으로 가는 링크 */
.monitor-dot a { color: inherit; text-decoration: none; }
.monitor-dot a:hover, .monitor-dot a:focus-visible { text-decoration: underline; }

@media (max-width: 900px) {
  .mon-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .mon-title { font-size: 20px; }
  .mon-head { align-items: flex-start; flex-direction: column; }
  .table-wrap.stack .row-fail td:first-child, .table-wrap.stack .row-muted td:first-child { border-left: 0; }
  .table-wrap.stack .progress-inline { white-space: normal; }
}
