:root {
  --brand-dark: #1b2a41;
  --brand-mid: #2c4257;
  --brand-accent: #e08e28;
  --brand-accent-dark: #c8761a;
  --success: #2f8f4e;
  --danger: #c0392b;
  --card-radius: 10px;

  /* Light theme (default) */
  --bg-page: #f4f6f8;
  --text-primary: #22303f;
  --text-heading: #1b2a41;
  --text-muted: #7a8794;
  --surface: #ffffff;
  --surface-border: transparent;
  --card-shadow: 0 1px 4px rgba(20,30,40,0.06);
  --topbar-bg: #ffffff;
  --topbar-border: #e3e8ee;
  --hover-bg: #eef2f5;
  --table-thead-color: #7a8794;
  --switch-track-off: #d7dee5;
}

/* Dark theme — palette taken from the Projects-Copy reference project */
html[data-theme="dark"] {
  --bg-page: #0a0e1a;
  --text-primary: #e5e7eb;
  --text-heading: #ffffff;
  --text-muted: #9ca3af;
  --surface: rgba(255,255,255,.03);
  --surface-border: rgba(255,255,255,.07);
  --card-shadow: none;
  --topbar-bg: #0f1420;
  --topbar-border: rgba(255,255,255,.08);
  --hover-bg: rgba(255,255,255,.08);
  --table-thead-color: #9ca3af;
  --switch-track-off: #3a4150;
}

body {
  background: var(--bg-page);
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  transition: background .2s ease, color .2s ease;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  background: linear-gradient(180deg, var(--brand-dark), var(--brand-mid));
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  font-weight: 700;
  font-size: 1.05rem;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.sidebar-brand i { color: var(--brand-accent); font-size: 1.4rem; }

.sidebar-project { padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,0.12); }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  text-decoration: none;
  color: inherit;
}
.sidebar-user:hover { background: rgba(255,255,255,0.06); color: inherit; }
.sidebar-user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.sidebar-user-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-accent);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
}
.sidebar-user-info { min-width: 0; }
.sidebar-user-name { color: #fff; font-weight: 600; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { color: rgba(255,255,255,0.6); font-size: 0.76rem; }

.profile-avatar-lg {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.profile-avatar-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-accent);
  color: #fff;
  font-weight: 700;
  font-size: 1.8rem;
}

.sidebar-nav { list-style: none; padding: 10px 0; margin: 0; flex: 1; }
.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  padding: 11px 20px;
  font-size: 0.92rem;
  border-left: 3px solid transparent;
  transition: all .15s ease;
}
.sidebar-nav li a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-nav li a.active {
  background: rgba(224,142,40,0.16);
  border-left-color: var(--brand-accent);
  color: #fff;
  font-weight: 600;
}
.sidebar-nav li a i { width: 18px; text-align: center; }

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  padding: 14px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  transition: background .2s ease, border-color .2s ease;
}
.topbar-title { font-size: 1.15rem; font-weight: 700; color: var(--text-heading); }
.topbar-user { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }

.role-badge { text-transform: uppercase; font-size: 0.68rem; letter-spacing: .04em; }
.role-admin { background: var(--brand-accent) !important; }
.role-accountant { background: #3a7bd5 !important; }
.role-member { background: #6c757d !important; }
.role-viewer { background: #9aa5b1 !important; }

.content { padding: 26px; flex: 1; }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--card-radius);
  padding: 18px 20px;
  box-shadow: var(--card-shadow);
  border-left: 4px solid var(--brand-accent);
  height: 100%;
}
.kpi-card .kpi-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; }
.kpi-card .kpi-value { font-size: 1.5rem; font-weight: 700; color: var(--text-heading); margin-top: 4px; }
.kpi-card.accent-blue { border-left-color: #3a7bd5; }
.kpi-card.accent-green { border-left-color: var(--success); }
.kpi-card.accent-red { border-left-color: var(--danger); }

.panel {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--card-radius);
  padding: 20px;
  box-shadow: var(--card-shadow);
  margin-bottom: 22px;
}
.panel-title {
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 14px;
  font-size: 1rem;
}

