:root {
  --bg: #F5F0EB;
  --surface: #FFFFFF;
  --primary: #E86030;
  --primary-light: #FDF0E0;
  --text: #2D2D2D;
  --text-muted: #6B6B6B;
  --border: #E8E0D8;
  --green: #5A9A5A;
  --yellow: #E8B830;
  --red: #D94A4A;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --radius: 12px;
  --bottom-h: 64px;
  --nav-h: 48px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, sans-serif;
  background: var(--bg); color: var(--text);
  width: 100%; min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
#iou-app {
  display: flex; flex-direction: column;
  min-height: 100vh; max-width: 480px;
  margin: 0 auto;
}
.iou-screen { display: none; flex-direction: column; flex: 1; }
.iou-screen.active { display: flex; }

/* ─── Status bar ─── */
.iou-status {
  display: flex; justify-content: center; align-items: center;
  padding: 10px 20px; font-size: 14px; font-weight: 700;
  color: var(--primary); background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.iou-status .version {
  font-size: 10px; font-weight: 600; color: var(--text-muted);
  margin-left: 6px;
}

/* ─── Navbar ─── */
.iou-nav {
  display: flex; align-items: center;
  padding: 0 16px; height: var(--nav-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.iou-nav .tabs { display: flex; gap: 16px; flex: 1; }
.iou-nav .tab {
  padding: 8px 0; font-size: 14px; font-weight: 600;
  color: var(--text-muted); cursor: pointer;
  border-bottom: 2px solid transparent; user-select: none;
}
.iou-nav .tab.active { color: var(--primary); border-color: var(--primary); }
.iou-nav .profile {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; cursor: pointer; position: relative;
}
.iou-nav .back-link {
  display: flex; align-items: center; gap: 6px;
  color: var(--primary); font-size: 14px; font-weight: 600;
  cursor: pointer; user-select: none; flex: 1;
}
.iou-nav .page-title {
  font-weight: 600; font-size: 15px;
  padding-right: 16px; text-align: center;
}
.iou-nav .spacer { width: 60px; }

/* ─── Dropdown ─── */
.iou-dropdown {
  display: none; position: absolute; top: 40px; right: 0;
  background: var(--surface); border-radius: 8px; box-shadow: var(--shadow);
  min-width: 170px; z-index: 100; border: 1px solid var(--border);
}
.iou-dropdown.show { display: block; }
.iou-dropdown-item {
  padding: 12px 16px; font-size: 14px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.iou-dropdown-item:last-child { border: none; }
.iou-dropdown-item:hover { background: var(--primary-light); }

/* ─── Content ─── */
.iou-content { flex: 1; overflow-y: auto; padding: 12px 16px calc(var(--bottom-h) + 16px); }
.iou-content.no-bottom { padding-bottom: 16px; }
.iou-content.centered {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
}

/* ─── Bottom bar ─── */
.iou-bottom {
  display: flex; justify-content: space-around; align-items: center;
  height: var(--bottom-h); background: var(--surface);
  border-top: 1px solid var(--border); padding: 0 8px;
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 480px; margin: 0 auto;
}
.iou-bottom-btn {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 6px 12px; border: none; background: none;
  font-size: 11px; color: var(--text-muted); cursor: pointer;
  border-radius: 8px; user-select: none;
}
.iou-bottom-btn .icon { font-size: 20px; line-height: 1; }
.iou-bottom-btn.active { color: var(--primary); background: var(--primary-light); }
.badge-dot {
  display: inline-block; width: 8px; height: 8px;
  background: var(--red); border-radius: 50%;
  position: absolute; top: -2px; right: -6px;
}
.iou-bottom-btn .icon { position: relative; }

/* ─── Login ─── */
.iou-login-header { text-align: center; padding: 60px 20px 40px; }
.iou-login-header .logo { font-size: 36px; font-weight: 800; color: var(--primary); margin-bottom: 8px; }
.iou-login-header .sub { font-size: 14px; color: var(--text-muted); }
.iou-login-error {
  background: #FFEBEE; color: var(--red); padding: 10px 14px;
  border-radius: 8px; margin-bottom: 12px; font-size: 13px; display: none;
}

/* ─── Banner ─── */
.iou-banner {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border-radius: var(--radius); padding: 12px 16px;
  margin-bottom: 12px; box-shadow: var(--shadow);
}
.iou-banner .amount { font-weight: 700; font-size: 16px; }
.iou-banner .amount.green { color: var(--green); }
.iou-banner .amount.red { color: var(--red); }
.iou-banner.col { flex-direction: column; align-items: flex-start; gap: 4px; }

/* ─── Alert ─── */
.iou-alert {
  background: #FFF8E1; border: 1px solid var(--yellow);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px;
  font-size: 13px; display: flex; align-items: center; gap: 8px;
}

/* ─── Card ─── */
.iou-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 8px; box-shadow: var(--shadow);
  cursor: pointer; user-select: none;
}
.iou-card:active { transform: scale(0.98); }
.iou-card .top { display: flex; justify-content: space-between; align-items: flex-start; }
.iou-card .name { font-weight: 600; font-size: 14px; }
.iou-card .time { font-size: 11px; color: var(--text-muted); }
.iou-card .desc { font-size: 14px; margin-top: 2px; }
.iou-card .desc .amount { font-weight: 700; color: var(--primary); }
.iou-card .meta { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.iou-card .meta .tag {
  font-size: 11px; padding: 2px 8px; border-radius: 4px;
  background: var(--primary-light); color: var(--primary);
}
.iou-card .meta .tag.green { background: #E8F5E8; color: var(--green); }
.iou-card .meta .tag.gray { background: #F0F0F0; color: var(--text-muted); }
.iou-card .debtors { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.iou-card.settle-debit { border-left: 3px solid var(--red); }
.iou-card.settle-credit { border-left: 3px solid var(--green); }

/* ─── Section title ─── */
.iou-section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  color: var(--text-muted); margin: 16px 0 8px; letter-spacing: 0.5px;
}

/* ─── Form ─── */
.iou-form-group { margin-bottom: 16px; }
.iou-form-group label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text); margin-bottom: 6px;
}
.iou-form-group label .required { color: var(--red); }
.iou-form-group input, .iou-form-group select {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  outline: none; transition: border-color 0.2s;
  font-family: inherit;
}
.iou-form-group input:focus { border-color: var(--primary); }
.iou-form-group input.amount-lg { font-size: 24px; font-weight: 700; }

/* ─── Buttons ─── */
.iou-btn-row { display: flex; gap: 10px; margin-top: 16px; }
.iou-btn {
  flex: 1; padding: 14px; border: none; border-radius: 8px;
  font-size: 15px; font-weight: 700; cursor: pointer;
  text-align: center; user-select: none;
}
.iou-btn:active { transform: scale(0.97); }
.iou-btn.primary { background: var(--primary); color: white; }
.iou-btn.secondary { background: var(--border); color: var(--text); }
.iou-btn.success { background: var(--green); color: white; }
.iou-btn.outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.iou-btn.danger { background: transparent; border: 1px solid var(--red); color: var(--red); }
.iou-btn.full { width: 100%; }
.iou-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ─── Debtor list ─── */
.iou-debtor-list { display: flex; flex-direction: column; gap: 6px; }
.iou-debtor-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--border); cursor: pointer; user-select: none;
}
.iou-debtor-item.selected { border-color: var(--primary); background: var(--primary-light); }
.iou-debtor-item .check {
  width: 20px; height: 20px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.iou-debtor-item .check.on { background: var(--primary); color: white; }
.iou-debtor-item .check.off { background: transparent; border: 2px solid var(--border); }
.iou-debtor-item .dname { flex: 1; font-size: 14px; font-weight: 500; }
.iou-debtor-item .damount-wrap {
  display: flex; align-items: center; gap: 0;
  border: 1px solid var(--border); border-radius: 6px;
  overflow: hidden; flex-shrink: 0;
}
.iou-debtor-item .damount-wrap:focus-within { border-color: var(--primary); }
.iou-debtor-item .damount-currency {
  padding: 4px 0 4px 6px; font-size: 12px; color: var(--text-muted);
  background: var(--bg);
}
.iou-debtor-item .damount {
  width: 65px; padding: 4px 6px 4px 2px; border: none;
  font-size: 13px; text-align: right; outline: none;
  font-family: inherit; background: transparent;
}
.iou-debtor-item .damount:disabled { color: var(--text-muted); }

.iou-debtor-actions { display: flex; gap: 8px; margin: 0 0 12px; }
.iou-debtor-actions .iou-btn { flex: 1; padding: 8px; font-size: 12px; }

/* ─── Progress ─── */
.iou-progress { width: 100%; height: 6px; background: var(--border); border-radius: 3px; margin: 8px 0; overflow: hidden; }
.iou-progress .fill { height: 100%; background: var(--primary); border-radius: 3px; }
.iou-progress-label { font-size: 12px; color: var(--text-muted); text-align: center; }
.iou-split-options { display: flex; gap: 8px; margin: 0 0 12px; }
.iou-split-options .iou-btn { flex: 1; padding: 10px; font-size: 13px; }

/* ─── Stats ─── */
.iou-stat-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.iou-stat-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 14px; text-align: center; box-shadow: var(--shadow);
}
.iou-stat-card .label { font-size: 11px; color: var(--text-muted); }
.iou-stat-card .value { font-size: 18px; font-weight: 700; margin-top: 4px; }
.iou-stat-card .value.credit { color: var(--green); }
.iou-stat-card .value.debit { color: var(--red); }
.iou-stat-card .value.net { color: var(--primary); }

/* ─── Modal overlay ─── */
.iou-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 200; justify-content: center; align-items: center;
}
.iou-overlay.show { display: flex; }
.iou-modal {
  background: var(--surface); border-radius: var(--radius);
  padding: 24px; max-width: 340px; width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.iou-modal h3 { font-size: 16px; margin-bottom: 8px; }
.iou-modal p { font-size: 14px; color: var(--text-muted); margin-bottom: 16px; }

/* ─── Loading ─── */
.iou-loading {
  display: flex; align-items: center; justify-content: center;
  padding: 40px; color: var(--text-muted); font-size: 14px;
}

/* ─── Placeholder ─── */
.iou-placeholder {
  text-align: center; padding: 40px 20px; color: var(--text-muted);
}
.iou-placeholder .icon { font-size: 48px; margin-bottom: 12px; }
.iou-placeholder .title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.iou-placeholder .desc { font-size: 13px; line-height: 1.6; }

/* ─── Responsive ─── */
@media (min-width: 481px) {
  #iou-app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
