/* Golden Goose 관리자 UI — 시그널 콘솔 테마 */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* ── 테마 토큰 ─────────────────────────────────────────────── */
/* 라이트: 오프화이트 + 파스텔 페리윙클(iris) */
:root {
  --bg: #f8f7f4;
  --panel: #ffffff;
  --panel-alt: #f1f1ee;
  --border: #e4e3dd;
  --hairline: #edece8;
  --text: #1c1d22;
  --muted: #74757d;
  --primary: #b3bdf5;        /* 파스텔 페리윙클 버튼 */
  --primary-hover: #a3aef0;
  --on-primary: #2e3358;     /* 파스텔 위 딥 인디고 텍스트 */
  --accent: #5b63c4;         /* 탭 밑줄·포커스·상태 강조 */
  --accent-soft: rgba(91, 99, 196, 0.12);
  --ok: #2f9e5f;
  --ok-soft: rgba(47, 158, 95, 0.14);
  --danger: #d0453f;
  --danger-strong: #b5342f;
  --danger-soft: rgba(208, 69, 63, 0.12);
  --warn: #c2852a;
  --warn-soft: rgba(194, 133, 42, 0.15);
  --secondary: #eeeef1;
  --secondary-text: #3a3b43;
  --secondary-hover: #e5e5e9;
  --badge-bg: #e9e9ed;
  --shadow: 0 1px 2px rgba(28, 29, 40, 0.05), 0 4px 16px rgba(28, 29, 40, 0.06);
  --shadow-lg: 0 12px 40px rgba(24, 25, 38, 0.16);
  --overlay: rgba(24, 25, 34, 0.42);
  --focus-ring: rgba(91, 99, 196, 0.38);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Consolas", "D2Coding", monospace;
}

/* 다크: 무드 있는 뉴트럴 블랙 + 소프트 인디고 */
:root[data-theme="dark"] {
  --bg: #0c0d11;
  --panel: #15161b;
  --panel-alt: #1c1d24;
  --border: #282a32;
  --hairline: #22232a;
  --text: #e8e9ee;
  --muted: #8e909b;
  --primary: #5c63c9;
  --primary-hover: #6b73da;
  --on-primary: #ffffff;
  --accent: #8f97e8;
  --accent-soft: rgba(143, 151, 232, 0.16);
  --ok: #46c07f;
  --ok-soft: rgba(70, 192, 127, 0.16);
  --danger: #e86a62;
  --danger-strong: #f0847d;
  --danger-soft: rgba(232, 106, 98, 0.16);
  --warn: #d9a441;
  --warn-soft: rgba(217, 164, 65, 0.16);
  --secondary: #212228;
  --secondary-text: #d7d8de;
  --secondary-hover: #2a2b33;
  --badge-bg: #212228;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 6px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);
  --overlay: rgba(0, 0, 0, 0.68);
  --focus-ring: rgba(143, 151, 232, 0.42);
}

/* OS 다크 선호 시(수동 설정 전) 자동 적용 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0d11; --panel: #15161b; --panel-alt: #1c1d24; --border: #282a32; --hairline: #22232a;
    --text: #e8e9ee; --muted: #8e909b; --primary: #5c63c9; --primary-hover: #6b73da; --on-primary: #ffffff;
    --accent: #8f97e8; --accent-soft: rgba(143,151,232,0.16); --ok: #46c07f; --ok-soft: rgba(70,192,127,0.16);
    --danger: #e86a62; --danger-strong: #f0847d; --danger-soft: rgba(232,106,98,0.16); --warn: #d9a441; --warn-soft: rgba(217,164,65,0.16);
    --secondary: #212228; --secondary-text: #d7d8de; --secondary-hover: #2a2b33; --badge-bg: #212228;
    --shadow: 0 1px 2px rgba(0,0,0,0.5), 0 6px 20px rgba(0,0,0,0.4); --shadow-lg: 0 16px 48px rgba(0,0,0,0.6);
    --overlay: rgba(0,0,0,0.68); --focus-ring: rgba(143,151,232,0.42);
  }
}

body {
  font-family: "Pretendard", "Malgun Gothic", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s ease, color 0.25s ease;
}
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ── 로그인 ────────────────────────────────────────────────── */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px;
  background: radial-gradient(120% 90% at 50% -10%, var(--accent-soft), transparent 60%); }
