:root {
  --ios-blue: #007AFF;
  --ios-bg: #F2F2F7;
  --ios-card: #FFFFFF;
  --ios-text: #000000;
  --ios-gray: #8E8E93;
  --ios-separator: #C6C6C8;
  --ios-danger: #FF3B30;
  --ios-green: #34C759;
  --ios-purple: #AF52DE;
  --ios-orange: #FF9500;
  --safe-area-bottom: env(safe-area-inset-bottom);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  margin: 0;
  background-color: var(--ios-bg);
  color: var(--ios-text);
  padding-bottom: 90px;
  /* Space for bottom nav */
  -webkit-tap-highlight-color: transparent;
}

header {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--ios-text);
  padding: 12px 16px;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1100;
  border-bottom: 0.5px solid var(--ios-separator);
}

/* Bottom Navigation */
.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--ios-separator);
  display: flex;
  justify-content: space-around;
  padding-bottom: var(--safe-area-bottom);
  z-index: 1000;
}

.tabs button {
  background: none;
  border: none;
  padding: 10px 0;
  color: var(--ios-gray);
  font-size: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.tabs button.active {
  color: var(--ios-blue);
}

.tabs button svg {
  width: 24px;
  height: 24px;
  /* stroke: currentColor; handled inline */
  fill: none;
}

/* Layout */
section {
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}

.hidden {
  display: none !important;
}

/* Cards */
.card {
  background: var(--ios-card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.card h3 {
  margin-top: 0;
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* Inputs */
input,
textarea,
select {
  width: 100%;
  padding: 12px;
  border: none;
  background: #E5E5EA;
  /* System Gray 5 */
  border-radius: 10px;
  font-size: 17px;
  font-family: inherit;
  box-sizing: border-box;
  margin-bottom: 12px;
  color: var(--ios-text);
}

input[type="radio"],
input[type="checkbox"] {
  width: auto;
  margin: 0 8px 0 0;
}

.radio-label {
  display: flex;
  align-items: center;
  font-size: 17px;
}

textarea:focus,
input:focus {
  outline: none;
  background: #D1D1D6;
}

/* Buttons */
.btn-primary {
  background: var(--ios-blue);
  color: white;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger {
  background: var(--ios-danger);
  color: white;
}

/* Action Buttons (Edit/Delete) */
.action-btn {
  background: #E5E5EA;
  /* Light gray circle */
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.action-btn:active {
  background: #D1D1D6;
}

.action-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
  pointer-events: none;
  /* Ensure click passes to button */
}

.action-btn.edit {
  color: var(--ios-blue);
}

.action-btn.delete {
  color: var(--ios-danger);
}


/* Notes List */
#notesList {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.note-item {
  background: var(--ios-card);
  padding: 16px;
  border-radius: 12px;
  border: none;
  /* box-shadow: 0 1px 3px rgba(0,0,0,0.1); */
}

.note-item strong {
  font-size: 17px;
  font-weight: 600;
  display: block;
  margin-bottom: 4px;
}

.note-item span {
  font-size: 15px;
  color: var(--ios-gray);
  display: block;
  line-height: 1.4;
}

/* Editor Modal (Full Screen Slide Up) */
#noteEditorOverlay,
#todoEditorOverlay,
#transactionModal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--ios-bg);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#noteEditorOverlay.open,
#todoEditorOverlay.open,
#transactionModal.open {
  transform: translateY(0);
}

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--ios-card);
  border-bottom: 0.5px solid var(--ios-separator);
}

.editor-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: var(--ios-bg);
  /* Ensure background is grey */
}

/* Header Buttons Fix */
.editor-header button {
  border: none;
  background: transparent;
}

/* iOS Inset Grouped List */
.ios-list {
  background: var(--ios-card);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 20px;
}

.ios-list-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--ios-card);
  border-bottom: 0.5px solid var(--ios-separator);
  min-height: 44px;
  /* Standard iOS row height */
}

.ios-list-item:last-child {
  border-bottom: none;
}

.ios-list-item label {
  width: auto;
  min-width: 80px;
  font-size: 17px;
  font-weight: 400;
  color: var(--ios-text);
  margin-right: 12px;
}

