@import url('https://fonts.googleapis.com/css2?family=Libre+Baskerville:wght@400;700&family=Roboto:wght@300;400;500;700&display=swap');

:root {
  --navy: #0A193E;
  --navy-light: #1a3060;
  --gold: #CD8E33;
  --gold-light: #e0a84a;
  --light: #F5F5F5;
  --white: #ffffff;
  --error: #e53e3e;
  --success: #38a169;
  --border: #e2e8f0;
  --text: #0A193E;
  --text-muted: #718096;
  --shadow: 0 4px 20px rgba(10,25,62,0.12);
  --shadow-sm: 0 2px 8px rgba(10,25,62,0.08);
  --radius: 14px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Roboto', sans-serif;
  background: var(--light);
  color: var(--text);
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ── VIEWS ── */
.view { display: none; min-height: 100vh; flex-direction: column; }
.view.active { display: flex; }

/* ── LOGIN ── */
#view-login {
  background: var(--navy);
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}

.login-logo { text-align: center; margin-bottom: 2.5rem; }
.login-logo img { max-width: 200px; height: auto; display: block; margin: 0 auto; }

.login-card {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(205,142,51,0.3);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  width: 100%;
}

.login-card h2 {
  font-family: 'Libre Baskerville', serif;
  color: var(--white);
  font-size: 1.1rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

/* ── FORMS ── */
.form-group { margin-bottom: 1.1rem; }

.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  margin-bottom: 0.4rem;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.form-group.light label { color: var(--text-muted); }

input, select, textarea {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid rgba(205,142,51,0.3);
  background: rgba(255,255,255,0.08);
  color: var(--white);
  font-family: 'Roboto', sans-serif;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--gold);
  background: rgba(255,255,255,0.12);
}

input.light, select.light, textarea.light {
  background: var(--white);
  color: var(--text);
  border-color: var(--border);
}
input.light:focus, select.light:focus, textarea.light:focus {
  border-color: var(--gold);
}

select option { background: var(--navy); color: var(--white); }
select.light option { background: var(--white); color: var(--text); }

input::placeholder, textarea::placeholder { color: rgba(255,255,255,0.35); }
input.light::placeholder, textarea.light::placeholder { color: #b0bec5; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.85rem 1.5rem;
  border-radius: var(--radius-sm);
  border: none;
  font-family: 'Roboto', sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.3px;
  text-decoration: none;
}

.btn-primary {
  background: var(--gold);
  color: var(--navy);
  width: 100%;
}
.btn-primary:hover, .btn-primary:active { background: var(--gold-light); transform: translateY(-1px); }

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: var(--white);
  border: 1px solid rgba(255,255,255,0.2);
}

.btn-outline {
  background: transparent;
  color: var(--gold);
  border: 1.5px solid var(--gold);
}
.btn-outline:hover { background: var(--gold); color: var(--navy); }

