:root {
  /* Palette matched to Boltwood timber + hardware logo */
  --bw-forest: #5d3a26;
  --bw-forest-deep: #3e2618;
  --bw-oak: #a87053;
  --bw-oak-soft: #b8964b;
  --bw-mist: #f4f1ee;
  --bw-panel: #2a1a12;
  --bw-panel-2: #3a2418;
  --bw-surface: #ffffff;
  --bw-ink: #1f1712;
  --bw-muted: #6b5f56;
  --bw-line: #e4ddd6;
  --bw-danger: #b91c1c;
  --bw-success: #15803d;
  --bw-info: #0369a1;
  --bw-shadow: 0 18px 40px rgba(61, 38, 24, 0.08);
  --sidebar-w: 272px;
  --header-h: 62px;
  --radius: 14px;
  --font: "DM Sans", "Segoe UI", sans-serif;
  --font-display: "Outfit", "DM Sans", sans-serif;
  --fs-base: 14.5px;
  --fs-sm: 13px;
  --fs-xs: 12px;
  --fs-md: 15px;
  --fs-lg: 16px;
  --fs-xl: 1.22rem;
  --fs-2xl: 1.4rem;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.55;
  letter-spacing: -0.01em;
  color: var(--bw-ink);
  background:
    radial-gradient(ellipse 90% 70% at 50% 0%, #ffffff 0%, #f7f8f7 55%, #eef1ef 100%);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
img { max-width: 100%; display: block; }

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

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--bw-panel) 0%, var(--bw-panel-2) 100%);
  color: #ecf4ee;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease;
  box-shadow: 8px 0 30px rgba(0,0,0,.12);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand img {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  object-fit: contain;
  background: #fff;
  padding: 2px;
}
.sidebar-brand .brand-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sidebar-brand .brand-line {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.sidebar-brand .brand-text strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-brand .brand-tagline {
  font-size: var(--fs-xs);
  opacity: .72;
  color: rgba(244, 241, 238, .88);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scrollbar-width: thin;
  scrollbar-color: rgba(244, 241, 238, 0.28) transparent;
}
.sidebar-nav::-webkit-scrollbar {
  width: 6px;
}
.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
  margin: 8px 0;
}
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(244, 241, 238, 0.22);
  border-radius: 999px;
  border: 1px solid transparent;
  background-clip: padding-box;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: rgba(244, 241, 238, 0.38);
}
.sidebar-nav::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}
.sidebar-nav::-webkit-scrollbar-corner {
  background: transparent;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 11px;
  color: rgba(244, 241, 238, .82);
  font-size: var(--fs-base);
  font-weight: 500;
  transition: .18s ease;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .9; }

.nav-link:hover, .nav-link.active {
  background: rgba(184, 150, 75, .18);
  color: #fff;
}
.sidebar-credit {
  padding: 14px 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 3px;
}
.sidebar-credit .credit-label {
  font-size: 10px;
  line-height: 1.4;
  color: rgba(236,244,238,.55);
}
.sidebar-credit .credit-brand {
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.35;
  color: rgba(236,244,238,.88);
}
.sidebar-credit .credit-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.35;
  color: #ffffff;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.sidebar-credit .credit-link svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  stroke: currentColor;
}
.sidebar-credit .credit-link:hover {
  color: rgba(255, 255, 255, 0.85);
  text-decoration: underline;
}

.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  isolation: isolate;
  background: transparent;
  min-height: 100vh;
}

.app-network {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  opacity: 0.42;
}

.app-network img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0.75;
  filter: grayscale(1);
}

.topbar {
  height: var(--header-h);
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(14px);
  background: rgba(255, 255, 255, 0.82);
  border-bottom: 1px solid var(--bw-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.topbar-search-form {
  flex: 1;
  min-width: 0;
  max-width: 360px;
}
.topbar-search-form .search {
  width: 100%;
  height: 38px;
  padding: 0 14px;
  border-radius: 12px;
  font-size: var(--fs-sm);
  font-weight: 500;
}

.topbar-period-wrap {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-left: auto;
  margin-right: 8px;
  flex-shrink: 0;
}
.topbar-period {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.topbar-period .bw-select {
  min-width: 132px;
  width: auto;
}

.topbar-period .bw-select-trigger {
  min-width: 132px;
}

.topbar-period .bw-select-menu {
  max-height: none;
  overflow: visible;
}

.topbar-period .period-date {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--bw-line);
  border-radius: 12px;
  background: #fff;
  color: var(--bw-ink);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
}

.topbar-period .period-date:hover {
  border-color: #c5d0c8;
}

.topbar-period .period-date:focus {
  outline: none;
  border-color: var(--bw-forest);
  box-shadow: 0 0 0 3px rgba(93, 58, 38, 0.12);
}

.topbar-period .custom-dates {
  display: none;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.topbar-period .custom-dates.is-open {
  display: flex;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.menu-btn {
  display: none;
  border: 0;
  background: var(--bw-surface);
  width: 40px; height: 40px;
  border-radius: 10px;
  box-shadow: var(--bw-shadow);
  cursor: pointer;
  font-size: var(--fs-md);
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.page-heading {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 650;
  margin: 0;
  letter-spacing: -0.035em;
  color: var(--bw-ink);
}
.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-left: auto;
}

.content {
  position: relative;
  z-index: 1;
  padding: 18px 22px 32px;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  box-sizing: border-box;
  min-width: 0;
  /* Keep page from sideways-shifting; tables scroll inside .table-wrap */
  overflow-x: clip;
}

.toolbar {
  display: none;
}
.dropdown-wrap { position: relative; }
.icon-btn {
  position: relative;
  width: 40px; height: 40px;
  border: 0;
  border-radius: 10px;
  background: var(--bw-surface);
  box-shadow: var(--bw-shadow);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}
.badge-dot {
  position: absolute;
  top: 6px; right: 6px;
  min-width: 14px; height: 14px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--bw-oak);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: min(300px, 86vw);
  background: var(--bw-surface);
  border: 1px solid var(--bw-line);
  border-radius: 12px;
  box-shadow: var(--bw-shadow);
  display: none;
  overflow: hidden;
  z-index: 50;
  font-size: var(--fs-sm);
}
.dropdown.open { display: block; }
.dropdown-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--bw-line);
  font-weight: 650;
  font-size: var(--fs-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dropdown-item {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f2;
  display: block;
}
.dropdown-item strong { font-size: var(--fs-sm); font-weight: 650; }
.dropdown-item small { display: block; color: var(--bw-muted); margin-top: 2px; font-size: var(--fs-xs); line-height: 1.4; }

.user-icon-btn .avatar {
  width: 32px;
  height: 32px;
  font-size: var(--fs-sm);
}
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bw-forest), var(--bw-oak));
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: var(--fs-xs);
  flex-shrink: 0;
}
.avatar-lg {
  width: 40px;
  height: 40px;
  font-size: var(--fs-base);
}
.user-dropdown { width: min(260px, 86vw); }
.user-dropdown-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--bw-line);
  background: #f8fbf8;
}
.user-dropdown-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.user-dropdown-info strong {
  font-size: var(--fs-sm);
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-dropdown-info > small {
  color: var(--bw-muted);
  font-size: var(--fs-xs);
}
.role-pill {
  display: inline-flex;
  align-self: flex-start;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e8f5ec;
  color: var(--bw-forest);
  font-size: var(--fs-xs);
  font-weight: 650;
  text-transform: capitalize;
}
.user-details { padding-top: 8px; padding-bottom: 8px; }
.dropdown-action {
  color: var(--bw-danger);
  font-weight: 650;
  font-size: var(--fs-sm);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.toolbar-actions, .filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.field, .select, .search {
  height: 40px;
  border: 1px solid var(--bw-line);
  border-radius: 12px;
  padding: 0 12px;
  background: #fff;
  color: var(--bw-ink);
  font-size: var(--fs-base);
  font-family: var(--font);
  font-weight: 400;
}
.field::placeholder,
.textarea::placeholder,
.search::placeholder,
.bw-select-search::placeholder {
  color: #a89c93;
  font-family: var(--font);
  font-weight: 300;
  font-style: normal;
  letter-spacing: 0.01em;
  opacity: 1;
}
.field::-webkit-input-placeholder,
.textarea::-webkit-input-placeholder,
.search::-webkit-input-placeholder {
  color: #a89c93;
  font-weight: 300;
}
.field::-moz-placeholder,
.textarea::-moz-placeholder,
.search::-moz-placeholder {
  color: #a89c93;
  font-weight: 300;
  opacity: 1;
}

#product-modal .field::placeholder,
#product-modal .textarea::placeholder {
  color: #b0a49b;
  font-weight: 300;
  font-size: var(--fs-sm);
  letter-spacing: 0.015em;
}

.bw-select.is-placeholder .bw-select-label {
  color: #b0a49b;
  font-weight: 300;
  font-style: normal;
  letter-spacing: 0.015em;
}
.search { min-width: min(240px, 100%); }

/* Modern custom selects */
select.select {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
}

.bw-select {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
}

.bw-select-trigger {
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px 0 14px;
  border: 1px solid var(--bw-line);
  border-radius: 12px;
  background: #fff;
  color: var(--bw-ink);
  font-size: var(--fs-base);
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.bw-select.select-sm .bw-select-trigger {
  height: 38px;
  font-size: var(--fs-sm);
}

.bw-select-trigger:hover {
  border-color: #c5d0c8;
}

.bw-select.open .bw-select-trigger,
.bw-select-trigger:focus {
  outline: none;
  border-color: var(--bw-forest);
  box-shadow: 0 0 0 3px rgba(93, 58, 38, 0.12);
}

.bw-select.is-disabled .bw-select-trigger {
  opacity: 0.6;
  cursor: not-allowed;
  background: #f5f7f5;
}

.bw-select-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bw-select-chevron {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  color: var(--bw-ink);
  transition: transform 0.18s ease;
}

.bw-select.open .bw-select-chevron {
  transform: rotate(180deg);
}

.bw-select-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 90;
  display: none;
  max-height: 280px;
  overflow-y: auto;
  padding: 6px;
  margin: 0;
  list-style: none;
  background: #fff;
  border: 1px solid var(--bw-line);
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(61, 38, 24, 0.12);
}

.bw-select.open .bw-select-menu {
  display: block;
}

.bw-select.drop-up .bw-select-menu {
  top: auto;
  bottom: calc(100% + 6px);
  box-shadow: 0 -8px 24px rgba(61, 38, 24, 0.1);
}

.bw-select-search-wrap {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 2px 2px 8px;
  background: #fff;
}

.bw-select-search {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--bw-line);
  border-radius: 10px;
  font-size: var(--fs-sm);
}

