:root {
  --primary: #16a34a;
  --primary-dark: #15803d;
  --primary-soft: #dcfce7;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  --radius: 14px;
  --nav-height: 68px;
  --app-max: 480px;
}

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, #f0fdf4 0%, var(--bg) 28%, #eef2f7 100%);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  max-width: var(--app-max);
  margin: 0 auto;
  min-height: 100%;
  background: var(--surface);
  box-shadow: 0 0 40px rgba(15, 23, 42, 0.06);
  position: relative;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 12px);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border: none;
  border-bottom: none;
  box-shadow: none;
  padding: 16px 18px 12px;
}

.list-header {
  padding-bottom: 8px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.tab-panel {
  display: none;
  padding: 16px 18px 8px;
  animation: fadeIn 0.22s ease;
}

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

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.form-label {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.form-control,
.form-select {
  border-radius: 12px;
  border-color: var(--border);
  padding: 0.75rem 0.9rem;
  font-size: 1rem;
  box-shadow: none !important;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15) !important;
}

.amount-input-wrap {
  position: relative;
}

.amount-input-wrap .currency {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-weight: 600;
  pointer-events: none;
}

.amount-input-wrap .form-control {
  padding-left: 32px;
  font-size: 1.25rem;
  font-weight: 700;
}

.person-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.person-row .form-select {
  flex: 1;
}

.btn-add-person {
  width: 48px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  border: 1px solid #bbf7d0;
  font-size: 1.25rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-add-person:hover,
.btn-add-person:focus {
  background: #bbf7d0;
  color: var(--primary-dark);
}

.upload-box {
  border: 1.5px dashed #cbd5e1;
  border-radius: var(--radius);
  padding: 14px;
  background: #f8fafc;
}

.upload-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-upload {
  border-radius: 12px;
  padding: 0.85rem 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-upload:active {
  transform: scale(0.98);
}

.image-preview {
  margin-top: 12px;
  display: none;
  position: relative;
}

.image-preview.visible {
  display: block;
}

.image-preview img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.btn-remove-image {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: rgba(15, 23, 42, 0.75);
  color: #fff;
  border-radius: 999px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary-app {
  background: var(--primary);
  border-color: var(--primary);
  border-radius: 14px;
  padding: 0.95rem 1rem;
  font-weight: 700;
  font-size: 1.05rem;
  width: 100%;
  box-shadow: 0 8px 20px rgba(22, 163, 74, 0.25);
}

.btn-primary-app:hover,
.btn-primary-app:focus {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.btn-primary-app:disabled {
  opacity: 0.7;
  box-shadow: none;
}

.filters {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.filter-select {
  border-radius: 14px !important;
  background: #fff;
  min-height: 46px;
}

.entry-list {
  display: grid;
  gap: 12px;
}

.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}

.entry-card:active {
  transform: scale(0.985);
}

.entry-card-main {
  min-width: 0;
}

.entry-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.entry-card-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.card-action-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 0.95rem;
}

.card-action-btn.edit {
  color: var(--primary-dark);
  background: var(--primary-soft);
  border-color: #bbf7d0;
}

.card-action-btn.delete {
  color: var(--danger);
  background: #fef2f2;
  border-color: #fecaca;
}

.entry-thumb {
  width: 72px;
  height: 72px;
  min-width: 72px;
  min-height: 72px;
  border-radius: 12px;
  object-fit: cover;
  background: #f1f5f9;
  display: block;
  flex-shrink: 0;
}

.entry-thumb.placeholder {
  display: flex !important;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 1.5rem;
  border: 1px dashed #cbd5e1;
}

.entry-amount {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary-dark);
  letter-spacing: -0.02em;
}

.entry-meta {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.entry-person {
  margin: 4px 0 0;
  font-weight: 600;
  font-size: 0.95rem;
}

.entry-notes {
  margin: 4px 0 0;
  color: #475569;
  font-size: 0.85rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}

.empty-state i {
  font-size: 2.4rem;
  color: #cbd5e1;
  display: block;
  margin-bottom: 10px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--app-max);
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  z-index: 40;
  box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.06);
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px;
}

.nav-btn i {
  font-size: 1.25rem;
}

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

.toast-container {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 24px));
  z-index: 1080;
  display: grid;
  gap: 8px;
}

.toast-msg {
  background: #0f172a;
  color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  animation: slideDown 0.25s ease;
}

.toast-msg.success {
  background: var(--primary-dark);
}

.toast-msg.error {
  background: var(--danger);
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.detail-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 100%;
  max-width: var(--app-max);
  margin-left: calc(var(--app-max) / -2);
  background: var(--surface);
  z-index: 50;
  transform: translateX(100vw);
  transition: transform 0.28s ease, visibility 0.28s ease;
  overflow-y: auto;
  padding-bottom: 24px;
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 480px) {
  .detail-panel {
    left: 0;
    margin-left: 0;
  }
}

.detail-panel.open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}

.detail-top {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 2;
}

.detail-top h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.btn-back {
  border: none;
  background: #f1f5f9;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.detail-body {
  padding: 18px;
}

.detail-amount {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary-dark);
  margin: 0 0 8px;
  letter-spacing: -0.03em;
}

.detail-image {
  width: 100%;
  border-radius: 14px;
  margin: 14px 0;
  max-height: 360px;
  object-fit: cover;
  box-shadow: var(--shadow);
}

.detail-image.placeholder {
  height: 180px;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 2rem;
}

.detail-row {
  margin-bottom: 14px;
}

.detail-row .label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 2px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-row .value {
  font-size: 1rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.bottom-sheet .modal-dialog {
  margin: 0;
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translate(-50%, 100%);
  width: 100%;
  max-width: var(--app-max);
}

.bottom-sheet.show .modal-dialog {
  transform: translate(-50%, 0);
}

.bottom-sheet .modal-content {
  border-radius: 20px 20px 0 0;
  border: none;
  box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.15);
}

.bottom-sheet .modal-header {
  border-bottom: 1px solid var(--border);
  padding: 16px 18px 10px;
}

.bottom-sheet .modal-body {
  padding: 10px 18px 8px;
}

.bottom-sheet .modal-footer {
  border-top: none;
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom, 0px));
}

.sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: #cbd5e1;
  margin: 0 auto 10px;
}

.spinner-border-sm {
  width: 1rem;
  height: 1rem;
  border-width: 0.15em;
}

.load-more-wrap {
  padding: 8px 0 16px;
}

#galleryInput,
#cameraInput,
#editGalleryInput,
#editCameraInput {
  display: none;
}

.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.btn-edit-entry,
.btn-delete-entry {
  border-radius: 12px;
  padding: 0.85rem 0.75rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-edit-entry {
  background: var(--primary-soft);
  border: 1px solid #bbf7d0;
  color: var(--primary-dark);
}

.btn-delete-entry {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
}

@media (min-width: 481px) {
  body {
    padding: 12px 0;
  }

  .app-shell {
    min-height: calc(100vh - 24px);
    border-radius: 20px;
    overflow: hidden;
  }

  .bottom-nav,
  .detail-panel {
    border-radius: 0 0 20px 20px;
  }
}
