/* ============================================================
   EasyShare – style.css
   Aesthetic: Refined dark editorial with warm gold accents
   Fonts: DM Serif Display (headings) + DM Sans (body)
   ============================================================ */

/* ---------- CSS CUSTOM PROPERTIES ---------- */
:root {
  --bg-base:        #0d1117;
  --bg-surface:     #161b22;
  --bg-elevated:    #1f2937;
  --border:         #2d3748;
  --border-light:   #374151;

  --gold:           #d4a853;
  --gold-light:     #e8c97a;
  --gold-dim:       rgba(212, 168, 83, 0.15);

  --text-primary:   #f0ece4;
  --text-secondary: #9ca3af;
  --text-muted:     #6b7280;

  --accent-green:   #34d399;
  --accent-red:     #f87171;
  --accent-blue:    #60a5fa;

  --radius-sm:  6px;
  --radius-md:  12px;
  --radius-lg:  18px;
  --radius-xl:  24px;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:  0 8px 32px rgba(0,0,0,0.6);

  --transition: 0.2s ease;

  --max-w: 560px;
  --header-h: 108px; /* approx header height */
}

/* ---------- RESET & BASE ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* subtle grain texture */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
}

/* ---------- HEADER ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px 0;
}

.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
}

.logo-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 24px;
  color: var(--gold);
  animation: pulse-gold 3s ease-in-out infinite;
  line-height: 1;
}

@keyframes pulse-gold {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.7; transform: scale(0.92); }
}

.app-name {
  font-family: 'DM Serif Display', serif;
  font-size: 1.6rem;
  font-weight: 400;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.app-subtitle {
  font-size: 0.72rem;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
  margin-top: 1px;
}

/* ---------- TAB NAVIGATION ---------- */
.tab-nav {
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  gap: 4px;
  padding-bottom: 0;
}

.tab-btn {
  flex: 1;
  padding: 10px 4px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}

.tab-btn:hover { color: var(--text-secondary); }

.tab-btn.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

/* ---------- MAIN CONTENT ---------- */
.main-content {
  flex: 1;
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

/* ---------- TAB PANELS ---------- */
.tab-panel { display: none; animation: fade-in 0.25s ease; }
.tab-panel.active { display: block; }
.tab-panel[hidden] { display: none !important; }

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

/* ---------- SECTION HEADER ---------- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.section-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.sub-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin: 24px 0 12px;
}

.section-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 18px;
  line-height: 1.5;
}

/* ---------- BADGE ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background: var(--gold-dim);
  border: 1px solid rgba(212, 168, 83, 0.3);
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--gold-light);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* ---------- CARDS ---------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.form-card {
  margin-bottom: 24px;
}

.form-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.05rem;
  font-weight: 400;
  color: var(--gold-light);
  margin-bottom: 16px;
}

/* ---------- INPUTS ---------- */
.field-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 14px;
}

.field-label:first-child { margin-top: 0; }

.text-input,
.select-input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

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

.text-input:focus,
.select-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212, 168, 83, 0.15);
}

.select-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.select-input option {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* ---------- INPUT ROW (members) ---------- */
.input-row {
  display: flex;
  gap: 10px;
}

.input-row .text-input { flex: 1; }

/* ---------- FIELD ROW ---------- */
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-group { display: flex; flex-direction: column; }
.field-group .field-label { margin-top: 0; }

/* ---------- RATE PREVIEW ---------- */
.rate-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--gold-dim);
  border: 1px dashed rgba(212, 168, 83, 0.3);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--gold-light);
  animation: fade-in 0.2s ease;
}

.rate-icon { font-size: 1rem; }

/* ---------- SPLIT CONTROLS ---------- */
.split-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  margin-top: 8px;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  font-size: 0.88rem;
}

.checkbox-item:has(input:checked) {
  border-color: var(--gold);
  background: var(--gold-dim);
}

.checkbox-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--gold);
  cursor: pointer;
  flex-shrink: 0;
}

/* ---------- BUTTONS ---------- */
.btn-primary {
  padding: 11px 20px;
  background: var(--gold);
  color: #0d1117;
  border: none;
  border-radius: var(--radius-md);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

.btn-primary:hover {
  background: var(--gold-light);
  box-shadow: 0 4px 12px rgba(212, 168, 83, 0.35);
  transform: translateY(-1px);
}

.btn-primary:active { transform: translateY(0); }

.btn-primary.full-width { width: 100%; }

.btn-ghost {
  padding: 11px 20px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}

.btn-ghost:hover { color: var(--text-primary); border-color: var(--text-secondary); }

.btn-sm {
  padding: 6px 12px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.btn-sm:hover { color: var(--gold); border-color: var(--gold); background: var(--gold-dim); }

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  color: var(--gold);
  cursor: pointer;
  transition: background var(--transition);
}

.btn-icon:hover { background: var(--gold-dim); }

.btn-danger {
  padding: 10px 20px;
  background: transparent;
  color: var(--accent-red);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius-md);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.1);
  border-color: var(--accent-red);
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- MEMBER LIST ---------- */
.member-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  animation: slide-in 0.2s ease;
  transition: border-color var(--transition);
}