.bw-select-search:focus {
  outline: none;
  border-color: var(--bw-forest);
  box-shadow: 0 0 0 3px rgba(93, 58, 38, 0.12);
}

.bw-select-empty {
  padding: 10px 12px;
  font-size: var(--fs-sm);
  color: var(--bw-muted);
  text-align: center;
}

.bw-select-option.is-hidden,
.bw-select-option[hidden] {
  display: none !important;
}

.bw-select-option {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--bw-ink);
  font-size: var(--fs-sm);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.bw-select-option:hover,
.bw-select-option.is-active {
  background: #eef6f0;
  color: var(--bw-forest-deep);
}

.bw-select-option.is-selected {
  background: var(--bw-forest);
  color: #fff;
}

.bw-select-option.is-selected:hover,
.bw-select-option.is-selected.is-active {
  background: var(--bw-forest-deep);
  color: #fff;
}

.bw-select-option:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.form-group .bw-select {
  width: 100%;
}
.form-group .dim-field .bw-select,
.dim-field > .bw-select {
  width: 84px !important;
  min-width: 84px !important;
  max-width: 84px !important;
  flex: none;
}
.textarea {
  width: 100%;
  border: 1px solid var(--bw-line);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 80px;
  resize: vertical;
  font-size: var(--fs-sm);
  font-family: var(--font);
  font-weight: 400;
  color: var(--bw-ink);
}

.btn {
  height: 40px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 650;
  font-size: var(--fs-base);
  line-height: 1;
  color: var(--bw-ink);
  background: #fff;
  transition: background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.btn:hover { filter: none; }
.btn:disabled,
.btn[disabled] {
  opacity: .55;
  cursor: not-allowed;
}
.btn-sm { height: 34px; padding: 0 10px; font-size: var(--fs-sm); border-radius: 9px; }
.btn-block {
  width: 100%;
  justify-content: center;
}

.btn-primary {
  background: linear-gradient(180deg, #6b4430 0%, var(--bw-forest) 100%);
  border-color: var(--bw-forest-deep);
  color: #fff;
  box-shadow: 0 6px 14px rgba(93, 58, 38, 0.22);
}
.btn-primary:hover {
  background: linear-gradient(180deg, var(--bw-forest) 0%, var(--bw-forest-deep) 100%);
  border-color: var(--bw-forest-deep);
  color: #fff;
}

.btn-accent {
  background: linear-gradient(180deg, #c08a6a 0%, var(--bw-oak) 100%);
  border-color: #8f5a40;
  color: #fff;
}
.btn-accent:hover {
  background: #8f5a40;
  border-color: #8f5a40;
  color: #fff;
}

.btn-ghost {
  background: #fff;
  border-color: var(--bw-line);
  color: var(--bw-forest-deep);
}
.btn-ghost:hover {
  background: var(--bw-mist);
  border-color: #d2c6ba;
  color: var(--bw-forest-deep);
}

.btn-danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--bw-danger);
}
.btn-danger:hover {
  background: var(--bw-danger);
  border-color: var(--bw-danger);
  color: #fff;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
}
.kpi-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--bw-line);
  border-radius: var(--radius);
  padding: 16px 16px 15px;
  box-shadow: var(--bw-shadow);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(6px);
}
.kpi-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--bw-forest);
  opacity: 0.75;
}
.kpi-card.accent::before { background: var(--bw-oak); }
.kpi-card.positive::before { background: var(--bw-success); }
.kpi-card.negative::before { background: var(--bw-danger); }
.kpi-card .label {
  color: var(--bw-muted);
  font-size: var(--fs-sm);
  margin-bottom: 10px;
  font-weight: 600;
}
.kpi-card .value {
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 1.4vw, 1.28rem);
  letter-spacing: -0.03em;
  font-weight: 650;
  color: var(--bw-ink);
  word-break: break-word;
}
.kpi-card.positive .value { color: var(--bw-success); }
.kpi-card.negative .value { color: var(--bw-danger); }
.kpi-card.accent .value { color: var(--bw-oak); }

.dashboard {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-bottom: 8px;
}
.dashboard .panel { margin-bottom: 0; }
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}
.panel {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--bw-line);
  border-radius: var(--radius);
  box-shadow: var(--bw-shadow);
  overflow: hidden;
  margin-bottom: 18px;
  backdrop-filter: blur(6px);
  max-width: 100%;
  min-width: 0;
}
.panel > .table-wrap {
  /* Keep scroll inside rounded panel */
  max-width: 100%;
}
.panel-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--bw-line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: rgba(250, 248, 246, 0.7);
}
.panel-head h3 {
  margin: 0;
  font-size: var(--fs-base);
  font-weight: 650;
  color: var(--bw-ink);
}
.panel-note {
  font-size: var(--fs-xs);
  color: var(--bw-muted);
  font-weight: 500;
  white-space: nowrap;
}
.panel-body { padding: 16px 18px; }
.panel-chart { margin-bottom: 0; }

