:root {
  color-scheme: light;
  --text: #31333f;
  --muted: #555;
  --line: #f0f2f6;
  --green: #28a745;
  --red: #ff4b4b;
  --blue: #007bff;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: #fff;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  line-height: 1.5;
}
#main, .login { max-width: 730px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.25rem; margin: 20px 0 10px; }
button, select, input { font: inherit; color: inherit; }
button {
  background: #fff; border: 1px solid #d6d6d9; border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
button:active { background: var(--line); }
.muted { color: var(--muted); }
.error { color: #c62828; min-height: 1.5em; margin: 0; }
hr { border: 0; border-top: 1px solid #e6e6ea; margin: 24px 0; }

/* 로그인 */
.login { display: flex; flex-direction: column; gap: 12px; padding-top: 20vh; }
.login input { padding: 10px 12px; border: 1px solid #d6d6d9; border-radius: 8px; }
.login button { padding: 10px; background: var(--green); border-color: var(--green); color: #fff; font-weight: bold; }

/* 머리 */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.top button { flex-shrink: 0; }
.status { font-size: 0.8rem; color: var(--muted); margin: 4px 0 8px; min-height: 1.2em; }
.status.stale { color: #c62828; }

/* 탭 */
.tabs { display: flex; border-bottom: 1px solid #e6e6ea; }
.tabs button {
  flex: 1 1 0; min-width: 0; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none;
  padding: 8px 4px; font-size: 0.9rem; line-height: 1.3; word-break: keep-all;
}
.tabs button[aria-selected="true"] { border-bottom-color: var(--red); color: var(--red); }
#form { width: 100%; border: 0; display: block; }

/* 대시보드: 막대그래프 */
.bars { display: grid; grid-template-columns: minmax(0, 40%) 1fr auto; gap: 6px 8px; align-items: center; font-size: 0.85rem; }
.bar-label { overflow-wrap: anywhere; }
.bar-track { background: var(--line); border-radius: 3px; height: 14px; }
.bar-fill { background: #83c9ff; height: 100%; border-radius: 3px; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }

/* 대시보드: 분류 카드 */
.cat { margin-bottom: 18px; }
.cat-title b { font-size: 1.1rem; }
.cat-title span { font-size: 0.9rem; }
.cat-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
/* 빨강은 예산의 120%까지 그려지므로 회색 칸을 1/1.2로 줄여 넘친 부분이 옆 상자를 덮지 않게 한다 */
.track-wrap { flex: 1; min-width: 0; }
.track { width: calc(100% / 1.2); position: relative; background: var(--line); border-radius: 4px; height: 18px; }
.track > div { position: absolute; top: 0; height: 100%; border-radius: 4px; }
.track .green { left: 0; background: var(--green); }
.track .red { background: var(--red); }
.track .marker { top: -2px; width: 2px; height: 22px; background: var(--blue); border-radius: 1px; z-index: 1; }
.badge {
  width: 155px; flex-shrink: 0; height: 55px; padding: 4px; border-radius: 6px; border: 1px solid;
  display: flex; flex-direction: column; justify-content: center; text-align: center; line-height: 1.25;
}
.badge .b1 { font-size: 12px; font-weight: bold; color: #111; }
.badge .b2 { font-size: 11px; color: var(--muted); }
.badge .b3 { font-size: 9px; font-weight: bold; white-space: nowrap; margin-top: 2px; }
.badge.saving { background: #e8f5e9; border-color: var(--green); }
.badge.saving .b3 { color: #2e7d32; }
.badge.over { background: #ffebee; border-color: var(--red); }
.badge.over .b3 { color: #c62828; }
.badge.unset { background: var(--line); border-color: #ccc; }
.badge.unset .b3 { color: var(--muted); }

/* 전체 내역 */
.month-nav { display: grid; grid-template-columns: 1fr 2fr 2fr 1fr; gap: 8px; margin-top: 12px; }
.month-nav select { padding: 6px; border: 1px solid #d6d6d9; border-radius: 8px; background: #fff; }
.table-wrap { overflow-x: auto; border: 1px solid #e6e6ea; border-radius: 6px; max-height: 420px; }
table { border-collapse: collapse; font-size: 0.8rem; width: 100%; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; text-align: left; }
th { background: #fafafa; position: sticky; top: 0; font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* 캘린더 */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-head { font-weight: bold; font-size: 11px; padding: 6px 0; background: var(--line); border-radius: 3px; text-align: center; color: var(--muted); }
.cal-day {
  border: 1px solid var(--line); border-radius: 3px; min-height: 45px; padding: 4px 0;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
}
.cal-day.today { border: 1.5px solid var(--blue); background: #e6f3ff; font-weight: bold; }
.cal-day .day { font-size: 12px; color: #333; }
.cal-day .amt { font-size: 10px; color: var(--red); font-weight: bold; white-space: nowrap; margin-top: 2px; }
.cal-day .none { font-size: 10px; color: #ccc; }
.link-btn {
  display: inline-block; padding: 8px 14px; border: 1px solid #d6d6d9; border-radius: 8px;
  color: inherit; text-decoration: none;
}
