/* ═══ Telegram Split Bill — Design System ═══ */
/* Dark theme, glassmorphism, premium feel (like Wheel of Names) */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #12122a;
  --bg-card: #1a1a3a;
  --accent-1: #7c5cfc;
  --accent-2: #00d4aa;
  --accent-3: #ff6b9d;
  --text-primary: #ffffff;
  --text-secondary: #a0a0c0;
  --text-muted: #6b6b8a;
  --danger: #ef5350;
  --warning: #ffa726;
  --border: #2a2a4a;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
  --radius: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  overflow-x: hidden;
}

/* ─── App Layout ─── */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 80px;
}

.app-header {
  text-align: center;
  padding: 16px 0 20px;
}

.app-header h1 {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-3));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

/* ─── Pages ─── */
.page { display: none; }
.page.active { display: block; }

.page-subheader {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 8px 0;
}

.page-subheader h2 {
  font-size: 18px;
  font-weight: 600;
}

.btn-back {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
}

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

.label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.badge {
  background: var(--accent-1);
  color: white;
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 20px;
  opacity: 0.8;
}

/* ─── Input ─── */
.input {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.2s;
}

.input:focus {
  border-color: var(--accent-1);
}

.input::placeholder {
  color: var(--text-muted);
}

/* ─── Chips (Participants) ─── */
.chips-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(124, 92, 252, 0.2);
  border: 1px solid rgba(124, 92, 252, 0.3);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  animation: chip-in 0.2s ease;
}

.chip .chip-remove {
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.chip .chip-remove:hover {
  opacity: 1;
}

.chip-input {
  flex: 1;
  min-width: 120px;
  margin-top: 4px;
}

@keyframes chip-in {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ─── Items Table ─── */
.item-row {
  display: grid;
  grid-template-columns: 1fr 60px 90px 32px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  animation: row-in 0.2s ease;
}

.item-row .input { font-size: 14px; padding: 10px; }

.item-row .item-name { grid-column: 1; }
.item-row .item-qty { grid-column: 2; text-align: center; }
.item-row .item-price { grid-column: 3; text-align: right; }
.item-row .item-del {
  grid-column: 4;
  background: none;
  border: none;
  color: var(--danger);
  font-size: 20px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s;
  padding: 4px;
}

.item-row .item-del:hover { opacity: 1; }

.item-row .item-assign {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
  min-height: 28px;
  padding: 2px 0;
}

.assign-chip {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  background: rgba(0, 212, 170, 0.15);
  border: 1px solid rgba(0, 212, 170, 0.25);
  color: var(--accent-2);
  cursor: pointer;
  transition: all 0.2s;
}

.assign-chip:hover {
  background: rgba(0, 212, 170, 0.25);
}

.assign-chip .qty-badge {
  background: var(--accent-2);
  color: #000;
  border-radius: 10px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 700;
  margin-left: 4px;
}

.assign-chip.unassigned {
  background: rgba(255, 167, 38, 0.1);
  border-color: rgba(255, 167, 38, 0.2);
  color: var(--warning);
}

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

/* ─── Buttons ─── */
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent-1), #6a4fe0);
  color: white;
  box-shadow: 0 4px 15px rgba(124, 92, 252, 0.3);
  margin-top: 16px;
}

.btn-primary:active {
  box-shadow: 0 2px 8px rgba(124, 92, 252, 0.2);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  margin-top: 8px;
}

/* ─── Mode Toggle (small: % / Rp) ─── */
.mode-toggle-sm {
  display: flex;
  gap: 2px;
  margin-right: 6px;
}

.mode-btn {
  padding: 6px 8px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  min-width: 32px;
  text-align: center;
}

.mode-btn:first-child {
  border-radius: 6px 0 0 6px;
}

.mode-btn:last-child {
  border-radius: 0 6px 6px 0;
}

.mode-btn.active {
  background: var(--accent-1);
  border-color: var(--accent-1);
  color: white;
}

/* ─── Settings ─── */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-secondary);
}

.setting-row:last-child { border-bottom: none; }

.setting-input-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.setting-input {
  width: 80px;
  text-align: center;
  padding: 8px;
  font-size: 14px;
}

.setting-suffix {
  color: var(--text-muted);
  font-size: 13px;
}

.toggle-group {
  display: flex;
  gap: 4px;
}

.toggle-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn.active {
  background: var(--accent-1);
  border-color: var(--accent-1);
  color: white;
}

/* ─── Assign Page ─── */
.assign-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.assign-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 16px;
}

.assign-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
}

.assign-item-name {
  font-weight: 500;
}

.assign-stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stepper-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.stepper-btn:hover {
  border-color: var(--accent-1);
}

.stepper-btn:active {
  transform: scale(0.9);
}

.stepper-value {
  font-size: 18px;
  font-weight: 700;
  min-width: 30px;
  text-align: center;
}

.assign-progress {
  margin: 16px 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.assign-progress-bar {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-card);
  overflow: hidden;
  position: relative;
}

.assign-progress-bar::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: var(--accent-2);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.assign-progress-bar[data-pct]::after {
  width: attr(data-pct '%');
}

.assign-progress-text {
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 40px;
  text-align: right;
}

/* ─── Results ─── */
.result-person {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.result-person h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--accent-2);
}

.result-item-line {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 2px 0;
}

.result-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

.result-total-line {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 2px 0;
}

.result-total-line.total {
  font-weight: 700;
  font-size: 16px;
  color: var(--text-primary);
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 4px;
}

.result-summary {
  background: linear-gradient(135deg, var(--bg-card), rgba(124,92,252,0.1));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
  text-align: center;
}

.result-summary h3 {
  color: var(--accent-2);
  margin-bottom: 8px;
}

.result-summary .grand-total {
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-3));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 212, 170, 0.9);
  color: #000;
  font-weight: 600;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 100;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.toast.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
  pointer-events: none;
}

.toast.error {
  background: rgba(239, 83, 80, 0.9);
  color: white;
}

/* ─── Misc ─── */
.hidden { display: none !important; }

.copy-textarea {
  position: absolute;
  left: -9999px;
  opacity: 0;
}