.payables-stack,
.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.chart-panel-body { padding: 4px 16px 18px; }
.chart-wrap {
  position: relative;
  height: clamp(240px, 32vw, 320px);
  width: 100%;
  padding: 4px 4px 0;
}
.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}
.panel-chart .panel-head {
  border-bottom: none;
  padding: 16px 18px 8px;
}
.panel-chart .panel-note { color: #80868b; }

.insight-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  margin: 0;
}
.insight-card {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--bw-line);
  border-radius: var(--radius);
  box-shadow: var(--bw-shadow);
  overflow: hidden;
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.insight-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid #f0ebe6;
}
.insight-head h3 {
  margin: 0 0 4px;
  font-size: var(--fs-base);
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--bw-ink);
}
.insight-head .panel-note { display: block; }
.insight-total {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  color: var(--bw-forest);
  white-space: nowrap;
  padding-top: 2px;
}
.insight-body {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(120px, 0.9fr);
  gap: 10px 12px;
  padding: 12px 14px 14px;
  align-items: center;
  flex: 1;
}
.insight-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.insight-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border-radius: 10px;
  background: rgba(247, 244, 241, 0.7);
}
.insight-rank {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--bw-forest);
}
.insight-row:nth-child(2) .insight-rank { background: #a87053; }
.insight-row:nth-child(3) .insight-rank { background: #b8964b; }
.insight-row:nth-child(4) .insight-rank { background: #6b5f56; }
.insight-row:nth-child(5) .insight-rank { background: #8b958f; }
.insight-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.insight-meta strong {
  font-size: var(--fs-sm);
  font-weight: 650;
  color: var(--bw-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.insight-meta span {
  font-size: 11px;
  color: var(--bw-muted);
  font-weight: 500;
}
.insight-amount {
  font-size: var(--fs-sm);
  font-weight: 650;
  color: var(--bw-ink);
  white-space: nowrap;
}
.insight-empty {
  color: var(--bw-muted);
  font-size: var(--fs-sm);
  padding: 22px 10px;
  text-align: center;
}
.insight-pie-wrap {
  position: relative;
  width: 100%;
  height: 150px;
  max-width: 170px;
  margin: 0 auto;
  padding: 4px;
}

table.data th, table.data td {
  padding: 10px 12px;
  border-bottom: 1px solid #f0ebe6;
  text-align: left;
  font-size: var(--fs-base);
  white-space: nowrap;
  vertical-align: middle;
}
table.data th {
  background: #faf7f4;
  color: var(--bw-muted);
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 650;
}
table.data tr:hover td { background: #fbf9f7; }

/* Date / money columns never crush on mid widths */
table.data th.col-date,
table.data td.col-date {
  min-width: 7.5rem;
  width: 7.5rem;
  font-variant-numeric: tabular-nums;
}
table.data th.col-money,
table.data td.col-money {
  min-width: 6.75rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.data th.col-phone,
table.data td.col-phone {
  min-width: 7.5rem;
}
table.data th.col-status,
table.data td.col-status {
  min-width: 5.5rem;
}
.actions {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 6px;
  white-space: nowrap;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.actions > .btn-icon,
.actions > .row-action-form {
  margin: 0;
}
.actions .row-action-form,
.row-actions .row-action-form {
  display: inline-flex;
  margin: 0;
  padding: 0;
  border: 0;
  width: 34px;
  height: 34px;
}
table.data th.col-actions,
table.data td.actions,
table.data td.col-actions {
  width: 1%;
  min-width: 118px;
  max-width: none;
  text-align: center;
  vertical-align: middle;
  padding-left: 10px;
  padding-right: 12px;
  box-sizing: border-box;
  white-space: nowrap;
  position: sticky;
  right: 0;
  z-index: 2;
  background: #fff;
  box-shadow: -8px 0 12px -10px rgba(61, 38, 24, 0.28);
}
table.data thead th.col-actions {
  background: #faf7f4;
  z-index: 3;
  text-align: center;
}
table.data tbody tr:hover td.actions,
table.data tbody tr:hover td.col-actions {
  background: #fbf9f7;
}

.btn-icon {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 9px;
  flex-shrink: 0;
}
.btn-icon svg {
  display: block;
  flex-shrink: 0;
}

/* Truncated cells — single line + ellipsis; full text via BwTip */
.cell-clip-td {
  max-width: 160px;
}
.cell-clip-td.is-wide {
  max-width: 280px;
}
.cell-clip {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}
table.data td.actions,
table.data td.cell-clip-td {
  overflow: visible;
}

/* App tooltip — fixed portal, matches Brandwood UI */
.bw-tip {
  position: fixed;
  z-index: 10050;
  left: 0;
  top: 0;
  padding: 7px 11px;
  border-radius: 9px;
  background: linear-gradient(180deg, #3a2418 0%, var(--bw-forest-deep) 100%);
  color: #fff7f0;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.3;
  white-space: nowrap;
  max-width: min(300px, calc(100vw - 16px));
  box-shadow: 0 10px 24px rgba(61, 38, 24, 0.28), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px) scale(0.98);
  transition: opacity .14s ease, transform .14s ease, visibility .14s ease;
}
.bw-tip.is-on {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}
.bw-tip.is-wrap {
  white-space: normal;
  text-align: left;
}
.bw-tip::after {
  content: "";
  position: absolute;
  left: var(--bw-tip-arrow, 50%);
  width: 8px;
  height: 8px;
  background: var(--bw-forest-deep);
  transform: translateX(-50%) rotate(45deg);
}
.bw-tip.is-above::after {
  bottom: -4px;
}
.bw-tip.is-below::after {
  top: -4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 650;
  background: #f3ebe4;
  color: var(--bw-forest);
}
.badge.due { background: #fff7ed; color: #c2410c; }
.badge.credit { background: #eff6ff; color: #1d4ed8; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 24, 16, .5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 28px 20px;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.modal-backdrop.open {
  display: flex;
  align-items: center;
  justify-content: center;
}
# Confirm must sit above the global loader (z-index 10000)
#bw-confirm-modal {
  z-index: 10060;
}
#desktop-update-modal {
  z-index: 10050;
}
#sync-modal.modal-backdrop {
  z-index: 10040;
}
.modal {
  width: min(640px, 100%);
  height: auto;
  max-height: min(86vh, 820px);
  max-height: min(86dvh, 820px);
  margin: auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(61, 38, 24, 0.25);
}
/* Forms that wrap head/body/foot must participate in flex scroll */
.modal > form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  width: 100%;
}
.modal-lg,
#product-modal .modal,
#sale-modal .modal {
  width: min(1120px, 96vw);
  max-height: min(90vh, 900px);
  max-height: min(90dvh, 900px);
}
.modal-sm { width: min(480px, 100%); }

.bw-confirm-message {
  margin: 0 0 12px;
  color: var(--bw-ink, #1a2e22);
  line-height: 1.45;
}
.bw-confirm-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}
.bw-confirm-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.92rem;
  line-height: 1.4;
}
.bw-confirm-effects li {
  background: rgba(21, 128, 61, 0.08);
  color: #14532d;
  border: 1px solid rgba(21, 128, 61, 0.18);
}
.bw-confirm-blockers li {
  background: rgba(194, 65, 12, 0.08);
  color: #7c2d12;
  border: 1px solid rgba(194, 65, 12, 0.2);
}
.bw-confirm-list li::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex: 0 0 auto;
}
.bw-confirm-effects li::before { background: #15803d; }
.bw-confirm-blockers li::before { background: #c2410c; }
#bw-confirm-modal.is-blocked #bw-confirm-ok {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
#bw-confirm-ok:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
#company-modal .modal,
#quick-company-modal .modal {
  width: min(560px, 96vw);
  height: auto;
  max-height: min(92vh, 720px);
  max-height: min(92dvh, 720px);
}
#quick-vendor-modal,
#quick-customer-modal,
#quick-company-modal {
  z-index: 220;
}
#user-modal .modal-user {
  width: min(640px, 96vw);
  height: auto;
  max-height: none;
  overflow: visible;
}
#user-modal .modal-user > form {
  overflow: visible;
  max-height: none;
  min-height: 0;
  flex: none;
}
#user-modal .modal-body {
  overflow: visible;
  flex: none;
  padding-bottom: 8px;
}
#user-modal .modal-foot {
  justify-content: flex-end;
  gap: 10px;
  padding-top: 12px !important;
}
#user-modal .form-grid {
  gap: 14px 16px;
}
#user-modal .company-pick {
  display: flex;
  align-items: center;
  gap: 8px;
}
#user-modal .company-pick > .select,
#user-modal .company-pick > .bw-select {
  flex: 1;
  min-width: 0;
}
#user-modal .company-pick .btn-add-vendor {
  width: 42px;
  height: 42px;
  flex: none;
}
#user-modal .user-active-row {
  margin-top: 2px;
}
#user-modal .user-active-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-sm);
  color: var(--bw-ink);
  font-weight: 600;
  cursor: pointer;
}
.sale-lines-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.sale-line {
  padding: 14px 0;
  border-top: 1px solid color-mix(in srgb, var(--border, #d7d2c8) 80%, transparent);
}
.sale-line:first-child {
  border-top: 0;
  padding-top: 0;
}
.sale-line-tools {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.sale-line-icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--bw-line, #ddd4c8);
  background: #fff;
  color: var(--bw-forest, #2f4a3a);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.sale-line-icon-btn svg {
  display: block;
}
.sale-line-icon-btn.is-add:hover {
  background: color-mix(in srgb, var(--bw-forest, #2f4a3a) 12%, #fff);
  border-color: var(--bw-forest, #2f4a3a);
}
.sale-line-icon-btn.is-remove {
  color: #9b2c2c;
}
.sale-line-icon-btn.is-remove:hover {
  background: #fef2f2;
  border-color: #c45c5c;
}
.sale-line-product {
  margin-bottom: 8px;
}
.sale-line-product label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--fs-sm);
  font-weight: 600;
}
.sale-line-meta {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.4;
}
.sale-line-fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
  align-items: end;
}
.sale-line-fields[hidden],
.sale-length-unit-wrap[hidden] {
  display: none !important;
}
.sale-line-fields .form-group {
  margin: 0;
}
.sale-line-fields .form-group label {
  font-size: 12px;
}
.sale-line-fields .sale-cost-hint {
  font-weight: 500;
  margin-left: 4px;
}
.sale-line-fields .sale-line-total {
  background: #f7f4ef;
  font-weight: 650;
}
.sale-qty-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.sale-qty-suffix {
  min-width: 2.5rem;
  font-size: 12px;
  font-weight: 600;
}
.sale-totals-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 18px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid color-mix(in srgb, var(--border, #d7d2c8) 80%, transparent);
  font-size: 14px;
}
@media (max-width: 900px) {
  .sale-line-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.vendor-pick {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 10px;
  align-items: stretch;
  width: 100%;
}
.vendor-pick > .bw-select,
.vendor-pick > .select {
  width: 100% !important;
  min-width: 0 !important;
  max-width: none !important;
  flex: none;
}
.vendor-pick .bw-select-trigger {
  width: 100%;
  height: 42px;
}
.btn-add-vendor {
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  flex: none;
}
.btn-add-vendor svg {
  display: block;
}
.modal-head,
.modal-foot {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: #fff;
}
.modal-foot[hidden],
.modal-body [hidden],
#desktop-update-modal [hidden] {
  display: none !important;
}
.modal-head {
  padding: 28px 28px 16px !important;
  border-bottom: 1px solid var(--bw-line);
}
.modal-head h3 {
  margin: 0;
  padding: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--bw-forest-deep);
}
#product-modal .modal-head {
  padding-top: 40px !important;
  padding-left: 28px !important;
  padding-right: 28px !important;
  padding-bottom: 20px !important;
}
.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 28px 24px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: rgba(93, 58, 38, 0.35) transparent;
}
.modal-body::-webkit-scrollbar {
  width: 6px;
}
.modal-body::-webkit-scrollbar-track {
  background: transparent;
  margin: 8px 0;
}
.modal-body::-webkit-scrollbar-thumb {
  background: rgba(93, 58, 38, 0.28);
  border-radius: 999px;
}
.modal-body::-webkit-scrollbar-thumb:hover {
  background: rgba(93, 58, 38, 0.45);
}
.modal-body::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}
.modal-foot {
  padding: 16px 28px 24px !important;
  border-top: 1px solid var(--bw-line);
  justify-content: flex-end;
  gap: 10px;
}
#vendor-modal .modal {
  width: min(560px, 100%);
}
#vendor-modal .modal-head {
  padding: 24px 24px 14px !important;
}
#vendor-modal .modal-body {
  padding: 18px 24px 20px;
}
#vendor-modal .modal-foot {
  padding: 14px 24px 20px !important;
}
#vendor-modal .form-grid {
  gap: 14px 16px;
}
#vendor-modal .textarea {
  min-height: 72px;
}
.form-group.is-hidden,
.form-section.is-hidden,
.form-grid.is-hidden,
.form-group[hidden],
.form-section[hidden],
.form-grid[hidden] {
  display: none !important;
}
.form-section {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #f0ebe6;
}
.form-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: 0;
}
.form-section-title {
  margin: 0 0 14px;
  font-size: var(--fs-sm);
  font-weight: 650;
  color: var(--bw-forest);
  letter-spacing: -0.01em;
}
.field-with-action {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.field-with-action .field { flex: 1; min-width: 0; }
.field-with-action .select,
.field-with-action .select-sm {
  flex: 0 0 auto;
  width: 90px;
  min-width: 90px;
}
.field-with-action .bw-select {
  flex: 0 0 88px;
  width: 88px;
  min-width: 88px;
  max-width: 88px;
}

/* Length height/width/thickness + unit */
.dim-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px;
  gap: 10px;
  align-items: stretch;
  width: 100%;
}
.dim-field > .field {
  width: 100%;
  min-width: 0;
}
.dim-field > .bw-select,
.dim-field > .select,
.dim-field > .select-sm {
  width: 84px;
  min-width: 84px;
  max-width: 84px;
}
.dim-field .bw-select-trigger {
  height: 40px;
  padding: 0 8px 0 10px;
  justify-content: space-between;
  font-size: var(--fs-sm);
  font-weight: 500;
}
.dim-grid {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #f0ebe6;
  gap: 14px 16px;
  align-items: start;
}
#product-modal .form-grid {
  gap: 14px 16px;
}
#product-modal .form-group {
  gap: 8px;
  min-width: 0;
}
#product-modal .form-group label {
  line-height: 1.3;
}
#product-modal .pack-section-grid,
#product-modal #pack-section > .form-grid:first-child {
  margin-bottom: 0;
}
#product-modal .field,
#product-modal .bw-select-trigger {
  height: 42px;
}
#product-modal .textarea {
  min-height: 88px;
}
#product-modal .form-section {
  margin-bottom: 22px;
  padding-bottom: 18px;
}
#product-modal .form-section-title {
  margin-bottom: 16px;
}
.field-hint {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--bw-muted);
  line-height: 1.4;
}
.badge-success {
  background: rgba(21, 128, 61, 0.12);
  color: var(--bw-success);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: var(--fs-sm); color: var(--bw-muted); font-weight: 650; }

