:root {
  --bg: #f5f4f0;
  --panel: #ffffff;
  --ink: #1d2230;
  --muted: #6b7180;
  --line: #e4e2dc;
  --side: #1d2230;
  --side-ink: #c9cdd8;
  --accent: #8a5a2b;
  --accent-ink: #ffffff;
  --accent-soft: #f4ebe1;
  --ok: #2f7d4f;   --ok-soft: #e4f3ea;
  --warn: #a8660c; --warn-soft: #fbefdc;
  --err: #b8322a;  --err-soft: #fbe5e3;
  --info: #2f5f9e; --info-soft: #e3ecf8;
  --wood: #2f8a4f;  --wood-soft: #e2f2e7;
  --fire: #c93a32;  --fire-soft: #fbe4e2;
  --earth: #b07d16; --earth-soft: #f8eed6;
  --metal: #6d7480; --metal-soft: #eceef1;
  --water: #234a86; --water-soft: #e1e9f6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 36, .06), 0 2px 8px rgba(20, 24, 36, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); }
code, .mono { font-family: "Cascadia Mono", Consolas, ui-monospace, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hanja { font-family: "Noto Serif KR", "Batang", "AppleMyungjo", serif; }

/* ---------- layout ---------- */
/* 사이드바 띠는 배경으로 깐다 — 긴 페이지에서도 왼쪽이 끝까지 이어진다 */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh;
  background: linear-gradient(to right, var(--side) 220px, transparent 220px); }
.side {
  background: var(--side); color: var(--side-ink);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; letter-spacing: -.01em; }
.brand small { display: block; color: var(--side-ink); font-weight: 400; font-size: 12px; opacity: .7; }
.side a {
  color: var(--side-ink); padding: 9px 12px; border-radius: 8px; display: flex;
  align-items: center; justify-content: space-between; gap: 8px;
}
.side a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.side a.on { background: rgba(255,255,255,.1); color: #fff; font-weight: 600; }
.side .pill { background: #d9a35b; color: #1d2230; border-radius: 99px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.side .grow { flex: 1; }
.side form button, .side .view-toggle { width: 100%; background: transparent; color: var(--side-ink); border: 1px solid rgba(255,255,255,.15); }
.side form button:hover, .side .view-toggle:hover { background: rgba(255,255,255,.06); color: #fff; }

.main { padding: 26px 32px 60px; min-width: 0; max-width: 1280px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 20px 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
/* 대운·세운 줄처럼 가로로 긴 내용이 칸을 밀어 넓히지 않게 (모바일 넘침 방지) */
.split > *, .grid > * { min-width: 0; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: inherit; }
.stat:hover { text-decoration: none; border-color: #cfc9bd; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.stat.alert .v { color: var(--err); }
.stat.hot .v { color: var(--accent); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #faf9f6; white-space: nowrap; }
tbody tr:hover { background: #fbfaf7; }
tbody tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
tr.clickable { cursor: pointer; }
.empty { padding: 36px; text-align: center; color: var(--muted); }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--metal-soft); color: var(--metal); }
.b-접수, .b-대기 { background: var(--info-soft); color: var(--info); }
.b-생성중, .b-실행중 { background: var(--warn-soft); color: var(--warn); }
.b-생성완료, .b-완료 { background: var(--ok-soft); color: var(--ok); }
.b-발송완료, .b-발송 { background: #e6e0f5; color: #5a3fa0; }
.b-오류, .b-실패 { background: var(--err-soft); color: var(--err); }
.b-보류, .b-취소, .b-미완 { background: var(--metal-soft); color: var(--metal); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.spin { display: inline-block; width: 10px; height: 10px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; margin-right: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- forms ---------- */
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
input[type=text], input[type=email], input[type=tel], input[type=date], input[type=time],
input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #d6d3cb; border-radius: 8px;
  background: #fff; color: var(--ink); font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #e4cfb6; border-color: var(--accent); }
.field { margin-bottom: 14px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.check { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; color: var(--ink); font-size: 13.5px; margin: 0 14px 0 0; cursor: pointer; }
.check input { margin: 0; }
.seg { display: inline-flex; border: 1px solid #d6d3cb; border-radius: 8px; overflow: hidden; }
.seg label { margin: 0; padding: 8px 14px; color: var(--ink); font-weight: 500; cursor: pointer; border-right: 1px solid #d6d3cb; }
.seg label:last-child { border-right: 0; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--accent); color: #fff; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 2px; margin: 0 0 16px; }
legend { font-weight: 700; padding: 0 6px; font-size: 13.5px; }

.btn, button {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 8px 14px; border-radius: 8px; border: 1px solid #d6d3cb; background: #fff;
  color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; line-height: 1.3;
}
.btn:hover, button:hover { text-decoration: none; background: #f7f5f1; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover, button.primary:hover { background: #774b20; }
.btn.danger, button.danger { color: var(--err); border-color: #eac3bf; }
.btn.danger:hover, button.danger:hover { background: var(--err-soft); }
.btn.sm, button.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.ghost, button.ghost { border-color: transparent; background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.filters > * { flex: 0 0 auto; }
.filters input[type=search] { width: 220px; }
.filters select, .filters input[type=date] { width: auto; }

/* ---------- flash ---------- */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 12px; font-weight: 500; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: #c6e5d1; }
.flash.error { background: var(--err-soft); color: var(--err); border-color: #f0c9c5; }
.flash.info { background: var(--info-soft); color: var(--info); border-color: #c8d8ef; }

/* ---------- key/value ---------- */
dl.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 14px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 12.5px; padding-top: 1px; }
dl.kv dd { margin: 0; word-break: break-all; }
.pre { white-space: pre-wrap; background: #faf9f6; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; max-height: 260px; overflow: auto; }

/* ---------- saju chart ---------- */
.saju { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; max-width: 520px; }
.pillar { text-align: center; }
.pillar .lbl { font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.pillar .god { font-size: 12px; color: var(--ink); min-height: 18px; font-weight: 600; }
.pillar .god.me { color: var(--accent); }
.cell {
  border-radius: 10px; padding: 8px 0 6px; margin: 4px 0; border: 1px solid transparent;
  font-family: "Noto Serif KR", "Batang", "AppleMyungjo", serif;
}
.cell .h { font-size: 34px; line-height: 1.1; font-weight: 700; }
.cell .k { font-size: 11.5px; font-family: inherit; opacity: .85; }
.cell.daymaster { box-shadow: inset 0 0 0 2px var(--accent); }
.el-wood { background: var(--wood-soft); color: var(--wood); }
.el-fire { background: var(--fire-soft); color: var(--fire); }
.el-earth { background: var(--earth-soft); color: var(--earth); }
.el-metal { background: var(--metal-soft); color: var(--metal); }
.el-water { background: var(--water-soft); color: var(--water); }
.hidden-stems { display: flex; gap: 3px; justify-content: center; margin-top: 4px; flex-wrap: wrap; }
.hidden-stems span { font-size: 12px; padding: 0 5px; border-radius: 5px; }
.stage { font-size: 12px; color: var(--muted); margin-top: 3px; }

.elements { display: grid; gap: 6px; max-width: 520px; }
.el-row { display: grid; grid-template-columns: 34px 1fr 30px; align-items: center; gap: 8px; font-size: 13px; }
.el-bar { height: 10px; border-radius: 99px; background: #efede8; overflow: hidden; }
.el-bar i { display: block; height: 100%; border-radius: 99px; }
.el-bar .wood { background: var(--wood); } .el-bar .fire { background: var(--fire); }
.el-bar .earth { background: var(--earth); } .el-bar .metal { background: var(--metal); }
.el-bar .water { background: var(--water); }

.luck { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; }
.luck .item { flex: 0 0 auto; width: 54px; text-align: center; border: 1px solid var(--line); border-radius: 9px; padding: 5px 0; background: #fff; }
.luck .item.now { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.luck .age { font-size: 11.5px; color: var(--muted); }
.luck .gj { font-family: "Noto Serif KR", "Batang", serif; font-size: 17px; font-weight: 700; line-height: 1.25; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12.5px; border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; background: #fff; }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--side); }
.auth .box { width: 100%; max-width: 360px; background: #fff; border-radius: 14px; padding: 28px 26px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.auth h1 { margin-bottom: 4px; }
.auth button { width: 100%; margin-top: 6px; padding: 11px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.on { color: var(--accent); border-color: var(--accent); }

.pager { display: flex; gap: 6px; justify-content: center; padding: 12px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
}
/* ---------- 모바일 화면 (html.m) ----------
   화면 폭이 아니라 html.m 클래스로 고른다. base.html 의 스크립트가 쿠키(view=auto|mobile|
   desktop)와 화면 폭을 보고 붙인다 — 휴대폰에서도 PC 화면을, PC 에서도 모바일 화면을 볼 수 있다. */
.topbar, .tabbar { display: none; }
.view-toggle { margin-bottom: 6px; }

html.m body { background: var(--bg); }
html.m .shell { display: block; background: none; }
html.m .side { display: none; }
html.m .topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  position: sticky; top: 0; z-index: 40; height: 52px; padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  background: var(--side); color: #fff;
}
html.m .topbar-brand { color: #fff; font-weight: 700; font-size: 16px; text-decoration: none; }
html.m .topbar .pill { background: #d9a35b; color: #1d2230; border-radius: 99px; font-size: 12px; font-weight: 700; padding: 3px 10px; text-decoration: none; }
html.m .tabbar {
  display: grid; grid-template-columns: repeat(5, 1fr);
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 16px rgba(20, 24, 36, .06);
}
html.m .tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: 58px; font-size: 11px; font-weight: 600; color: var(--muted); text-decoration: none;
}
html.m .tabbar a .ico { font-size: 19px; line-height: 1; }
html.m .tabbar a.on { color: var(--accent); }
html.m .tabbar a.new .ico {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 20px; margin-top: -4px;
}
html.m .main { padding: 14px 14px calc(84px + env(safe-area-inset-bottom)); max-width: none; }

html.m h1 { font-size: 20px; }
html.m .head { margin-bottom: 12px; }
html.m .head .actions { width: 100%; }
html.m .head .actions > * { flex: 1 1 auto; }
html.m .card { border-radius: 12px; margin-bottom: 12px; }
html.m .card:not(.flush) { padding: 16px; }
html.m .card.flush > h2 { padding: 14px 16px 0; }
html.m .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
html.m .stat { padding: 12px 14px; }
html.m .stat .v { font-size: 22px; }
html.m .split, html.m .g2, html.m .g3 { grid-template-columns: 1fr; gap: 12px; }
html.m dl.kv { grid-template-columns: 84px 1fr; }
html.m .filters { padding: 12px; }
html.m .filters > div { flex: 1 1 45%; }
html.m .filters > .search, html.m .filters > .filter-actions { flex-basis: 100%; }
html.m .filters.collapsible > .opt { display: none; }
html.m .filters.collapsible.open > .opt { display: block; }
html.m .filter-actions { display: flex; gap: 8px; }
html.m .filter-actions > * { flex: 1; }
html.m .filters input[type=search], html.m .filters select, html.m .filters input[type=date] { width: 100%; }
html.m .cell .h { font-size: 28px; }
html.m .hide-sm { display: none; }
/* 아이폰은 16px 보다 작은 입력칸에 들어가면 화면을 확대한다 */
html.m input, html.m select, html.m textarea { font-size: 16px; }
html.m .btn, html.m button { min-height: 40px; }
html.m .btn.sm, html.m button.sm { min-height: 34px; }

/* 표 → 카드 목록. 첫 줄은 이름(.t)과 상태(.end), 나머지는 아래 줄로 흐른다. */
html.m table.resp thead { display: none; }
html.m table.resp, html.m table.resp tbody { display: block; }
html.m table.resp tr {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
html.m table.resp tbody tr:last-child { border-bottom: 0; }
html.m table.resp td { display: block; padding: 0; border: 0; font-size: 13px; color: var(--ink); }
html.m table.resp td:empty, html.m table.resp td.hide-sm { display: none; }
/* 이름과 상태가 첫 줄을 꽉 채워야 나머지가 아랫줄로 내려간다 */
html.m table.resp td.t { order: -2; flex: 0 0 calc(100% - 96px); font-size: 15px; }
html.m table.resp td.end { order: -1; flex: 0 0 86px; text-align: right; }
html.m table.resp tr:not(:has(td.end)) td.t { flex-basis: 100%; }
html.m table.resp td[data-label]::before { content: attr(data-label) " "; color: var(--muted); font-size: 12px; }
html.m table.resp td.right { text-align: left; }
html.m table.resp td.actions { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 6px; text-align: left; white-space: normal; padding-top: 4px; }
html.m table.resp td.actions form.inline { display: contents; }

/* 주문 상세 — 휴대폰에서는 주문 정보·연락처를 사주팔자보다 먼저 */
html.m .detail-split > div:last-child { order: -1; }
html.m .detail-split { display: flex; flex-direction: column; align-items: stretch; }

/* 필터 펼치기 버튼은 모바일에서만 */
.filter-toggle { display: none; }
html.m .filter-toggle { display: inline-flex; }

/* 더보기 */
.menu-list a {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 16px;
  border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none;
}
.menu-list a:last-child { border-bottom: 0; }
.menu-list a span { font-weight: 600; font-size: 15px; }
.menu-list a small { color: var(--muted); font-size: 12.5px; }
.menu-list a:hover { background: #fbfaf7; }
.view-seg { display: flex; }
.view-seg label { flex: 1; text-align: center; }

/* 입금 확인 — 표 칸 안의 작은 폼 */
.inline-form { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 2px 0; }
.inline-form select { max-width: 100%; }
html.m .inline-form { display: flex; width: 100%; }
html.m .inline-form select[name=web_order_id] { flex: 1 1 100%; }
