/* 상담 데스크 — 색은 신호 체계처럼 씁니다: 호박색=대기, 초록=상담 중, 회색=종료 */
:root {
  --paper: #f3f5f2;
  --surface: #ffffff;
  --ink: #17232b;
  --muted: #5b6a73;
  --line: #d9dfdb;
  --wait: #c97a00;
  --wait-soft: #fff4dc;
  --go: #17795a;
  --go-soft: #e2f3ec;
  --stop: #b3372f;
  --action: #1f4fbf;
  --focus: #1f4fbf;
  --radius: 6px;
  font-family: Pretendard, "Noto Sans KR", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--paper); }
#app { height: 100%; display: flex; flex-direction: column; }
h1, h2, p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.button {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}
.button:hover:not(:disabled) { border-color: var(--ink); }
.button:disabled { opacity: 0.5; cursor: default; }
.button.primary { background: var(--action); border-color: var(--action); color: #fff; font-weight: 600; }
.button.danger { border-color: var(--stop); color: var(--stop); }
.button.quiet { border-color: transparent; background: none; color: inherit; }
.hint, .sub { color: var(--muted); font-size: 13px; }
.sub { display: block; }

/* ── 로그인 ── */
.login { flex: 1; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(360px, 100%); display: grid; gap: 14px; padding: 32px; background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--go); border-radius: var(--radius); }
.login-card h1 { font-size: 24px; letter-spacing: -0.02em; }
.login-lead { color: var(--muted); }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input, .field input, .field select, .stack input {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); font-size: 15px; min-width: 0;
}
.form-error { min-height: 1.5em; color: var(--stop); font-size: 13px; }