.table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-gutter: stable;
  /* Soft edge hint that more columns exist */
  background:
    linear-gradient(90deg, #fff 70%, rgba(255,255,255,0)) 0 0 / 28px 100% local,
    linear-gradient(90deg, rgba(255,255,255,0), #fff 30%) 100% 0 / 36px 100% local,
    radial-gradient(farthest-side at 0 50%, rgba(61,38,24,.12), transparent) 0 0 / 14px 100% local,
    radial-gradient(farthest-side at 100% 50%, rgba(61,38,24,.14), transparent) 100% 0 / 16px 100% local;
  background-repeat: no-repeat;
  background-attachment: local, local, scroll, scroll;
}
.table-wrap::-webkit-scrollbar {
  height: 8px;
}
.table-wrap::-webkit-scrollbar-track {
  background: #f3efe9;
}
.table-wrap::-webkit-scrollbar-thumb {
  background: #cbb8a8;
  border-radius: 999px;
}

.list-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 1px solid rgba(61, 38, 24, 0.08);
  background: #faf8f5;
}
.list-pagination-meta {
  font-size: var(--fs-sm);
  color: var(--bw-muted);
  font-weight: 600;
}
.list-pagination-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.list-page-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 76px;
  justify-content: center;
}
.list-page-btn.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}
.list-page-status {
  font-size: var(--fs-sm);
  font-weight: 650;
  color: var(--bw-text);
  min-width: 88px;
  text-align: center;
}
table.data {
  /* Prefer natural column widths; scroll horizontally instead of crushing cells */
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}
table.data.data-payables {
  min-width: 0;
}
table.data.data-payables th:last-child,
table.data.data-payables td:last-child:not(.empty) {
  text-align: right;
}
table.data.data-payables th:nth-child(4),
table.data.data-payables td:nth-child(4) {
  text-align: right;
}
table.data.data-payables .actions {
  justify-content: center;
}