.login-box { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 40px; width: 100%; max-width: 372px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow-lg); }
.login-box h1 { font-size: 20px; text-align: center; margin-bottom: 8px; letter-spacing: -0.01em; }

/* ── 브랜드 워드마크 ───────────────────────────────────────── */
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.brand-sep { width: 1px; height: 14px; background: var(--border); margin: 0 2px; }
.brand-sub { font-size: 12px; font-weight: 600; letter-spacing: 0.12em; color: var(--accent); text-transform: uppercase; white-space: nowrap; }
#brand-home { cursor: pointer; border-radius: 8px; padding: 4px 6px; margin: -4px -6px; transition: background-color 0.15s ease; }
#brand-home:hover { background: var(--accent-soft); }
#brand-home:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }

/* ── 헤더/탭 ───────────────────────────────────────────────── */
header { display: flex; justify-content: space-between; align-items: center; background: var(--panel);
  border-bottom: 1px solid var(--border); padding: 12px 24px; gap: 12px; position: sticky; top: 0; z-index: 40; }
.header-right { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); min-width: 0; }
.admin-email { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12px; }
nav#tabs { display: flex; gap: 2px; background: var(--panel); border-bottom: 1px solid var(--border); padding: 0 20px; overflow-x: auto; position: sticky; top: 51px; z-index: 30; -webkit-overflow-scrolling: touch; scrollbar-width: none; -ms-overflow-style: none; }
/* 탭 줄은 필요 시 가로 스크롤되지만 스크롤바는 숨긴다(불필요한 바 노출 방지) */
nav#tabs::-webkit-scrollbar { display: none; }
nav#tabs button { border: none; background: none; padding: 13px 15px; font-size: 14px; cursor: pointer; color: var(--muted);
  position: relative; white-space: nowrap; transition: color 0.15s ease; }
nav#tabs button::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; background: var(--accent);
  border-radius: 2px 2px 0 0; transform: scaleX(0); transition: transform 0.2s ease; }
nav#tabs button:hover { color: var(--text); }
nav#tabs button.active { color: var(--text); font-weight: 600; }
nav#tabs button.active::after { transform: scaleX(1); }
main { padding: 24px; max-width: 1560px; margin: 0 auto; }

/* 탭 전환 페이드 */
.tab { animation: tab-in 0.22s ease both; }
@keyframes tab-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── 대시보드: 인스트루먼트 스트립 ─────────────────────────── */
.instruments { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  box-shadow: var(--shadow); margin-bottom: 24px; }
.instrument { display: flex; align-items: center; gap: 12px; padding: 18px 20px; border-right: 1px solid var(--hairline); }
.instrument:last-child { border-right: none; }
.instrument .meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.instrument h3 { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.instrument p { font-size: 19px; font-weight: 700; font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); animation: breathe 2.6s ease-in-out infinite; }
.dot.bad { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.dot.neutral { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
@keyframes breathe { 0%, 100% { box-shadow: 0 0 0 2px var(--ok-soft); } 50% { box-shadow: 0 0 0 5px transparent; } }
@media (prefers-reduced-motion: reduce) { .dot.ok { animation: none; } .tab { animation: none; } }

/* ── 카드/패널 ─────────────────────────────────────────────── */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 22px; margin-bottom: 24px; box-shadow: var(--shadow); }
.panel h2 { font-size: 15px; margin-bottom: 8px; letter-spacing: -0.01em; }
.danger-panel { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
/* 킬스위치 패널 — 대시보드 히어로 컨트롤 */
.killswitch { position: relative; overflow: hidden; }
.killswitch::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--danger); }
.desc { font-size: 13px; color: var(--muted); margin-bottom: 12px; line-height: 1.6; }
.meta { font-size: 12px; color: var(--muted); margin-top: 8px; min-height: 16px; font-family: var(--mono); word-break: break-word; }
.control-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.control-row input[type="text"] { flex: 1; min-width: 200px; }

