/* ============================================================
   FinTrack Pro — Theme
   assets/css/theme.css
   
   Centralised colour palette — edit CSS variables here to
   retheme the whole application.
   ============================================================ */

/* ---- CSS Custom Properties (mirrors config.php defines) ---- */
:root {
  --color-primary:    #4A90D9;
  --color-primary-dk: #3270B5;
  --color-primary-lt: #EBF4FF;
  --color-secondary:  #6CB8B2;
  --color-success:    #5CB85C;
  --color-danger:     #E05252;
  --color-warning:    #F0AD4E;
  --color-info:       #5BC0DE;
  --color-light:      #F8FAFC;
  --color-dark:       #2C3E50;
  --color-muted:      #8898A4;
  --color-border:     #DDE4EB;

  --nav-height:       60px;
  --sidebar-width:    250px;
  --sidebar-collapsed:64px;

  --nav-bg:           #FFFFFF;
  --nav-shadow:       0 2px 8px rgba(0,0,0,.08);
  --sidebar-bg:       #F0F4F8;
  --sidebar-hover:    #E0E9F4;
  --sidebar-active:   var(--color-primary);
  --sidebar-text:     #3A4A58;
  --sidebar-icon:     var(--color-primary);

  --body-bg:          #F4F7FB;
  --card-bg:          #FFFFFF;
  --card-radius:      10px;
  --card-shadow:      0 2px 12px rgba(74,144,217,.07);

  --font-main:        'Nunito', 'Segoe UI', sans-serif;
  --transition:       .22s ease;
}

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

body {
  font-family: var(--font-main);
  background: var(--body-bg);
  color: var(--color-dark);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ============================================================
   TOP NAVBAR
   ============================================================ */
.top-navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: var(--nav-bg);
  box-shadow: var(--nav-shadow);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  z-index: 1000;
  gap: .75rem;
}

.navbar-brand {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--color-primary);
  text-decoration: none;
  letter-spacing: -.5px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.navbar-brand span { color: var(--color-secondary); }