.toast-wrap {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  min-width: 260px;
  max-width: 380px;
  padding: 12px 14px;
  border-radius: 14px;
  color: #fff;
  box-shadow: var(--bw-shadow);
  animation: slideIn .25s ease;
}
.toast.success { background: var(--bw-success); }
.toast.error { background: var(--bw-danger); }
.toast.info { background: var(--bw-info); }
@keyframes slideIn {
  from { transform: translateY(-8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.login-page {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(ellipse 90% 70% at 50% 0%, #ffffff 0%, #f7f8f7 55%, #eef1ef 100%);
}

.login-network {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  opacity: 0.55;
}

.login-network img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0.7;
  filter: grayscale(1);
  animation: networkFloat 28s ease-in-out infinite alternate;
}

.login-shell {
  position: relative;
  z-index: 2;
  width: min(420px, 100%);
  margin: auto;
  animation: loginRise 0.7s ease both;
}

.login-card {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background: #fff;
  border: 1px solid rgba(215, 226, 218, 0.95);
  border-radius: 22px;
  padding: 32px 28px 24px;
  box-shadow:
    0 18px 40px rgba(61, 38, 24, 0.08),
    0 2px 8px rgba(61, 38, 24, 0.04);
}

.login-brand {
  text-align: center;
  margin-bottom: 26px;
  animation: loginFade 0.8s ease 0.1s both;
}

.login-brand img {
  width: 88px;
  height: 88px;
  margin: 0 auto 14px;
  border-radius: 50%;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 10px 24px rgba(61, 38, 24, 0.12);
}

.login-brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.45rem, 5vw, 1.95rem);
  font-weight: 650;
  letter-spacing: -0.04em;
  color: var(--bw-forest);
  line-height: 1.15;
  word-break: break-word;
}

.login-brand p {
  margin: 8px 0 0;
  color: var(--bw-muted);
  font-size: clamp(0.7rem, 2.5vw, var(--fs-sm));
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.login-field {
  margin-bottom: 4px;
}

.login-field label {
  font-size: 0.78rem;
  color: var(--bw-muted);
  font-weight: 650;
  margin-bottom: 6px;
  display: block;
}

.login-field .field {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  border-radius: 12px;
  height: 44px;
  font-size: 16px;
}

.login-remember {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 6px 0 18px;
  color: var(--bw-muted);
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}

.login-remember input {
  accent-color: var(--bw-forest);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.login-submit {
  width: 100%;
  height: 46px;
  border-radius: 12px;
  font-size: var(--fs-md);
  letter-spacing: 0.01em;
}

.login-credit {
  text-align: center;
  margin: 20px 0 0;
  font-size: 0.75rem;
  color: var(--bw-muted);
  line-height: 1.45;
}

.login-credit a {
  color: var(--bw-forest);
  font-weight: 600;
}

.login-credit a:hover {
  text-decoration: underline;
}

@keyframes loginRise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

@keyframes loginFade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes networkFloat {
  from { transform: scale(1) translate3d(0, 0, 0); }
  to { transform: scale(1.04) translate3d(-1.5%, 1%, 0); }
}

@media (max-width: 480px) {
  .login-page {
    padding: max(16px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
    align-items: start;
    padding-top: max(28px, env(safe-area-inset-top));
  }
  .login-shell { width: 100%; }
  .login-card {
    border-radius: 18px;
    padding: 24px 18px 18px;
  }
  .login-brand { margin-bottom: 20px; }
  .login-brand img {
    width: 72px;
    height: 72px;
    border-radius: 50%;
  }
  .login-field .field,
  .login-submit { height: 48px; }
  .password-toggle {
    width: 40px;
    height: 40px;
  }
  .login-network { opacity: 0.4; }
}

@media (min-width: 768px) {
  .login-shell { width: min(440px, 100%); }
  .login-card { padding: 36px 32px 28px; }
}

@media (min-width: 1200px) {
  .login-shell { width: min(460px, 100%); }
}

@media (max-height: 640px) and (orientation: landscape) {
  .login-page {
    place-items: start center;
    padding-top: 16px;
    padding-bottom: 16px;
  }
  .login-brand { margin-bottom: 14px; }
  .login-brand img {
    width: 52px;
    height: 52px;
    margin-bottom: 8px;
  }
  .login-brand h1 { font-size: 1.35rem; }
  .login-card { padding: 18px 20px 14px; }
  .login-credit { margin-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .login-network img { animation: none; }
  .login-shell,
  .login-brand { animation: none; }
}

.form-alert {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--bw-danger);
  font-size: .85rem;
  transition: opacity .25s ease, max-height .25s ease, margin .25s ease, padding .25s ease;
  overflow: hidden;
}
.form-alert.is-hiding,
.field-error.is-hiding {
  opacity: 0;
  max-height: 0;
  margin-top: 0;
  padding-top: 0;
  padding-bottom: 0;
}
.field-invalid {
  border-color: #f87171 !important;
  background: #fffafa;
  transition: border-color .25s ease, background .25s ease;
}
.field-error {
  display: block;
  min-height: 18px;
  margin-top: 4px;
  font-size: .75rem;
  color: var(--bw-danger);
  transition: opacity .25s ease, max-height .25s ease, margin .25s ease;
  overflow: hidden;
}

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.password-wrap .field-with-toggle {
  width: 100%;
  padding-right: 44px;
}
.password-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--bw-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: color .15s ease, background .15s ease;
}
.password-toggle:hover {
  color: var(--bw-forest);
  background: rgba(93, 58, 38, .08);
}
.password-toggle svg {
  width: 18px;
  height: 18px;
}
.password-toggle .icon-eye-closed { display: none; }
.password-toggle.is-visible .icon-eye-open { display: none; }
.password-toggle.is-visible .icon-eye-closed { display: block; }

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 35;
}
.overlay.open { display: block; }

.empty,
table.data td.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--bw-muted);
  white-space: normal;
  position: sticky;
  left: 0;
  min-width: min(100vw, 360px);
  box-sizing: border-box;
}