/* ── 배지/상태 ─────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 8px; font-size: 12px; font-weight: 600; background: var(--badge-bg); color: var(--secondary-text); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* ── 폼 요소 ───────────────────────────────────────────────── */
input, select { height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: 9px; font-size: 14px;
  background: var(--panel); color: var(--text); transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease; max-width: 100%; }
input::placeholder { color: var(--muted); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
input[type="date"] { color-scheme: light dark; font-family: var(--mono); }

/* ── 커스텀 셀렉트(드롭박스) ───────────────────────────────── */
select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  padding-right: 36px; cursor: pointer; font-weight: 500;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238b8d98' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 14px;
}
select:hover { border-color: var(--accent); background-color: var(--accent-soft); }
select:focus { background-color: var(--panel); }
/* 열린 목록의 각 항목(지원 브라우저 한정) */
select option { background: var(--panel); color: var(--text); padding: 8px; }

/* ── 버튼 시스템 ───────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 9px; background: var(--primary); color: var(--on-primary); font-size: 14px; font-weight: 600;
  cursor: pointer; white-space: nowrap; line-height: 1; transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.06s ease, box-shadow 0.15s ease; }
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-strong); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-ok:hover { filter: brightness(1.06); }
.btn-secondary { background: var(--secondary); color: var(--secondary-text); border-color: var(--border); }
.btn-secondary:hover { background: var(--secondary-hover); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--secondary); color: var(--text); }
.btn-block { width: 100%; }
.btn-icon { width: 38px; padding: 0; }
.btn-icon svg { width: 18px; height: 18px; }
.btn-sm { height: 30px; padding: 0 11px; font-size: 12px; border-radius: 7px; }
/* 활성화/비활성화처럼 라벨 길이가 다른 토글 버튼 — 폭 고정으로 아래 버튼들까지 정렬 */
.btn-toggle { min-width: 74px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; text-align: center; }

/* 표 액션 버튼: 라인마다 위치가 흔들리지 않도록 정렬된 그리드 */
.row-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.row-actions .btn-sm { margin: 0; }

/* ── 툴바 ──────────────────────────────────────────────────── */
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
.toolbar .grow { flex: 1; min-width: 200px; }

/* ── 토글 스위치 ───────────────────────────────────────────── */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--muted); user-select: none; position: relative; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track { position: relative; width: 40px; height: 22px; border-radius: 999px; background: var(--badge-bg); transition: background-color 0.2s ease; flex-shrink: 0; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.35); transition: transform 0.2s ease; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--focus-ring); }

/* ── 커스텀 체크박스 (모달 내) ─────────────────────────────── */
#modal-body input[type="checkbox"] { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; margin: 0; padding: 0;
  border: 1.5px solid var(--border); border-radius: 6px; background: var(--panel); cursor: pointer; position: relative; flex-shrink: 0;
  transition: background-color 0.15s ease, border-color 0.15s ease; }
#modal-body input[type="checkbox"]:hover { border-color: var(--accent); }
#modal-body input[type="checkbox"]:checked { background: var(--primary); border-color: var(--primary); }
#modal-body input[type="checkbox"]:checked::after { content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px; border: solid var(--on-primary); border-width: 0 2px 2px 0; transform: rotate(45deg); }
#modal-body input[type="checkbox"]:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }

