/* ============================================================
   스마트 가계부 · app.css — 레이아웃 · 컴포넌트
   ============================================================ */

/* ---------- 공통 컴포넌트 ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border: 1px solid var(--border-2);
  background: var(--surface); border-radius: var(--radius-sm);
  cursor: pointer; font-weight: 550; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 550; color: var(--muted); }
.input {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  background: var(--surface); outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 18px; }

.msg { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; }
.msg-error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.msg-ok    { background: color-mix(in srgb, var(--income) 14%, transparent); color: var(--income); }
.msg-info  { background: var(--surface-2); color: var(--muted); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: 12px; font-weight: 550; background: var(--surface-2); color: var(--muted);
}
.badge-accent { background: var(--accent-weak); color: var(--accent); }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.row   { display: flex; align-items: center; gap: 10px; }
.spacer{ flex: 1; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; font-weight: 600; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl td.r, table.tbl th.r { text-align: right; }

/* ---------- 중앙 정렬 화면 (로그인 / 가계부 선택) ---------- */

.centered {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.panel { width: 100%; max-width: 400px; }
.panel-wide { max-width: 520px; }
.brand { text-align: center; margin-bottom: 22px; }
.brand-mark { font-size: 30px; line-height: 1; }
.brand-name { font-size: 19px; font-weight: 700; margin-top: 8px; letter-spacing: -.02em; }
.brand-sub  { font-size: 13px; color: var(--muted); margin-top: 4px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.tabs-inline { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: var(--radius-sm); }
.tabs-inline button {
  flex: 1; padding: 7px; border: none; background: transparent;
  border-radius: 4px; cursor: pointer; font-weight: 550; color: var(--muted);
}
.tabs-inline button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- 앱 셸 ---------- */

.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--border); }
.sidebar-title { font-weight: 700; font-size: 15px; letter-spacing: -.02em; }
.sidebar-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav button {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border: none; background: transparent; border-radius: var(--radius-sm);
  cursor: pointer; text-align: left; color: var(--muted); font-weight: 550; width: 100%;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.on { background: var(--accent-weak); color: var(--accent); }
.nav .ico { width: 18px; text-align: center; font-size: 15px; }
.sidebar-foot { padding: 10px; border-top: 1px solid var(--border); font-size: 12px; color: var(--faint); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 20px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.content { padding: 20px; min-width: 0; }

.page-head { margin-bottom: 16px; }
.page-head h1 { margin-bottom: 4px; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.stat { padding: 14px 16px; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 550; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }

.empty {
  padding: 44px 20px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border-2); border-radius: var(--radius);
}
.empty .big { font-size: 30px; margin-bottom: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 3px 9px; border-radius: 99px; font-size: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
}

/* ---------- 설정 하위 탭 ---------- */

.subtabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border); margin-bottom: 16px; padding-bottom: 2px;
}
.subtabs button {
  padding: 8px 13px; border: none; background: transparent; cursor: pointer;
  color: var(--muted); font-weight: 550; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border-bottom: 2px solid transparent; margin-bottom: -3px; white-space: nowrap;
}
.subtabs button:hover { color: var(--text); background: var(--surface-2); }
.subtabs button.on { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- 표 편집기 ---------- */

.input-sm { padding: 5px 8px; font-size: 13px; }
table.editor td { vertical-align: middle; }
table.editor tr.editing { background: var(--accent-weak); }
table.editor tr.editing td { padding: 6px 8px; }
table.editor tbody tr:hover:not(.editing) { background: var(--surface-2); }

/* ---------- 드래그 앤 드롭 업로드 ---------- */

.dropzone {
  border: 2px dashed var(--border-2); border-radius: var(--radius);
  padding: 22px; margin-bottom: 16px; text-align: center; cursor: pointer;
  background: var(--surface); color: var(--muted);
  transition: border-color .15s, background .15s, transform .15s;
}
.dropzone:hover { border-color: var(--accent); background: var(--surface-2); }
.dropzone .dz-icon { font-size: 26px; line-height: 1; margin-bottom: 8px; }

.dragging .dropzone {
  border-color: var(--accent);
  background: var(--accent-weak);
  color: var(--accent);
  transform: scale(1.01);
}
.dragging .dropzone .dz-icon { transform: translateY(-2px); }

.spin {
  width: 16px; height: 16px; border: 2px solid var(--border-2);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav button { white-space: nowrap; }
}

/* ---------- KPI 클릭 → 상세 패널 ---------- */

.stat.clickable { cursor: pointer; transition: border-color .15s, transform .12s, box-shadow .15s; }
.stat.clickable:hover { border-color: var(--border-2); transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.stat.clickable .stat-label::after { content: ' ▸'; font-size: 10px; opacity: .5; }
.stat.open { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-weak); }
.stat.open .stat-label::after { content: ' ▾'; opacity: 1; color: var(--accent); }

.kpi-detail { margin-top: -4px; }
.kpi-detail .kpi-head {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px solid var(--border);
}

/* 카테고리 아코디언 */
.acc-item { border-bottom: 1px solid var(--border); }
.acc-item:last-child { border-bottom: none; }
.acc-head {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 4px; cursor: pointer; user-select: none;
}
.acc-head:hover { background: var(--surface-2); }
.acc-caret { width: 12px; font-size: 10px; color: var(--muted); transition: transform .15s; }
.acc-item.open .acc-caret { transform: rotate(90deg); }
.acc-dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.acc-name { font-weight: 600; }
.acc-count { font-size: 11px; color: var(--faint); }
.acc-bar {
  flex: none; width: 72px; height: 5px; border-radius: 99px;
  background: var(--surface-2); overflow: hidden;
}
.acc-bar > div { height: 100%; border-radius: 99px; }
.acc-body { display: none; padding: 2px 4px 12px 25px; }
.acc-item.open .acc-body { display: block; }
.acc-sub {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0; font-size: 12px; color: var(--muted);
}
.acc-sub + .acc-tx { margin-top: 2px; }
.acc-tx {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0 4px 12px; font-size: 12px;
  border-left: 2px solid var(--border);
}
.acc-tx:hover { background: var(--surface-2); }

/* ---------- 좁은 화면: 손가락으로 누를 수 있는 크기 ---------- */

@media (max-width: 760px) {
  /* 조작 요소는 최소 40px — 손가락으로 정확히 눌리는 크기 */
  .btn            { min-height: 40px; padding: 9px 14px; }
  .btn-sm         { min-height: 36px; padding: 8px 12px; }
  .input          { min-height: 42px; font-size: 16px; }   /* 16px = iOS 확대 방지 */
  .input-sm       { min-height: 38px; font-size: 15px; }
  select.input    { min-height: 42px; }

  input[type="checkbox"],
  input[type="radio"] { width: 20px; height: 20px; }

  .acc-head       { padding: 12px 4px; min-height: 44px; }
  .subtabs button { min-height: 42px; padding: 10px 14px; }
  .nav button     { min-height: 44px; }

  /* 표는 손가락 스크롤이 잘 먹도록 */
  table.tbl th, table.tbl td { padding: 10px 8px; }
  .card-pad { padding: 14px; }
  .content  { padding: 14px; }

  /* KPI 카드는 2열로 */
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-value { font-size: 19px; }

  /* 가로로 긴 필터 줄은 스크롤되게 */
  .page-head { flex-wrap: wrap; gap: 8px; }
}

@media (max-width: 420px) {
  .grid-4 { grid-template-columns: 1fr; }
}

/* ---------- 좁은 화면: 거래 표를 카드처럼 ---------- */

@media (max-width: 760px) {
  table.editor { display: block; }
  table.editor thead { display: none; }
  table.editor tbody { display: block; }

  table.editor tr {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "pick date   amt"
      "pick memo   memo"
      "pick cat    cat"
      "pick meta   act";
    gap: 2px 8px;
    align-items: center;
    padding: 10px 12px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
  }
  table.editor tr:hover:not(.editing) { background: var(--surface-2); }

  table.editor td { display: block; border: none; padding: 2px 0; }

  table.editor td.col-pick { grid-area: pick; padding-right: 4px; }
  table.editor td.col-date { grid-area: date; font-size: 12px; color: var(--muted); }
  table.editor td.col-memo { grid-area: memo; font-weight: 600; }
  table.editor td.col-amt  { grid-area: amt;  font-size: 16px; text-align: right; }
  table.editor td.col-act  { grid-area: act;  text-align: right; }

  /* 대분류·소분류·결제수단·명의·출처는 한 줄에 몰아 보여줍니다 */
  table.editor td[data-label="대분류"]   { grid-area: cat; }
  table.editor td[data-label="소분류"],
  table.editor td[data-label="결제수단"],
  table.editor td[data-label="명의"],
  table.editor td[data-label="출처"] {
    grid-area: meta; display: inline-block; font-size: 12px; margin-right: 8px;
  }

  /* 편집 중일 때는 위아래로 쌓고 항목 이름을 붙입니다 */
  table.editor tr.editing {
    display: block;
    background: var(--accent-weak);
  }
  table.editor tr.editing td {
    display: flex; align-items: center; gap: 10px; padding: 5px 0;
  }
  table.editor tr.editing td::before {
    content: attr(data-label);
    flex: none; width: 68px;
    font-size: 12px; color: var(--muted);
  }
  table.editor tr.editing td.col-pick { display: none; }
  table.editor tr.editing td:last-child { justify-content: flex-end; padding-top: 8px; }
  table.editor tr.editing td:last-child::before { content: none; }
}
