/* =========================================================
   Japati Office - Corporate Flat Theme
   Primary: #f26223  |  Dark: #111827
   ========================================================= */

/* Suppress all transitions on initial page load to prevent FOUC */
html.preload * { transition: none !important; }

/* Skip-to-content link for keyboard accessibility */
.skip-to-content {
  position: absolute;
  top: -100%;
  left: 16px;
  z-index: 9999;
  padding: 8px 16px;
  background: var(--primary, #f26223);
  color: #fff;
  border-radius: 0 0 6px 6px;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  transition: top .15s;
}
.skip-to-content:focus {
  top: 0;
}

/* Focus outline for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--primary, #f26223);
  outline-offset: 2px;
}

:root {
  --primary:        #f26223;
  --primary-dark:   #d4521a;
  --primary-light:  #fef0e7;
  --dark:           #111827;
  --dark-soft:      #1f2937;
  --gray-900:       #111827;
  --gray-800:       #1f2937;
  --gray-700:       #374151;
  --gray-600:       #4b5563;
  --gray-500:       #6b7280;
  --gray-400:       #9ca3af;
  --gray-300:       #d1d5db;
  --gray-200:       #e5e7eb;
  --gray-100:       #f3f4f6;
  --gray-50:        #f9fafb;
  --white:          #ffffff;
  --danger:         #ef4444;
  --danger-light:   #fef2f2;
  --success:        #10b981;
  --success-light:  #ecfdf5;
  --warning:        #f59e0b;
  --warning-light:  #fffbeb;
  --info:           #3b82f6;
  --info-light:     #eff6ff;
  --sidebar-width:  260px;
  --sidebar-collapsed: 68px;
  --topbar-height:  60px;
  --radius:         8px;
  --radius-sm:      4px;
  --radius-lg:      12px;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.08);
  --shadow:         0 4px 12px rgba(0,0,0,.1);
  --shadow-lg:      0 8px 24px rgba(0,0,0,.12);
  --transition:     all .2s ease;
  --font-sans:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

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

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

body {
  font-family: var(--font-sans);
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  overflow-x: hidden;
}

a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-dark); }

img { max-width: 100%; display: block; }

/* ---- LAYOUT ---- */
.app-body { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--dark);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: width .25s ease, transform .25s ease;
  overflow: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .user-mini-info { display: none; }
.sidebar.collapsed .sidebar-logo,
.sidebar.collapsed .sidebar-logo-text { display: none; }
.sidebar.collapsed .sidebar-brand { justify-content: center; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 0; height: 48px; }
.sidebar.collapsed .sidebar-footer { justify-content: center; }
.sidebar.collapsed .user-mini { display: none; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--topbar-height);
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  min-width: 0;
}

.sidebar-logo { width: 32px; height: 32px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; }

.sidebar-logo-text {
  width: 32px; height: 32px;
  background: var(--primary);
  color: var(--white);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}

.sidebar-title {
  color: var(--white);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-toggle-btn {
  background: none; border: none; cursor: pointer;
  color: var(--gray-400); padding: 4px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center;
  transition: var(--transition);
  flex-shrink: 0;
}
.sidebar-toggle-btn:hover { color: var(--white); background: rgba(255,255,255,.08); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }

.nav-section { margin-bottom: 4px; }

.nav-section-label {
  display: block;
  color: var(--gray-500);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  padding: 10px 20px 4px;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 42px;
  color: var(--gray-400);
  font-size: 13.5px;
  font-weight: 500;
  border-radius: 0;
  white-space: nowrap;
  transition: var(--transition);
  position: relative;
}
.nav-item:hover { color: var(--white); background: rgba(255,255,255,.06); }
.nav-item.active {
  color: var(--white);
  background: rgba(242,98,35,.15);
  border-right: 3px solid var(--primary);
}
.nav-item.active .nav-icon { color: var(--primary); }

.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ---- Collapsible nav group ---- */
.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 42px;
  width: 100%;
  color: var(--gray-400);
  font-size: 13.5px;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
  text-align: left;
}
.nav-group-toggle:hover { color: var(--white); background: rgba(255,255,255,.06); }
.nav-group-toggle .nav-group-chevron {
  margin-left: auto;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  transition: transform .2s ease;
}
.nav-group.open > .nav-group-toggle { color: var(--white); }
.nav-group.open > .nav-group-toggle .nav-group-chevron { transform: rotate(90deg); }

.nav-group-children {
  overflow: hidden;
  max-height: 0;
  transition: max-height .25s ease;
}
.nav-group.open > .nav-group-children { max-height: 500px; }

.nav-sub-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px 0 44px;
  height: 38px;
  color: var(--gray-400);
  font-size: 13px;
  white-space: nowrap;
  transition: var(--transition);
}
.nav-sub-item:hover { color: var(--white); background: rgba(255,255,255,.06); }
.nav-sub-item.active {
  color: var(--white);
  background: rgba(242,98,35,.12);
  border-right: 3px solid var(--primary);
  font-weight: 500;
}
.nav-sub-item.soon { opacity: .4; cursor: default; pointer-events: none; }

/* Nested nav-group toggle (e.g. General Ledger inside Finance) */
.nav-sub-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px 0 44px;
  height: 38px;
  width: 100%;
  color: var(--gray-400);
  font-size: 13px;
  font-weight: 400;
  background: none;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
  text-align: left;
}
.nav-sub-toggle:hover { color: var(--white); background: rgba(255,255,255,.06); }
.nav-sub-toggle .nav-group-chevron { margin-left: auto; width: 12px; height: 12px; flex-shrink: 0; transition: transform .2s ease; }
.nav-group.open > .nav-sub-toggle { color: var(--white); }
.nav-group.open > .nav-sub-toggle .nav-group-chevron { transform: rotate(90deg); }
/* Sub-items inside nested nav-group (deeper indent) */
.nav-group-children .nav-group-children .nav-sub-item {
  padding-left: 60px;
  height: 36px;
  font-size: 12.5px;
}

.sidebar.collapsed .nav-group-toggle span,
.sidebar.collapsed .nav-group-toggle .nav-group-chevron { display: none; }
.sidebar.collapsed .nav-group-toggle { justify-content: center; padding: 0; height: 48px; }
.sidebar.collapsed .nav-group-children { display: none; }

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.07);
  gap: 8px;
  flex-shrink: 0;
}

