/* ============================================================
   레이아웃 · 공통 컴포넌트
   색은 전부 themes.css 의 CSS 변수만 사용한다.
   ============================================================ */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.45;
}
button { font-family: inherit; }
a { color: var(--accent); }

/* ---------- 상단바(모바일 전용) ---------- */
.topbar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--accent);
  color: var(--on-accent);
  position: sticky; top: 0; z-index: 40;
}
.topbar-title { font-weight: 700; flex: 1; }
.icon-btn {
  background: rgba(255,255,255,.18);
  color: var(--on-accent);
  border: none; border-radius: 10px;
  width: 38px; height: 38px; font-size: 18px; cursor: pointer;
}
.sync-pill {
  font-size: 12px; font-weight: 600;
  background: rgba(255,255,255,.18); color: var(--on-accent);
  padding: 6px 10px; border-radius: 999px; white-space: nowrap;
}

/* ---------- 레이아웃 ---------- */
.layout { display: flex; min-height: 100%; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px 14px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; font-size: 20px;
}
.brand-name { font-weight: 800; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--text-weak); }

.nav { display: flex; flex-direction: column; gap: 3px; padding: 8px 12px; flex: 1; overflow: auto; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 13px; border: none; background: transparent;
  color: var(--text); text-align: left; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14.5px; font-weight: 600;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--accent); color: var(--on-accent); }
.nav-ico { width: 20px; text-align: center; }
.nav-sep { height: 1px; background: var(--border); margin: 8px 6px; }
.nav-grp { font-size: 11px; font-weight: 800; color: var(--text-weak); text-transform: none; letter-spacing: .3px; padding: 12px 14px 4px; }

/* AI 비서 알림 */
.ai-alert { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; cursor: pointer; background: var(--surface-2); font-size: 14px; }
.ai-alert:hover { border-color: var(--accent); }
.ai-ico { font-size: 17px; }

/* 상세페이지 템플릿 선택 */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tpl-card { text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 14px; cursor: pointer; }
.tpl-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.tpl-emoji { font-size: 26px; }
.tpl-name { font-weight: 800; margin-top: 6px; }
.tpl-desc { font-size: 12.5px; color: var(--text-weak); margin-top: 4px; }

/* 마케팅 공유 출력 */
.mk-out { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; font-size: 13.5px; line-height: 1.6; margin: 10px 0 0; font-family: var(--font); max-height: 260px; overflow: auto; }

/* 매뉴얼 */
.help-body ul { margin: 2px 0; padding-left: 20px; }
.help-body li { margin: 6px 0; line-height: 1.6; }

.sidebar-foot { padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.sync-status { font-size: 12px; color: var(--text-weak); margin-bottom: 10px; }
.theme-row { display: flex; flex-wrap: wrap; gap: 7px; }
.theme-dot {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border); cursor: pointer; padding: 0;
}
.theme-dot.sel { outline: 2px solid var(--accent); outline-offset: 2px; }

.content { flex: 1; min-width: 0; padding: 26px 30px 60px; max-width: 1180px; }

.scrim { display: none; }

