/* ============================================================
   OM CHITS v2.0 — Complete Stylesheet
   Design: Deep navy + gold accent, clean financial dashboard
   ============================================================ */

:root {
  --bg-base:     #0A0A14;
  --bg-surface:  #12121F;
  --bg-card:     #1A1A2E;
  --bg-hover:    #22223A;
  --border:      #2A2A45;
  --border-light:#333358;
  --gold:        #F59E0B;
  --gold-light:  #FCD34D;
  --gold-dim:    #B45309;
  --text-primary:#F1F0F8;
  --text-secondary:#9A99B8;
  --text-muted:  #5A5A78;
  --green:       #10B981;
  --green-bg:    #052E1A;
  --red:         #EF4444;
  --red-bg:      #2A0A0A;
  --blue:        #3B82F6;
  --blue-bg:     #0A1A3A;
  --purple:      #8B5CF6;
  --sidebar-w:   260px;
  --topbar-h:    56px;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
  --transition:  all 0.2s ease;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}

/* ============================================================ LAYOUT */
body:not(.login-page) {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: auto 1fr;
}

.sidebar {
  grid-row: 1 / -1;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  z-index: 100;
}

.topbar {
  display: none;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  height: var(--topbar-h);
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 99;
  grid-column: 2;
}

.main-content {
  min-height: calc(100vh - 0px);
  padding: 2rem;
  overflow-y: auto;
  grid-column: 2;
}

/* ============================================================ SIDEBAR */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
}

.sidebar-title { font-size: 1.1rem; font-weight: 700; color: var(--gold); }
.sidebar-sub { font-size: 0.7rem; color: var(--text-muted); }

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: rgba(245,158,11,0.12); color: var(--gold); border-left: 3px solid var(--gold); }
.nav-icon { font-size: 1rem; width: 1.25rem; text-align: center; }

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-chip { display: flex; align-items: center; gap: 0.5rem; flex: 1; overflow: hidden; }
.user-avatar {
  width: 32px; height: 32px;
  background: var(--gold);
  color: #000;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.875rem; flex-shrink: 0;
}
.user-name { font-size: 0.8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.7rem; color: var(--text-muted); }
.btn-logout { padding: 0.4rem; color: var(--text-muted); text-decoration: none; border-radius: 6px; transition: var(--transition); }
.btn-logout:hover { color: var(--red); background: var(--red-bg); }

/* ============================================================ TOPBAR (mobile) */
.menu-btn { background: none; border: none; color: var(--text-primary); font-size: 1.25rem; cursor: pointer; }
.topbar-title { font-weight: 700; color: var(--gold); flex: 1; }
.user-badge {
  width: 32px; height: 32px;
  background: var(--gold); color: #000;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.875rem;
}
.topbar-right { display: flex; align-items: center; gap: 0.5rem; }

/* ============================================================ LOGIN PAGE */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; }
.login-orb { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.15; }
.orb1 { width: 400px; height: 400px; background: var(--gold); top: -100px; right: -100px; }
.orb2 { width: 300px; height: 300px; background: var(--purple); bottom: -80px; left: -80px; }

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  position: relative;
  z-index: 1;
  box-shadow: var(--shadow);
}

.login-brand { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
.brand-icon { width: 52px; height: 52px; border-radius: 14px; overflow: hidden; background: rgba(245,158,11,0.1); display: flex; align-items: center; justify-content: center; font-size: 1.75rem; }
.brand-icon img { width: 100%; height: 100%; object-fit: cover; }
.brand-fallback { font-size: 1.75rem; }
.login-brand h1 { font-size: 1.4rem; font-weight: 800; color: var(--gold); line-height: 1.2; }
.login-brand p { font-size: 0.75rem; color: var(--text-secondary); }

.login-features {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.login-features span {
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 0.25rem 0.6rem; border-radius: 20px;
  font-size: 0.7rem; color: var(--text-secondary);
}

.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-footer { text-align: center; font-size: 0.7rem; color: var(--text-muted); margin-top: 1.25rem; }

/* ============================================================ FORMS */
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
label { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); }

input, select, textarea {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  padding: 0.6rem 0.85rem;
  width: 100%;
  outline: none;
  transition: var(--transition);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(245,158,11,0.1); }
input::placeholder { color: var(--text-muted); }
select option { background: var(--bg-card); }
textarea { resize: vertical; min-height: 80px; }

.select-wrap, .input-wrap { position: relative; }
.input-wrap input { padding-right: 2.5rem; }
.toggle-pw {
  position: absolute; right: 0.6rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 1rem; padding: 0.25rem;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* ============================================================ BUTTONS */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 600;
  border: none; cursor: pointer; transition: var(--transition);
  text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--gold); color: #000; }
.btn-primary:hover { background: var(--gold-light); }
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-light); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { opacity: 0.85; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 0.4rem 0.6rem; }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================ CARDS */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; gap: 1rem;
}
.card-title { font-size: 1rem; font-weight: 700; color: var(--text-primary); }
.card-sub { font-size: 0.75rem; color: var(--text-secondary); }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(180px,1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  transition: var(--transition);
}
.stat-card:hover { border-color: var(--border-light); }
.stat-icon { font-size: 1.5rem; }
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--text-primary); }
.stat-label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 500; }
.stat-change { font-size: 0.75rem; font-weight: 600; }
.stat-change.up { color: var(--green); }
.stat-change.down { color: var(--red); }

/* ============================================================ TABLES */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th {
  background: var(--bg-surface); color: var(--text-secondary);
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
  color: var(--text-primary); vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }
.td-muted { color: var(--text-secondary); font-size: 0.8rem; }
.td-actions { display: flex; gap: 0.35rem; }