.ios-list-item input,
.ios-list-item select {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  font-size: 17px;
  color: var(--ios-blue);
  text-align: right;
  /* Allow text to utilize full width and wrap/overflow properly */
  min-width: 0;
  padding-right: 4px;
  /* Fix clipping */
}

.ios-list-item input::placeholder {
  color: var(--ios-gray);
}

/* Prominent Amount Input */
.amount-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 30px 0;
}

.amount-display input {
  background: transparent;
  border: none;
  font-size: 48px;
  font-weight: 700;
  text-align: center;
  width: 100%;
  color: var(--ios-text);
  margin: 0;
  padding: 10px;
}

/* iOS Segmented Control */
.ios-segmented-control {
  display: flex;
  background: #E5E5EA;
  /* System Gray 5 */
  border-radius: 9px;
  padding: 2px;
  margin-bottom: 24px;
}

.ios-segmented-control button {
  flex: 1;
  background: transparent;
  border: none;
  padding: 6px 0;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ios-text);
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}

.ios-segmented-control button.active {
  background: var(--ios-card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  /* Drop shadow for active segment */
  font-weight: 600;
}

/* Toast Notification */
#toast-notification {
  position: fixed;
  top: -100px;
  /* Start hidden above */
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 12px 24px;
  border-radius: 25px;
  font-size: 15px;
  font-weight: 500;
  z-index: 3000;
  transition: top 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

#toast-notification.show {
  top: 20px;
  /* Slide down to visible */
}

/* Custom Confirm Modal */
#confirmModal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

#confirmModal.open {
  opacity: 1;
  pointer-events: auto;
}

.confirm-box {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  width: 270px;
  border-radius: 14px;
  text-align: center;
  transform: scale(1.1);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

#confirmModal.open .confirm-box {
  transform: scale(1);
}

.confirm-text {
  padding: 20px 16px;
  font-size: 17px;
  font-weight: 600;
  color: var(--ios-text);
  border-bottom: 0.5px solid var(--ios-separator);
}

.confirm-actions {
  display: flex;
}

.confirm-actions button {
  flex: 1;
  background: transparent;
  border: none;
  font-size: 17px;
  padding: 12px 0;
  cursor: pointer;
  color: var(--ios-blue);
}

.confirm-actions button:first-child {
  border-right: 0.5px solid var(--ios-separator);
  font-weight: 400;
}

.confirm-actions button:last-child {
  font-weight: 600;
  color: var(--ios-danger);
}

.confirm-actions button:active {
  background: rgba(0, 0, 0, 0.05);
}

/* Calculator Buttons */
.calc-btn {
  background: #505050;
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 22px;
  font-weight: 400;
  padding: 0;
  aspect-ratio: 1;
  min-height: 60px;
  max-height: 60px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.calc-btn:active {
  opacity: 0.7;
}

.calc-btn.calc-operator {
  background: var(--ios-blue);
  font-size: 26px;
}

.calc-btn.calc-function {
  background: #A5A5A5;
  color: #000;
}

/* Split Modal */
#splitModal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--ios-bg);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#splitModal.open {
  transform: translateY(0);
}

/* Friend Card in Split */
.friend-card {
  background: var(--ios-card);
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.friend-balance {
  font-weight: 600;
  font-size: 16px;
}

.friend-balance.owes {
  color: var(--ios-danger);
}

.friend-balance.owed {
  color: var(--ios-green);
}

/* Split Checkbox */
.split-checkbox {
  display: flex;
  align-items: center;
  padding: 12px;
  background: var(--ios-card);
  border-radius: 10px;
  margin-bottom: 8px;
}

.split-checkbox input[type="checkbox"] {
  width: 24px;
  height: 24px;
  margin-right: 12px;
}

.split-checkbox label {
  flex: 1;
  font-size: 17px;
}

/* Group Modal */
#groupModal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--ios-bg);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#groupModal.open {
  transform: translateY(0);
}

/* Document Modal */
#documentModal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--ios-bg);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#documentModal.open {
  transform: translateY(0);
}

/* Filter Buttons */
.filter-btn {
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn.active {
  background: var(--ios-blue) !important;
  color: white !important;
}

/* Search Filter Buttons */
.search-filter-btn {
  cursor: pointer;
  transition: all 0.2s;
}

.search-filter-btn.active {
  background: var(--ios-blue) !important;
  color: white !important;
}