.member-item:hover { border-color: var(--border-light); }

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

.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gold-dim);
  border: 1px solid rgba(212, 168, 83, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'DM Serif Display', serif;
  font-size: 1rem;
  color: var(--gold);
  flex-shrink: 0;
}

.member-name {
  flex: 1;
  font-weight: 500;
  font-size: 0.95rem;
}

.member-name-input-inline {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--gold);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
}

.member-name-input-inline:focus { outline: none; }

.member-actions { display: flex; gap: 6px; }

.member-action-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}

.member-action-btn:hover { background: var(--border); color: var(--text-primary); }
.member-action-btn.delete:hover { background: rgba(248, 113, 113, 0.15); color: var(--accent-red); }
.member-action-btn.save:hover  { background: rgba(212, 168, 83, 0.15); color: var(--gold); }

/* ---------- EXPENSE LIST ---------- */
.expense-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.expense-item {
  display: flex;
  flex-direction: column;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  gap: 6px;
  animation: slide-in 0.2s ease;
  position: relative;
  overflow: hidden;
}

.expense-item::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--gold);
  opacity: 0.6;
}

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

.expense-desc {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  flex: 1;
}

.expense-amount {
  font-family: 'DM Serif Display', serif;
  font-size: 1.05rem;
  color: var(--gold-light);
  white-space: nowrap;
}

.expense-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
}

.expense-hkd-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

.expense-delete-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}

.expense-delete-btn:hover {
  background: rgba(248, 113, 113, 0.15);
  color: var(--accent-red);
}

/* ---------- BALANCE GRID ---------- */
.balance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}

.balance-card {
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-align: center;
}

.balance-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'DM Serif Display', serif;
  font-size: 1.1rem;
}

.balance-avatar.positive {
  background: rgba(52, 211, 153, 0.15);
  border: 1px solid rgba(52, 211, 153, 0.35);
  color: var(--accent-green);
}

.balance-avatar.negative {
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: var(--accent-red);
}

.balance-avatar.neutral {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
}

.balance-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.balance-amount {
  font-family: 'DM Serif Display', serif;
  font-size: 1rem;
}

.balance-amount.positive { color: var(--accent-green); }
.balance-amount.negative { color: var(--accent-red); }
.balance-amount.neutral  { color: var(--text-muted); }

.balance-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

/* ---------- SETTLEMENT LIST ---------- */
.settlement-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 32px;
}

.settlement-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  animation: slide-in 0.2s ease;
}

.settlement-from,
.settlement-to {
  flex: 1;
  text-align: center;
}

.s-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.s-role {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.settlement-arrow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--gold);
}

.arrow-icon { font-size: 1.2rem; }

.s-amount {
  font-family: 'DM Serif Display', serif;
  font-size: 0.9rem;
  color: var(--gold-light);
  white-space: nowrap;
}

/* ---------- EMPTY STATE ---------- */
.empty-state {
  display: none;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.empty-state.visible { display: block; }

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.6;
}

/* ---------- DANGER ZONE ---------- */
.danger-zone {
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
}

/* ---------- TOAST ---------- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 9999;
  max-width: 90vw;
  text-align: center;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success { border-color: rgba(52, 211, 153, 0.4); color: var(--accent-green); }
.toast.error   { border-color: rgba(248, 113, 113, 0.4); color: var(--accent-red); }

/* ---------- FOOTER ---------- */
.app-footer {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 20px 16px;
  text-align: center;
  max-width: 100%;
}

.disclaimer {
  font-size: 0.75rem;
  color: var(--text-muted);
  max-width: var(--max-w);
  margin: 0 auto 8px;
  line-height: 1.6;
}

.footer-credit {
  font-size: 0.72rem;
  color: var(--border-light);
  letter-spacing: 0.04em;
}

/* ---------- SCROLLBAR ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 400px) {
  .field-row { grid-template-columns: 1fr; }
  .checkbox-grid { grid-template-columns: 1fr 1fr; }
  .balance-grid { grid-template-columns: 1fr 1fr; }
  .settlement-item { flex-wrap: wrap; justify-content: center; }
}

@media (min-width: 600px) {
  .main-content { padding: 32px 24px 60px; }
}