/* ---------- 공통 요소 ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 800; margin: 0; }
.page-sub { color: var(--text-weak); font-size: 13.5px; margin-top: 3px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

/* 하위 탭 */
.tabbar { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab { border: none; background: transparent; color: var(--text-weak); padding: 10px 15px; font-size: 14px; font-weight: 700; cursor: pointer; border-bottom: 2px solid transparent; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }

/* 상세페이지 편집기 */
.editor-top { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.editor-grid { display: grid; grid-template-columns: minmax(300px, 1fr) minmax(300px, 1.05fr); gap: 18px; align-items: start; }
.block-card { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); padding: 9px 11px; margin-bottom: 8px; }
.block-card .bc-type { font-weight: 800; font-size: 12px; color: var(--accent); min-width: 58px; }
.block-card .bc-sum { flex: 1; min-width: 0; color: var(--text-weak); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.block-card .bc-ops { display: flex; gap: 3px; flex-wrap: nowrap; }
.preview-canvas { background: #fff; color: #222; border: 1px solid var(--border); border-radius: 10px; padding: 18px; overflow: auto; max-height: 74vh; }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
@media (max-width: 980px) { .editor-grid { grid-template-columns: 1fr; } }

/* 월간 달력 */
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.cal-title { font-weight: 800; font-size: 18px; min-width: 92px; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-wd { margin-bottom: 6px; }
.cal-wdcell { text-align: center; font-size: 12.5px; font-weight: 700; padding: 4px 0; }
.cal-cell { min-height: 80px; border: 1px solid var(--border); border-radius: 8px; padding: 5px 6px; background: var(--surface-2); cursor: pointer; overflow: hidden; }
.cal-cell.empty { background: transparent; border-color: transparent; cursor: default; }
.cal-cell:hover:not(.empty) { border-color: var(--accent); }
.cal-cell.today { background: var(--surface); box-shadow: inset 0 0 0 2px var(--accent); }
.cal-cell.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.cal-num { font-size: 12.5px; font-weight: 700; margin-bottom: 3px; }
.cal-ev { font-size: 11px; background: var(--accent); color: var(--on-accent); border-radius: 4px; padding: 1px 5px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev b { font-weight: 700; }
.cal-more { font-size: 10.5px; color: var(--text-weak); }
@media (max-width: 860px) { .cal-cell { min-height: 58px; } .cal-ev { font-size: 10px; padding: 1px 3px; } }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 14px; font-weight: 600; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px; }

/* KPI 카드 */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--gap); margin-bottom: var(--gap); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .k-label { font-size: 13px; color: var(--text-weak); font-weight: 600; }
.kpi .k-value { font-size: 25px; font-weight: 800; margin-top: 6px; letter-spacing: -.3px; }
.kpi .k-sub { font-size: 12px; color: var(--text-weak); margin-top: 4px; }
.kpi.accent { background: var(--accent); border-color: var(--accent); }
.kpi.accent .k-label, .kpi.accent .k-value, .kpi.accent .k-sub { color: var(--on-accent); }
.pos { color: var(--good); } .neg { color: var(--bad); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.section-title { font-size: 15px; font-weight: 800; margin: 2px 0 12px; }

/* 테이블 */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { padding: 10px 11px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data th { color: var(--text-weak); font-weight: 700; font-size: 12.5px; background: var(--surface-2); position: sticky; top: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:hover td { background: var(--surface-2); }
.pill { display:inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--text-weak); border: 1px solid var(--border); }

/* 폼 */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--text-weak); }
.input, select.input, textarea.input {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 9px 11px; font-size: 14px; width: 100%;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.help { font-size: 12.5px; color: var(--text-weak); }

/* 막대그래프(SVG) */
.chart-card { padding: 16px 18px; }
.chart-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-weak); margin-top: 8px; flex-wrap: wrap; }
.lg-dot { display:inline-block; width:10px; height:10px; border-radius:3px; margin-right:6px; vertical-align: middle; }

/* 안내 배너 */
.banner { border: 1px dashed var(--border); background: var(--surface-2); border-radius: var(--radius); padding: 14px 16px; color: var(--text-weak); font-size: 13.5px; }
.placeholder { text-align:center; padding: 56px 20px; color: var(--text-weak); }
.placeholder .big { font-size: 40px; margin-bottom: 10px; }

/* 모달 */
.modal-root { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; background: rgba(0,0,0,.42); padding: 18px; }
.modal-root[hidden] { display: none; }   /* hidden 속성을 CSS가 덮어쓰지 않도록(클릭 가로채기 방지) */
.modal { background: var(--panel); color: var(--text); border-radius: var(--radius-lg); box-shadow: var(--shadow-pop); width: min(560px, 100%); max-height: 88vh; overflow: auto; }
.modal-head { display:flex; align-items:center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); position: sticky; top:0; background: var(--panel); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display:flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; background: var(--panel); }

/* 상태 알약(StatusPill) — bg+fg 토큰 (디자인시스템) */
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: transparent; }
.pill.bad { background: var(--bad-bg); color: var(--bad-fg); border-color: transparent; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 600; z-index: 100; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* 넓은 표 → 휴대폰 카드형 (table.data.rtable) */
@media (max-width: 600px) {
  table.data.rtable thead { display: none; }
  table.data.rtable, table.data.rtable tbody, table.data.rtable tr, table.data.rtable td { display: block; width: 100%; }
  table.data.rtable tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 4px 12px; background: var(--surface); }
  table.data.rtable tr:hover td { background: transparent; }
  table.data.rtable td { border: none; padding: 7px 0; display: flex; align-items: center; justify-content: space-between; gap: 14px; text-align: right; white-space: normal; }
  table.data.rtable td::before { content: attr(data-label); color: var(--text-weak); font-weight: 700; font-size: 12.5px; text-align: left; flex: 0 0 auto; }
  table.data.rtable td.num { text-align: right; }
  table.data.rtable td:last-child { justify-content: flex-end; border-top: 1px solid var(--border); padding-top: 10px; margin-top: 2px; }
  table.data.rtable td:last-child::before { display: none; }
}

/* ---------- 반응형: 휴대폰 ---------- */
@media (max-width: 860px) {
  .topbar { display: flex; }
  .content { padding: 18px 16px 70px; }
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 60;
    transform: translateX(-104%); transition: transform .22s ease;
    height: 100vh; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; }
  .kpi .k-value { font-size: 22px; }
}
