/* === Poitav Theme === */
:root {
  --navy: #1a1d4e;
  --navy-2: #1e2060;
  --gold: #c9a428;
  --white: #ffffff;
  --body-text: #2c2c2c;
  --light-bg: #f5f6fa;
  --border: #e0e3ef;
}

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

body {
  font-family: 'Inter', 'Poppins', sans-serif;
  background: var(--light-bg);
  color: var(--body-text);
  min-height: 100vh;
}

/* Navbar */
.navbar {
  background: var(--navy);
  padding: 0 2rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.navbar-brand .logo-text {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: 0.03em;
}
.navbar-brand .logo-text span {
  color: var(--gold);
}
.navbar-meta {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.5);
}
.sync-badge {
  font-size: 0.72rem;
  color: var(--gold);
  border: 1px solid var(--gold);
  border-radius: 20px;
  padding: 3px 10px;
}

/* Page layout */
.page-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Section heading */
.section-heading {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 1.25rem;
}
.section-heading span {
  color: var(--gold);
}

/* Client filter bar */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 1rem;
}
.filter-bar-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--navy);
}
.filter-bar select {
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 0.85rem;
  color: var(--body-text);
  background: var(--white);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
  min-width: 200px;
}
.filter-bar select:focus {
  border-color: var(--navy);
}

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}
.kpi-card {
  background: var(--navy);
  border-radius: 12px;
  padding: 1.4rem 1.5rem;
  position: relative;
  overflow: hidden;
  color: var(--white);
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 4px 16px rgba(26,29,78,0.15);
}
.kpi-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.55);
}
.kpi-value {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--white);
  line-height: 1;
}
.kpi-value.gold {
  color: var(--gold);
}
.kpi-sub {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.4);
}
.kpi-active-indicator {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: transparent;
  transition: background 0.2s;
}
.kpi-clickable {
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}
.kpi-clickable:hover {
  border-color: rgba(201,164,40,0.5);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(26,29,78,0.3);
}
.kpi-clickable.active {
  border-color: var(--gold);
  box-shadow: 0 8px 28px rgba(201,164,40,0.25);
}
.kpi-clickable.active .kpi-active-indicator {
  background: var(--gold);
}
.kpi-clickable.active .kpi-label {
  color: var(--gold);
}
.kpi-separated {
  margin-left: 2.5rem;
}

/* Overview header row */
.overview-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}
.overview-header .section-heading {
  margin-bottom: 0;
}

/* Date filter */
.date-filter {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.period-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.period-btn {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 0.78rem;
  font-weight: 500;
  color: #666;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.period-btn:hover {
  border-color: var(--navy);
  color: var(--navy);
}
.period-btn.active {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--white);
}
.custom-dates {
  display: none;
  align-items: center;
  gap: 8px;
}
.custom-dates.visible {
  display: flex;
}
.custom-dates input[type="date"] {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.82rem;
  color: var(--body-text);
  outline: none;
  transition: border 0.15s;
}
.custom-dates input[type="date"]:focus {
  border-color: var(--navy);
}
.btn-apply {
  background: var(--navy);
  border: none;
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--white);
  cursor: pointer;
  transition: background 0.15s;
}
.btn-apply:hover {
  background: var(--navy-2);
}