.table thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--table-thead-color);
  border-bottom-width: 1px;
}

.btn-brand {
  background: var(--brand-accent);
  border-color: var(--brand-accent);
  color: #fff;
}
.btn-brand:hover { background: var(--brand-accent-dark); border-color: var(--brand-accent-dark); color: #fff; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand-mid));
}
.login-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 40px 36px;
  width: 380px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.login-card h3 { color: var(--text-heading); font-weight: 700; }
.sidebar-section-label { padding: 12px 16px 5px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #8b95a7; font-weight: 700; }

/* Dark/light toggle switch */
.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  padding: 4px;
  cursor: pointer;
  line-height: 1;
}
.theme-switch i { font-size: .8rem; color: var(--text-muted); }
.theme-switch .switch-track {
  width: 38px;
  height: 20px;
  border-radius: 999px;
  background: var(--switch-track-off);
  position: relative;
  transition: background .2s ease;
  flex-shrink: 0;
}
.theme-switch .switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
html[data-theme="dark"] .theme-switch .switch-track { background: var(--brand-accent); }
html[data-theme="dark"] .theme-switch .switch-track::after { transform: translateX(18px); }

/* Dark-theme adjustments for Bootstrap components */
html[data-theme="dark"] .table {
  --bs-table-bg: transparent;
  --bs-table-color: #e5e7eb;
  --bs-table-striped-bg: rgba(255,255,255,.025);
  --bs-table-striped-color: #e5e7eb;
  --bs-table-hover-bg: rgba(255,255,255,.035);
  --bs-table-hover-color: #fff;
  --bs-table-border-color: rgba(255,255,255,.08);
}
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
  background-color: #131826;
  border-color: rgba(255,255,255,.15);
  color: #e5e7eb;
}
html[data-theme="dark"] .form-control::placeholder { color: #6b7280; }
html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
  background-color: #131826;
  color: #fff;
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 .2rem rgba(224,142,40,.25);
}
html[data-theme="dark"] .btn-outline-secondary { color: #e5e7eb; border-color: rgba(255,255,255,.25); }
html[data-theme="dark"] .btn-outline-secondary:hover { background: rgba(255,255,255,.08); color: #fff; }
html[data-theme="dark"] .btn-outline-danger { color: #f87171; border-color: rgba(248,113,113,.4); }
html[data-theme="dark"] .btn-outline-danger:hover { background: rgba(248,113,113,.12); color: #fff; }
html[data-theme="dark"] .alert-warning { background: rgba(245,158,11,.12); border-color: rgba(245,158,11,.3); color: #fbbf24; }
html[data-theme="dark"] .dropdown-menu { background: #131826; border-color: rgba(255,255,255,.08); }
html[data-theme="dark"] .dropdown-item { color: #e5e7eb; }
html[data-theme="dark"] .dropdown-item:hover,
html[data-theme="dark"] .dropdown-item:focus { background: rgba(255,255,255,.08); color: #fff; }
html[data-theme="dark"] hr { border-color: rgba(255,255,255,.08); }
html[data-theme="dark"] code { color: #f59e0b; background: rgba(255,255,255,.06); }
html[data-theme="dark"] .text-muted { color: var(--text-muted) !important; }
html[data-theme="dark"] .sidebar-toggle:hover { background: rgba(255,255,255,.08); }

/* Responsive navigation and mobile usability */
.topbar-left { display:flex; align-items:center; gap:10px; min-width:0; }
.sidebar-toggle { display:none; border:0; background:transparent; color:var(--text-heading); font-size:1.2rem; padding:6px 8px; border-radius:6px; }
.sidebar-toggle:hover { background: var(--hover-bg); }
.sidebar-backdrop { display:none; }
.table-responsive { overflow-x:auto; -webkit-overflow-scrolling:touch; }

@media (max-width: 991.98px) {
  .sidebar { position:fixed; left:0; top:0; bottom:0; height:100vh; z-index:1045; transform:translateX(-100%); transition:transform .2s ease; box-shadow:4px 0 18px rgba(0,0,0,.18); }
  .sidebar.open { transform:translateX(0); }
  .sidebar-backdrop.show { display:block; position:fixed; inset:0; z-index:1040; background:rgba(0,0,0,.45); }
  .sidebar-toggle { display:inline-flex; align-items:center; justify-content:center; }
  .topbar { padding:10px 14px; }
  .topbar-user > span:not(.role-badge) { display:none; }
  .content { padding:16px; }
}

@media (max-width: 575.98px) {
  .content { padding:10px; }
  .topbar-title { font-size:1rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .topbar-user .role-badge { display:none; }
  .panel { padding:14px; margin-bottom:14px; }
  .login-card { width:min(92vw,380px); padding:28px 20px; }
  .btn { min-height:38px; }
  .form-control, .form-select { min-height:40px; }
  .table { font-size:.86rem; }
  .table td, .table th { white-space:nowrap; }
}


/* ---- Dark-mode readability fixes (text / background / calendar icons) ---- */
html[data-theme="dark"] { color-scheme: dark; }
html[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
html[data-theme="dark"] input[type="month"]::-webkit-calendar-picker-indicator,
html[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator,
html[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(1.6); opacity: .9; cursor: pointer;
}
html[data-theme="dark"] .form-text { color: var(--text-muted) !important; }
html[data-theme="dark"] .form-label,
html[data-theme="dark"] label { color: var(--text-primary); }
html[data-theme="dark"] .form-select option { background: #131826; color: #e5e7eb; }
html[data-theme="dark"] .form-control:disabled,
html[data-theme="dark"] .form-select:disabled { background-color: #0f1420; color: #9ca3af; }
html[data-theme="dark"] .input-group-text { background: #1a2133; color: #e5e7eb; border-color: rgba(255,255,255,.15); }

/* highlighted table row (e.g. the project you are viewing) */
html[data-theme="dark"] .table > :not(caption) > * > * { color: var(--bs-table-color); }
html[data-theme="dark"] .table-active,
html[data-theme="dark"] .table > tbody > tr.table-active > * {
  --bs-table-bg-state: rgba(255,255,255,.07);
  --bs-table-color-state: #fff;
  color: #fff;
}
html[data-theme="dark"] .table-light,
html[data-theme="dark"] .table > thead.table-light > tr > * { --bs-table-bg: #1a2133; --bs-table-color: #e5e7eb; background: #1a2133; color: #e5e7eb; }

/* tabs */
html[data-theme="dark"] .nav-tabs { border-bottom-color: rgba(255,255,255,.12); }
html[data-theme="dark"] .nav-tabs .nav-link { color: #8ab4f8; border-color: transparent; }
html[data-theme="dark"] .nav-tabs .nav-link:hover,
html[data-theme="dark"] .nav-tabs .nav-link:focus { border-color: rgba(255,255,255,.12) rgba(255,255,255,.12) transparent; color: #fff; background: rgba(255,255,255,.06); }
html[data-theme="dark"] .nav-tabs .nav-link.active { background: #131826; color: #fff; border-color: rgba(255,255,255,.15) rgba(255,255,255,.15) #131826; }

/* list groups (contractor / labor / loan / deposit side lists) */
html[data-theme="dark"] .list-group { --bs-list-group-bg: transparent; --bs-list-group-color: #e5e7eb; --bs-list-group-border-color: rgba(255,255,255,.08);
  --bs-list-group-action-color: #e5e7eb; --bs-list-group-action-hover-color: #fff; --bs-list-group-action-hover-bg: rgba(255,255,255,.06);
  --bs-list-group-action-active-bg: rgba(255,255,255,.1); --bs-list-group-action-active-color: #fff; }
html[data-theme="dark"] .list-group-item { background: transparent; color: #e5e7eb; border-color: rgba(255,255,255,.08); }
html[data-theme="dark"] .list-group-item.active { background: rgba(224,142,40,.22); border-color: rgba(224,142,40,.5); color: #fff; }
html[data-theme="dark"] .list-group-item .text-muted { color: #9ca3af !important; }
html[data-theme="dark"] .list-group-item.active .text-muted,
html[data-theme="dark"] .list-group-item.active .text-white-50 { color: #e5e7eb !important; }

/* light-only helpers */
html[data-theme="dark"] .bg-light { background-color: rgba(255,255,255,.05) !important; color: #e5e7eb !important; }
html[data-theme="dark"] .bg-white { background-color: #131826 !important; color: #e5e7eb !important; }
html[data-theme="dark"] .badge.bg-light { background-color: #1f2740 !important; color: #e5e7eb !important; border-color: rgba(255,255,255,.18) !important; }
html[data-theme="dark"] .text-dark { color: #e5e7eb !important; }
html[data-theme="dark"] .badge.text-dark.bg-warning,
html[data-theme="dark"] .badge.bg-info.text-dark,
html[data-theme="dark"] .badge.bg-warning.text-dark { color: #111827 !important; }
html[data-theme="dark"] .border,
html[data-theme="dark"] .border-bottom,
html[data-theme="dark"] .border-top { border-color: rgba(255,255,255,.1) !important; }
html[data-theme="dark"] .alert-info { background: rgba(59,130,246,.12); border-color: rgba(59,130,246,.3); color: #93c5fd; }
html[data-theme="dark"] .alert-success { background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.3); color: #86efac; }
html[data-theme="dark"] .alert-danger { background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.3); color: #fca5a5; }
html[data-theme="dark"] .alert-secondary { background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.12); color: #d1d5db; }
html[data-theme="dark"] .btn-outline-primary { color: #8ab4f8; border-color: rgba(138,180,248,.5); }
html[data-theme="dark"] .btn-outline-primary:hover { background: rgba(138,180,248,.15); color: #fff; }
html[data-theme="dark"] .btn-outline-success { color: #4ade80; border-color: rgba(74,222,128,.45); }
html[data-theme="dark"] .btn-outline-success:hover { background: rgba(74,222,128,.15); color: #fff; }
html[data-theme="dark"] .modal-content { background: #131826; color: #e5e7eb; }
html[data-theme="dark"] .page-link { background: #131826; color: #e5e7eb; border-color: rgba(255,255,255,.12); }

/* ---- Ledger tools (quick ranges, search, sortable headers) ---- */
.lt-chip.active { background: var(--brand-accent); border-color: var(--brand-accent); color: #fff; }
html[data-theme="dark"] .lt-chip.active { color: #fff; }
.lt-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.lt-sortable:hover { color: var(--brand-accent); }
.lt-arrow { font-size: .7em; color: var(--brand-accent); }
html[data-theme="dark"] .lt-search { background-color: #131826; color: #e5e7eb; border-color: rgba(255,255,255,.15); }

/* ---- Click-to-filter bar (period / money / entry ...) ---- */
.lt-filterbar { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; padding: 10px 12px;
  border: 1px solid var(--surface-border); border-radius: 10px; background: var(--surface); }
.lt-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.lt-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.lt-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.lt-pill { padding: 2px 10px; font-size: .8rem; border: 1px solid rgba(120,130,145,.45); border-radius: 999px;
  color: var(--text-primary); background: transparent; text-decoration: none; }
.lt-pill:hover { background: var(--hover-bg); color: var(--text-heading); }
.lt-pill.active { background: var(--brand-accent); border-color: var(--brand-accent); color: #fff; font-weight: 600; }
.lt-custom { display: flex; align-items: center; gap: 4px; margin: 0; }
.lt-custom .form-control { width: 140px; }
.lt-select { width: auto; min-width: 150px; }
.lt-reset { font-size: .8rem; color: var(--text-muted); text-decoration: none; }
.lt-reset:hover { color: var(--brand-accent); }
.lt-search-wrap { margin-left: auto; }
.lt-search-wrap input { min-width: 200px; }
html[data-theme="dark"] .lt-search-wrap input { background-color: #131826; color: #e5e7eb; border-color: rgba(255,255,255,.15); }