.btn-sidebar-toggle {
  background: none;
  border: none;
  color: var(--color-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: .35rem .5rem;
  border-radius: 6px;
  transition: var(--transition);
  line-height: 1;
}
.btn-sidebar-toggle:hover { background: var(--color-primary-lt); color: var(--color-primary); }

.navbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.navbar-user {
  display: flex;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
  padding: .3rem .6rem;
  border-radius: 8px;
  transition: var(--transition);
  text-decoration: none;
  color: var(--color-dark);
  font-weight: 600;
  font-size: .9rem;
}
.navbar-user:hover { background: var(--color-primary-lt); color: var(--color-primary); }

.avatar-circle {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  position: fixed;
  top: var(--nav-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--transition);
  z-index: 900;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-menu {
  list-style: none;
  padding: .75rem 0;
  flex: 1;
}

.sidebar-item { position: relative; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .7rem 1rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 0 24px 24px 0;
  margin: 1px .5rem 1px 0;
  transition: var(--transition);
  white-space: nowrap;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
}
.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: var(--color-primary);
}
.sidebar-link.active {
  background: var(--color-primary-lt);
  color: var(--color-primary);
}
.sidebar-link i {
  width: 20px;
  text-align: center;
  font-size: 1rem;
  color: var(--sidebar-icon);
  flex-shrink: 0;
}
.sidebar-link .link-text { transition: opacity var(--transition); }
.sidebar-link .caret {
  margin-left: auto;
  font-size: .7rem;
  transition: transform var(--transition);
}
.sidebar-link.has-children.open .caret { transform: rotate(90deg); }

/* Submenu */
.sidebar-submenu {
  list-style: none;
  overflow: hidden;
  max-height: 0;
  transition: max-height .3s ease;
  background: rgba(0,0,0,.02);
}
.sidebar-submenu.open { max-height: 500px; }
.sidebar-submenu .sidebar-link {
  padding-left: 1rem;
  font-size: .875rem;
  font-weight: 500;
}
/* Sub-item icon — same left column as parent, smaller dot-style */
.sidebar-submenu .sidebar-link i {
  width: 20px;
  font-size: .7rem;
  color: var(--color-muted);
  text-align: center;
  flex-shrink: 0;
}
.sidebar-submenu .sidebar-link:hover i,
.sidebar-submenu .sidebar-link.active i { color: var(--color-primary); }

/* Collapsed state — icons perfectly centered, text/caret take zero space */
.sidebar.collapsed .link-text,
.sidebar.collapsed .caret {
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  pointer-events: none;
  flex-shrink: 1;
  transition: opacity var(--transition), max-width var(--transition);
}
.sidebar.collapsed .sidebar-link {
  justify-content: center;
  padding: .72rem 0;
  margin: 2px 8px;
  border-radius: 10px;
  gap: 0;
  width: calc(var(--sidebar-collapsed) - 16px);
}
.sidebar.collapsed .sidebar-link i {
  width: 22px;
  font-size: 1.1rem;
  text-align: center;
  flex-shrink: 0;
  margin: 0;
}
.sidebar.collapsed .sidebar-submenu { display: none; }
.sidebar.collapsed .sidebar-divider  { margin: .5rem 8px; }

/* Tooltip on collapsed */
.sidebar.collapsed .sidebar-item { position: relative; }
.sidebar.collapsed .sidebar-item:hover::after {
  content: attr(data-label);
  position: absolute;
  left: calc(var(--sidebar-collapsed) + 2px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--color-dark);
  color: #fff;
  padding: .3rem .75rem;
  border-radius: 7px;
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
  z-index: 1100;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
/* Arrow on tooltip */
.sidebar.collapsed .sidebar-item:hover::before {
  content: '';
  position: absolute;
  left: calc(var(--sidebar-collapsed) - 3px);
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-right-color: var(--color-dark);
  z-index: 1101;
  pointer-events: none;
}

.sidebar-divider {
  height: 1px;
  background: var(--color-border);
  margin: .5rem 1rem;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-wrapper {
  margin-left: var(--sidebar-width);
  margin-top: var(--nav-height);
  transition: margin-left var(--transition);
  min-height: calc(100vh - var(--nav-height));
  padding: 1.5rem;
}
.main-wrapper.sidebar-collapsed { margin-left: var(--sidebar-collapsed); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  border: 1px solid var(--color-border);
  margin-bottom: 1.25rem;
}
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: .75rem;
  background: transparent;
  border-radius: var(--card-radius) var(--card-radius) 0 0;
}
.card-header h5, .card-header .card-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  color: var(--color-dark);
}
.card-body { padding: 1.25rem; }
.card-footer {
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--color-border);
  background: transparent;
}

/* ============================================================
   STAT CARDS (Dashboard)
   ============================================================ */
.stat-card {
  border-radius: var(--card-radius);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--card-shadow);
  border: 1px solid transparent;
  transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(74,144,217,.13); }