.user-mini { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-mini-avatar {
  width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.15);
}
.user-mini-info { min-width: 0; }
.user-mini-name { display: block; color: var(--white); font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-mini-role { display: block; color: var(--gray-500); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.logout-btn {
  color: var(--gray-400); padding: 6px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center;
  flex-shrink: 0;
  transition: var(--transition);
}
.logout-btn:hover { color: var(--danger); background: rgba(239,68,68,.1); }

/* =========================================================
   Light-mode sidebar (white)
   — overrides the dark-sidebar defaults above
   ========================================================= */
.sidebar { background: #ffffff; border-right: 1px solid var(--gray-200); }
.sidebar-header { border-bottom-color: var(--gray-200); }
.sidebar-nav { scrollbar-color: var(--gray-200) transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--gray-200); }
.sidebar-title { color: var(--gray-800); }
.sidebar-toggle-btn { color: var(--gray-500); }
.sidebar-toggle-btn:hover { color: var(--gray-800); background: var(--gray-100); }
.nav-section-label { color: var(--gray-400); }
.nav-item { color: var(--gray-600); }
.nav-item:hover { color: var(--gray-900); background: var(--gray-50); }
.nav-item.active { color: var(--primary); background: var(--primary-light); }
.nav-item.active .nav-icon { color: var(--primary); }
.nav-group-toggle { color: var(--gray-600); }
.nav-group-toggle:hover { color: var(--gray-900); background: var(--gray-50); }
.nav-group.open > .nav-group-toggle { color: var(--gray-900); }
.nav-sub-item { color: var(--gray-500); }
.nav-sub-item:hover { color: var(--gray-900); background: var(--gray-50); }
.nav-sub-item.active { color: var(--primary); background: rgba(242,98,35,.08); }
.nav-sub-toggle { color: var(--gray-500); }
.nav-sub-toggle:hover { color: var(--gray-900); background: var(--gray-50); }
.nav-group.open > .nav-sub-toggle { color: var(--gray-900); }
.sidebar-footer { border-top-color: var(--gray-200); }
.user-mini-avatar { border-color: var(--gray-200); }
.user-mini-name { color: var(--gray-800); }
.user-mini-role { color: var(--gray-500); }
.logout-btn { color: var(--gray-500); }
.logout-btn:hover { color: var(--danger); background: var(--danger-light); }

/* ---- MAIN WRAPPER ---- */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: margin-left .25s ease;
}
.sidebar.collapsed ~ .sidebar-overlay ~ .main-wrapper,
body.sidebar-collapsed .main-wrapper { margin-left: var(--sidebar-collapsed); }

/* ---- TOPBAR ---- */
.topbar {
  height: var(--topbar-height);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-left { display: flex; align-items: center; gap: 16px; }

.topbar-menu-btn {
  background: none; border: none; cursor: pointer;
  color: var(--gray-600); padding: 4px;
  display: none; align-items: center;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.topbar-menu-btn:hover { color: var(--dark); background: var(--gray-100); }

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--gray-500); }
.breadcrumb a { color: var(--gray-500); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb span { color: var(--gray-800); font-weight: 500; }
.breadcrumb-sep { color: var(--gray-300); }

.topbar-right { display: flex; align-items: center; gap: 12px; }

/* ── Global Search ─────────────────────────────────── */
.global-search-wrap { position: relative; align-self: stretch; display: flex; align-items: center; }
.global-search-btn {
  background: none; border: none; cursor: pointer;
  color: var(--gray-500); padding: 6px;
  display: flex; align-items: center; border-radius: var(--radius-sm);
  transition: var(--transition);
}
.global-search-btn:hover { color: var(--primary); background: var(--gray-100); }
.global-search-panel {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 420px; background: var(--white);
  border: 1px solid var(--gray-200); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); z-index: 9999; overflow: hidden;
}
.global-search-input-wrap {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--gray-100);
}
.global-search-input {
  flex: 1; border: none; outline: none; font-size: 14px;
  background: transparent; color: var(--dark);
}
.global-search-results { max-height: 360px; overflow-y: auto; }
.global-search-hint { padding: 20px; text-align: center; font-size: 13px; color: var(--gray-400); }
.global-search-group-label {
  padding: 8px 14px 4px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; color: var(--gray-400);
}
.global-search-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; text-decoration: none; color: var(--dark);
  transition: var(--transition); cursor: pointer;
}
.global-search-item:hover, .global-search-item.active { background: var(--gray-50); }
.global-search-item-icon {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--gray-100); color: var(--gray-500); flex-shrink: 0;
}
.global-search-item-title { font-size: 13px; font-weight: 500; }
.global-search-item-sub { font-size: 11px; color: var(--gray-400); margin-top: 1px; }
.global-search-no-results { padding: 24px; text-align: center; font-size: 13px; color: var(--gray-400); }
@media (max-width: 640px) {
  .global-search-panel { width: calc(100vw - 24px); right: -8px; }
}

.topbar-user {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; padding: 6px 10px;
  border-radius: var(--radius);
  transition: var(--transition);
  position: relative;
  user-select: none;
}
.topbar-user:hover { background: var(--gray-100); }

.topbar-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gray-200); }
.topbar-username { font-size: 13px; font-weight: 500; color: var(--gray-700); }

.topbar-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px); right: 0;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 180px;
  z-index: 200;
  padding: 6px 0;
}
.topbar-dropdown.open { display: block; }

.dropdown-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px;
  color: var(--gray-700);
  font-size: 13px;
  transition: var(--transition);
}
.dropdown-item:hover { background: var(--gray-50); color: var(--primary); }
.dropdown-item.text-danger:hover { color: var(--danger); background: var(--danger-light); }

.dropdown-divider { height: 1px; background: var(--gray-200); margin: 4px 0; }

/* ---- PAGE CONTENT ---- */
.page-content { flex: 1; padding: 24px; }