/* ── 상단 줄 ── */
.top { display: flex; align-items: center; gap: 16px; padding: 0 16px; min-height: 52px; background: var(--ink); color: #fff; flex-wrap: wrap; }
.brand { font-size: 17px; letter-spacing: -0.01em; }
.top-nav { display: flex; gap: 4px; flex: 1; }
.top-nav a { padding: 15px 10px; color: #b9c6cc; text-decoration: none; border-bottom: 3px solid transparent; }
.top-nav a.current { color: #fff; border-bottom-color: #4fd1a5; }
.alert-controls { display: flex; align-items: center; gap: 4px; }
.top .button.quiet { color: #dfe8ec; }
.top .button.quiet:hover { background: rgba(255, 255, 255, 0.12); }
.top .button[aria-pressed="false"] { color: #f2b84b; }
.top .hint { color: #f2b84b; }
.who { color: #b9c6cc; font-size: 13px; }

.view { flex: 1; min-height: 0; }

/* ── 상담 화면 ── */
.console { display: grid; grid-template-columns: 340px 1fr; }
.queue { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.queue-head { padding: 16px; border-bottom: 1px solid var(--line); display: grid; gap: 12px; }
.waiting-count { color: var(--muted); }
.waiting-number { font-size: 34px; font-weight: 700; line-height: 1; margin-right: 4px; color: var(--ink); font-variant-numeric: tabular-nums; }
.waiting-count.some .waiting-number { color: var(--wait); }
.tabs { display: flex; gap: 4px; }
.tab { flex: 1; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); cursor: pointer; }
.tab.current { background: var(--ink); border-color: var(--ink); color: #fff; }
.rows { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.queue-empty { padding: 24px 16px; color: var(--muted); }
.row { display: grid; gap: 4px; width: 100%; padding: 12px 16px; border: 0; border-bottom: 1px solid var(--line); border-left: 4px solid transparent; background: none; text-align: left; cursor: pointer; }
.row:hover { background: var(--paper); }
.row.selected { background: var(--paper); border-left-color: var(--ink); }
.row-waiting { background: var(--wait-soft); border-left-color: var(--wait); }
.row-top { display: flex; align-items: center; gap: 8px; }
.row-name { font-weight: 600; }
.row-site { margin-left: auto; color: var(--muted); font-size: 12px; }
.row-preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }

.pill { padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill-waiting { background: var(--wait); color: #fff; }
.pill-active { background: var(--go-soft); color: var(--go); }
.pill-closed { background: var(--paper); color: var(--muted); border: 1px solid var(--line); }

/* 자동 종료까지 남은 시간: 숫자와 줄어드는 막대 */
.timer { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.timer-track { width: 56px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.timer-fill { display: block; height: 100%; width: 100%; background: var(--go); transition: width 1s linear; }
.timer.urgent { color: var(--stop); font-weight: 600; }
.timer.urgent .timer-fill { background: var(--stop); }

.thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.thread-empty { margin: auto; max-width: 380px; padding: 24px; text-align: center; color: var(--muted); }
.thread-empty h2 { color: var(--ink); font-size: 20px; margin-bottom: 8px; }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.thread-title { flex: 1; min-width: 120px; }
.thread-title h2 { font-size: 17px; }
.thread-title p { color: var(--muted); font-size: 13px; }
.back { display: none; }
.thread-log { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: min(70%, 560px); }
.msg-text { padding: 9px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-meta { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.from-visitor { align-self: flex-start; }
.from-visitor .msg-text { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 2px; }
.from-agent { align-self: flex-end; text-align: right; }
.from-agent .msg-text { background: var(--go); color: #fff; border-bottom-right-radius: 2px; text-align: left; }
.from-system { align-self: center; max-width: none; color: var(--muted); font-size: 12px; }
.bot-log { align-self: stretch; padding: 10px 14px; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface); font-size: 13px; }
.bot-log summary { cursor: pointer; color: var(--muted); }
.log-line { margin-top: 8px; white-space: pre-wrap; color: var(--muted); }
.log-line b { display: inline-block; min-width: 36px; color: var(--ink); }
.log-visitor { color: var(--ink); }
.composer { display: flex; gap: 8px; padding: 12px 20px; background: var(--surface); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius); resize: none; font-size: 15px; }
.composer textarea:disabled { background: var(--paper); }

/* ── 관리 화면 ── */
.admin { overflow-y: auto; padding: 24px; display: grid; gap: 40px; align-content: start; max-width: 1000px; width: 100%; margin: 0 auto; }
.admin h2 { font-size: 20px; }
.admin .lead { color: var(--muted); margin: 4px 0 16px; }
.card { display: grid; gap: 12px; padding: 16px; margin-bottom: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card.inline { grid-template-columns: 1fr auto; align-items: end; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.code { margin: 0; padding: 12px; background: var(--ink); color: #e6edf0; border-radius: var(--radius); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 6px; color: var(--ink); font-size: 14px; }
.checks label { display: inline-flex; align-items: center; gap: 5px; }
.stack { display: grid; gap: 6px; }
.table-wrap { overflow-x: auto; margin-bottom: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.inactive td { opacity: 0.55; }

/* ── 실적 화면 ── */
.filter input[type="date"], .filter select { padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.filter .actions { align-items: center; }
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin: 0 0 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.figure { padding: 14px 16px; border-right: 1px solid var(--line); }
.figure:last-child { border-right: 0; }
.figure dt { color: var(--muted); font-size: 13px; }
.figure dd { margin: 2px 0 0; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.figure dd .sub { font-size: 12px; font-weight: 400; }
td.number { font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats-result .hint { margin-top: 8px; }

/* ── 알림 ── */
#toasts { position: fixed; right: 16px; top: 64px; display: grid; gap: 8px; z-index: 10; }
.toast { padding: 10px 14px; border-radius: var(--radius); background: var(--ink); color: #fff; max-width: 340px; }
.toast-error { background: var(--stop); }
.toast-warn { background: var(--wait); }

@media (max-width: 800px) {
  .console { grid-template-columns: 1fr; }
  .console .thread { display: none; }
  .console.show-thread .queue { display: none; }
  .console.show-thread .thread { display: flex; }
  .back { display: inline-block; }
  .msg { max-width: 86%; }
  .who { display: none; }
  .admin { padding: 16px; }
  .card.inline { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .timer-fill { transition: none; }
}