.stat-card .icon-wrap {
  width: 52px; height: 52px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.stat-card .stat-label { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; opacity: .7; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 800; line-height: 1.2; }
.stat-card .stat-sub { font-size: .8rem; opacity: .7; margin-top: .15rem; }

.stat-income  { background: #EBF9EB; border-color: #C3E8C3; }
.stat-income  .icon-wrap { background: #5CB85C20; color: var(--color-success); }
.stat-income  .stat-value { color: var(--color-success); }

.stat-expense { background: #FDF0F0; border-color: #F5CECE; }
.stat-expense .icon-wrap { background: #E0525220; color: var(--color-danger); }
.stat-expense .stat-value { color: var(--color-danger); }

.stat-balance { background: #EBF4FF; border-color: #BDD8F5; }
.stat-balance .icon-wrap { background: #4A90D920; color: var(--color-primary); }
.stat-balance .stat-value { color: var(--color-primary); }

.stat-records { background: #F3F0FF; border-color: #D5C8F5; }
.stat-records .icon-wrap { background: #7C5CFC20; color: #7C5CFC; }
.stat-records .stat-value { color: #7C5CFC; }

/* ============================================================
   DATA TABLE / GRID
   ============================================================ */
.table-card .card-header { justify-content: space-between; flex-wrap: wrap; gap: .5rem; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: var(--color-primary-lt);
  color: var(--color-primary-dk);
  font-weight: 700;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: .7rem 1rem;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}
.data-table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
  font-size: .9rem;
}
.data-table tbody tr:hover { background: var(--color-primary-lt); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Action buttons in table */
.btn-action {
  width: 30px; height: 30px;
  border: none;
  border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .8rem;
  cursor: pointer;
  transition: var(--transition);
}
.btn-view   { background: #EBF4FF; color: var(--color-primary); }
.btn-edit   { background: #FFF8E6; color: var(--color-warning); }
.btn-delete { background: #FDF0F0; color: var(--color-danger); }
.btn-view:hover   { background: var(--color-primary); color: #fff; }
.btn-edit:hover   { background: var(--color-warning); color: #fff; }
.btn-delete:hover { background: var(--color-danger); color: #fff; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem 1rem;
  border-radius: 7px;
  border: none;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
  font-family: var(--font-main);
}
.btn-sm { padding: .3rem .7rem; font-size: .82rem; }
.btn-lg { padding: .65rem 1.4rem; font-size: 1rem; }

.btn-primary   { background: var(--color-primary);   color: #fff; }
.btn-primary:hover   { background: var(--color-primary-dk); color: #fff; }
.btn-success   { background: var(--color-success);   color: #fff; }
.btn-success:hover   { background: #4cae4c; }
.btn-danger    { background: var(--color-danger);    color: #fff; }
.btn-danger:hover    { background: #c0392b; }
.btn-warning   { background: var(--color-warning);   color: #fff; }
.btn-warning:hover   { background: #d68910; }
.btn-secondary { background: #E5EDF5; color: var(--color-dark); }
.btn-secondary:hover { background: var(--color-border); }
.btn-outline-primary { background: transparent; border: 1.5px solid var(--color-primary); color: var(--color-primary); }
.btn-outline-primary:hover { background: var(--color-primary); color: #fff; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block;
  font-size: .88rem;
  font-weight: 600;
  margin-bottom: .35rem;
  color: var(--color-dark);
}
.form-control {
  width: 100%;
  padding: .5rem .85rem;
  border: 1.5px solid var(--color-border);
  border-radius: 7px;
  font-size: .92rem;
  font-family: var(--font-main);
  color: var(--color-dark);
  background: #fff;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(74,144,217,.13);
}
.form-control.is-invalid { border-color: var(--color-danger); }
.invalid-feedback { color: var(--color-danger); font-size: .82rem; margin-top: .25rem; }

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ============================================================
   BADGE
   ============================================================ */
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .3px;
}
.badge-success { background: #EBF9EB; color: var(--color-success); }
.badge-danger  { background: #FDF0F0; color: var(--color-danger); }
.badge-primary { background: var(--color-primary-lt); color: var(--color-primary); }
.badge-warning { background: #FFF8E6; color: var(--color-warning); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(44,62,80,.45);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 540px;
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
  animation: modalIn .25s ease;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-box.modal-lg { max-width: 760px; }
@keyframes modalIn {
  from { transform: scale(.96) translateY(10px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h5 { font-size: 1.05rem; font-weight: 700; margin: 0; }
.modal-close {
  background: none; border: none;
  font-size: 1.2rem; cursor: pointer;
  color: var(--color-muted);
  line-height: 1;
  padding: .2rem;
}
.modal-close:hover { color: var(--color-danger); }
.modal-body { padding: 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--color-border);
  display: flex; justify-content: flex-end; gap: .5rem;
}

/* ============================================================
   ALERTS / TOASTS
   ============================================================ */
.alert {
  padding: .75rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: .9rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: 1rem;
}
.alert-success { background: #EBF9EB; border-color: #C3E8C3; color: #2E7D32; }
.alert-danger  { background: #FDF0F0; border-color: #F5CECE; color: #C62828; }
.alert-warning { background: #FFF8E6; border-color: #FFE0A0; color: #795548; }
.alert-info    { background: #EBF4FF; border-color: #BDD8F5; color: #1565C0; }

#toast-container {
  position: fixed;
  top: calc(var(--nav-height) + 10px);
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  min-width: 280px;
  max-width: 360px;
}
.toast {
  display: flex; align-items: center; gap: .65rem;
  padding: .75rem 1rem;
  border-radius: 9px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  font-size: .9rem;
  font-weight: 600;
  animation: toastIn .3s ease;
  cursor: pointer;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }
.toast-success { background: #2E7D32; color: #fff; }
.toast-error   { background: #C62828; color: #fff; }
.toast-info    { background: var(--color-primary); color: #fff; }

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.25rem;
}
.page-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--color-dark);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.page-title i { color: var(--color-primary); }

.breadcrumb { display: flex; gap: .35rem; font-size: .82rem; color: var(--color-muted); align-items: center; }
.breadcrumb a { color: var(--color-primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ============================================================
   SEARCH / FILTER BAR
   ============================================================ */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  margin-bottom: 1rem;
  align-items: flex-end;
}
.filter-bar .form-group { margin-bottom: 0; }
.filter-bar .form-control { min-width: 150px; }

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #EBF4FF 0%, #F0F4F8 60%, #EBF9EB 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.auth-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(74,144,217,.13);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}
.auth-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}
.auth-logo h1 { font-size: 2rem; font-weight: 900; color: var(--color-primary); }
.auth-logo h1 span { color: var(--color-secondary); }
.auth-logo p { color: var(--color-muted); font-size: .9rem; }
.auth-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 1.25rem; text-align: center; }
.auth-footer { text-align: center; margin-top: 1.25rem; font-size: .88rem; color: var(--color-muted); }
.auth-footer a { color: var(--color-primary); text-decoration: none; font-weight: 600; }

/* ============================================================
   SWITCH TOGGLE
   ============================================================ */
.switch { position: relative; display: inline-block; width: 44px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; inset: 0;
  background: #ccc;
  border-radius: 22px;
  transition: .3s;
  cursor: pointer;
}
.switch-slider::before {
  content: '';
  position: absolute;
  height: 16px; width: 16px;
  left: 3px; bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .3s;
}
input:checked + .switch-slider { background: var(--color-primary); }
input:checked + .switch-slider::before { transform: translateX(22px); }

/* ============================================================
   PERMISSIONS GRID
   ============================================================ */
.perm-table th:not(:first-child) { text-align: center; width: 80px; }
.perm-table td:not(:first-child) { text-align: center; }

/* ============================================================
   UTILITY
   ============================================================ */
.text-primary   { color: var(--color-primary) !important; }
.text-success   { color: var(--color-success) !important; }
.text-danger    { color: var(--color-danger)  !important; }
.text-warning   { color: var(--color-warning) !important; }
.text-muted     { color: var(--color-muted)   !important; }
.text-center    { text-align: center; }
.text-right     { text-align: right; }
.fw-bold        { font-weight: 700; }
.d-flex         { display: flex; }
.align-center   { align-items: center; }
.gap-1          { gap: .25rem; }
.gap-2          { gap: .5rem; }
.gap-3          { gap: .75rem; }
.mt-1 { margin-top: .25rem; } .mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: 1rem; }   .mb-1 { margin-bottom: .25rem; }
.mb-2 { margin-bottom: .5rem;} .mb-3 { margin-bottom: 1rem; }
.p-0  { padding: 0; }
.w-100 { width: 100%; }
.row { display: flex; flex-wrap: wrap; gap: 1rem; }
.col-6 { flex: 0 0 calc(50% - .5rem); min-width: 0; }
.col-4 { flex: 0 0 calc(33.333% - .67rem); min-width: 0; }
.col-3 { flex: 0 0 calc(25% - .75rem); min-width: 0; }
.col-12 { flex: 0 0 100%; }
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-muted);
}
.empty-state i { font-size: 3rem; margin-bottom: 1rem; display: block; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 992px) {
  :root { --sidebar-width: 220px; }
}

@media (max-width: 768px) {
  .sidebar {
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform var(--transition), width var(--transition);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar.collapsed   { width: var(--sidebar-width); transform: translateX(-100%); }

  .main-wrapper,
  .main-wrapper.sidebar-collapsed { margin-left: 0; }

  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.3);
    z-index: 850;
  }
  .sidebar-overlay.active { display: block; }

  .col-6, .col-4, .col-3 { flex: 0 0 100%; }
  .filter-bar { flex-direction: column; align-items: stretch; }
}

@media (max-width: 480px) {
  .main-wrapper { padding: 1rem .75rem; }
  .auth-card { padding: 1.75rem 1.25rem; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .data-table td, .data-table th { padding: .5rem .6rem; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }

/* Chart.js canvas */
canvas { max-width: 100%; }