/* ---- ALERTS ---- */
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13.5px;
  position: relative;
}
.alert-success { background: var(--success-light); color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger   { background: var(--danger-light);  color: #991b1b; border: 1px solid #fecaca; }
.alert-warning  { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-info     { background: var(--info-light);    color: #1e40af; border: 1px solid #bfdbfe; }
.alert-close {
  position: absolute; top: 8px; right: 12px;
  background: none; border: none; cursor: pointer;
  font-size: 18px; line-height: 1; opacity: .6;
  transition: var(--transition);
}
.alert-close:hover { opacity: 1; }
.alert ul { margin: 4px 0 0 16px; }

/* ---- CARDS ---- */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
}
.card-title { font-size: 15px; font-weight: 600; color: var(--gray-900); }
.card-body { padding: 20px; }
.card-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ---- STAT CARDS ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon.primary { background: var(--primary-light); color: var(--primary); }
.stat-icon.success { background: var(--success-light); color: var(--success); }
.stat-icon.info    { background: var(--info-light);    color: var(--info); }
.stat-icon.warning { background: var(--warning-light); color: var(--warning); }
.stat-icon.danger  { background: var(--danger-light);  color: var(--danger); }
.stat-value { font-size: 24px; font-weight: 700; color: var(--gray-900); line-height: 1; }
.stat-label { font-size: 12px; color: var(--gray-500); margin-top: 4px; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 13.5px; font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer; transition: var(--transition);
  white-space: nowrap; text-decoration: none;
  line-height: 1.4;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary   { background: var(--primary);  color: var(--white);  border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: var(--white); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--gray-200); color: var(--gray-800); }
.btn-danger    { background: var(--danger);   color: var(--white);  border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; color: var(--white); }
.btn-success   { background: var(--success);  color: var(--white);  border-color: var(--success); }
.btn-outline   { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: var(--white); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-icon { padding: 7px; width: 34px; height: 34px; justify-content: center; }

/* ---- FORMS ---- */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block; margin-bottom: 6px;
  font-size: 13px; font-weight: 500; color: var(--gray-700);
}
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-control, .form-select {
  display: block; width: 100%;
  padding: 9px 12px;
  font-size: 13.5px; color: var(--gray-800);
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  transition: var(--transition);
  outline: none;
  appearance: none;
  font-family: inherit;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(242,98,35,.12);
}
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.form-control.is-invalid, .form-select.is-invalid { border-color: var(--danger); }
.invalid-feedback { color: var(--danger); font-size: 12px; margin-top: 4px; }
.form-hint { color: var(--gray-500); font-size: 12px; margin-top: 4px; }
.form-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
input[type=number].form-control { padding-right: 4px; }

/* ---- TABLE ---- */
.table-responsive { overflow-x: auto; }
.table {
  width: 100%; border-collapse: collapse;
  font-size: 13.5px;
}
.table th {
  background: var(--gray-50); color: var(--gray-600);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  padding: 10px 16px; text-align: left;
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
}
.table td {
  padding: 12px 16px; color: var(--gray-700);
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--gray-50); }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- BADGES ---- */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: #065f46; }
.badge-danger  { background: var(--danger-light);  color: #991b1b; }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-gray    { background: var(--gray-100);      color: var(--gray-600); }
.row-overdue   { background: #fff7f3; }

/* ---- AVATAR ---- */
.avatar { border-radius: 50%; object-fit: cover; }
.avatar-lg { width: 80px; height: 80px; }
.avatar-md { width: 48px; height: 48px; }
.avatar-sm { width: 32px; height: 32px; }

/* ---- PAGE HEADER ---- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.page-header-left {}
.page-title { font-size: 20px; font-weight: 700; color: var(--gray-900); }
.page-subtitle { font-size: 13px; color: var(--gray-500); margin-top: 2px; }

/* ---- GRID ---- */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ---- SECTION TABS ---- */
.tabs { display: flex; border-bottom: 2px solid var(--gray-200); gap: 0; margin-bottom: 24px; }
.tab-btn {
  padding: 10px 20px; font-size: 13.5px; font-weight: 500;
  color: var(--gray-500); background: none; border: none;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  cursor: pointer; transition: var(--transition); white-space: nowrap;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---- PROFILE ---- */
.profile-header {
  display: flex; align-items: center; gap: 20px;
  padding: 24px; background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
}
.profile-avatar-wrapper { position: relative; }
.profile-avatar { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; border: 3px solid var(--primary); }
.profile-info { flex: 1; }
.profile-name { font-size: 20px; font-weight: 700; color: var(--gray-900); }
.profile-role { color: var(--gray-500); font-size: 13px; margin-top: 2px; }
.profile-meta { display: flex; gap: 20px; margin-top: 10px; flex-wrap: wrap; }
.profile-meta-item { display: flex; align-items: center; gap: 6px; color: var(--gray-600); font-size: 13px; }

/* ---- MODAL ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000; padding: 16px;
  animation: fadeIn .15s ease;
}
.modal-box {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 440px;
  animation: slideUp .2s ease;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--gray-200);
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: var(--gray-400); line-height: 1;
  transition: var(--transition); padding: 2px 6px;
  border-radius: var(--radius-sm);
}
.modal-close:hover { color: var(--gray-700); background: var(--gray-100); }
.modal-body { padding: 20px; font-size: 13.5px; color: var(--gray-700); }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--gray-200);
}

/* ---- PERMISSIONS TABLE ---- */
.perm-table th, .perm-table td { text-align: center; }
.perm-table td:first-child { text-align: left; }

/* ---- PAGINATION ---- */
.pagination { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.page-btn {
  min-width: 34px; height: 34px; padding: 0 8px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
  font-size: 13px; color: var(--gray-600); background: var(--white);
  cursor: pointer; transition: var(--transition);
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: var(--white); }
.page-btn:disabled { opacity: .4; cursor: default; }

/* ---- LOGIN PAGE ---- */
.auth-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--dark) 0%, var(--dark-soft) 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 420px;
  overflow: hidden;
}
.auth-header {
  background: var(--primary);
  padding: 32px;
  text-align: center;
}
.auth-logo-img {
  height: 56px; max-width: 160px; width: auto;
  display: block;
  margin: 0 auto 12px;
  object-fit: contain;
  background: #fff;
  padding: 8px 12px;
  border-radius: var(--radius);
}
.auth-logo {
  width: 56px; height: 56px;
  background: rgba(255,255,255,.2);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
  font-size: 22px; font-weight: 800; color: var(--white);
}
.auth-title { color: var(--white); font-size: 20px; font-weight: 700; }
.auth-subtitle { color: rgba(255,255,255,.75); font-size: 13px; margin-top: 4px; }
.auth-body { padding: 32px; }

/* ---- ANIMATIONS ---- */
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity:0; } to { transform: translateY(0); opacity:1; } }

/* ---- SIDEBAR OVERLAY ---- */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 999;
}

/* ---- UTILS ---- */
.mb-0 { margin-bottom: 0; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.text-danger { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 12px; }
.font-bold { font-weight: 700; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { height: 1px; background: var(--gray-200); margin: 20px 0; }
.search-box { position: relative; }
.search-box .form-control { padding-left: 36px; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--gray-400); pointer-events: none; }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .sidebar-overlay.active { display: block; }
  .main-wrapper { margin-left: 0 !important; }
  .topbar-menu-btn { display: flex; }
  .topbar-username { display: none; }
  .page-content { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .page-header { flex-direction: column; align-items: flex-start; }
  .profile-header { flex-direction: column; text-align: center; }
  .profile-meta { justify-content: center; }
  .modal-box { margin: 16px; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .auth-body { padding: 20px; }
  .auth-header { padding: 24px; }
}

/* ─── UTILITY GRID CLASSES ────────────────────────────
   Use these in views instead of inline grid-template-columns.
   Each class applies display:grid automatically.
   ───────────────────────────────────────────────────── */

.grid-2col        { display: grid; grid-template-columns: 1fr 1fr;             gap: 16px; }
.grid-3col        { display: grid; grid-template-columns: repeat(3,1fr);       gap: 16px; }
.grid-4col        { display: grid; grid-template-columns: repeat(4,1fr);       gap: 16px; }
.grid-sidebar     { display: grid; grid-template-columns: 1fr 300px;           gap: 20px; align-items: start; }
.grid-sidebar-sm  { display: grid; grid-template-columns: 1fr 280px;           gap: 20px; align-items: start; }
.grid-sidebar-320 { display: grid; grid-template-columns: 1fr 320px;           gap: 20px; align-items: start; }
.grid-sidebar-lft { display: grid; grid-template-columns: 200px 1fr;           gap: 20px; align-items: start; }
.grid-form-2col   { display: grid; grid-template-columns: 1fr 1fr;             gap: 16px; }
.grid-stats-4     { display: grid; grid-template-columns: repeat(4,1fr);       gap: 16px; margin-bottom: 20px; }
.grid-stats-auto  { display: grid; grid-template-columns: repeat(auto-fill,minmax(160px,1fr)); gap: 16px; margin-bottom: 20px; }

@media (max-width: 960px) {
  .grid-sidebar, .grid-sidebar-sm, .grid-sidebar-320, .grid-sidebar-lft { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .grid-3col, .grid-4col, .grid-stats-4 { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 640px) {
  .grid-2col, .grid-form-2col, .grid-3col, .grid-4col, .grid-stats-4 { grid-template-columns: 1fr; }
  .grid-stats-auto { grid-template-columns: 1fr 1fr; }
}

/* ─── SMALL SCREEN COMPATIBILITY ──────────────────────
   Uses CSS attribute selectors to override inline styles
   without modifying individual view files.
   ───────────────────────────────────────────────────── */

/* 960px: collapse main-content + sidebar panels */
@media (max-width: 960px) {
  [style*="grid-template-columns:1fr 280px"],
  [style*="grid-template-columns:1fr 300px"],
  [style*="grid-template-columns:1fr 320px"],
  [style*="grid-template-columns:1fr 340px"],
  [style*="grid-template-columns:1fr 360px"],
  [style*="grid-template-columns:1fr 380px"],
  [style*="grid-template-columns:200px 1fr"],
  [style*="grid-template-columns:280px 1fr"],
  [style*="grid-template-columns:300px 1fr"],
  [style*="grid-template-columns:2fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

/* 768px: stat grids → 2 cols; topbar; tabs; table fallback */
@media (max-width: 768px) {
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns:repeat(5,1fr)"],
  [style*="grid-template-columns:repeat(3,1fr)"],
  [style*="grid-template-columns:1fr 1fr 1fr"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  /* Topbar: tighten padding, prevent breadcrumb overflow */
  .topbar { padding: 0 12px; }
  .topbar-left { flex: 1; min-width: 0; overflow: hidden; }
  .breadcrumb { overflow: hidden; white-space: nowrap; flex-wrap: nowrap; }
  /* Hide clock to save horizontal space */
  #serverClock { display: none; }
  /* Tabs: allow horizontal scroll instead of wrapping */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 1px; }
  /* Tables without .table-responsive: make them scroll */
  .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }
  /* Restore display for tables already inside .table-responsive */
  .table-responsive .table { display: table; overflow-x: visible; width: 100%; }
  /* Page header: wrap action buttons */
  .page-header .d-flex { flex-wrap: wrap; }
}

/* 640px: single column, tighter spacing */
@media (max-width: 640px) {
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns:120px 1fr 160px"],
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns:repeat(5,1fr)"],
  [style*="grid-template-columns:repeat(3,1fr)"],
  [style*="grid-template-columns:repeat(2,1fr)"] {
    grid-template-columns: 1fr !important;
  }
  .page-title { font-size: 17px; }
  .page-content { padding: 12px; }
  .card-body { padding: 14px; }
  .card-header { padding: 12px 14px; }
  .stat-card { padding: 14px; gap: 12px; }
  .stat-value { font-size: 20px; }
  .stat-icon { width: 40px; height: 40px; }
  /* Ensure print options panel doesn't overflow viewport */
  #printOptionsPanel {
    left: 0;
    right: auto !important;
    min-width: min(260px, calc(100vw - 24px)) !important;
  }
}

/* =========================================================
   ENHANCED MOBILE RESPONSIVENESS
   Covers gaps not handled by the utility-class breakpoints:
   filter forms, flex containers, detail pages, modals, etc.
   ========================================================= */

/* ── 768px: tablets / landscape phones ──────────────────── */
@media (max-width: 768px) {
  /* Filter form inputs: remove fixed min-widths so they wrap gracefully */
  .form-select[style*="min-width"],
  .form-control[style*="min-width"],
  .search-box[style*="min-width"],
  div[style*="min-width:200px"],
  div[style*="min-width:180px"] {
    min-width: 0 !important;
    flex: 1 1 calc(50% - 8px) !important;
  }
  .form-select[style*="width:1"],
  .form-control[style*="width:1"] {
    width: auto !important;
    flex: 1 1 calc(50% - 8px) !important;
  }

  /* Action button groups: always wrap */
  .d-flex.gap-2,
  .d-flex.gap-3,
  [style*="display:flex"][style*="gap:6px"],
  [style*="display:flex"][style*="gap:4px"],
  [style*="display:flex"][style*="gap:8px"],
  [style*="display:flex"][style*="gap:10px"],
  [style*="display:flex"][style*="gap:12px"] {
    flex-wrap: wrap !important;
  }

  /* Show-page header: stack title & actions vertically */
  [style*="display:flex"][style*="justify-content:space-between"][style*="align-items:flex-start"],
  [style*="display:flex"][style*="justify-content:space-between"][style*="margin-bottom:32px"],
  [style*="display:flex"][style*="justify-content:space-between"][style*="margin-bottom:28px"],
  [style*="display:flex"][style*="justify-content:space-between"][style*="margin-bottom:24px"] {
    flex-direction: column !important;
    gap: 12px !important;
  }

  /* Inline tab-like flex rows: horizontal scroll */
  [style*="display:flex"][style*="border-bottom:2px solid"] {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    padding-bottom: 1px;
  }

  /* Key-value detail tables (inline td with padding): tighten */
  td[style*="padding:3px 16px 3px 0"],
  td[style*="padding:8px 16px"] {
    padding-left: 0 !important;
    padding-right: 8px !important;
  }

  /* Cards with max-width (site management): allow full width */
  .card[style*="max-width:700px"],
  .card[style*="max-width:600px"],
  .card[style*="max-width:500px"] {
    max-width: 100% !important;
  }

  /* Modal: ensure it fits viewport */
  .modal-box { max-width: calc(100vw - 32px) !important; }
  [style*="max-width:420px"][style*="border-radius"] { max-width: calc(100vw - 32px) !important; }
  [style*="max-width:500px"][style*="border-radius"] { max-width: calc(100vw - 32px) !important; }
  [style*="max-width:600px"][style*="border-radius"] { max-width: calc(100vw - 32px) !important; }

  /* Notification dropdown: fit screen */
  #notifDropdown { width: calc(100vw - 24px) !important; max-width: 340px !important; right: -8px !important; }
}

/* ── 640px: small phones ────────────────────────────────── */
@media (max-width: 640px) {
  /* Filter inputs: full width single column */
  .form-select[style*="min-width"],
  .form-control[style*="min-width"],
  .search-box[style*="min-width"],
  .form-select[style*="width:1"],
  .form-control[style*="width:1"] {
    min-width: 0 !important;
    width: 100% !important;
    flex: 1 1 100% !important;
  }

  /* Show-page detail info grids: single column */
  [style*="display:grid"][style*="grid-template-columns:1fr 1fr"][style*="gap:24px"],
  [style*="display:grid"][style*="grid-template-columns:1fr 1fr"][style*="gap:20px"],
  [style*="display:grid"][style*="grid-template-columns:1fr 1fr"][style*="gap:16px"],
  [style*="display:grid"][style*="grid-template-columns:repeat(2,1fr)"][style*="gap:12px"] {
    grid-template-columns: 1fr !important;
  }

  /* PM Kanban board (4-col): horizontal scroll instead of squash */
  [style*="grid-template-columns:repeat(4,1fr)"][style*="align-items:start"] {
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 12px !important;
    padding-bottom: 8px;
  }
  [style*="grid-template-columns:repeat(4,1fr)"][style*="align-items:start"] > * {
    min-width: 260px;
    flex-shrink: 0;
  }

  /* Buttons in tight spaces: shrink padding */
  .page-header .btn { padding: 6px 10px; font-size: 12px; }
  .page-header .btn svg { width: 14px; height: 14px; }

  /* Table min-width overrides inside responsive wrappers */
  .table-responsive .table[style*="min-width"] { min-width: 0 !important; }

  /* Compact detail page spacing */
  [style*="margin-bottom:32px"] { margin-bottom: 16px !important; }
  [style*="margin-bottom:28px"] { margin-bottom: 14px !important; }

  /* Date range inputs: side by side → stack */
  input[type="date"].form-control[style*="width:140px"],
  input[type="date"].form-control[style*="width:130px"] {
    width: 100% !important;
    flex: 1 1 100% !important;
  }
}

/* ── 480px: extra-small phones ──────────────────────────── */
@media (max-width: 480px) {
  /* Topbar: tighter */
  .topbar { padding: 0 8px; gap: 4px; }
  .topbar-right { gap: 4px; }
  .topbar-user { padding: 4px 6px; }
  .topbar-avatar { width: 28px; height: 28px; }

  /* Page content: minimal padding */
  .page-content { padding: 10px; }

  /* Cards: tighter */
  .card-body { padding: 12px; }
  .card-header { padding: 10px 12px; }

  /* Modals: edge-to-edge */
  .modal-overlay { padding: 8px; }
  .modal-box { max-width: 100% !important; }

  /* Profile: compact */
  .profile-header { padding: 16px; gap: 12px; }
  .profile-avatar { width: 56px !important; height: 56px !important; }

  /* Pagination: compact */
  .page-btn { min-width: 28px; height: 28px; font-size: 11px; }
}

/* =========================================================
   Shared filter-row: single line on large screens
   ========================================================= */
.filter-row { flex-wrap: wrap; }
@media (min-width: 1024px) { .filter-row { flex-wrap: nowrap; } }

/* =========================================================
   Custom Date Picker
   ========================================================= */
.dp-wrap { position: relative; display: inline-block; }
.dp-trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; text-align: left; white-space: nowrap; gap: 6px;
}
.dp-trigger::after {
  content: ''; display: inline-block; flex-shrink: 0; width: 14px; height: 14px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E") no-repeat center / contain;
}
.dp-popup {
  display: none; position: absolute; z-index: 1060;
  top: calc(100% + 4px); left: 0;
  background: var(--white); border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 14px; min-width: 252px; color: var(--gray-800);
}
.dp-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
.dp-btn-nav {
  background: none; border: 1px solid var(--gray-200); color: var(--gray-500);
  cursor: pointer; padding: 3px 8px; border-radius: var(--radius-sm);
  font-size: 1.2rem; line-height: 1; transition: var(--transition);
}
.dp-btn-nav:hover { background: var(--gray-100); color: var(--gray-800); border-color: var(--gray-300); }
.dp-caption {
  background: none; border: none; color: var(--gray-800); cursor: pointer;
  font-weight: 600; font-size: .875rem; padding: 4px 8px; border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 4px; transition: var(--transition);
}
.dp-caption:hover { background: var(--gray-100); }
.dp-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  text-align: center; font-size: .72rem; color: var(--gray-400); margin-bottom: 4px;
}
.dp-weekdays span { padding: 4px 0; }
.dp-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.dp-day {
  background: none; border: none; color: var(--gray-700); cursor: pointer;
  padding: 5px 2px; border-radius: var(--radius-sm); font-size: .8rem;
  text-align: center; transition: background .1s;
}
.dp-day:hover { background: var(--gray-100); }
.dp-day.dp-today { color: var(--primary); font-weight: 700; }
.dp-day.dp-sel { background: var(--primary); color: #fff; font-weight: 600; }
.dp-day.dp-sel:hover { background: var(--primary-dark); }
.dp-day.dp-empty { visibility: hidden; pointer-events: none; }
.dp-my-cols { display: flex; gap: 8px; }
.dp-my-col { flex: 1; max-height: 164px; overflow-y: auto; border: 1px solid var(--gray-200); border-radius: var(--radius-sm); }
.dp-my-item {
  padding: 7px 10px; cursor: pointer; font-size: .8rem;
  text-align: center; color: var(--gray-700); transition: background .1s;
}
.dp-my-item:hover { background: var(--gray-100); }
.dp-my-item.dp-my-sel { background: var(--primary); color: #fff; font-weight: 600; }
.dp-footer { margin-top: 10px; display: flex; justify-content: flex-end; }
.dp-clear-btn {
  background: none; border: 1px solid var(--gray-200); color: var(--gray-500);
  cursor: pointer; padding: 4px 14px; border-radius: var(--radius-sm); font-size: .8rem;
  transition: var(--transition);
}
.dp-clear-btn:hover { background: var(--gray-100); color: var(--gray-700); }

/* ---- Badge info (was missing) ---- */
.badge-info { background: var(--info-light); color: #1e40af; }

/* =========================================================
   Dark Mode
   ========================================================= */

/* Apply theme early — set data-theme="dark" on <html> before render */
html[data-theme="dark"] {
  --white:         #1e293b;
  --gray-50:       #1e293b;
  --gray-100:      #334155;
  --gray-200:      #475569;
  --gray-300:      #64748b;
  --gray-400:      #94a3b8;
  --gray-500:      #94a3b8;
  --gray-600:      #cbd5e1;
  --gray-700:      #e2e8f0;
  --gray-800:      #f1f5f9;
  --gray-900:      #f8fafc;
  --dark:          #020617;
  --dark-soft:     #0f172a;
  --primary-light: rgba(242,98,35,.2);
  --danger-light:  rgba(239,68,68,.15);
  --success-light: rgba(16,185,129,.15);
  --warning-light: rgba(245,158,11,.15);
  --info-light:    rgba(59,130,246,.15);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  --shadow:    0 4px 12px rgba(0,0,0,.5);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.6);
  color-scheme: dark;  /* browser-native UI chrome (spin buttons, scrollbars) → dark */
}

html[data-theme="dark"] body { background: #0f172a; color: #e2e8f0; }

/* Sidebar: restore dark look with literal white text (not var(--white) which is dark in dark mode) */
html[data-theme="dark"] .sidebar { background: #020617; border-right-color: #1e293b; }
html[data-theme="dark"] .sidebar-header { border-bottom-color: rgba(255,255,255,.05); }
html[data-theme="dark"] .sidebar-nav { scrollbar-color: rgba(255,255,255,.1) transparent; }
html[data-theme="dark"] .sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); }
html[data-theme="dark"] .sidebar-title { color: #ffffff; }
html[data-theme="dark"] .sidebar-toggle-btn { color: #94a3b8; }
html[data-theme="dark"] .sidebar-toggle-btn:hover { color: #ffffff; background: rgba(255,255,255,.08); }
html[data-theme="dark"] .nav-section-label { color: #64748b; }
html[data-theme="dark"] .nav-item { color: #94a3b8; }
html[data-theme="dark"] .nav-item:hover { color: #ffffff; background: rgba(255,255,255,.06); }
html[data-theme="dark"] .nav-item.active { color: #ffffff; background: rgba(242,98,35,.15); }
html[data-theme="dark"] .nav-item.active .nav-icon { color: var(--primary); }
html[data-theme="dark"] .nav-group-toggle { color: #94a3b8; }
html[data-theme="dark"] .nav-group-toggle:hover { color: #ffffff; background: rgba(255,255,255,.06); }
html[data-theme="dark"] .nav-group.open > .nav-group-toggle { color: #ffffff; }
html[data-theme="dark"] .nav-sub-item { color: #94a3b8; }
html[data-theme="dark"] .nav-sub-item:hover { color: #ffffff; background: rgba(255,255,255,.06); }
html[data-theme="dark"] .nav-sub-item.active { color: #ffffff; background: rgba(242,98,35,.12); }
html[data-theme="dark"] .nav-sub-toggle { color: #94a3b8; }
html[data-theme="dark"] .nav-sub-toggle:hover { color: #ffffff; background: rgba(255,255,255,.06); }
html[data-theme="dark"] .nav-group.open > .nav-sub-toggle { color: #ffffff; }
html[data-theme="dark"] .sidebar-footer { border-top-color: rgba(255,255,255,.05); }
html[data-theme="dark"] .user-mini-avatar { border-color: rgba(255,255,255,.15); }
html[data-theme="dark"] .user-mini-name { color: #ffffff; }
html[data-theme="dark"] .user-mini-role { color: #64748b; }
html[data-theme="dark"] .logout-btn { color: #94a3b8; }
html[data-theme="dark"] .logout-btn:hover { color: var(--danger); background: rgba(239,68,68,.1); }

/* Topbar */
html[data-theme="dark"] .topbar { background: #1e293b; border-bottom-color: #334155; }
html[data-theme="dark"] .topbar-menu-btn { color: #94a3b8; }
html[data-theme="dark"] .topbar-menu-btn:hover { background: #334155; color: #f1f5f9; }
html[data-theme="dark"] .topbar-username { color: #e2e8f0; }
html[data-theme="dark"] .topbar-user:hover { background: #334155; }
html[data-theme="dark"] .topbar-avatar { border-color: #475569; }
html[data-theme="dark"] .breadcrumb a { color: #94a3b8; }
html[data-theme="dark"] .breadcrumb span { color: #e2e8f0; }
html[data-theme="dark"] .breadcrumb-sep { color: #475569; }

/* User dropdown */
html[data-theme="dark"] .topbar-dropdown { background: #1e293b; border-color: #334155; }
html[data-theme="dark"] .dropdown-item { color: #e2e8f0; }
html[data-theme="dark"] .dropdown-item:hover { background: #334155; color: var(--primary); }
html[data-theme="dark"] .dropdown-item.text-danger:hover { color: var(--danger); background: rgba(239,68,68,.15); }
html[data-theme="dark"] .dropdown-divider { background: #334155; }

/* Alerts */
html[data-theme="dark"] .alert-success { background: rgba(16,185,129,.15); color: #6ee7b7; border-color: rgba(16,185,129,.3); }
html[data-theme="dark"] .alert-danger  { background: rgba(239,68,68,.15);  color: #fca5a5; border-color: rgba(239,68,68,.3); }
html[data-theme="dark"] .alert-warning { background: rgba(245,158,11,.15); color: #fcd34d; border-color: rgba(245,158,11,.3); }
html[data-theme="dark"] .alert-info    { background: rgba(59,130,246,.15); color: #93c5fd; border-color: rgba(59,130,246,.3); }

/* Badges */
html[data-theme="dark"] .badge-primary { background: rgba(242,98,35,.2);  color: #fdba74; }
html[data-theme="dark"] .badge-success { background: rgba(16,185,129,.2); color: #6ee7b7; }
html[data-theme="dark"] .badge-danger  { background: rgba(239,68,68,.2);  color: #fca5a5; }
html[data-theme="dark"] .row-overdue   { background: rgba(239,68,68,.07); }
html[data-theme="dark"] .badge-warning { background: rgba(245,158,11,.2); color: #fcd34d; }
html[data-theme="dark"] .badge-info    { background: rgba(59,130,246,.2); color: #93c5fd; }
html[data-theme="dark"] .badge-gray    { background: #334155; color: #94a3b8; }

/* Buttons */
html[data-theme="dark"] .btn-primary { color: #ffffff; }
html[data-theme="dark"] .btn-primary:hover { color: #ffffff; }
html[data-theme="dark"] .btn-danger { color: #ffffff; }
html[data-theme="dark"] .btn-danger:hover { color: #ffffff; }
html[data-theme="dark"] .btn-secondary { background: #334155; color: #e2e8f0; border-color: #475569; }
html[data-theme="dark"] .btn-secondary:hover { background: #475569; color: #f8fafc; }

/* Current month row in tax recap table */
.row-current-month { background: rgba(242,98,35,.07); }
html[data-theme="dark"] .row-current-month { background: rgba(242,98,35,.12); }

/* Modal */
html[data-theme="dark"] .modal-box { background: #1e293b; }
html[data-theme="dark"] .modal-box .modal-title { color: #f1f5f9; }
html[data-theme="dark"] .modal-box .modal-desc  { color: #94a3b8; }

/* Cards */
html[data-theme="dark"] .card { background: #1e293b; border-color: #334155; }
html[data-theme="dark"] .card-header { border-bottom-color: #334155; }
html[data-theme="dark"] .card-footer { background: #0f172a; border-top-color: #334155; }

/* Stat cards */
html[data-theme="dark"] .stat-card { background: #1e293b; border-color: #334155; }
html[data-theme="dark"] .stat-icon.primary { background: rgba(242,98,35,.2); }
html[data-theme="dark"] .stat-icon.success { background: rgba(16,185,129,.15); }
html[data-theme="dark"] .stat-icon.info    { background: rgba(59,130,246,.15); }
html[data-theme="dark"] .stat-icon.warning { background: rgba(245,158,11,.15); }
html[data-theme="dark"] .stat-icon.danger  { background: rgba(239,68,68,.15); }

/* Tables */
html[data-theme="dark"] .table th { background: #334155; border-bottom-color: #475569; color: #94a3b8; }
html[data-theme="dark"] .table td { border-bottom-color: #334155; color: #e2e8f0; }
html[data-theme="dark"] .table tr:hover td { background: rgba(255,255,255,.03); }

/* Forms */
html[data-theme="dark"] .form-label { color: #e2e8f0; }
html[data-theme="dark"] .form-hint  { color: #94a3b8; }
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
  background: #334155;
  border-color: #475569;
  color: #f1f5f9;
}
html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus { background: #3d4f66; border-color: var(--primary); }
html[data-theme="dark"] .form-control::placeholder { color: #64748b; }
html[data-theme="dark"] .form-select option { background: #1e293b; color: #f1f5f9; }
html[data-theme="dark"] .form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* Modals */
html[data-theme="dark"] .modal-box { background: #1e293b; border: 1px solid #334155; }
html[data-theme="dark"] .modal-header { border-bottom-color: #334155; }
html[data-theme="dark"] .modal-footer { border-top-color: #334155; background: #1e293b; }
html[data-theme="dark"] .modal-body { color: #e2e8f0; }
html[data-theme="dark"] .modal-close:hover { background: #334155; color: #e2e8f0; }

/* Global search */
html[data-theme="dark"] .global-search-panel { background: #1e293b; border-color: #334155; }
html[data-theme="dark"] .global-search-input-wrap { border-bottom-color: #334155; }
html[data-theme="dark"] .global-search-input { color: #f1f5f9; }
html[data-theme="dark"] .global-search-btn:hover { background: #334155; }
html[data-theme="dark"] .global-search-item { color: #e2e8f0; }
html[data-theme="dark"] .global-search-item:hover,
html[data-theme="dark"] .global-search-item.active { background: #334155; }
html[data-theme="dark"] .global-search-item-icon { background: #334155; }

/* Notification dropdown (inline styles need !important) */
html[data-theme="dark"] #notifDropdown {
  background: #1e293b !important;
  border-color: #334155 !important;
}
html[data-theme="dark"] #notifDropdown > div:first-child { border-bottom-color: #334155 !important; }
html[data-theme="dark"] #notifDropdown span[style*="font-weight:600"] { color: #e2e8f0 !important; }

/* Date picker */
html[data-theme="dark"] .dp-popup { background: #1e293b; border-color: #334155; color: #e2e8f0; }
html[data-theme="dark"] .dp-btn-nav { border-color: #475569; color: #94a3b8; }
html[data-theme="dark"] .dp-btn-nav:hover { background: #334155; color: #f1f5f9; border-color: #64748b; }
html[data-theme="dark"] .dp-caption { color: #f1f5f9; }
html[data-theme="dark"] .dp-caption:hover { background: #334155; }
html[data-theme="dark"] .dp-day { color: #e2e8f0; }
html[data-theme="dark"] .dp-day:hover { background: #334155; }
html[data-theme="dark"] .dp-my-col { border-color: #475569; }
html[data-theme="dark"] .dp-my-item { color: #e2e8f0; }
html[data-theme="dark"] .dp-my-item:hover { background: #334155; }
html[data-theme="dark"] .dp-clear-btn { border-color: #475569; color: #94a3b8; }
html[data-theme="dark"] .dp-clear-btn:hover { background: #334155; color: #e2e8f0; }

/* Pagination */
html[data-theme="dark"] .page-btn { background: #1e293b; border-color: #475569; color: #94a3b8; }
html[data-theme="dark"] .page-btn:hover { border-color: var(--primary); color: var(--primary); }

/* Tabs */
html[data-theme="dark"] .tabs { border-bottom-color: #334155; }
html[data-theme="dark"] .tab-btn { color: #94a3b8; }
html[data-theme="dark"] .tab-btn:hover,
html[data-theme="dark"] .tab-btn.active { color: var(--primary); }

/* Profile */
html[data-theme="dark"] .profile-header { background: #1e293b; border-color: #334155; }

/* Divider */
html[data-theme="dark"] .divider { background: #334155; }

/* Auth (login) page */
html[data-theme="dark"] .auth-page { background: linear-gradient(135deg, #020617 0%, #0f172a 100%); }
html[data-theme="dark"] .auth-card { background: #1e293b; }

/* Theme toggle button hover */
#themeToggle:hover { color: var(--primary); background: var(--gray-100); }

/* Theme toggle icon visibility */
#themeToggle .icon-sun  { display: none; }
#themeToggle .icon-moon { display: block; }
html[data-theme="dark"] #themeToggle .icon-sun  { display: block; }
html[data-theme="dark"] #themeToggle .icon-moon { display: none; }

/* =========================================================
   #invoiceDoc — always light (print preview area)
   Reset CSS variables so inline var() references work correctly,
   then override any hardcoded dark-mode rules that reach inside.
   ========================================================= */
html[data-theme="dark"] #invoiceDoc {
  color-scheme: light;  /* native UI chrome stays light inside print preview */
  --white:         #ffffff;
  --gray-50:       #f9fafb;
  --gray-100:      #f3f4f6;
  --gray-200:      #e5e7eb;
  --gray-300:      #d1d5db;
  --gray-400:      #9ca3af;
  --gray-500:      #6b7280;
  --gray-600:      #4b5563;
  --gray-700:      #374151;
  --gray-800:      #1f2937;
  --gray-900:      #111827;
  --primary-light: #fef0e7;
  --danger-light:  #fef2f2;
  --success-light: #ecfdf5;
  --warning-light: #fffbeb;
  --info-light:    #eff6ff;
  background: #ffffff !important;
  color: #1f2937 !important;
  border-color: #e5e7eb !important;
}
/* Hardcoded dark colours used in component rules above must be explicitly reset */
html[data-theme="dark"] #invoiceDoc .card        { background: #ffffff !important; border-color: #e5e7eb !important; }
html[data-theme="dark"] #invoiceDoc .card-header { background: #ffffff !important; border-bottom-color: #e5e7eb !important; }
html[data-theme="dark"] #invoiceDoc .card-footer { background: #f9fafb !important; border-top-color: #e5e7eb !important; }
html[data-theme="dark"] #invoiceDoc .table th    { background: #f9fafb !important; color: #4b5563 !important; border-bottom-color: #e5e7eb !important; }
html[data-theme="dark"] #invoiceDoc .table td    { background: #ffffff !important; color: #374151 !important; border-bottom-color: #f3f4f6 !important; }
html[data-theme="dark"] #invoiceDoc .table tr:hover td { background: #f9fafb !important; }

html[data-theme="dark"] #poDoc             { background: #ffffff !important; border-color: #e5e7eb !important; color: #1f2937 !important; }
html[data-theme="dark"] #poDoc .card       { background: #ffffff !important; border-color: #e5e7eb !important; }
html[data-theme="dark"] #poDoc .card-header{ background: #ffffff !important; border-bottom-color: #e5e7eb !important; }
html[data-theme="dark"] #poDoc .card-footer{ background: #f9fafb !important; border-top-color: #e5e7eb !important; }
html[data-theme="dark"] #invoiceDoc .btn-secondary     { background: #f3f4f6 !important; color: #374151 !important; border-color: #d1d5db !important; }
html[data-theme="dark"] #invoiceDoc .form-control,
html[data-theme="dark"] #invoiceDoc .form-select       { background: #ffffff !important; border-color: #d1d5db !important; color: #1f2937 !important; }
html[data-theme="dark"] #invoiceDoc .badge-primary { background: #fef0e7 !important; color: #f26223 !important; }
html[data-theme="dark"] #invoiceDoc .badge-success { background: #ecfdf5 !important; color: #065f46 !important; }
html[data-theme="dark"] #invoiceDoc .badge-danger  { background: #fef2f2 !important; color: #991b1b !important; }
html[data-theme="dark"] #invoiceDoc .badge-warning { background: #fffbeb !important; color: #92400e !important; }
html[data-theme="dark"] #invoiceDoc .badge-info    { background: #eff6ff !important; color: #1e40af !important; }
html[data-theme="dark"] #invoiceDoc .badge-gray    { background: #f3f4f6 !important; color: #4b5563 !important; }
html[data-theme="dark"] #invoiceDoc .divider       { background: #e5e7eb !important; }
html[data-theme="dark"] #invoiceDoc .text-muted    { color: #6b7280 !important; }

/* ── Guide body dark mode ─────────────────────────────────────────────────── */
/* Neutral gray (table headers, step pills, misc boxes) */
html[data-theme="dark"] .guide-body [style*="background:#f9fafb"],
html[data-theme="dark"] .guide-body [style*="background:#f3f4f6"] { background: #1e293b !important; }
html[data-theme="dark"] .guide-body [style*="border:1px solid #e5e7eb"]    { border-color: #334155 !important; }
html[data-theme="dark"] .guide-body [style*="border-bottom:1px solid #e5e7eb"] { border-bottom-color: #334155 !important; }
html[data-theme="dark"] .guide-body [style*="border-bottom:1px solid #f3f4f6"] { border-bottom-color: #1e293b !important; }

/* Orange-tinted (vendor role badge, invoice boxes) */
html[data-theme="dark"] .guide-body [style*="background:#fff7ed"]           { background: #2a1500 !important; }
html[data-theme="dark"] .guide-body [style*="border:1px solid #fed7aa"]     { border-color: #c2460a !important; }

/* Mascot gradient (Buni intro box) */
html[data-theme="dark"] .guide-body [style*="linear-gradient(135deg,#fff7ed"] {
    background: linear-gradient(135deg,#2a1500,#2a1c00) !important;
    border-color: #b45309 !important;
}

/* Blue-tinted (finance role badge, info boxes, blue gBadge bg) */
html[data-theme="dark"] .guide-body [style*="background:#eff6ff"],
html[data-theme="dark"] .guide-body [style*="background:#dbeafe"]           { background: #0a1e3d !important; }
html[data-theme="dark"] .guide-body [style*="border:1px solid #bfdbfe"]     { border-color: #1e40af !important; }

/* Green-tinted (success / confirmation boxes, green gBadge bg) */
html[data-theme="dark"] .guide-body [style*="background:#f0fdf4"],
html[data-theme="dark"] .guide-body [style*="background:#dcfce7"]           { background: #052e16 !important; }
html[data-theme="dark"] .guide-body [style*="border:1px solid #bbf7d0"]     { border-color: #166534 !important; }

/* Red-tinted (rejected / danger gBadge bg) */
html[data-theme="dark"] .guide-body [style*="background:#fee2e2"]           { background: #3b0a0a !important; }

/* Purple-tinted (JCR note, purple gBadge bg) */
html[data-theme="dark"] .guide-body [style*="background:#fdf4ff"],
html[data-theme="dark"] .guide-body [style*="background:#ede9fe"]           { background: #1e0a3c !important; }
html[data-theme="dark"] .guide-body [style*="border:1px solid #e9d5ff"]     { border-color: #6d28d9 !important; }

/* Yellow/orange-tinted (notes, orange gBadge bg) */
html[data-theme="dark"] .guide-body [style*="background:#fef3c7"]           { background: #2a1c00 !important; }
html[data-theme="dark"] .guide-body [style*="border:1px solid #fde68a"]     { border-color: #b45309 !important; }

/* Teal gBadge bg */
html[data-theme="dark"] .guide-body [style*="background:#cffafe"]           { background: #062830 !important; }

/* Text colors — darken to light equivalents */
html[data-theme="dark"] .guide-body [style*="color:#374151"]  { color: #e2e8f0 !important; }
html[data-theme="dark"] .guide-body [style*="color:#4b5563"]  { color: #cbd5e1 !important; }
html[data-theme="dark"] .guide-body [style*="color:#6b7280"]  { color: #94a3b8 !important; }
html[data-theme="dark"] .guide-body [style*="color:#92400e"]  { color: #fcd34d !important; }
html[data-theme="dark"] .guide-body [style*="color:#78350f"]  { color: #fbbf24 !important; }
html[data-theme="dark"] .guide-body [style*="color:#2563eb"]  { color: #93c5fd !important; }
html[data-theme="dark"] .guide-body [style*="color:#1d4ed8"]  { color: #93c5fd !important; }
html[data-theme="dark"] .guide-body [style*="color:#15803d"]  { color: #86efac !important; }
html[data-theme="dark"] .guide-body [style*="color:#7c3aed"]  { color: #c4b5fd !important; }
html[data-theme="dark"] .guide-body [style*="color:#dc2626"]  { color: #fca5a5 !important; }
html[data-theme="dark"] .guide-body [style*="color:#16a34a"]  { color: #86efac !important; }

/* Table row separators & header background in guide body */
html[data-theme="dark"] .guide-body table tr[style*="background:#f9fafb"] td,
html[data-theme="dark"] .guide-body table tr[style*="background:#f9fafb"] th { background: #1e293b !important; }

/* Workflow badges (outside .guide-body, same color set) */
html[data-theme="dark"] .guide-workflow [style*="background:#f3f4f6"]  { background: #1e293b !important; }
html[data-theme="dark"] .guide-workflow [style*="background:#dbeafe"]  { background: #0a1e3d !important; }
html[data-theme="dark"] .guide-workflow [style*="background:#dcfce7"]  { background: #052e16 !important; }
html[data-theme="dark"] .guide-workflow [style*="background:#fee2e2"]  { background: #3b0a0a !important; }
html[data-theme="dark"] .guide-workflow [style*="background:#ede9fe"]  { background: #1e0a3c !important; }
html[data-theme="dark"] .guide-workflow [style*="background:#fef3c7"]  { background: #2a1c00 !important; }
html[data-theme="dark"] .guide-workflow [style*="background:#cffafe"]  { background: #062830 !important; }
html[data-theme="dark"] .guide-workflow [style*="background:#fff7ed"]  { background: #2a1500 !important; }

/* ---- Toast Notifications ---- */
.toast-container { position:fixed; top:20px; right:20px; z-index:10001; display:flex; flex-direction:column; gap:8px; pointer-events:none; }
.toast { padding:12px 20px; border-radius:8px; font-size:13px; font-weight:500; color:#fff; pointer-events:auto; opacity:0; transform:translateX(40px); transition:opacity .3s, transform .3s; box-shadow:0 4px 12px rgba(0,0,0,.15); max-width:360px; word-break:break-word; }
.toast-show { opacity:1; transform:translateX(0); }
.toast-error   { background:#dc2626; }
.toast-success { background:#16a34a; }
.toast-warning { background:#d97706; }
.toast-info    { background:#2563eb; }