@media (max-width: 1400px) {
  .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .insight-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .insight-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-105%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .menu-btn { display: inline-grid; place-items: center; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .insight-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-h);
    padding: 10px 12px;
    gap: 8px;
  }
  .topbar-left { flex: 1 1 100%; }
  .topbar-search-form { max-width: none; flex: 1; }
  .topbar-period-wrap {
    margin-right: 0;
    margin-left: 0;
    flex: 1 1 auto;
    justify-content: flex-start;
  }
  .topbar-right { margin-left: auto; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .page-actions { width: 100%; justify-content: flex-end; margin-left: 0; }
  .chart-wrap { height: 220px; }
  .app-network { opacity: 0.32; }
  .panel-head { flex-wrap: wrap; }
  .insight-body {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 14px 16px 16px;
  }
  .insight-pie-wrap {
    height: 168px;
    max-width: 190px;
  }
  .dashboard { gap: 16px; }
  .insight-grid,
  .dashboard-grid,
  .payables-stack { gap: 16px; }

  /* Full-screen scrollable modals on tablet/phone */
  .modal-backdrop,
  .modal-backdrop.open {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
    overflow: hidden;
  }
  .modal,
  .modal-lg,
  .modal-sm,
  #product-modal .modal,
  #sale-modal .modal,
  #vendor-modal .modal,
  #user-modal .modal-user,
  #sync-modal .sync-compare-modal {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .modal-head {
    padding: 16px 16px 12px !important;
  }
  #product-modal .modal-head,
  #vendor-modal .modal-head {
    padding: 16px 16px 12px !important;
  }
  .modal-body,
  #vendor-modal .modal-body {
    padding: 14px 16px 18px;
  }
  .modal-foot,
  #vendor-modal .modal-foot {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)) !important;
    gap: 10px;
    flex-wrap: wrap;
  }
  .modal-foot .btn {
    min-height: 42px;
  }
  .sale-line-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .bw-select-menu {
    max-height: min(240px, 45vh);
  }
  .panel-note { white-space: normal; }
  .topbar-period {
    width: 100%;
    flex-wrap: wrap;
  }
  .topbar-period .bw-select,
  .topbar-period .bw-select-trigger {
    min-width: 0;
    flex: 1 1 140px;
  }
  .topbar-period .custom-dates.is-open {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    gap: 8px;
  }
  .topbar-period .period-date {
    flex: 1 1 120px;
    min-width: 0;
  }
  #user-modal .modal-user {
    max-height: min(92vh, 720px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  #user-modal .modal-user > form {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 100%;
    overflow: hidden;
  }
  #user-modal .modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1 1 auto;
    min-height: 0;
  }
}
@media (max-width: 560px) {
  .content { padding: 14px 12px 24px; }
  .kpi-grid { grid-template-columns: 1fr; gap: 12px; }
  .kpi-card { padding: 14px; }
  .topbar { padding: 10px 10px; }
  .chart-wrap { height: 210px; }
  .chart-panel-body { padding: 4px 12px 14px; }
  .panel-chart .panel-head,
  .insight-head { padding-left: 14px; padding-right: 14px; }
  .insight-body { padding: 12px 12px 14px; }
  .table-wrap {
    margin: 0;
    border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
  }
  table.data th, table.data td { padding: 9px 10px; font-size: var(--fs-sm); }
  table.data th.col-date,
  table.data td.col-date { min-width: 7.25rem; width: 7.25rem; }
  table.data th.col-actions,
  table.data td.actions { min-width: 112px; }
  .panel-note { white-space: normal; }
  .sale-line-fields {
    grid-template-columns: 1fr;
  }
  .cat-card .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .ledger-facts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .topbar,
  .sidebar,
  .content {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  .topbar {
    padding-top: max(10px, env(safe-area-inset-top));
  }
}
@media (min-width: 1100px) {
  .dashboard-grid {
    grid-template-columns: 1.15fr 0.85fr;
    align-items: start;
  }
  .payables-stack { gap: 20px; }
}
@media (min-width: 1600px) {
  .kpi-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .chart-wrap { height: 320px; }
  .content { padding: 20px 28px 36px; }
}

/* Global sync loader — Moblix orbits + saw cutting timber */
.bw-loader {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bw-mist) 42%, rgba(42, 26, 18, 0.38));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.bw-loader.is-on {
  display: flex;
}
body.bw-busy {
  cursor: wait;
}
body.bw-busy .app-shell,
body.bw-busy .login-shell,
body.bw-busy .login-page,
body.bw-busy .toast-wrap {
  pointer-events: none;
  user-select: none;
}
.bw-loader-card {
  display: grid;
  place-items: center;
  animation: bw-busy-pop 0.22s ease;
}
.bw-loader-stage {
  width: 140px;
  height: 140px;
  animation: bw-timber-dash 1.5s ease-in-out infinite;
}
.bw-loader-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}
.bw-orbit,
.bw-orbit-2 {
  fill: none;
  stroke: var(--bw-oak);
  stroke-linecap: round;
}
.bw-orbit {
  stroke-width: 2.6;
  stroke-dasharray: 14 12;
  transform-origin: 70px 70px;
  animation: bw-orbit-spin 1.1s linear infinite;
}
.bw-orbit-2 {
  stroke-width: 1.6;
  stroke-dasharray: 8 16;
  opacity: 0.4;
  transform-origin: 70px 70px;
  animation: bw-orbit-spin 1.7s linear infinite reverse;
}
.bw-plank {
  fill: color-mix(in srgb, #c4895a 55%, var(--bw-oak));
  stroke: var(--bw-forest);
  stroke-width: 2;
  filter: drop-shadow(0 8px 14px color-mix(in srgb, var(--bw-oak) 30%, transparent));
}
.bw-plank-grain {
  fill: none;
  stroke: rgba(62, 38, 24, 0.35);
  stroke-width: 1.4;
  stroke-linecap: round;
}
.bw-cut-line {
  fill: none;
  stroke: var(--bw-forest-deep);
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
  opacity: 0.55;
  animation: bw-cut-glow 0.7s ease-in-out infinite;
}
.bw-saw {
  transform-origin: 70px 60px;
  animation: bw-saw-cut 0.55s ease-in-out infinite;
}
.bw-saw-blade {
  fill: color-mix(in srgb, #e8e0d8 70%, var(--bw-oak-soft));
  stroke: var(--bw-forest);
  stroke-width: 1.6;
}
.bw-saw-teeth {
  fill: none;
  stroke: var(--bw-forest-deep);
  stroke-width: 1.8;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.bw-saw-handle {
  fill: var(--bw-forest);
  stroke: var(--bw-forest-deep);
  stroke-width: 1.4;
}
.bw-saw-grip {
  fill: none;
  stroke: rgba(244, 241, 238, 0.35);
  stroke-width: 1.5;
  stroke-linecap: round;
}
@keyframes bw-orbit-spin {
  to { transform: rotate(360deg); }
}
@keyframes bw-timber-dash {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-8px) rotate(1.5deg); }
}
@keyframes bw-busy-pop {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes bw-saw-cut {
  0%, 100% { transform: translate(0, 0) rotate(-6deg); }
  50% { transform: translate(-10px, 3px) rotate(4deg); }
}
@keyframes bw-cut-glow {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 0.85; }
}

/* Company logo uploader */
.logo-upload-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
.logo-upload-stage {
  border: 1.5px dashed color-mix(in srgb, var(--bw-oak) 50%, var(--bw-line));
  border-radius: 16px;
  background: linear-gradient(180deg, #fff 0%, #faf7f4 100%);
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
  overflow: hidden;
}
.logo-upload.is-dragover .logo-upload-stage {
  border-color: var(--bw-forest);
  background: color-mix(in srgb, var(--bw-oak) 12%, #fff);
  box-shadow: 0 0 0 3px rgba(93, 58, 38, 0.1);
}
.logo-upload.has-file .logo-upload-stage {
  border-style: solid;
  border-color: var(--bw-line);
}
.logo-upload-empty,
.logo-upload-filled {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 16px;
}
.logo-upload-empty[hidden],
.logo-upload-filled[hidden] {
  display: none !important;
}
.logo-upload-empty {
  flex-direction: column;
  text-align: center;
  padding: 28px 20px;
  gap: 12px;
}
.logo-upload-ph {
  width: 88px;
  height: 88px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: color-mix(in srgb, var(--bw-oak) 14%, #fff);
  color: var(--bw-forest);
  border: 1px solid color-mix(in srgb, var(--bw-oak) 22%, transparent);
}
.logo-upload-ph svg { width: 52px; height: 52px; }
.logo-upload-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.logo-upload-copy strong {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 650;
  color: var(--bw-forest-deep);
  letter-spacing: -0.02em;
}
.logo-upload-copy span {
  font-size: var(--fs-xs);
  color: var(--bw-muted);
}
.logo-upload-pick { margin-top: 4px; min-width: 132px; }
.logo-upload-thumb-wrap {
  flex: none;
  width: 84px;
  height: 84px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--bw-line);
  box-shadow: 0 8px 18px rgba(61, 38, 24, 0.08);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.logo-upload-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.logo-upload-filled-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.logo-upload-filled-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.logo-upload-filled-text strong {
  font-size: var(--fs-sm);
  font-weight: 650;
  color: var(--bw-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logo-upload-sub {
  font-size: var(--fs-xs);
  color: var(--bw-muted);
}
.logo-upload-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.logo-upload-tools .btn { min-height: 34px; }
.logo-upload-clear { color: var(--bw-danger); }

/* Logo editor modal */
.logo-editor-backdrop { z-index: 260; }
.logo-editor-modal {
  width: min(480px, 96vw);
  height: auto;
  max-height: min(92vh, 720px);
  max-height: min(92dvh, 720px);
}
.logo-editor-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  overflow: visible !important;
}
.logo-editor-stage {
  position: relative;
  width: min(360px, 100%);
  aspect-ratio: 1;
  border-radius: 18px;
  overflow: hidden;
  background: #f3eee8;
  border: 1px solid var(--bw-line);
  touch-action: none;
  cursor: grab;
}
.logo-editor-stage:active { cursor: grabbing; }
.logo-editor-stage canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.logo-editor-frame {
  pointer-events: none;
  position: absolute;
  inset: 18px;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 0 999px rgba(47, 32, 22, 0.28);
}
.logo-editor-toolbar {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.logo-editor-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.logo-editor-group input[type='range'] {
  width: min(160px, 40vw);
  accent-color: var(--bw-forest);
}
.logo-editor-btn {
  min-width: 40px;
  height: 40px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--bw-line);
  background: #fff;
  color: var(--bw-forest-deep);
  font-weight: 650;
  font-size: 1rem;
  cursor: pointer;
}
.logo-editor-btn:hover {
  background: #faf7f4;
  border-color: color-mix(in srgb, var(--bw-oak) 40%, var(--bw-line));
}
.logo-editor-hint {
  margin: 0;
  font-size: var(--fs-xs);
  color: var(--bw-muted);
  text-align: center;
}

/* Offline desktop in-app update modal */
.desktop-update-modal .desktop-update-lead {
  margin: 0 0 0.5rem;
  font-size: var(--fs-md, 1rem);
}
.desktop-update-changes {
  margin-top: 0.85rem;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  background: var(--surface-2, #f4f4f5);
}
.desktop-update-changes strong {
  display: block;
  margin-bottom: 0.4rem;
  font-size: var(--fs-sm, 0.875rem);
}
.desktop-update-changes ul {
  margin: 0;
  padding-left: 1.15rem;
}
.desktop-update-changes li {
  margin: 0.25rem 0;
  font-size: var(--fs-sm, 0.875rem);
}
.desktop-update-bar {
  height: 10px;
  margin: 0.75rem 0 0.35rem;
  border-radius: 999px;
  background: var(--border, #e4e4e7);
  overflow: hidden;
}
.desktop-update-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--accent, #0f766e);
  transition: width 0.25s ease;
}
#desktop-update-modal .modal-foot {
  justify-content: space-between;
  flex-wrap: wrap;
}
#desktop-update-modal .modal-foot .btn[hidden] {
  display: none !important;
}
.desktop-update-details {
  margin-top: 0.65rem;
  font-size: var(--fs-sm, 0.875rem);
  color: var(--bw-muted, #6b7280);
}
.desktop-update-details summary {
  cursor: pointer;
  user-select: none;
}
.desktop-update-error-detail {
  margin: 0.45rem 0 0;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: #f4f4f5;
  color: #3f3f46;
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
  -webkit-user-select: text;
}
/* Allow selecting/copying text in the offline desktop WebView */
body {
  -webkit-user-select: text;
  user-select: text;
}
input, textarea, .field, .textarea, pre, code, td, th, p, li, span, label, h1, h2, h3 {
  -webkit-user-select: text;
  user-select: text;
}
.desktop-update-banner {
  display: none !important;
}
.cat-manage { display: flex; flex-direction: column; gap: 16px; max-width: 100%; min-width: 0; }
.cat-card {
  max-width: 100%;
  min-width: 0;
}
.cat-card .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  box-sizing: border-box;
}
.cat-card .panel-head .cat-card-title {
  min-width: 0;
  flex: 1 1 auto;
  text-align: left;
}
.cat-card .panel-head h3 {
  margin: 0 0 4px;
  max-width: 100%;
  color: var(--bw-ink);
}
.cat-card .panel-head .actions {
  flex: 0 0 auto;
  width: auto;
  max-width: none;
  margin-left: auto;
  margin-right: 0;
  justify-content: flex-end;
}
/* Compact 3-col subcategory tables — fit card, no horizontal scroll */
.cat-card .table-wrap {
  padding: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: none;
  scrollbar-gutter: auto;
}
.cat-card table.data {
  width: 100%;
  min-width: 0 !important;
  max-width: 100%;
  table-layout: fixed;
}
.cat-card table.data th,
.cat-card table.data td {
  white-space: nowrap;
}
.cat-card table.data th:nth-child(1),
.cat-card table.data td:nth-child(1) {
  width: auto;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cat-card table.data th:nth-child(2),
.cat-card table.data td:nth-child(2) {
  width: 110px;
  min-width: 110px;
}
.cat-card table.data th.col-actions,
.cat-card table.data td.actions {
  position: static;
  width: 96px;
  min-width: 96px;
  max-width: 96px;
  box-shadow: none;
  padding-left: 8px;
  padding-right: 12px;
  background: transparent;
}
.cat-card table.data thead th.col-actions {
  background: #faf7f4;
}
.cat-card table.data tbody tr:hover td.actions {
  background: #fbf9f7;
}
.cat-card table.data th.col-actions {
  /* Full "Actions" label — was clipped to "ACT" */
  overflow: visible;
  text-overflow: clip;
  letter-spacing: 0.02em;
}

.ledger-hero {
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 260px);
  gap: 8px 20px;
  align-items: stretch;
  padding: 18px 20px;
}
.ledger-hero-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}
.ledger-party-identity {
  display: flex;
  align-items: center;
  gap: 14px;
}
.ledger-avatar {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #2f5d3f, #14532d);
  color: #fff;
  font-weight: 700;
  font-size: 1.15rem;
  flex-shrink: 0;
}
.ledger-party-name {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 650;
  color: var(--bw-forest-deep);
  letter-spacing: -0.02em;
}
.ledger-party-meta {
  margin: 0;
  color: var(--bw-muted);
  font-size: var(--fs-sm);
}
.ledger-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 16px;
  padding: 0;
  border: 0;
  margin: 0;
}
.ledger-fact {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.ledger-fact.wide { grid-column: 1 / -1; }
.ledger-fact .k {
  font-size: var(--fs-xs);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--bw-muted);
  font-weight: 650;
}
.ledger-fact .v {
  font-size: var(--fs-sm);
  color: var(--bw-ink);
  overflow-wrap: anywhere;
}
.ledger-hero-chart {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 4px 0;
  border-left: 1px solid var(--bw-line);
  padding-left: 18px;
}
.ledger-chart-wrap {
  position: relative;
  width: 148px;
  height: 148px;
}
.ledger-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}
.ledger-chart-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
  padding: 18px;
}
.ledger-chart-center .k {
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--bw-muted);
  font-weight: 650;
}
.ledger-chart-center strong {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--bw-forest-deep);
  line-height: 1.2;
  margin-top: 2px;
}
.ledger-chart-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  max-width: 168px;
  font-size: var(--fs-xs);
  color: var(--bw-muted);
}
.ledger-chart-legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ledger-chart-legend b {
  margin-left: auto;
  color: var(--bw-ink);
  font-variant-numeric: tabular-nums;
}
.ledger-chart-legend .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ledger-chart-legend .dot.paid { background: #15803d; }
.ledger-chart-legend .dot.unpaid { background: #c2410c; }
.ledger-kpis { margin-bottom: 16px; }

table.data.money-table th.num,
table.data.money-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.badge-type { font-size: 11px; }
.badge-type-sale { background: #e8f4ff; color: #0369a1; }
.badge-type-paid { background: #e8f8ee; color: #15803d; }
.badge-type-partial { background: #fff7ed; color: #c2410c; }
.badge-type-unpaid { background: #fef2f2; color: #b91c1c; }
.badge-type-open { background: #f3ebe4; color: #7c2d12; }
.badge-type-idle { background: #f1f5f3; color: #5b6b61; }

@media (max-width: 900px) {
  .ledger-hero {
    grid-template-columns: 1fr;
  }
  .ledger-hero-chart {
    border-left: 0;
    border-top: 1px solid var(--bw-line);
    padding-left: 0;
    padding-top: 16px;
    flex-direction: row;
    justify-content: flex-start;
    gap: 18px;
  }
  .ledger-chart-legend { max-width: none; }
}
@media (max-width: 560px) {
  .ledger-facts { grid-template-columns: 1fr 1fr; }
  .ledger-hero-chart { flex-direction: column; align-items: center; }
}

.backup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.backup-card .panel-body { padding: 18px 20px 22px; }
.backup-copy {
  margin: 0 0 16px;
  color: var(--bw-muted);
  font-size: var(--fs-sm);
  line-height: 1.5;
}
.backup-folder-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 16px;
}
.backup-folder-label {
  font-size: var(--fs-sm);
  color: var(--bw-muted);
}
.backup-db-path {
  word-break: break-all;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  margin-bottom: 12px;
}
.backup-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.backup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.backup-company-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.backup-sync-card {
  margin-top: 0;
}
.backup-sync-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 14px;
}
.backup-sync-file {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 16px;
  max-width: 420px;
}
.backup-sync-file label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--bw-ink);
}
.backup-sync-file .field-hint {
  margin: 0;
}
.backup-offline-card {
  order: -1;
}
.backup-offline-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.backup-offline-card .backup-offline-actions .btn {
  min-height: 40px;
}
.backup-offline-card code {
  font-size: 0.92em;
}
.backup-company-pick .panel-body {
  padding-top: 14px;
}
.backup-company-form .select {
  width: 100%;
  max-width: 420px;
}
.backup-sync-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1.3;
  border: 1px solid var(--bw-line);
  background: var(--bw-mist);
  color: var(--bw-ink);
}
.backup-sync-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bw-muted);
  flex: 0 0 auto;
}
.backup-sync-status.is-checking {
  color: var(--bw-muted);
}
.backup-sync-status.is-online {
  background: #ecfdf3;
  border-color: #bbf7d0;
  color: #166534;
}
.backup-sync-status.is-online::before {
  background: var(--bw-success);
}
.backup-sync-status.is-offline {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}
.backup-sync-status.is-offline::before {
  background: var(--bw-danger);
}
.backup-sync-status.is-busy {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}
.backup-sync-status.is-busy::before {
  background: var(--bw-info);
}

/* Sync compare modal — fits any desktop window / resolution */
#sync-modal.modal-backdrop,
#sync-modal.modal-backdrop.open {
  padding: clamp(10px, 2.5vh, 24px) clamp(10px, 2vw, 20px);
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#sync-modal .sync-compare-modal {
  width: min(920px, calc(100vw - 20px));
  max-width: 100%;
  height: auto;
  max-height: min(92vh, calc(100dvh - 20px));
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
#sync-modal .modal-head {
  flex: 0 0 auto;
}
#sync-modal .sync-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#sync-modal .sync-modal-foot {
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 10px;
}
#sync-modal .sync-modal-foot .btn {
  min-height: 40px;
}

