/* =====================================================================
   NKM Agri Tech - Vyapar-style Theme
   ===================================================================== */

:root {
  --brand: #1ea672;
  --brand-dark: #137d54;
  --brand-light: #e6f7f0;
  --navy: #102a43;
  --navy-light: #1b3a5c;
  --text-dark: #1f2937;
  --text-muted: #6b7280;
  --border-color: #e5e7eb;
  --bg-body: #f4f6f9;
  --danger: #e05353;
  --warning: #f0a93f;
  --success: #1ea672;
  --info: #2f6fed;
  --sidebar-width: 250px;
  --card-bg: #ffffff;
  --input-bg: #ffffff;
}

/* ---------------------------------------------------------------------
   Dark mode - overrides the same variables; component CSS below uses
   var(--card-bg)/var(--input-bg) instead of hardcoded #fff so this
   cascades through cards, tables, and forms app-wide automatically.
   --------------------------------------------------------------------- */
[data-theme="dark"] {
  --text-dark: #e5e7eb;
  --text-muted: #9ca3af;
  --border-color: #2d3748;
  --bg-body: #0f172a;
  --brand-light: #143b2e;
  --card-bg: #1a2332;
  --input-bg: #1a2332;
}
/* Re-point Bootstrap's own CSS variables at our dark palette so every
   default Bootstrap component (tables, modals, dropdowns, list-groups,
   buttons) that reads --bs-* internally switches automatically, instead
   of silently keeping Bootstrap's light-mode white. */
[data-theme="dark"] {
  --bs-body-bg: var(--bg-body);
  --bs-body-color: var(--text-dark);
  --bs-border-color: var(--border-color);
  --bs-border-color-translucent: var(--border-color);
  --bs-tertiary-bg: var(--card-bg);
  --bs-secondary-bg: var(--card-bg);
  --bs-table-bg: var(--card-bg);
  --bs-table-color: var(--text-dark);
  --bs-table-striped-bg: #20293a;
  --bs-table-hover-bg: #1f293b;
  --bs-table-border-color: var(--border-color);
  --bs-heading-color: var(--text-dark);
  --bs-emphasis-color: var(--text-dark);
  /* Bootstrap's .text-muted/.text-secondary read this var, not --text-muted -
     without this override they stay dark-gray-on-dark-background (invisible). */
  --bs-secondary-color: var(--text-muted);
  --bs-secondary-color-rgb: 156, 163, 175;
}
[data-theme="dark"] .text-muted,
[data-theme="dark"] .text-secondary,
[data-theme="dark"] .text-body-secondary,
[data-theme="dark"] small {
  color: var(--text-muted) !important;
}
[data-theme="dark"] body { background: var(--bg-body); color: var(--text-dark); }
[data-theme="dark"] .topbar { background: var(--card-bg); border-color: var(--border-color); }

/* Belt-and-suspenders: force every table cell explicitly, regardless of
   whichever Bootstrap variable chain it was reading from before. */