.btn-danger {
  background: #fee2e2;
  color: var(--error);
  border: 1px solid #fecaca;
}
.btn-danger:hover { background: #fecaca; }

.btn-pause {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}
.btn-pause:hover { background: #fde68a; }

.btn-activate {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}
.btn-activate:hover { background: #bbf7d0; }

.btn-sm { padding: 0.5rem 1rem; font-size: 0.82rem; }
.btn-icon { padding: 0.6rem; border-radius: 50%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ── HEADER ── */
.app-header {
  background: var(--navy);
  padding: 0 1rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.header-logo img { width: 36px; height: 36px; border-radius: 50%; }
.header-logo span {
  font-family: 'Libre Baskerville', serif;
  color: var(--white);
  font-size: 0.95rem;
  letter-spacing: 0.5px;
}

.header-right { display: flex; align-items: center; gap: 0.5rem; }

.company-selector {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(205,142,51,0.4);
  color: var(--white);
  padding: 0.35rem 0.6rem;
  border-radius: 20px;
  font-size: 0.78rem;
  max-width: 130px;
  cursor: pointer;
}
.company-selector option { background: var(--navy); }

.avatar-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--navy);
  font-weight: 700;
  font-size: 0.85rem;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ── BOTTOM NAV ── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%; max-width: 480px;
  background: var(--white);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(10,25,62,0.1);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 0.2rem;
  cursor: pointer;
  border: none;
  background: none;
  gap: 0.2rem;
  transition: color 0.2s;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-family: 'Roboto', sans-serif;
}
.nav-item .nav-icon { font-size: 1.3rem; }
.nav-item.active { color: var(--gold); }
.nav-item.active .nav-icon { transform: scale(1.1); }

/* ── MAIN CONTENT ── */
.main-content {
  flex: 1;
  padding: 1rem 1rem 5.5rem;
  overflow-y: auto;
}

/* ── STATS CARDS ── */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.2rem;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  border-left: 3px solid var(--gold);
}
.stat-card .stat-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 0.3rem; }
.stat-card .stat-value { font-size: 1.3rem; font-weight: 700; color: var(--navy); }
.stat-card .stat-sub { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ── SECTION HEADER ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}
.section-title {
  font-family: 'Libre Baskerville', serif;
  font-size: 1rem;
  color: var(--navy);
}

/* ── MONTH FILTER ── */
.month-filter {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
}
.month-filter select {
  flex: 1;
  background: var(--white);
  color: var(--text);
  border-color: var(--border);
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
}
.month-filter select:focus { border-color: var(--gold); }

/* ── EXPENSE CARDS ── */
.expense-list { display: flex; flex-direction: column; gap: 0.6rem; }

.expense-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border-left: 3px solid transparent;
}
.expense-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.expense-card.factura { border-left-color: var(--navy); }
.expense-card.boleta { border-left-color: var(--gold); }

.expense-icon {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  background: var(--light);
}

.expense-info { flex: 1; min-width: 0; }
.expense-category { font-weight: 500; font-size: 0.9rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.1rem; display: flex; gap: 0.5rem; }

.expense-right { text-align: right; flex-shrink: 0; }
.expense-amount { font-weight: 700; font-size: 0.95rem; color: var(--navy); }
.expense-doc {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 500;
  padding: 0.15rem 0.45rem;
  border-radius: 20px;
  margin-top: 0.2rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.doc-factura { background: #dbeafe; color: #1d4ed8; }
.doc-boleta { background: #fef3c7; color: #92400e; }
.has-photo { font-size: 0.7rem; color: var(--gold); }

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: 70px; right: calc(50% - 240px + 16px);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--navy);
  font-size: 1.6rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(205,142,51,0.5);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  z-index: 90;
}
.fab:hover, .fab:active { transform: scale(1.1); box-shadow: 0 6px 20px rgba(205,142,51,0.6); }

@media (max-width: 480px) {
  .fab { right: 16px; }
}

/* ── ADD EXPENSE SHEET ── */
.bottom-sheet-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(10,25,62,0.6);
  z-index: 200;
  backdrop-filter: blur(2px);
}
.bottom-sheet-overlay.open { display: flex; align-items: flex-end; }

.bottom-sheet {
  background: var(--white);
  border-radius: 24px 24px 0 0;
  width: 100%; max-width: 480px;
  margin: 0 auto;
  max-height: 95vh;
  overflow-y: auto;
  padding: 1.5rem 1.5rem 2rem;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32,0.72,0,1);
}
.bottom-sheet-overlay.open .bottom-sheet { transform: translateY(0); }

.sheet-handle {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 0 auto 1.5rem;
}

.sheet-title {
  font-family: 'Libre Baskerville', serif;
  font-size: 1.15rem;
  color: var(--navy);
  margin-bottom: 1.5rem;
  text-align: center;
}

