* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 15px;
  color: inherit;
}

/* ---------- App shell ---------- */
#app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: filter 0.2s ease;
}
#app-shell.is-blurred {
  filter: blur(6px);
  pointer-events: none;
}

.topbar {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar__logo {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.outlet {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-3) 88px;
}

/* ---------- Navigation: bottom bar (mobile) <-> sidebar (desktop) ---------- */
.nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
}
.nav__item {
  position: relative;
}
.nav__link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  padding: var(--space-2);
  width: 100%;
  cursor: pointer;
  color: var(--color-text-muted);
}
.nav__item.is-active .nav__link {
  color: var(--color-primary);
}
.nav__icon { font-size: 20px; }
.nav__label { font-size: 10px; }

.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  z-index: 20;
}
.nav .nav__list { justify-content: space-around; }
.nav__more {
  position: absolute;
  bottom: 100%;
  right: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-2);
  width: 220px;
}
.nav__more .nav__list { flex-direction: column; }
.nav__more .nav__link { flex-direction: row; justify-content: flex-start; gap: var(--space-2); }

@media (min-width: 900px) {
  #app-shell { flex-direction: row; }
  .topbar { display: none; }
  .nav {
    position: sticky;
    top: 0;
    height: 100vh;
    width: 220px;
    border-top: none;
    border-right: 1px solid var(--color-border);
    flex-shrink: 0;
  }
  .nav__list { flex-direction: column; padding: var(--space-3); gap: 2px; }
  .nav__link { flex-direction: row; justify-content: flex-start; gap: var(--space-2); border-radius: var(--radius-sm); }
  .nav__item.is-active .nav__link { background: var(--color-bg); }
  .nav__more { position: static; width: auto; box-shadow: none; border: none; margin-top: var(--space-2); }
  .outlet { padding: var(--space-4); padding-bottom: var(--space-4); max-width: 720px; }
}

/* ---------- Page / cards / lists ---------- */
.page__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.page__header h2 { margin: 0; font-size: 20px; }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}
.card__label { margin: 0 0 4px; font-size: 13px; color: var(--color-text-muted); }
.card__value { margin: 0; font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 700; }
.card__value--income { color: var(--color-income); }
.card__value--expense { color: var(--color-expense); }
.card--networth { background: linear-gradient(135deg, var(--color-primary), #1e40af); color: #fff; border: none; }
.card--networth .card__label { color: rgba(255,255,255,0.8); }
.card--networth .card__value { color: #fff; }

.grid { display: grid; gap: var(--space-3); }
.grid--2 { grid-template-columns: 1fr 1fr; }

.card-list { display: flex; flex-direction: column; gap: var(--space-2); }

.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
}
.list-item--saving { flex-wrap: wrap; }
.list-item__dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.list-item__body { flex: 1; min-width: 0; }
.list-item__title { margin: 0; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item__sub { margin: 2px 0 0; font-size: 12px; color: var(--color-text-muted); }
.list-item__value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 700; font-size: 14px; white-space: nowrap; }
.list-item__actions { display: flex; gap: 6px; }
.list-item__actions button {
  border: none; background: var(--color-bg); border-radius: var(--radius-sm);
  padding: 6px 8px; font-size: 12px; cursor: pointer; color: var(--color-text-muted);
}
.list-item__actions button:hover { color: var(--color-primary); }

.simple-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.simple-list li { padding: 6px 0; border-bottom: 1px dashed var(--color-border); display: flex; justify-content: space-between; gap: 8px; }
.simple-list li:last-child { border-bottom: none; }
.simple-list button { border: none; background: none; color: var(--color-expense); cursor: pointer; }

.empty, .empty-note { color: var(--color-text-muted); font-size: 13px; }
.skeleton { color: var(--color-text-muted); }

.text-income { color: var(--color-income); font-family: var(--font-mono); }
.text-expense { color: var(--color-expense); font-family: var(--font-mono); }

.tabs { display: flex; gap: var(--space-2); margin-bottom: var(--space-3); }
.tab {
  border: 1px solid var(--color-border); background: var(--color-surface);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer; color: var(--color-text-muted);
}
.tab.is-active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }

.badge { font-size: 11px; padding: 3px 8px; border-radius: 999px; font-weight: 600; }
.badge--open { background: #fef3c7; color: #92400e; }
.badge--partial { background: #dbeafe; color: #1e40af; }
.badge--settled { background: #dcfce7; color: #166534; }

.progress { height: 8px; border-radius: 999px; background: var(--color-bg); overflow: hidden; margin-top: 6px; }
.progress__bar { height: 100%; background: var(--color-primary); border-radius: 999px; }
.progress__bar--over { background: var(--color-expense); }

.chart-wrap { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.legend { list-style: none; margin: 0; padding: 0; font-size: 12px; flex: 1; min-width: 140px; }
.legend li { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.legend__dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.export-row { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-3); }

/* ---------- Forms ---------- */
.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--color-border);
  border-radius: var(--radius-sm); background: var(--color-surface); color: var(--color-text);
  margin-bottom: var(--space-3);
}
.form { display: flex; flex-direction: column; gap: var(--space-3); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--color-text-muted); }
.field input, .field select, .field textarea {
  padding: 10px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  background: var(--color-bg); color: var(--color-text);
}
.field textarea { min-height: 60px; resize: vertical; }
.field--checkbox { flex-direction: row; align-items: center; gap: var(--space-2); }
.field--color input { padding: 2px; height: 36px; }
.form__error { color: var(--color-expense); font-size: 13px; margin: 0; }

.btn {
  border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text);
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; font-size: 13px;
}
.btn--primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn--danger { background: var(--color-expense); border-color: var(--color-expense); color: #fff; }
.btn--ghost { background: transparent; }
.btn:hover { opacity: 0.9; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100;
}
.modal {
  background: var(--color-surface); width: 100%; max-width: 480px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 90vh; overflow-y: auto;
  animation: slideUp 0.2s ease;
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius-lg); }
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal__header { display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border); }
.modal__header h3 { margin: 0; font-size: 16px; }
.modal__close { border: none; background: none; font-size: 16px; cursor: pointer; color: var(--color-text-muted); }
.modal__body { padding: var(--space-4); }
.modal__footer { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-top: 1px solid var(--color-border); }

/* ---------- Toast ---------- */
.toast-container { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 13px; opacity: 0; transition: opacity 0.25s ease, transform 0.25s ease; transform: translateY(8px);
  box-shadow: var(--shadow-md);
}
.toast--visible { opacity: 1; transform: translateY(0); }
.toast--success { background: #166534; }
.toast--error { background: #991b1b; }

/* ---------- Lock screen ---------- */
.lock-screen {
  position: fixed; inset: 0; background: var(--color-bg); z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.lock-screen__box { text-align: center; width: 260px; }
.lock-screen__title { font-size: 18px; font-weight: 700; margin-bottom: var(--space-4); }
.lock-screen__box input {
  width: 100%; padding: 12px; text-align: center; font-size: 20px; letter-spacing: 6px;
  border: 1px solid var(--color-border); border-radius: var(--radius-sm); margin-bottom: var(--space-3);
  background: var(--color-surface); color: var(--color-text);
}
.lock-screen__box .btn { width: 100%; }
.lock-screen__error { color: var(--color-expense); font-size: 13px; margin-top: var(--space-2); }