/* Aging section */
.aging-section {
  background: var(--white);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  margin-bottom: 2rem;
  overflow: hidden;
}
.aging-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.aging-section-header:hover { background: #f5f6fa; }
.aging-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--navy);
}
.aging-section-title span { color: var(--gold); }
.aging-toggle-btn {
  background: none;
  border: none;
  color: var(--navy);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 8px;
}
.aging-body { padding: 0 1.5rem 1.5rem; }
.aging-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  /* top-5 + others = 6 cards; adjust automatically if fewer */
  gap: 1rem;
}
.aging-card {
  background: var(--navy);
  border-radius: 10px;
  padding: 1rem 1rem 0.85rem;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.aging-card:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(26,29,78,0.25);
}
.aging-card.active {
  border-color: var(--gold);
  box-shadow: 0 6px 20px rgba(201,164,40,0.25);
}
.aging-card-others {
  border-style: dashed;
  border-color: rgba(201,164,40,0.35);
  opacity: 0.85;
  cursor: default;
}
.aging-card-others:hover {
  transform: none;
  box-shadow: none;
  border-color: rgba(201,164,40,0.5);
}
.aging-others-count {
  font-size: 0.7rem;
  color: var(--gold);
  opacity: 0.75;
}
.aging-cname {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--white);
  margin-bottom: 0.75rem;
  white-space: normal;
  overflow-wrap: break-word;
  min-height: 2.2em;
}
.aging-stats { display: flex; flex-direction: column; gap: 0.35rem; }
.aging-stat  { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; }
.aging-stat-label {
  font-size: 0.62rem;
  color: rgba(255,255,255,0.45);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.aging-stat-value { font-size: 0.78rem; font-weight: 600; color: var(--white); white-space: nowrap; }
.aging-warn  { color: #f5c842; }
.aging-alert { color: #ff6b6b; }
@media (max-width: 1100px) { .aging-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px)  { .aging-grid { grid-template-columns: repeat(2, 1fr); } }

/* Chart grid */
.charts-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}
.chart-card {
  background: var(--white);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  border: 1px solid var(--border);
}
.chart-card h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--navy);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chart-card h3::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 16px;
  background: var(--gold);
  border-radius: 2px;
}
.chart-breakdown canvas { max-height: 300px; }
.chart-accounts canvas  { max-height: 360px; }

/* Table section */
.table-section {
  background: var(--white);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  border: 1px solid var(--border);
}
.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  align-items: center;
}
.table-toolbar input,
.table-toolbar select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 0.85rem;
  color: var(--body-text);
  background: var(--white);
  outline: none;
  transition: border 0.15s;
}
.table-toolbar input:focus,
.table-toolbar select:focus {
  border-color: var(--navy);
}
.table-toolbar input[type="text"] {
  flex: 1;
  min-width: 200px;
}
.btn-subtotals {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.82rem;
  color: #888;
  cursor: pointer;
  transition: border 0.15s, color 0.15s, background 0.15s;
}
.btn-subtotals:hover {
  border-color: var(--navy);
  color: var(--navy);
}
.btn-subtotals.active {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--white);
}
.btn-reset {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.82rem;
  color: #888;
  cursor: pointer;
  transition: border 0.15s, color 0.15s;
}
.btn-reset:hover {
  border-color: var(--navy);
  color: var(--navy);
}

/* Table summary bar (legacy div — now empty) */
.table-summary { display: none; }

/* In-table summary row */
.tbl-summary-row { pointer-events: none; }
.tbl-sum-cell {
  padding: 0.35rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #888;
  background: rgba(0,0,0,0.08);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  white-space: nowrap;
}
.tbl-sum-amount {
  color: var(--gold);
  text-align: right;
}

