*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #7c3aed;
  --primary-light: #a78bfa;
  --primary-dark: #6d28d9;
  --success: #22c55e;
  --warning: #fbbf24;
  --danger: #f43f5e;
  --bg: #fdf4ff;
  --card-bg: #ffffff;
  --text: #374151;
  --text-muted: #9ca3af;
  --border: #f3e8ff;
  --radius: 16px;
  --shadow: 0 2px 8px rgba(124,58,237,0.08);
  --shadow-md: 0 8px 20px rgba(124,58,237,0.14);
  --nav-height: 66px;
  --header-height: 54px;
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Zen Maru Gothic', sans-serif;
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  touch-action: manipulation;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(55,65,81,0.42);
  backdrop-filter: blur(6px);
}

.modal-content {
  width: min(90vw, 360px);
  padding: 28px 24px;
  text-align: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.modal-content h2 {
  margin-bottom: 20px;
  font-size: 1.22rem;
  font-weight: 700;
}

.modal-content h3 {
  margin-bottom: 16px;
  font-size: 1.12rem;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.modal-actions .btn {
  flex: 1;
}

.user-select-btns {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-card {
  text-align: left;
}

.auth-card h2 {
  text-align: center;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-link {
  display: block;
  width: 100%;
  margin-top: 16px;
  color: var(--primary-dark);
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
  background: transparent;
  border: 0;
  cursor: pointer;
}

/* Header */
header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--header-height);
  color: #fff;
  background: var(--primary);
  box-shadow: var(--shadow-md);
  transition: background 0.2s ease;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100%, 480px);
  height: 100%;
  margin: 0 auto;
  padding: 0 16px;
}

header h1 {
  font-size: 1.12rem;
  font-weight: 700;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-badge {
  padding: 3px 11px;
  color: #fff;
  font-size: 0.86rem;
  font-weight: 700;
  background: rgba(255,255,255,0.24);
  border-radius: 999px;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  color: #fff;
  font-size: 1.25rem;
  background: rgba(255,255,255,0.16);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease;
}

.btn-icon:hover {
  transform: scale(1.03);
  background: rgba(255,255,255,0.24);
}

.btn-icon:active {
  transform: scale(0.96);
}

/* Layout */
main {
  width: min(100%, 480px);
  margin: 0 auto;
  padding-top: calc(var(--header-height) + 14px);
  padding-bottom: calc(var(--nav-height) + 16px);
}

.tab-content {
  display: none;
  padding: 0 16px;
}

.tab-content.active {
  display: block;
}

/* Bottom Nav */
nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  display: flex;
  height: var(--nav-height);
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 18px rgba(124,58,237,0.08);
}

.nav-btn {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  gap: 3px;
  color: var(--text-muted);
  font-size: 0.62rem;
  font-weight: 700;
  background: none;
  border: 0;
  cursor: pointer;
  transition: color 0.16s ease, transform 0.16s ease;
}

.nav-btn.active {
  color: var(--primary);
}

.nav-btn:active {
  transform: scale(0.96);
}

.nav-btn svg {
  width: 21px;
  height: 21px;
}

.nav-btn span {
  white-space: nowrap;
}

.badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 20px);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--danger);
  border: 2px solid #fff;
  border-radius: 999px;
}

/* Hero Repaid */
.hero-repaid {
  padding: 24px 16px 16px;
  text-align: center;
}

.hero-label {
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.hero-amount {
  color: var(--success);
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.15;
  font-feature-settings: 'tnum';
}

/* Milestone */
.milestone-block {
  margin-bottom: 12px;
  padding: 16px 18px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.milestone-block.achieved {
  animation: milestone-celebrate 0.5s ease;
}

@keyframes milestone-celebrate {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.milestone-text {
  margin-bottom: 12px;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 700;
  text-align: center;
}

.milestone-highlight {
  color: var(--primary);
}

.milestone-achieved-text {
  color: var(--success);
  font-size: 0.92rem;
  font-weight: 700;
}

.progress-track {
  position: relative;
  height: 14px;
  overflow: hidden;
  background: var(--border);
  border-radius: 7px;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--primary-light), var(--success));
  border-radius: 7px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 30px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3));
  border-radius: 0 7px 7px 0;
}

.milestone-markers {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 500;
}