.sync-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--bw-line);
  background: var(--bw-mist);
  font-size: var(--fs-sm);
  color: var(--bw-ink);
}
.sync-summary strong {
  font-weight: 700;
}
.sync-diff-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.sync-diff-card {
  border: 1px solid var(--bw-line);
  background: #fff;
  padding: 12px 14px;
  min-width: 0;
  overflow: hidden;
}
.sync-diff-card.status-both_changed {
  border-color: #f59e0b;
  background: #fffbeb;
}
.sync-diff-card.status-only_offline {
  border-color: #86efac;
  background: #f0fdf4;
}
.sync-diff-card.status-only_online {
  border-color: #93c5fd;
  background: #eff6ff;
}
.sync-diff-card.status-identical {
  opacity: 0.92;
}
.sync-diff-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 8px;
  min-width: 0;
}
.sync-diff-title strong {
  font-size: var(--fs-md);
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.sync-status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: var(--fs-xs, 0.75rem);
  font-weight: 600;
  background: var(--bw-mist);
  border: 1px solid var(--bw-line);
  color: var(--bw-ink);
  white-space: nowrap;
}
.status-both_changed .sync-status-pill {
  background: #fef3c7;
  border-color: #fcd34d;
  color: #92400e;
}
.status-only_offline .sync-status-pill {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}
.status-only_online .sync-status-pill {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1e40af;
}
.status-identical .sync-status-pill {
  background: #f3f4f6;
  color: #4b5563;
}
.sync-same-note {
  margin: 0 0 6px;
  font-size: var(--fs-sm);
  color: var(--bw-muted);
}
.sync-choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 4px 0 8px;
  font-size: var(--fs-sm);
}
.sync-choice-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.sync-diff-details {
  margin-top: 4px;
  min-width: 0;
}
.sync-diff-details summary {
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--bw-ink);
  margin-bottom: 8px;
}
.sync-fields-empty {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--bw-muted);
}
.sync-fields-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.sync-fields-table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  table-layout: fixed;
}
.sync-fields-table th,
.sync-fields-table td {
  border: 1px solid var(--bw-line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.sync-fields-table th {
  background: var(--bw-mist);
  font-weight: 600;
}
.sync-fields-table tr.is-same td.sync-field-online,
.sync-fields-table tr.is-same td.sync-field-offline {
  color: var(--bw-muted);
}
.sync-fields-table tr.is-diff td.sync-field-online,
.sync-fields-table tr.is-diff td.sync-field-offline {
  background: #fef3c7;
}
.sync-fields-table .sync-field-name {
  width: 22%;
  font-weight: 600;
  color: var(--bw-muted);
}
.sync-fields-table .sync-field-online,
.sync-fields-table .sync-field-offline {
  width: 39%;
}

/* Stack Online/Offline values on narrow windows */
@media (max-width: 720px) {
  #sync-modal.modal-backdrop,
  #sync-modal.modal-backdrop.open {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }
  #sync-modal .sync-compare-modal {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }
  .sync-fields-table {
    min-width: 0;
    display: block;
  }
  .sync-fields-table thead {
    display: none;
  }
  .sync-fields-table tbody,
  .sync-fields-table tr,
  .sync-fields-table td {
    display: block;
    width: 100%;
  }
  .sync-fields-table tr {
    border: 1px solid var(--bw-line);
    margin-bottom: 8px;
    padding: 6px 0;
    background: #fff;
  }
  .sync-fields-table tr.is-diff {
    background: #fffbeb;
  }
  .sync-fields-table td {
    border: 0;
    padding: 4px 10px;
  }
  .sync-fields-table .sync-field-name {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
  }
  .sync-fields-table .sync-field-online::before {
    content: "Online: ";
    font-weight: 600;
    color: var(--bw-muted);
  }
  .sync-fields-table .sync-field-offline::before {
    content: "Offline: ";
    font-weight: 600;
    color: var(--bw-muted);
  }
  .sync-choice-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}

@media (max-width: 900px) {
  .backup-grid { grid-template-columns: 1fr; }
}

/* Account disabled lock (offline desktop) */
.account-lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(28, 18, 12, 0.72);
  backdrop-filter: blur(3px);
}
.account-lock-overlay[hidden] {
  display: none !important;
}
.account-lock-card {
  width: min(420px, 100%);
  background: #fffaf4;
  border: 1px solid rgba(93, 58, 38, 0.18);
  border-radius: 16px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 18px 48px rgba(28, 18, 12, 0.28);
}
.account-lock-card h2 {
  margin: 0 0 10px;
  font-size: 1.35rem;
  color: #5d3a26;
}
.account-lock-card p {
  margin: 0 0 18px;
  color: #6b5344;
  line-height: 1.45;
}
body.account-locked .app-shell {
  pointer-events: none;
  user-select: none;
  filter: grayscale(0.35);
}