/* Data table */
.data-table-wrapper {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
thead th {
  background: var(--navy);
  color: rgba(255,255,255,0.85);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
thead tr:first-child th:first-child { border-radius: 8px 0 0 0; }
thead tr:first-child th:last-child  { border-radius: 0 8px 0 0; }

/* Filter row */
tr.filter-row td {
  background: #eef0f9;
  padding: 5px 6px;
  border-bottom: 2px solid var(--border);
}
.col-filter-cell { vertical-align: top; }
.col-filter-select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 5px;
  font-size: 0.72rem;
  color: var(--body-text);
  background: var(--white);
  cursor: pointer;
  outline: none;
}
.col-filter-select:focus { border-color: var(--navy); }
#col-custom-dates {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
#col-custom-dates input[type="date"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 0.7rem;
  color: var(--body-text);
  outline: none;
}
#col-custom-dates input[type="date"]:focus { border-color: var(--navy); }
.btn-apply-sm {
  background: var(--navy);
  border: none;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--white);
  cursor: pointer;
  transition: background 0.15s;
}
.btn-apply-sm:hover { background: var(--navy-2); }
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
tbody tr:hover { background: #f0f2fb; }
tbody tr.row-link { cursor: pointer; }
tbody tr.row-link:hover { background: #e8ecf8; }
tbody td {
  padding: 9px 12px;
  color: var(--body-text);
  vertical-align: top;
}
td.col-date { white-space: nowrap; }
td.col-vendor {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
td.desc {
  max-width: 320px;
  white-space: pre-line;
  word-break: break-word;
  font-size: 0.78rem;
  color: #555;
}
td.amount { text-align: right; font-weight: 600; white-space: nowrap; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-paid    { background: #e6f4ea; color: #2e7d32; }
.badge-open    { background: #fff8e1; color: #e65100; }
.badge-overdue { background: #fde8e8; color: #c62828; }
.badge-partial { background: #e3f2fd; color: #1565c0; }
.badge-other   { background: #f3f3f3; color: #666; }
.badge-billable     { background: #e8f5e9; color: #2e7d32; }
.badge-nonbillable  { background: #fce4ec; color: #c62828; }
.badge-reimb-no     { background: #fde8e8; color: #c62828; }
.badge-reimb-billed { background: #fff8e1; color: #b45309; }
.badge-reimb-yes    { background: #e8f5e9; color: #2e7d32; }

/* Sortable headers */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: #c9a428; }
th.sort-asc::after  { content: ' ▲'; color: #c9a428; font-size: 0.75em; }
th.sort-desc::after { content: ' ▼'; color: #c9a428; font-size: 0.75em; }

/* Draggable column handles */
th[draggable] { user-select: none; }
.col-drag-handle {
  display: inline-block;
  cursor: grab;
  margin-right: 5px;
  color: rgba(255,255,255,0.28);
  font-size: 0.95rem;
  vertical-align: middle;
  line-height: 1;
  transition: color 0.15s;
}
.col-drag-handle:active { cursor: grabbing; }
th:hover .col-drag-handle { color: rgba(255,255,255,0.65); }
th.col-dragging { opacity: 0.45; }
th.col-drag-over {
  background: rgba(201,164,40,0.18) !important;
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

/* Account grouping (logbook view) */
tr.account-section-header {
  cursor: pointer;
  user-select: none;
}
tr.account-section-header td {
  background: var(--navy);
  color: var(--gold);
  padding: 9px 12px;
  border-top: 5px solid var(--light-bg);
}
tr.account-section-header:first-child td {
  border-top: none;
}
tr.account-section-header:hover td {
  background: var(--navy-2);
}
.acct-name {
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-right: 0.75rem;
}
.acct-total {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--white) !important;
}
.acct-toggle {
  background: none;
  border: 1px solid rgba(201,164,40,0.5);
  border-radius: 4px;
  color: var(--gold);
  cursor: pointer;
  padding: 2px 8px;
  font-size: 0.75rem;
  line-height: 1.4;
  transition: background 0.15s, border-color 0.15s;
}
.acct-toggle:hover {
  background: rgba(201,164,40,0.15);
  border-color: var(--gold);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.pagination-info { font-size: 0.8rem; color: #888; }
.pagination-controls { display: flex; gap: 6px; }
.page-btn {
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
.page-btn:hover { border-color: var(--navy); background: #f0f2fb; }
.page-btn.active { background: var(--navy); color: var(--white); border-color: var(--navy); }
.page-btn:disabled { opacity: 0.4; cursor: default; }

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, #e8e8e8 25%, #f5f5f5 50%, #e8e8e8 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 6px;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Responsive */
@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .overview-header { flex-direction: column; }
  .date-filter { align-items: flex-start; }
  .period-pills { justify-content: flex-start; }
}