/* Secondary Stats */
.secondary-stats {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

.stat-mini {
  flex: 1;
  padding: 12px 14px;
  text-align: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-mini-label {
  display: block;
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 700;
}

.stat-mini-value {
  display: block;
  font-size: 0.92rem;
  font-weight: 700;
}

.stat-mini-total { color: var(--primary); }
.stat-mini-pending { color: #d97706; }

/* Shared card styles */
.item-card,
.comment-card,
.guide-card,
.chart-container {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.chart-container {
  padding: 12px;
}

/* Controls */
.filter-bar {
  display: flex;
  gap: 7px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.filter-btn {
  flex: 0 0 auto;
  padding: 7px 15px;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.16s ease, color 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.filter-btn:hover {
  transform: scale(1.03);
}

.filter-btn:active {
  transform: scale(0.96);
}

.filter-btn.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.list-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.list-controls input,
.list-controls select,
.form-group input,
.form-group textarea {
  color: var(--text);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.list-controls input,
.list-controls select {
  min-width: 0;
  padding: 10px 12px;
  font-size: 0.86rem;
}

.list-controls input {
  flex: 1 1 auto;
}

.list-controls select {
  flex: 0 0 150px;
}

.list-controls input:focus,
.list-controls select:focus,
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(167,139,250,0.22);
}

/* Items */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.item-card {
  padding: 14px 16px;
}

.item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}

.item-desc {
  flex: 1;
  min-width: 0;
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.item-amount {
  flex: 0 0 auto;
  color: var(--primary-dark);
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 9px;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 1.45;
}

.item-dates {
  flex-basis: 100%;
}

.status-tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 9px;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 12px;
}

.status-active { color: #1d4ed8; background: #dbeafe; }
.status-repaid { color: #15803d; background: #dcfce7; }
.status-pending_add { color: #6d28d9; background: #ede9fe; }
.status-pending_delete { color: #be123c; background: #ffe4e6; }
.status-pending_repay { color: #b45309; background: #fef3c7; }
.history-result-approved { color: #15803d; background: #dcfce7; }
.history-result-rejected,
.history-result-canceled { color: #4b5563; background: #e5e7eb; }

.approval-section {
  margin: 2px 0 10px;
}

.approval-history-section {
  margin-top: 20px;
}

.approval-section h2 {
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 700;
}

.approval-card {
  position: relative;
  overflow: hidden;
  padding-left: 20px;
}

.approval-card::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 6px;
  background: var(--primary);
}

.approval-card.action-add::before {
  background: #6366f1;
}

.approval-card.action-repay::before {
  background: #22c55e;
}

.approval-card.action-delete::before {
  background: #f43f5e;
}

.approval-card.result-muted::before {
  background: #9ca3af;
}

.item-actions {
  display: flex;
  gap: 7px;
  padding-top: 9px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
}

.item-actions .btn {
  padding: 6px 13px;
  font-size: 0.76rem;
}

.item-meta-inline {
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 30px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 20px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  background: var(--card-bg);
  border: 0;
  border-radius: 24px;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(124,58,237,0.08);
  transition: transform 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.btn:hover {
  transform: scale(1.03);
  box-shadow: 0 5px 12px rgba(124,58,237,0.14);
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  color: #fff;
  background: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  color: var(--primary-dark);
  background: var(--border);
}

.btn-success {
  color: #fff;
  background: var(--success);
}

.btn-danger {
  color: #fff;
  background: var(--danger);
}

.btn-outline {
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
}

.btn-block {
  width: 100%;
}

.btn-lg {
  min-height: 48px;
  padding: 14px 24px;
  font-size: 1rem;
}

.btn-sm {
  min-height: 30px;
  padding: 5px 12px;
  font-size: 0.75rem;
}

/* Forms */
.register-form,
.comment-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.register-form {
  padding: 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.comment-form {
  margin-bottom: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.form-group label {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 11px 14px;
  font-size: 1rem;
}

.form-group textarea {
  min-height: 96px;
  line-height: 1.55;
  resize: vertical;
}

.payer-toggle {
  display: flex;
  gap: 8px;
}

.payer-btn {
  flex: 1;
  min-width: 0;
  padding: 11px 12px;
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: transform 0.16s ease, color 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.payer-btn:hover {
  transform: scale(1.03);
}

.payer-btn:active {
  transform: scale(0.96);
}

.payer-btn.active {
  color: var(--primary);
  background: #f5f3ff;
  border-color: var(--primary-light);
}

/* Comments */
.comment-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.comment-card {
  padding: 12px 14px;
}

.comment-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 0.74rem;
  line-height: 1.4;
}

.comment-user {
  color: var(--primary);
  font-weight: 700;
}

.comment-body {
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.comment-delete-btn {
  display: block;
  margin: 10px 0 0 auto;
  padding: 4px 12px;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--danger);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease;
}

.comment-delete-btn:hover {
  transform: scale(1.03);
  background: #e11d48;
}

.comment-delete-btn:active {
  transform: scale(0.96);
}

/* Guide */
.guide-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.guide-card {
  padding: 14px 16px;
}

.guide-card h2 {
  margin-bottom: 6px;
  color: var(--primary-dark);
  font-size: 0.98rem;
  font-weight: 700;
}

.guide-card p {
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

/* Feedback */
.empty-state {
  padding: 40px 20px;
  color: var(--text-muted);
  text-align: center;
}

.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  left: 50%;
  z-index: 200;
  max-width: min(90vw, 420px);
  padding: 11px 18px;
  color: #fff;
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  background: var(--text);
  border-radius: 999px;
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 481px) {
  .hero-amount {
    font-size: 2.5rem;
  }

  .progress-track {
    height: 16px;
    border-radius: 8px;
  }

  .progress-fill {
    border-radius: 8px;
  }

  .secondary-stats {
    gap: 16px;
  }

  .stat-mini-value {
    font-size: 1.02rem;
  }
}