/* ============================================================ BADGES & PILLS */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.6rem; border-radius: 20px;
  font-size: 0.7rem; font-weight: 600; white-space: nowrap;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-gold { background: rgba(245,158,11,0.1); color: var(--gold); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-gray { background: var(--bg-surface); color: var(--text-secondary); }

/* ============================================================ PAGE STRUCTURE */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap;
}
.page-title { font-size: 1.5rem; font-weight: 800; }
.page-sub { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.1rem; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.section-gap { display: flex; flex-direction: column; gap: 1.5rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1.5rem; }

/* ============================================================ PAYMENT GRID */
.payment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
}
.payment-cell {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}
.payment-cell:hover { border-color: var(--gold); transform: translateY(-1px); }
.payment-cell.paid { border-color: var(--green); background: var(--green-bg); }
.payment-cell.unpaid { border-color: var(--border); }
.payment-cell.overdue { border-color: var(--red); background: var(--red-bg); }
.pc-month { font-size: 0.65rem; color: var(--text-muted); }
.pc-name { font-size: 0.75rem; font-weight: 600; margin: 0.2rem 0; }
.pc-amount { font-size: 0.7rem; color: var(--text-secondary); }
.pc-status { font-size: 0.7rem; margin-top: 0.25rem; }

/* ============================================================ ALERTS */
.alert {
  display: flex; align-items: flex-start; gap: 0.75rem;
  padding: 0.85rem 1rem; border-radius: var(--radius-sm);
  font-size: 0.875rem; margin-bottom: 1rem;
}
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(16,185,129,0.3); }
.alert-info { background: var(--blue-bg); color: var(--blue); border: 1px solid rgba(59,130,246,0.3); }
.alert-warning { background: rgba(245,158,11,0.08); color: var(--gold); border: 1px solid rgba(245,158,11,0.3); }

/* ============================================================ MODAL */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.7); z-index: 200; backdrop-filter: blur(4px);
}
.modal {
  display: none; position: fixed;
  top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: 90%; max-width: 560px; max-height: 90vh;
  overflow-y: auto; z-index: 201;
}
.modal-overlay.open, .modal.open { display: block; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-surface); z-index: 1;
}
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.1rem; padding: 0.25rem; border-radius: 4px; }
.modal-close:hover { color: var(--text-primary); background: var(--bg-hover); }
.modal-body { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.75rem; padding-top: 0.5rem; }

/* ============================================================ TOAST */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 300; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.75rem 1rem;
  box-shadow: var(--shadow); font-size: 0.875rem; max-width: 320px;
  display: flex; align-items: center; gap: 0.75rem;
  animation: slideIn 0.3s ease; cursor: pointer;
}
.toast.success { border-left: 4px solid var(--green); }
.toast.error { border-left: 4px solid var(--red); }
.toast.info { border-left: 4px solid var(--blue); }
@keyframes slideIn { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform: translateX(0); } }

/* ============================================================ LOADER */
.page-loader {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 40vh; gap: 1rem;
}
.loader-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { color: var(--text-secondary); font-size: 0.875rem; }

/* ============================================================ SEARCH / FILTER BAR */
.filter-bar {
  display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center;
  margin-bottom: 1rem;
}
.filter-bar input { max-width: 280px; }
.filter-bar select { max-width: 200px; }

/* ============================================================ TABS */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
.tab {
  padding: 0.6rem 1rem; font-size: 0.875rem; font-weight: 600;
  color: var(--text-secondary); cursor: pointer; border-bottom: 2px solid transparent;
  transition: var(--transition); white-space: nowrap;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--gold); border-bottom-color: var(--gold); }

/* ============================================================ PROGRESS */
.progress-bar-wrap { background: var(--bg-surface); border-radius: 20px; height: 6px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 20px; background: var(--gold); transition: width 0.5s ease; }

/* ============================================================ EMPTY STATE */
.empty-state {
  text-align: center; padding: 3rem 1rem; color: var(--text-secondary);
}
.empty-state .es-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-state .es-title { font-size: 1rem; font-weight: 600; color: var(--text-primary); margin-bottom: 0.5rem; }
.empty-state .es-desc { font-size: 0.875rem; margin-bottom: 1.25rem; }

/* ============================================================ MONEY */
.money-positive { color: var(--green); font-weight: 700; }
.money-negative { color: var(--red); font-weight: 700; }
.money-neutral { color: var(--gold); font-weight: 700; }

/* ============================================================ TIMELINE */
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item { display: flex; gap: 1rem; }
.timeline-dot-col { display: flex; flex-direction: column; align-items: center; }
.timeline-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gold); flex-shrink: 0; margin-top: 0.35rem; }
.timeline-line { width: 2px; background: var(--border); flex: 1; margin: 4px auto; }
.timeline-item:last-child .timeline-line { display: none; }
.timeline-content { padding-bottom: 1rem; flex: 1; }

/* ============================================================ RESPONSIVE */
@media (max-width: 768px) {
  body:not(.login-page) { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: -100%; top: 0; height: 100%;
    width: var(--sidebar-w); z-index: 200;
    transition: left 0.3s ease;
  }
  .sidebar.open { left: 0; }
  .topbar { display: flex; grid-column: 1; }
  .main-content { grid-column: 1; padding: 1rem; padding-top: calc(var(--topbar-h) + 1rem); }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .modal { max-width: 96%; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

/* Print */
@media print {
  .sidebar, .topbar, .modal-overlay, .toast-container { display: none !important; }
  .main-content { grid-column: 1 / -1; padding: 0; }
  body { background: #fff; color: #000; }
  .card { border: 1px solid #ddd; }
  th { background: #f5f5f5 !important; color: #333 !important; }
}