/* ── 테이블 ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
/* 기본은 한 줄 유지 — ID·시각·IP 같은 값이 좁은 칸에서 줄바꿈되어 밀리지 않게 한다.
   여러 줄이 필요한 값(JSON <pre>, .wrap 지정 칸)만 예외로 접는다. */
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--hairline); vertical-align: top; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
th { background: var(--panel-alt); color: var(--text); font-weight: 700; font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; position: sticky; top: 0; }
tbody tr { transition: background-color 0.12s ease; }
tbody tr:hover { background: var(--accent-soft); }
td.wrap { white-space: normal; }
td.mono { font-family: var(--mono); font-size: 12px; }
td .btn-sm { margin-right: 4px; margin-bottom: 2px; }
td pre { font-size: 11px; white-space: pre-wrap; word-break: break-all; max-width: 220px; max-height: 80px; overflow: auto; font-family: var(--mono); color: var(--muted); }
.truncate { max-width: 168px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-row td { text-align: center; color: var(--muted); padding: 28px; }

/* ── 행 클릭 복사 ─────────────────────────────────────────────
   데이터 행을 클릭하면 그 행의 값이 클립보드로 복사된다(버튼/입력 제외). */
.table-wrap tbody tr { cursor: copy; }
.table-wrap tbody tr.empty-row { cursor: default; }
tbody tr.row-copied { animation: row-flash 0.6s ease; }
@keyframes row-flash { 0%, 45% { background: var(--ok-soft); } 100% { background: transparent; } }
@media (prefers-reduced-motion: reduce) { tbody tr.row-copied { animation: none; } }

/* ── 페이지네이션 ──────────────────────────────────────────── */
.pager { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 16px; flex-wrap: wrap; }
.pager:empty { display: none; }
.pager button { min-width: 34px; height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); color: var(--text); font-size: 13px; font-family: var(--mono); cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease; }
.pager button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pager button.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 700; }
.pager button:disabled { opacity: 0.4; cursor: not-allowed; }
.pager .pager-info { color: var(--muted); font-size: 12px; margin: 0 8px; font-family: var(--mono); }
.pager .pager-ellipsis { color: var(--muted); padding: 0 4px; }

/* ── 모달 ──────────────────────────────────────────────────── */
#modal-backdrop { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; backdrop-filter: blur(2px); animation: fade 0.15s ease both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
#modal { width: 448px; max-width: 100%; max-height: 85vh; overflow-y: auto; margin: 0; box-shadow: var(--shadow-lg); animation: pop 0.18s ease both; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #modal-backdrop, #modal { animation: none; } }
#modal-body { display: flex; flex-direction: column; gap: 12px; margin: 18px 0; }
#modal-body label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
#modal-body label.checkbox-row { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ── 폼 그리드 ─────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.form-grid + .desc { margin-top: 16px; margin-bottom: 0; }

/* ── 토스트 ────────────────────────────────────────────────── */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-left: 3px solid var(--accent); padding: 12px 18px; border-radius: 10px; font-size: 14px; z-index: 200;
  max-width: calc(100vw - 32px); box-shadow: var(--shadow-lg); animation: toast-up 0.2s ease both; }
@keyframes toast-up { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) { #toast { animation: none; } }

/* ── 반응형 ────────────────────────────────────────────────── */
/* 태블릿: 인스트루먼트가 줄바꿈되면 세로 구분선 대신 가로 구분선 */
@media (max-width: 719px) {
  .instrument { border-right: none; border-bottom: 1px solid var(--hairline); }
  .instrument:last-child { border-bottom: none; }
}
/* 모바일: 헤더/탭 고정 해제(줄바꿈 시 겹침 방지), 여백 축소 */
@media (max-width: 640px) {
  header { padding: 10px 14px; flex-wrap: wrap; row-gap: 8px; position: static; }
  .header-right { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
  nav#tabs { position: static; padding: 0 8px; }
  main { padding: 16px 14px; }
  .panel { padding: 18px 16px; }
  .brand-sep, .brand-sub, .admin-email { display: none; }
  .brand-name { font-size: 15px; }
  #server-status { font-size: 11px; padding: 3px 8px; }
}
/* 좁은 화면: 툴바 컨트롤을 세로로 쌓아 가로 넘침 방지 */
@media (max-width: 560px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar > * { width: 100%; }
  .toolbar .grow { min-width: 0; }
  .toolbar .switch { justify-content: flex-start; }
  .control-row { flex-direction: column; align-items: stretch; }
  .control-row input[type="text"] { min-width: 0; }
  .control-row .btn { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
}
