:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --shadow: 0 2px 10px rgba(17, 24, 39, 0.08);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}

body {
  min-height: 100dvh;
}

button, input, textarea {
  font-family: inherit;
  font-size: 16px;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.hidden {
  display: none !important;
}

#app {
  max-width: 460px;
  margin: 0 auto;
  padding: 0 14px calc(32px + var(--safe-bottom));
}

.view {
  display: none;
  animation: fadeIn 0.22s ease;
}

.view.active {
  display: block;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(14px + var(--safe-top)) 0 12px;
  background: var(--bg);
}

.title {
  flex: 1;
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 18px;
  color: var(--text);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.12s ease;
}

.icon-btn:active {
  transform: scale(0.92);
  background: var(--border);
}

.icon-spacer {
  width: 44px;
  flex: 0 0 44px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 14px 14px;
  min-height: 130px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  animation: fadeIn 0.25s ease;
}

.card:active {
  transform: scale(0.97);
}

.card-add {
  background: transparent;
  border: 2px dashed var(--border);
  box-shadow: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  text-align: center;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.card-add-icon {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  background: var(--blue-bg);
  color: var(--blue);
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-add-text {
  font-size: 14px;
  font-weight: 600;
}

.card-add:active {
  border-color: var(--blue);
  background: var(--blue-bg);
}

.card-head {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.card-name {
  flex: 1;
  font-weight: 700;
  font-size: 16px;
  padding-top: 4px;
  line-height: 1.25;
  word-break: break-word;
  padding-right: 4px;
}

.card-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 9px;
  background: var(--blue-bg);
  color: var(--blue);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-menu {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  margin: -6px -8px 0 0;
  border-radius: 50%;
  font-size: 15px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-menu:active {
  background: var(--border);
}

.card-stats {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  margin-top: auto;
}

.card-stat {
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.card-stat span:first-child {
  color: var(--muted);
}

.card-stat strong {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.green { color: var(--green); }
.red { color: var(--red); }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.big-btn i {
  margin-right: 7px;
  font-size: 0.92em;
}

.big-btn {
  width: 100%;
  min-height: 56px;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.3px;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.big-btn:active {
  transform: scale(0.97);
}

.big-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.big-btn.kirim {
  background: var(--green-bg);
  color: var(--green);
}

.big-btn.chiqim {
  background: var(--red-bg);
  color: var(--red);
}

.big-btn.save,
.big-btn.primary {
  background: var(--blue);
  color: #fff;
}

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

.big-btn.ghost {
  background: var(--bg);
  color: var(--text);
  box-shadow: none;
  border: 1px solid var(--border);
}

.summary {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  margin-bottom: 14px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 15px;
}

.summary-row span {
  color: var(--muted);
}

.summary-row strong {
  font-variant-numeric: tabular-nums;
}

.summary-row.total {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 10px;
  font-size: 17px;
}

.records {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.record {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: transform 0.12s ease;
  animation: fadeIn 0.2s ease;
}

.record:active {
  transform: scale(0.98);
}

.record-dot {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 12px;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.record-dot.green {
  background: var(--green-bg);
}

.record-dot.red {
  background: var(--red-bg);
}

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

.record-text {
  font-weight: 600;
  font-size: 16px;
  word-break: break-word;
}

.record-date {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.record-amount {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.editor {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.hint code {
  background: var(--card);
  padding: 2px 6px;
  border-radius: 6px;
}

.textarea, .input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  padding: 14px;
  font-size: 18px;
  line-height: 1.5;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease;
}

.textarea {
  min-height: 46dvh;
  max-height: 60dvh;
  resize: none;
}

.input {
  min-height: 52px;
  padding-right: 118px;
}

.input-wrap {
  position: relative;
  margin-bottom: 12px;
}

.input-date {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  opacity: 0.45;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.input-date:hover {
  opacity: 0.8;
}

.input-date:active {
  opacity: 1;
  background: var(--border);
}

.textarea:focus, .input:focus {
  border-color: var(--blue);
}

.error {
  background: var(--red-bg);
  color: var(--red);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 15px;
  white-space: pre-wrap;
  line-height: 1.45;
  animation: fadeIn 0.2s ease;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  font-size: 15px;
  line-height: 1.5;
}

.empty-icon {
  font-size: 40px;
  color: #c3c8d0;
  margin-bottom: 12px;
}

.empty i {
  color: #9aa1ac;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.4);
  z-index: 20;
  opacity: 0;
  animation: overlayIn 0.2s ease forwards;
}

@keyframes overlayIn {
  to { opacity: 1; }
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  max-width: 460px;
  margin: 0 auto;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(22px + var(--safe-bottom));
  box-shadow: 0 -4px 24px rgba(17, 24, 39, 0.15);
  animation: sheetIn 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes sheetIn {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 0 auto 14px;
}

.sheet-title {
  margin: 0 0 12px;
  font-size: 19px;
  font-weight: 700;
  word-break: break-word;
}

.sheet-text {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-item i {
  width: 22px;
  text-align: center;
  font-size: 16px;
  color: var(--muted);
  flex: 0 0 22px;
}

.menu-item.danger i {
  color: var(--red);
}

.menu-item {
  width: 100%;
  min-height: 54px;
  border-radius: 14px;
  background: var(--bg);
  font-size: 17px;
  font-weight: 600;
  text-align: left;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.12s ease;
}

.menu-item:active {
  background: var(--border);
}

.menu-item.danger {
  color: var(--red);
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 40;
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 15px;
  max-width: calc(100% - 32px);
  text-align: center;
  box-shadow: var(--shadow);
  animation: fadeIn 0.2s ease;
}