/* ── CATEGORY GRID ── */
.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.cat-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.7rem 0.3rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--white);
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Roboto', sans-serif;
  text-align: center;
}
.cat-btn .cat-icon { font-size: 1.4rem; }
.cat-btn .cat-name { font-size: 0.65rem; color: var(--text-muted); line-height: 1.2; }
.cat-btn:hover { border-color: var(--gold); background: #fffbf4; }
.cat-btn.selected { border-color: var(--gold); background: #fef3c7; }
.cat-btn.selected .cat-name { color: var(--navy); font-weight: 500; }

/* ── DOC TYPE TOGGLE ── */
.doc-toggle {
  display: flex;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  overflow: hidden;
  margin-bottom: 1rem;
}
.doc-toggle-btn {
  flex: 1;
  padding: 0.75rem;
  border: none;
  background: var(--white);
  cursor: pointer;
  font-family: 'Roboto', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.2s;
}
.doc-toggle-btn.active { background: var(--navy); color: var(--white); }
.doc-toggle-btn:first-child { border-right: 1px solid var(--border); }
.pay-toggle-btn {
  flex: 1;
  padding: 0.75rem;
  border: none;
  background: var(--white);
  cursor: pointer;
  font-family: 'Roboto', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.2s;
}
.pay-toggle-btn.active { background: var(--navy); color: var(--white); }
.pay-toggle-btn:first-child { border-right: 1px solid var(--border); }

/* ── PHOTO UPLOAD ── */
.photo-upload {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 1.2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--light);
  position: relative;
}
.photo-upload:hover { border-color: var(--gold); background: #fffbf4; }
.photo-upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.photo-upload .upload-icon { font-size: 2rem; color: var(--text-muted); }
.photo-upload p { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.3rem; }
.photo-preview { width: 100%; max-height: 160px; object-fit: cover; border-radius: var(--radius-sm); margin-top: 0.5rem; }

/* ── EXPENSE DETAIL MODAL ── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(10,25,62,0.6);
  z-index: 300;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius);
  width: 100%; max-width: 400px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.2rem;
}
.modal-header h3 { font-family: 'Libre Baskerville', serif; font-size: 1.1rem; color: var(--navy); }

.detail-row {
  display: flex; align-items: flex-start;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--light);
  gap: 0.75rem;
}
.detail-row:last-of-type { border-bottom: none; }
.detail-label { font-size: 0.75rem; color: var(--text-muted); width: 100px; flex-shrink: 0; padding-top: 0.1rem; }
.detail-value { font-size: 0.9rem; color: var(--text); font-weight: 500; }
.detail-photo { width: 100%; border-radius: var(--radius-sm); margin-top: 0.5rem; cursor: pointer; }

/* ── ADMIN ── */
.admin-section { margin-bottom: 2rem; }
.admin-section-title {
  font-family: 'Libre Baskerville', serif;
  font-size: 1rem;
  color: var(--navy);
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--gold);
  margin-bottom: 1rem;
}

.admin-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  margin-bottom: 0.5rem;
}
.admin-card-info { flex: 1; min-width: 0; }
.admin-card-title { font-weight: 500; font-size: 0.9rem; }
.admin-card-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.1rem; }
.admin-card-actions { display: flex; gap: 0.4rem; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 500;
}
.badge-admin { background: #fce7f3; color: #9d174d; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #f3f4f6; color: #6b7280; }

/* ── ALERTS ── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.alert-error { background: #fee2e2; color: var(--error); border-left: 3px solid var(--error); }
.alert-success { background: #dcfce7; color: var(--success); border-left: 3px solid var(--success); }

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-state h3 { font-size: 1rem; color: var(--text); margin-bottom: 0.4rem; }
.empty-state p { font-size: 0.85rem; }

/* ── LOADING ── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--light);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 2rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── CLOSE BTN ── */
.close-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--light);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: 80px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy);
  color: var(--white);
  padding: 0.7rem 1.4rem;
  border-radius: 24px;
  font-size: 0.85rem;
  z-index: 500;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap;
  box-shadow: var(--shadow);
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.success { background: var(--success); }
#toast.error { background: var(--error); }

/* ── DIVIDER ── */
.divider { height: 1px; background: var(--border); margin: 1rem 0; }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── PWA ── */
@media (display-mode: standalone) {
  .app-header { padding-top: env(safe-area-inset-top); height: calc(60px + env(safe-area-inset-top)); }
  .bottom-nav { padding-bottom: env(safe-area-inset-bottom); }
}
