/* ═══════════════════════════════════════════════════
   Casa Regal — Expense Logger
   expenses.css  |  Stylesheet
   ═══════════════════════════════════════════════════ */

:root {
  --bg: #f5f6fa;
  --surface: #fff;
  --border: #e2e6ef;
  --text: #1a1d2e;
  --muted: #7b8299;
  --accent: #4f6ef7;
  --radius: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

/* ══ LOGIN ══════════════════════════════════════════ */

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #eef1ff 0%, #f5f6fa 100%);
}

.login-wrap {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.login-logo {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.login-icon {
  width: 52px;
  height: 52px;
  background: var(--accent);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 4px 16px rgba(79,110,247,.35);
}

.login-brand {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.login-sub {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .3px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-err {
  background: #fff0f0;
  border: 1px solid #fcc;
  border-radius: 7px;
  padding: 10px 14px;
  font-size: 13px;
  color: #c0392b;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-lbl {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .2px;
}

.field-inp {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s;
  width: 100%;
}

.field-inp:focus {
  border-color: var(--accent);
}

.login-btn {
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  margin-top: 4px;
}

.login-btn:hover { opacity: .88; }
.login-btn:disabled { opacity: .55; cursor: not-allowed; }

/* ══ APP SHELL ══════════════════════════════════════ */

#app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.exp-hdr {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  min-height: 54px;
}

.exp-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.exp-brand-icon {
  width: 34px;
  height: 34px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.exp-brand-name {
  font-size: 16px;
  font-weight: 700;
}

.exp-brand-sub {
  font-size: 11px;
  color: var(--muted);
}

.exp-signout {
  padding: 6px 13px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
}

.exp-signout:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ══ LIST VIEW ══════════════════════════════════════ */

#list-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-bottom: 100px; /* room for FAB */
}

/* Stats strip */
.stats-strip {
  display: flex;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
}

.stat-card {
  flex: 1;
  min-width: 100px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.stat-lbl {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}

.stat-val {
  font-size: 20px;
  font-weight: 700;
  margin-top: 3px;
  color: var(--accent);
}

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.filter-bar::-webkit-scrollbar { display: none; }

.fchip {
  flex-shrink: 0;
  padding: 5px 13px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.fchip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.fchip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Expense list */
#exp-list {
  flex: 1;
  padding: 0 16px;
}

.list-loading {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 14px;
}

.list-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.list-empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

/* Date group header */
.date-group-hdr {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 16px 0 6px;
}

/* Expense row */
.exp-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  transition: box-shadow .15s;
}

.exp-row:hover {
  box-shadow: 0 3px 14px rgba(0,0,0,.1);
}

.exp-cat-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}

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

.exp-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.exp-row-desc {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.exp-row-amount {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}

.exp-row-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.exp-tag {
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
}


.exp-status-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.exp-status-pending  { background: #fef3c7; color: #92400e; }
.exp-status-approved { background: #d1fae5; color: #065f46; }
.exp-status-declined { background: #fee2e2; color: #991b1b; }

.exp-tag-reason {
  color: #991b1b;
  border-color: #fca5a5;
  background: #fff1f2;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: middle;
}

.exp-receipt-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #27ae60;
  flex-shrink: 0;
  title: "Has receipt";
}

/* FAB */
.fab {
  position: fixed;
  bottom: 24px;
  right: 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 28px;
  padding: 14px 22px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(79,110,247,.45);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform .15s, box-shadow .15s;
  z-index: 90;
}

.fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(79,110,247,.5);
}

.fab-plus {
  font-size: 22px;
  line-height: 1;
  margin-top: -1px;
}

/* ══ FORM VIEW ══════════════════════════════════════ */

#form-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.form-hdr {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.form-back {
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  padding: 4px 0;
  flex-shrink: 0;
}

.form-title {
  flex: 1;
  font-size: 16px;
  font-weight: 700;
}

.form-delete {
  background: none;
  border: none;
  font-size: 13px;
  font-weight: 600;
  color: #e74c3c;
  cursor: pointer;
  padding: 4px 0;
  flex-shrink: 0;
}

.form-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 32px;
}

.form-section {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;   /* prevent flex children from blowing out the column */
}

.form-lbl {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .2px;
}

.form-inp {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s;
  width: 100%;
  font-family: inherit;
}

.form-inp:focus {
  border-color: var(--accent);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Category grid */
.cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.cat-btn {
  padding: 10px 8px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  transition: all .15s;
  line-height: 1.4;
}

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

.cat-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Optional tag */
.optional-tag {
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: middle;
  margin-left: 4px;
}

/* Receipt picker */
.receipt-pick {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s;
  gap: 6px;
}

.receipt-pick:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#receipt-preview {
  margin-top: 8px;
}

#receipt-preview img {
  max-width: 100%;
  max-height: 180px;
  border-radius: 7px;
  border: 1px solid var(--border);
  display: block;
}

/* Form actions */
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.btn-cancel {
  flex: 1;
  padding: 13px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
}

.btn-cancel:hover {
  border-color: var(--muted);
}

.btn-save {
  flex: 2;
  padding: 13px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}

.btn-save:hover { opacity: .88; }
.btn-save:disabled { opacity: .55; cursor: not-allowed; }

/* ══ CATEGORY CUSTOM DROPDOWN ═══════════════════════ */

.cat-display-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border);
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}

.cat-display-btn:focus {
  outline: none;
  border-color: var(--accent);
}

.cat-chevron {
  color: var(--muted);
  font-size: 13px;
  flex-shrink: 0;
}

/* ══ PAID-BY COMBOBOX ═══════════════════════════════ */

.paidby-wrap {
  position: relative;
}

.paidby-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.12);
  overflow-y: auto;
  max-height: 200px;
  z-index: 200;
}

.paidby-opt {
  padding: 9px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background .1s;
}

.paidby-opt:hover,
.paidby-opt.focused {
  background: #eef1ff;
}

.paidby-opt-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.paidby-opt-sub {
  font-size: 11px;
  color: var(--muted);
}

/* ══ LOCKED FORM NOTICE ═════════════════════════════ */

.form-locked-notice {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-locked-status {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.form-locked-reason {
  font-size: 12px;
  color: #991b1b;
  font-style: italic;
}

.form-locked-hint {
  font-size: 11px;
  color: var(--muted);
}

/* ══ TOAST ══════════════════════════════════════════ */

.exp-toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: #1a1d2e;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  z-index: 999;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  text-align: center;
}

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

/* ══ RESPONSIVE ══════════════════════════════════════ */

@media (max-width: 480px) {
  .stats-strip {
    padding: 10px 12px;
    gap: 8px;
  }

  .stat-val {
    font-size: 17px;
  }

  .cat-grid {
    grid-template-columns: 1fr 1fr;
  }

  .form-row-2 {
    grid-template-columns: 1fr;
  }

  .exp-hdr {
    padding: 10px 14px;
  }

  #exp-list {
    padding: 0 12px;
  }

  .form-body {
    padding: 12px;
  }
}