[data-theme="dark"] .table,
[data-theme="dark"] .app-table,
[data-theme="dark"] .app-table > :not(caption) > * > * {
  background-color: var(--card-bg);
  color: var(--text-dark);
  border-color: var(--border-color);
}
[data-theme="dark"] .app-table thead th { background: #161f2e; }
[data-theme="dark"] .app-table tbody tr:hover,
[data-theme="dark"] .app-table tbody tr:hover > * { background-color: #1f293b; }
[data-theme="dark"] .table-light,
[data-theme="dark"] .table-light > * { background-color: #161f2e !important; color: var(--text-dark); }

[data-theme="dark"] .modal-content { background: var(--card-bg); color: var(--text-dark); }
[data-theme="dark"] .dropdown-menu { background: var(--card-bg); color: var(--text-dark); border-color: var(--border-color); }
[data-theme="dark"] .dropdown-item { color: var(--text-dark); }
[data-theme="dark"] .dropdown-item:hover { background: #1f293b; color: var(--text-dark); }
[data-theme="dark"] .form-control, [data-theme="dark"] .form-select {
  background: var(--input-bg); color: var(--text-dark); border-color: var(--border-color);
}
[data-theme="dark"] .form-control::placeholder { color: var(--text-muted); }
[data-theme="dark"] .form-check-input { background-color: var(--input-bg); border-color: var(--border-color); }
[data-theme="dark"] .badge-secondary { background: #2d3748; color: var(--text-muted); }
[data-theme="dark"] .search-results-dropdown, [data-theme="dark"] .col-filter-panel { background: var(--card-bg); }
[data-theme="dark"] .qa-btn { background: var(--card-bg); }
[data-theme="dark"] .kpi-card { background: var(--card-bg); }
[data-theme="dark"] a { color: #5fd0a3; }
[data-theme="dark"] .link-more { color: #5fd0a3; }
[data-theme="dark"] .biz-card-preview { background: linear-gradient(135deg, #143b2e 0%, var(--card-bg) 70%); }
[data-theme="dark"] .alert { background: var(--card-bg); border-color: var(--border-color); color: var(--text-dark); }
[data-theme="dark"] .nav-tabs .nav-link { color: var(--text-muted); }
[data-theme="dark"] .nav-tabs .nav-link.active { background: var(--card-bg); color: var(--text-dark); border-color: var(--border-color); }
[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-body);
  color: var(--text-dark);
  font-size: 14px;
}

.tamil-text, [lang="ta"] {
  font-family: 'Noto Sans Tamil', 'Inter', sans-serif;
}

a { text-decoration: none; }

/* ---------------------------------------------------------------------
   Layout
   --------------------------------------------------------------------- */

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

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy) 0%, #0a1d30 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: var(--brand);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.55);
}

.sidebar-nav {
  flex: 1;
  padding: 14px 10px;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  color: rgba(255,255,255,0.75);
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav .nav-link i { font-size: 16px; width: 20px; text-align: center; }

.sidebar-nav .nav-link:hover {
  background: rgba(255,255,255,0.07);
  color: #fff;
}

.sidebar-nav .nav-link.active {
  background: var(--brand);
  color: #fff;
}

.nav-divider {
  border-top: 1px solid rgba(255,255,255,0.08);
  margin: 10px 6px;
}

.sidebar-footer {
  padding: 14px 18px;
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  border-top: 1px solid rgba(255,255,255,0.08);
}

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

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border-color);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-title {
  font-size: 19px;
  font-weight: 700;
  margin: 0;
  flex: 1;
}

.btn-icon {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-dark);
}

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

.lang-switch {
  display: flex;
  background: var(--bg-body);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.lang-switch a {
  padding: 5px 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 6px;
}
.lang-switch a.active {
  background: var(--brand);
  color: #fff;
}

.page-content {
  padding: 24px 28px 50px;
}

/* ---------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------- */

.btn-brand {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}
.btn-brand:hover, .btn-brand:focus {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
  color: #fff;
}

/* ---------------------------------------------------------------------
   Quick Actions
   --------------------------------------------------------------------- */

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}

.qa-btn {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 18px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  color: var(--text-dark);
  border: 1px solid var(--border-color);
  transition: transform 0.15s, box-shadow 0.15s;
}
.qa-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.07); }
.qa-btn i { font-size: 22px; }
.qa-blue i { color: var(--info); }
.qa-green i { color: var(--success); }
.qa-orange i { color: var(--warning); }
.qa-red i { color: var(--danger); }
.qa-teal i { color: #0d9488; }
.qa-btn { border: 1px solid var(--border-color); width: 100%; text-align: left; }
.qa-btn:focus { outline: none; }

/* ---------------------------------------------------------------------
   KPI Cards
   --------------------------------------------------------------------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.kpi-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border-color);
}

.kpi-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.kpi-icon-blue { background: #e8f0fe; color: var(--info); }
.kpi-icon-green { background: var(--brand-light); color: var(--brand); }
.kpi-icon-orange { background: #fdf1e0; color: var(--warning); }
.kpi-icon-red { background: #fbe9e9; color: var(--danger); }

.kpi-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.kpi-value { font-size: 20px; font-weight: 700; color: var(--text-dark); margin-top: 2px; }

/* ---------------------------------------------------------------------
   Panels / Cards
   --------------------------------------------------------------------- */

.card-panel {
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  padding: 20px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-header h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.link-more { font-size: 13px; font-weight: 600; color: var(--brand); }
.link-more:hover { color: var(--brand-dark); }

/* ---------------------------------------------------------------------
   Dashboard quick-search dropdown
   --------------------------------------------------------------------- */

.search-results-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  max-height: 320px;
  overflow-y: auto;
}

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  text-decoration: none;
  color: var(--text-dark);
  border-bottom: 1px solid var(--border-color);
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-light, #f7f8fa); }

.search-result-empty {
  padding: 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* ---------------------------------------------------------------------
   Business Profile card preview (Settings page)
   --------------------------------------------------------------------- */

.biz-card-preview {
  display: flex;
  align-items: center;
  gap: 16px;
  background: linear-gradient(135deg, var(--brand-light) 0%, #fff 70%);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px 18px;
}
.biz-card-logo {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  color: var(--brand);
  overflow: hidden;
}
.biz-card-logo img { width: 100%; height: 100%; object-fit: contain; }
.biz-card-info { font-size: 12.5px; color: var(--text-muted); line-height: 1.5; }
.biz-card-name { font-size: 16px; font-weight: 800; color: var(--text-dark); margin-bottom: 2px; }

.snapshot-list { list-style: none; margin: 0; padding: 0; }
.snapshot-list li {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 13.5px;
}
.snapshot-list li:last-child { border-bottom: none; }
.snapshot-list li span { color: var(--text-muted); }

/* ---------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------- */

.app-table {
  margin-bottom: 0;
  font-size: 13.5px;
}
.app-table thead th {
  background: #f9fafb;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11.5px;
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border-color);
  padding: 12px;
}
.app-table tbody td {
  padding: 12px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-color);
}
.app-table tbody tr:last-child td { border-bottom: none; }
.app-table tbody tr:hover { background: #fafbfc; }

/* ---------------------------------------------------------------------
   Badges
   --------------------------------------------------------------------- */

.badge { font-weight: 600; font-size: 11.5px; padding: 5px 10px; border-radius: 6px; }
.badge-success { background: var(--brand-light); color: var(--brand-dark); }
.badge-danger { background: #fbe9e9; color: #b53030; }
.badge-warning { background: #fdf1e0; color: #9a6a16; }
.badge-secondary { background: #eef0f3; color: var(--text-muted); }
.badge-dark { background: #2b2f36; color: #fff; }

/* ---------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------- */

.form-label { font-weight: 600; font-size: 13px; color: var(--text-dark); margin-bottom: 4px; }
.form-control, .form-select { font-size: 13.5px; border-color: var(--border-color); }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }

/* ---------------------------------------------------------------------
   Bill Summary (sticky sidebar in invoice create/edit)
   --------------------------------------------------------------------- */

.sticky-summary { position: sticky; top: 90px; }

.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 13.5px;
}
.summary-row.total-row {
  font-size: 16px;
  font-weight: 700;
  border-top: 2px solid var(--text-dark);
  border-bottom: 2px solid var(--text-dark);
  padding: 12px 0;
  margin: 6px 0;
}

/* ---------------------------------------------------------------------
   Invoice Print Sheet (A4)
   --------------------------------------------------------------------- */

.invoice-body {
  background: #eef1f5;
  font-family: 'Inter', sans-serif;
}

.invoice-toolbar {
  max-width: 820px;
  margin: 18px auto 0;
  padding: 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.invoice-card-preview {
  max-width: 420px;
  margin: 0 auto 18px;
  padding: 0 10px;
  text-align: center;
}
.invoice-card-preview-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.invoice-card-preview img {
  width: 100%;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

/* ---------------------------------------------------------------------
   HTML bill card (captured client-side via html2canvas for sharing /
   downloading) - real browser text rendering, so Tamil shapes correctly
   without any of GD's script-shaping limitations.
   --------------------------------------------------------------------- */

.bill-card-html {
  width: 100%;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  overflow: hidden;
  font-family: 'Inter', sans-serif;
  color: #1f2937;
  text-align: left;
}
.bcard-topbar { height: 6px; background: #1ea672; }
.bcard-body { padding: 20px; }
.bcard-header { display: flex; align-items: flex-start; gap: 12px; }
.bcard-logo { width: 48px; height: 48px; object-fit: contain; flex-shrink: 0; }
.bcard-company-name { font-size: 17px; font-weight: 800; color: #102a43; margin-bottom: 2px; }
.bcard-meta { font-size: 11.5px; color: #6b7280; line-height: 1.45; }
.bcard-divider { border-top: 1px solid #e5e7eb; margin: 14px 0; }
.bcard-billto-row { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.bcard-label { font-size: 10px; font-weight: 700; color: #6b7280; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 2px; }
.bcard-name { font-size: 13px; font-weight: 700; color: #1f2937; }
.bcard-muted { font-size: 11.5px; color: #6b7280; }
.bcard-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 4px; }
.bcard-table thead th { text-align: left; font-size: 10.5px; font-weight: 700; color: #6b7280; text-transform: uppercase; padding: 6px 4px; border-bottom: 1px solid #e5e7eb; }
.bcard-table tbody td { padding: 7px 4px; border-bottom: 1px solid #e5e7eb; color: #1f2937; }
.bcard-totals { background: #f0faf6; border-radius: 8px; padding: 10px 14px; margin-top: 12px; font-size: 12.5px; border: 1px solid #d1fae5; }
.bcard-totals > div { display: flex; justify-content: space-between; padding: 3px 0; color: #6b7280; }
.bcard-totals > div strong { color: #1f2937; font-size: 13.5px; }
.bcard-total-amt  { color: #1f2937 !important; font-size: 14px !important; font-weight: 800 !important; }
.bcard-received-amt { color: #059669 !important; font-weight: 700 !important; }
.bcard-balance-amt  { color: #dc2626 !important; font-size: 14px !important; font-weight: 800 !important; }
.bcard-paid-badge   { color: #059669 !important; font-weight: 700 !important; letter-spacing: .04em; }
.bcard-paid-amt     { color: #059669 !important; font-weight: 600 !important; }
.bcard-thankyou { text-align: center; font-size: 11.5px; color: #6b7280; margin-top: 14px; line-height: 1.6; }

.invoice-sheet {
  max-width: 820px;
  margin: 18px auto 60px;
  background: #fff;
  padding: 50px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  min-height: 1000px;
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 3px solid var(--brand);
  padding-bottom: 20px;
  margin-bottom: 20px;
}

.invoice-logo { width: 64px; height: 64px; object-fit: contain; flex-shrink: 0; }

.invoice-company-name { font-size: calc(24px * var(--invoice-scale, 1)); font-weight: 800; margin: 0 0 6px; color: var(--navy); }
.invoice-company-meta { font-size: calc(12.5px * var(--invoice-scale, 1)); color: var(--text-muted); line-height: 1.5; }
.invoice-company-tagline { font-size: calc(12px * var(--invoice-scale, 1)); color: var(--text-muted); font-style: italic; margin: 2px 0 6px; }

.invoice-title-block { text-align: right; }
.invoice-title { font-size: calc(18px * var(--invoice-scale, 1)); font-weight: 700; letter-spacing: 1px; color: var(--text-muted); }
.invoice-number { font-size: calc(20px * var(--invoice-scale, 1)); font-weight: 700; margin: 4px 0 8px; }
.invoice-title-block .badge { margin-left: 4px; }

.invoice-meta-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 30px;
}

.meta-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.meta-name { font-size: calc(15px * var(--invoice-scale, 1)); font-weight: 700; margin-bottom: 2px; }

.invoice-dates { text-align: right; font-size: calc(13px * var(--invoice-scale, 1)); }
.invoice-dates > div { margin-bottom: 8px; }
.invoice-dates strong { display: block; font-size: calc(14px * var(--invoice-scale, 1)); }

.invoice-items-table { width: 100%; border-collapse: collapse; font-size: calc(13px * var(--invoice-scale, 1)); margin-bottom: 20px; }
.invoice-items-table thead th {
  background: var(--navy);
  color: #fff;
  padding: 10px 12px;
  text-align: left;
  font-size: calc(11.5px * var(--invoice-scale, 1));
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.invoice-items-table tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border-color); }
.invoice-items-table tbody tr:nth-child(even) { background: #fafbfc; }

.invoice-totals-row { display: flex; justify-content: space-between; gap: 30px; margin-top: 10px; }
.invoice-terms { font-size: calc(12px * var(--invoice-scale, 1)); color: var(--text-muted); max-width: 320px; }
.invoice-totals { width: 280px; }

.total-line { display: flex; justify-content: space-between; padding: 7px 0; font-size: calc(13.5px * var(--invoice-scale, 1)); }
.total-line.grand { font-weight: 700; font-size: calc(16px * var(--invoice-scale, 1)); border-top: 2px solid var(--text-dark); border-bottom: 2px solid var(--text-dark); padding: 10px 0; margin: 6px 0; }
.total-line.balance { font-weight: 700; color: var(--danger); font-size: calc(14.5px * var(--invoice-scale, 1)); }

.invoice-footer { display: flex; justify-content: flex-end; margin-top: 60px; }
.signature-block { text-align: center; font-size: 12.5px; color: var(--text-muted); }
.signature-line { width: 180px; border-bottom: 1px solid var(--text-dark); margin-bottom: 8px; height: 40px; }
.invoice-signature-img { max-height: 50px; max-width: 180px; display: block; margin: 0 auto 8px; }

.invoice-thankyou { text-align: center; margin-top: 30px; font-size: calc(13px * var(--invoice-scale, 1)); color: var(--text-muted); font-style: italic; }

/* ---------------------------------------------------------------------
   Invoice text size (Settings > Invoice Settings > Text Size)
   --------------------------------------------------------------------- */

.invoice-sheet.fs-small  { --invoice-scale: 0.85; }
.invoice-sheet.fs-medium { --invoice-scale: 1; }
.invoice-sheet.fs-large  { --invoice-scale: 1.18; }

/* ---------------------------------------------------------------------
   Invoice Print Themes
   --------------------------------------------------------------------- */

/* Modern: bold brand-coloured header band */
.theme-modern .invoice-header {
  background: var(--brand);
  padding: 26px 50px;
  margin: -50px -50px 24px;
  border-bottom: none;
}
.theme-modern .invoice-company-name,
.theme-modern .invoice-title,
.theme-modern .invoice-number { color: #fff; }
.theme-modern .invoice-company-meta { color: rgba(255,255,255,0.85); }
.theme-modern .invoice-title-block .badge { background: rgba(255,255,255,0.18); color: #fff; }
.theme-modern .total-line.grand { background: var(--brand-light); padding: 10px 14px; border-radius: 6px; border-top: none; border-bottom: none; }

/* Simple: minimal, no shading, thin rules only */
.theme-simple .invoice-header { border-bottom: 1px solid var(--border-color); }
.theme-simple .invoice-items-table thead th { background: #fff; color: var(--text-dark); border-bottom: 2px solid var(--text-dark); }
.theme-simple .invoice-items-table tbody tr:nth-child(even) { background: transparent; }
.theme-simple .total-line.grand { border-top: 1px solid var(--text-dark); border-bottom: 1px solid var(--text-dark); }

/* GST / Tax-Invoice style: boxed grid layout */
.theme-gst .invoice-meta-row { gap: 0; border: 1px solid var(--border-color); border-radius: 4px; overflow: hidden; }
.theme-gst .invoice-meta-row > div { padding: 14px 16px; }
.theme-gst .invoice-bill-to { border-right: 1px solid var(--border-color); flex: 1; }
.theme-gst .invoice-dates { flex: 1; }
.theme-gst .invoice-items-table { border: 1px solid var(--border-color); }
.theme-gst .invoice-items-table thead th { background: #f1f3f5; color: var(--text-dark); border-bottom: 2px solid var(--text-dark); }
.theme-gst .invoice-items-table tbody td { border-right: 1px solid var(--border-color); }
.theme-gst .invoice-items-table tbody td:last-child { border-right: none; }
.theme-gst .invoice-terms { border: 1px solid var(--border-color); border-radius: 4px; padding: 12px 14px; }
.theme-gst .invoice-totals { border: 1px solid var(--border-color); border-radius: 4px; padding: 12px 14px; }
.theme-gst .total-line.grand { background: #f1f3f5; padding: 10px 14px; border-radius: 4px; border-top: none; border-bottom: none; }

/* ---------------------------------------------------------------------
   Thermal Receipt Print Layout
   --------------------------------------------------------------------- */

.receipt-sheet {
  width: 272px;
  margin: 18px auto 60px;
  background: #fff;
  padding: 14px 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  font-size: 12px;
  color: #111;
}
.receipt-sheet.w-58mm { width: 218px; }
.receipt-sheet.w-72mm { width: 272px; }
.receipt-sheet.w-80mm { width: 300px; }

.receipt-center { text-align: center; }
.receipt-company-name { font-weight: 800; font-size: 14px; margin-bottom: 2px; }
.receipt-muted { color: var(--text-muted); font-size: 10.5px; }
.receipt-divider { border-top: 1px dashed #999; margin: 8px 0; }

.receipt-row { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; padding: 1px 0; }
.receipt-row.receipt-total { font-weight: 800; font-size: 13.5px; border-top: 1px dashed #999; padding-top: 6px; margin-top: 4px; }

.receipt-items-table { width: 100%; border-collapse: collapse; font-size: 11.5px; margin: 4px 0; }
.receipt-items-table th { text-align: left; font-weight: 700; border-bottom: 1px dashed #999; padding-bottom: 3px; }
.receipt-items-table th:last-child, .receipt-items-table td:last-child { text-align: right; }
.receipt-items-table th:nth-child(2), .receipt-items-table td:nth-child(2) { text-align: right; }
.receipt-items-table td { padding: 4px 0; vertical-align: top; }

.receipt-thankyou { margin-top: 10px; font-size: 11px; font-style: italic; color: var(--text-muted); }

@media print {
  .receipt-sheet { box-shadow: none; margin: 0 auto; }
}

/* ---------------------------------------------------------------------
   Print
   --------------------------------------------------------------------- */

.print-only { display: none; }

@media print {
  .no-print { display: none !important; }
  .print-only { display: block !important; }
  .invoice-body { background: #fff; }
  .invoice-sheet { box-shadow: none; margin: 0; max-width: 100%; }
  .sidebar, .topbar { display: none !important; }
  .page-content { padding: 0 !important; }
}

/* ---------------------------------------------------------------------
   All Transactions report: per-column filter popovers
   --------------------------------------------------------------------- */

.col-filter { display: inline-block; position: relative; margin-left: 4px; }
.col-filter summary {
  list-style: none;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-block;
}
.col-filter summary::-webkit-details-marker { display: none; }
.col-filter[open] summary { color: var(--brand); }
.col-filter-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 40;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 10px;
  width: 180px;
  text-align: left;
  text-transform: none;
  font-weight: 400;
}

/* ---------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */

@media (max-width: 991px) {
  .sidebar {
    position: fixed;
    left: -100%;
    transition: left 0.2s;
    z-index: 200;
  }
  .sidebar.show { left: 0; }
  .page-content { padding: 18px; }
  .sticky-summary { position: static; top: auto; }
}

/* ---------------------------------------------------------------------
   Mobile / on-site entry friendliness (phones, ~<=768px)
   --------------------------------------------------------------------- */

@media (max-width: 768px) {
  body { font-size: 14px; }

  .topbar {
    padding: 10px 14px;
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .page-title { font-size: 16px; order: 1; }
  .topbar-actions { order: 3; flex-basis: 100%; justify-content: space-between; }
  #sidebarToggle { order: 0; }

  .page-content { padding: 12px; padding-bottom: 28px; }
  .card-panel { padding: 14px; border-radius: 10px; }
  .panel-header { flex-wrap: wrap; row-gap: 8px; }
  .panel-header h2 { font-size: 15px; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-card { padding: 12px; gap: 10px; }
  .kpi-icon { width: 40px; height: 40px; font-size: 18px; }
  .kpi-value { font-size: 15px; }
  .kpi-label { font-size: 11px; }

  .quick-actions { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .qa-btn { padding: 14px 10px; font-size: 13px; }

  /* Bigger touch targets for on-site, gloved/one-handed use */
  .btn, .form-control, .form-select { min-height: 42px; }
  .btn-sm, .form-control-sm, .form-select-sm { min-height: 38px; }
  .btn { font-size: 14px; }

  .app-table { font-size: 12.5px; }
  .table-responsive { -webkit-overflow-scrolling: touch; }

  .modal-dialog { margin: 10px; }

  .invoice-sheet { padding: 20px; }
  .receipt-sheet, .receipt-sheet.w-58mm, .receipt-sheet.w-72mm, .receipt-sheet.w-80mm { width: 100%; max-width: 320px; }
}

/* ---------------------------------------------------------------------
   Service Items entry: card layout instead of a wide scrolling table
   (this is the main "fill out a bill standing in the field" screen)
   --------------------------------------------------------------------- */

@media (max-width: 700px) {
  #itemsTable thead { display: none; }
  #itemsTable, #itemsTable tbody, #itemsTable tr, #itemsTable td {
    display: block;
    width: 100%;
  }
  #itemsTable tbody tr {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 12px;
    position: relative;
    background: var(--card-bg);
  }
  #itemsTable td {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    border: none;
  }
  #itemsTable td::before {
    content: attr(data-label);
    flex: 0 0 78px;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
  }
  #itemsTable td.line-amount-cell {
    justify-content: flex-start;
    font-weight: 700;
  }
  #itemsTable td:last-child {
    position: absolute;
    top: 8px;
    right: 8px;
    width: auto;
    padding: 0;
  }
  #itemsTable td:last-child::before { content: none; }
}

/* ---------------------------------------------------------------------
   Sticky bottom "Save" bar for long entry forms on mobile (Create/Edit
   Invoice) - keeps the primary action reachable with one thumb.
   --------------------------------------------------------------------- */

.mobile-save-bar { display: none; }

@media (max-width: 991px) {
  .mobile-save-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 150;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
  }
  .mobile-save-bar-total { font-size: 12px; color: var(--text-muted); line-height: 1.3; }
  .mobile-save-bar-total strong { display: block; font-size: 17px; color: var(--text-dark); }
  .mobile-save-bar .btn { flex-shrink: 0; }
  .mobile-save-bar-spacer { height: 78px; }
}

/* ============================================================
   Welcome Card — Glassmorphism Auto-Slider (Dashboard)
   ============================================================ */
.welcome-glass-card {
  position: relative;
  overflow: hidden;
  border-radius: 18px;
  padding: 22px 24px 18px;
  background: linear-gradient(135deg, #0f5132 0%, #1a6b42 40%, #1d5fa3 100%);
  box-shadow: 0 8px 32px rgba(16,80,50,0.28), 0 2px 8px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 110px;
  animation: wcSlideIn 0.5s ease;
}
.wc-bg-decor {
  position: absolute;
  top: -30px; right: -30px;
  width: 160px; height: 160px;
  background: rgba(255,255,255,0.07);
  border-radius: 50%;
  pointer-events: none;
}
.wc-bg-decor::after {
  content:'';
  position: absolute;
  bottom: -60px; left: -60px;
  width: 120px; height: 120px;
  background: rgba(255,255,255,0.05);
  border-radius: 50%;
}
.wc-icon {
  font-size: 2rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
  transition: transform 0.3s ease;
}
.wc-content { flex: 1; }
.wc-text {
  font-size: 1.04rem;
  font-weight: 600;
  line-height: 1.7;
  color: rgba(255,255,255,0.96);
  letter-spacing: 0.01em;
}
.wc-text.wc-fade-in {
  animation: wcFadeIn 0.55s ease;
}
@keyframes wcFadeIn {
  from { opacity: 0; transform: translateX(14px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes wcSlideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.wc-dots {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 4px;
}
.wc-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  cursor: pointer;
  transition: all 0.25s;
  flex-shrink: 0;
}
.wc-dot.active {
  background: #fff;
  width: 18px;
  border-radius: 3px;
}
@media (max-width: 480px) {
  .wc-text { font-size: 0.94rem; }
  .welcome-glass-card { padding: 18px 16px 14px; }
}

/* KPI period form */
.kpi-period-form {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 14px;
}
.kpi-period-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.kpi-period-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}
.kpi-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.kpi-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  border-radius: 6px;
  border: 1.5px solid var(--border-color);
  background: var(--card-bg);
  color: var(--text-secondary);
  font-size: 0.80rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.kpi-btn:hover {
  background: var(--brand-light);
  border-color: var(--brand);
  color: var(--brand);
  text-decoration: none;
}
.kpi-btn-active {
  background: var(--brand) !important;
  border-color: var(--brand) !important;
  color: #fff !important;
  font-weight: 600;
}
