:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f0f2f5;
  --border: #dfe3e8;
  --text: #16191d;
  --text-dim: #5d656f;
  --accent: #2f6df6;
  --accent-text: #ffffff;
  --danger: #c2372b;
  --ok: #1f7a4d;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f24;
    --surface-muted: #23272d;
    --border: #2f343b;
    --text: #e9ecf1;
    --text-dim: #9aa3ae;
    --accent: #6c9bff;
    --accent-text: #10131a;
    --danger: #ef7a6d;
    --ok: #62c795;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
               "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

.view {
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.view-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 16px;
  padding-right: 16px;
}

/* 로딩 */
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
}

/* 카드 */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card + .card,
.card + .bucket,
#accounts-list + .card {
  margin-top: 16px;
}

.bucket + .bucket { margin-top: 16px; }

.card-muted {
  background: var(--surface-muted);
  box-shadow: none;
}

.card-empty { text-align: center; }

.card-login {
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.logo {
  margin: 0 0 8px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.lead {
  margin: 8px 0 16px;
  color: var(--text-dim);
}

.card-empty .lead { margin-bottom: 20px; }

.fineprint {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

/* 버튼 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:disabled { opacity: .55; cursor: default; }

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: var(--accent-text);
}

.btn-compact { width: auto; }

.btn-ghost {
  min-height: 34px;
  padding: 0 12px;
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
  font-weight: 500;
}

.btn-mini {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

/* 상단바 */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-brand { font-weight: 700; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-name {
  color: var(--text-dim);
  font-size: 13px;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 본문 */
.main {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.01em;
}

.page-sub {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 14px;
}

/* 버킷 */
.bucket-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bucket-note {
  margin: 2px 0 14px;
  color: var(--text-dim);
  font-size: 13px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
}

.summary {
  cursor: pointer;
  font-weight: 600;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
}

/* 계좌 줄 */
.account {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.stack > .account:first-child { border-top: 0; }

.dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.account-body {
  flex: 1 1 auto;
  min-width: 0;
}

.account-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.account-meta {
  color: var(--text-dim);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.account-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
}

.tag {
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.tag-debt {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
}

/* 대화상자 */
.dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(10, 13, 18, .45);
}

.dialog-body { padding: 24px; }

.dialog-title {
  margin: 0 0 20px;
  font-size: 18px;
  font-weight: 700;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

/* 입력 */
.field {
  display: block;
  margin-bottom: 16px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
}

.field-help {
  display: block;
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 400;
}

.optional {
  color: var(--text-dim);
  font-weight: 400;
}

.input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

select.input { padding: 0 8px; }

.input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
}

.check input { margin-top: 4px; }

.check .field-label { margin-bottom: 0; }

.radios {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.radios.is-locked { opacity: .55; }

.radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  font-size: 14px;
}

.radios.is-locked .radio { cursor: default; }

.swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
}

.swatch.is-on {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--surface) inset;
}

/* 메시지 */
.msg {
  margin: 16px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
}

.msg-error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  text-align: left;
}

#app-error { margin: 0 0 16px; }

@media (max-width: 420px) {
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .btn { width: 100%; }
  .account { flex-wrap: wrap; }
  .account-actions { width: 100%; justify-content: flex-end; }
}
