/* 소상공인 운영허브 공통 스타일. 색은 모두 토큰으로만 쓴다(다크/라이트 자동 전환). */
:root {
  --bg: #f8fafc; --surface: #f1f5f9; --card: #fff; --card-hover: #f8fafc;
  --text: #0f172a; --muted: #475569; --faint: #94a3b8; --line: #e2e8f0;
  --primary: #2563eb; --primary-soft: #e0f2fe; --primary-text: #0284c7;
  --good: #059669; --bad: #e11d48; --danger: #e11d48;
  --purple: #7c3aed; --orange: #f97316; --emerald: #10b981;
  --side: #0e1321; --side-text: #cbd5e1;
  --hero: linear-gradient(90deg, #eff6ff, #f0f9ff, #eef2ff);
  --shadow: 0 1px 2px rgba(15, 23, 42, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #090e1c; --surface: #0e1321; --card: #161b2a; --card-hover: #1e2438;
    --text: #f8fafc; --muted: #94a3b8; --faint: #64748b; --line: rgba(255, 255, 255, .08);
    --primary-soft: rgba(37, 99, 235, .18); --primary-text: #38bdf8;
    --good: #10b981; --bad: #f43f5e; --purple: #8b5cf6; --orange: #ea580c;
    --side: #0e1321; --hero: linear-gradient(90deg, #13203f, #0f2236, #1a1a3a);
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #090e1c; --surface: #0e1321; --card: #161b2a; --card-hover: #1e2438;
  --text: #f8fafc; --muted: #94a3b8; --faint: #64748b; --line: rgba(255, 255, 255, .08);
  --primary-soft: rgba(37, 99, 235, .18); --primary-text: #38bdf8;
  --good: #10b981; --bad: #f43f5e; --purple: #8b5cf6; --orange: #ea580c;
  --side: #0e1321; --hero: linear-gradient(90deg, #13203f, #0f2236, #1a1a3a);
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Pretendard, system-ui, "Malgun Gothic", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* ── 뼈대: PC는 왼쪽 사이드바, 모바일은 하단 탭 ── */
.layout { display: flex; min-height: 100vh; }
.side { width: 232px; flex-shrink: 0; background: var(--side); color: #fff; padding: 16px 12px; display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 4px 6px; }
.brand i { width: 30px; height: 30px; border-radius: 10px; background: var(--primary); display: grid; place-items: center; font-style: normal; }
.brand small { font-size: 10px; padding: 2px 6px; border-radius: 4px; background: rgba(37, 99, 235, .3); color: #93c5fd; font-weight: 600; }
.tabs { display: flex; flex-direction: column; gap: 4px; }
.tabs button, .tabs a { display: flex; align-items: center; gap: 10px; text-align: left; padding: 10px 12px; border-radius: 12px; background: transparent; color: var(--side-text); border: none; text-decoration: none; font-weight: 500; }
.tabs button:hover, .tabs a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.tabs button.active { background: var(--primary); color: #fff; font-weight: 700; }
.tabs .ic { width: 20px; text-align: center; }
body:not(.authed) .tabs button { display: none; }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--line); min-height: 60px; }
.top .lead { color: var(--muted); font-size: 12px; margin-right: auto; }
#themeBtn { margin-left: auto; padding: 7px 10px; }
#userBox { display: flex; align-items: center; gap: 8px; font-size: 13px; }
main { width: 100%; max-width: 1200px; margin: 0 auto; padding: 24px; }

@media (max-width: 768px) {
  .layout { display: block; }
  .side { position: fixed; z-index: 10; bottom: 0; left: 0; right: 0; top: auto; width: auto; height: auto; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .brand { display: none; }
  .tabs { flex-direction: row; justify-content: space-around; }
  .tabs button, .tabs a { flex-direction: column; gap: 2px; font-size: 10px; padding: 6px 2px; flex: 1; text-align: center; white-space: nowrap; }
  .top { padding: 10px 16px; }
  .top .lead { display: none; }
  #userEmail { display: none; }
  main { padding: 16px 16px 96px; }
}

/* ── 공통 부품 ── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
h2 { font-size: 15px; margin: 0 0 12px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.grid textarea { grid-column: 1 / -1; }
input, select, textarea, button { font: inherit; padding: 9px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
button { background: var(--primary); color: #fff; border: none; cursor: pointer; font-weight: 600; }
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--primary-text); border: 1px solid var(--line); }
button.danger { background: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
.ghost-link { color: var(--primary-text); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; text-decoration: none; font-size: 13px; }
.hidden { display: none !important; }
.msg { padding: 10px 14px; border-radius: 12px; margin-bottom: 12px; background: var(--primary-soft); color: var(--primary-text); }
.msg.error { background: rgba(244, 63, 94, .12); color: var(--bad); }
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 12px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:hover { background: var(--card-hover); }
.list li small { color: var(--muted); display: block; }
.detail { white-space: pre-wrap; border-top: 2px solid var(--line); margin-top: 12px; padding-top: 12px; line-height: 1.6; }
.chips { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; }
.chips li.off { opacity: .45; text-decoration: line-through; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { color: var(--muted); font-weight: 600; background: var(--surface); }
th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.up { color: var(--good); } .down { color: var(--bad); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); }
.stat span { color: var(--muted); font-size: 12px; display: block; }
.stat b { display: block; font-size: 22px; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.stat small { display: block; color: var(--muted); font-size: 12px; }
.stat.good b { color: var(--good); }
.badge { padding: 4px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-text); font-size: 12px; font-weight: 600; }
details { margin-top: 8px; }
summary { cursor: pointer; color: var(--primary-text); }

/* ── 홈 대시보드 ── */
.hero { background: var(--hero); border: 1px solid var(--line); border-radius: 20px; padding: 28px; margin-bottom: 16px; }
.hero h1 { font-size: 22px; margin: 10px 0 6px; line-height: 1.4; }
.hero p { color: var(--muted); font-size: 13px; margin: 0; }
.services { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.svc { display: flex; flex-direction: column; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; color: var(--text); text-decoration: none; text-align: left; font-weight: 400; box-shadow: var(--shadow); }
.svc:hover { border-color: var(--accent); filter: none; }
.svc .tag { align-self: flex-start; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.svc b { font-size: 15px; }
.svc span:not(.tag) { color: var(--muted); font-size: 12px; line-height: 1.5; flex: 1; }
.svc em { font-style: normal; font-size: 12px; font-weight: 700; color: var(--accent); margin-top: 8px; }
.home-bottom { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.home-bottom .stats { margin: 0; }
@media (max-width: 960px) { .services { grid-template-columns: repeat(2, 1fr); } .home-bottom { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .stats { grid-template-columns: 1fr; } .hero { padding: 20px; } .hero h1 { font-size: 18px; } }
iframe.app { width: 100%; height: calc(100vh - 230px); min-height: 600px; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
@media (max-width: 768px) { iframe.app { height: calc(100vh - 260px); } }
.hint a { color: var(--primary-text); font-weight: 600; }

/* PR #33의 지원사업·상권분석 탭에 분석 화면 영역을 확보한다. */
body.authed .support-direct { display: none; }
body:is([data-tab="trade"], [data-tab="support"]) #loginView,
body:is([data-tab="trade"], [data-tab="support"]) #appView > .card:first-child { display: none; }
:is(#tab-trade, #tab-support) iframe.app { height: calc(100vh - 150px); background: var(--bg); }
@media (max-width: 768px) {
  :is(#tab-trade, #tab-support) iframe.app { height: calc(100vh - 175px); min-height: 480px; }
}

/* ── 월말정산 화면 부품 (Stitch 시안) ── */
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.card-head h2 { margin: 0; display: flex; align-items: center; gap: 8px; }
.card.flush { padding: 0; overflow: hidden; }
.card .pad { padding: 16px 20px 0; }
.card p.pad { padding: 0 20px 16px; margin: 8px 0 0; }
.card-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 20px; background: var(--surface); border-top: 1px solid var(--line); }
.eyebrow { display: block; font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.ic-chip { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: var(--primary-soft); font-size: 18px; }
.month-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.month-title { font-size: 18px; letter-spacing: -.02em; }
.badge.warn { background: rgba(245, 158, 11, .14); color: #b45309; }
:root[data-theme="dark"] .badge.warn { color: #fbbf24; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.warn { color: #fbbf24; } }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; justify-content: space-between; gap: 14px; }
.kpi.good { border-color: color-mix(in srgb, var(--good) 40%, var(--line)); }
.kpi-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.kpi-label { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.kpi-label::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--k); }
.kpi b { display: block; font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi.good b { color: var(--good); }
.kpi i { font-style: normal; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; font-weight: 800; color: var(--k); background: color-mix(in srgb, var(--k) 12%, transparent); }
.kpi-foot { border-top: 1px solid var(--line); padding-top: 10px; }
.kpi-foot small { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.bar { height: 6px; border-radius: 999px; background: var(--surface); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--k); transition: width .4s; }

.entry-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.entry-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.entry-form label.wide { grid-column: span 2; }
.entry-form .form-actions { display: flex; gap: 6px; }
.entry-form .form-actions button { flex: 1; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; }
.pill.income { background: var(--primary-soft); color: var(--primary-text); }
.pill.expense { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
td.amt { font-weight: 700; }
td.amt.income { color: var(--primary-text); }
td.amt.expense { color: var(--bad); }
td.amt.income::before { content: "+"; }
td.amt.expense::before { content: "-"; }
#entrySearch { min-width: 200px; }
.split { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; }
.split > .card { margin-bottom: 16px; min-width: 0; }
#catForm input { flex: 1; min-width: 0; }
@media (max-width: 960px) { .split { grid-template-columns: minmax(0, 1fr); } .kpis { grid-template-columns: 1fr; } .entry-form label.wide { grid-column: auto; } }

/* 모바일 월말정산: 거래 표를 카드 목록으로 (날짜·구분·분류·금액 / 메모 / 결제수단·버튼) */
@media (max-width: 560px) {
  #entryTable tr:first-child { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } /* 머리글은 화면에서만 숨김(읽기 도구용으로 남김) */
  #entryTable tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  #entryTable td { border: 0; padding: 0; white-space: normal; }
  #entryTable td.amt { margin-left: auto; font-size: 15px; }
  #entryTable td:nth-child(6) { order: 5; flex-basis: 100%; color: var(--muted); font-size: 12px; }
  #entryTable td:nth-child(5) { order: 6; font-size: 12px; color: var(--muted); }
  #entryTable td:nth-child(7) { order: 7; margin-left: auto; }
  #entryTable td[colspan] { flex-basis: 100%; }
  #entrySearch { min-width: 0; flex: 1; }
}

/* Stitch 모바일 정산: 수입·지출 2열, 순이익 전체 폭. 라이트는 순이익을 먼저 강조. */
@media (max-width: 560px) {
  #tab-settle .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  #tab-settle .kpi { padding: 14px; min-width: 0; }
  #tab-settle .kpi b { font-size: 19px; overflow-wrap: anywhere; }
  #tab-settle .kpi i { width: 22px; height: 22px; border-radius: 7px; flex-shrink: 0; }
  #tab-settle .kpi-foot small { font-size: 10px; }
  #tab-settle .kpi.good { grid-column: 1 / -1; order: -1; background: linear-gradient(115deg, #2563eb, #4f46e5); color: white; }
  #tab-settle .kpi.good b { color: white; font-size: 26px; }
  #tab-settle .kpi.good .kpi-label, #tab-settle .kpi.good small { color: #e0e7ff; }
  :root[data-theme="dark"] #tab-settle .kpi.good { order: 0; background: var(--card); }
  :root[data-theme="dark"] #tab-settle .kpi.good b { color: var(--good); }
}
@media (max-width: 560px) and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #tab-settle .kpi.good { order: 0; background: var(--card); }
  :root:not([data-theme="light"]) #tab-settle .kpi.good b { color: var(--good); }
}

/* 메인 시안의 소개 배너, 서비스 카드, 핵심 요약 */
.mobile-brand { display: none; }
body:not(.authed) .store-picker { display: none; }
.guest-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 14px; margin-bottom: 14px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--primary-soft);
}
.guest-bar p { margin: 0; color: var(--muted); font-size: 13px; }
.guest-bar b { color: var(--text); }
.home-hero { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.home-hero h1 { font-size: clamp(22px, 3vw, 34px); letter-spacing: -.045em; }
.hero-store {
  display: grid; place-items: center; width: 110px; height: 110px; flex-shrink: 0;
  border: 1px solid var(--line); border-radius: 28px; background: var(--card);
  box-shadow: var(--shadow); font-size: 50px;
}
.services-section h2 { margin: 0 0 10px; font-size: 17px; }
.services .svc { min-width: 0; gap: 10px; }
.svc .svc-top { display: flex; align-items: center; justify-content: space-between; flex: none; gap: 5px; }
.svc .svc-icon {
  display: grid; place-items: center; flex: none; width: 42px; height: 42px; border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 15%, var(--card)); font-size: 20px;
}
.svc .tag { align-self: center; color: var(--text); }
.svc .svc-copy { overflow-wrap: anywhere; }
.svc em { padding: 9px 4px; text-align: center; border-radius: 9px; background: var(--accent); color: white; }
.home-card-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 5px; margin-bottom: 12px; }
.home-card-head h2 { margin: 0; }
.home-actions { display: flex; flex-direction: column; gap: 6px; }
.home-actions h2 { margin-bottom: 5px; }
.home-actions button { display: flex; align-items: center; justify-content: space-between; text-align: left; }

@media (max-width: 768px) {
  .mobile-brand { display: block; font-size: 14px; }
  .hero-store { width: 64px; height: 64px; border-radius: 16px; font-size: 29px; }
}
@media (max-width: 560px) {
  .home-hero { align-items: flex-start; gap: 8px; padding: 16px; }
  .home-hero h1 { font-size: clamp(16px, 5vw, 22px); }
  .services { gap: 9px; }
  .services .svc { padding: 12px; gap: 8px; }
  .svc .svc-icon { width: 32px; height: 32px; font-size: 17px; }
  .svc b { font-size: 14px; }
  .svc em { font-size: 11px; }
  .home-bottom .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .home-bottom .stat:last-child { grid-column: 1 / -1; }
}

/* 모바일에서는 안내만 표시하고 데스크톱 진단 화면은 숨긴다. */
.place-mobile-notice { display: none; }
.place-mobile-notice a { color: var(--primary-text); overflow-wrap: anywhere; font-weight: 600; }
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
  .place-mobile-notice { display: block; }
  .place-desktop-view { display: none; }
}
