@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --ink: #0b2f3a;
  --muted: #6b7c86;
  --brand: #00b090;
  --navy: #024558;
  --navy-dark: #013847;
  --input: #eef3f7;
  --line: #e2e8ee;
  --bg: #f4f6f8;
  --link: #024558;
  --badge-bg: #e8eefc;
  --badge-text: #3558c7;
  --font: 'Inter', system-ui, sans-serif;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select {
  font: inherit;
}

.brand-tax {
  color: var(--brand);
}

/* —— Shared logo mark —— */
.mark {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: inline-block;
  flex-shrink: 0;
  overflow: hidden;
  line-height: 0;
}

.mark img,
img.mark {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.mark-lg {
  width: 70px;
  height: 70px;
  border-radius: 20px;
}

/* —— Login / auth layout —— */
.auth-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  background-image: radial-gradient(#c9d3da 1px, transparent 1px);
  background-size: 18px 18px;
}

.auth-top {
  padding: 1.25rem 1.75rem 0;
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.auth-brand:hover {
  text-decoration: none;
}

.auth-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem 2rem;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(15, 40, 55, 0.08);
  padding: 2.1rem 2rem 1.75rem;
  border: 1px solid rgba(15, 40, 55, 0.04);
}

.auth-card.wide {
  max-width: 480px;
}

.auth-head {
  text-align: center;
  margin-bottom: 1.4rem;
}

.auth-head .mark {
  margin: 0 auto 0.85rem;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.product {
  font-weight: 700;
  font-size: 1.15rem;
}

.badge {
  display: inline-flex;
  padding: 0.18rem 0.45rem;
  border-radius: 5px;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.auth-head h1 {
  margin: 0 0 0.4rem;
  font-size: 1.85rem;
  letter-spacing: -0.02em;
}

.auth-sub {
  margin: 0 auto;
  max-width: 22rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.field {
  margin-bottom: 0.25rem;
}

.field label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.84rem;
  font-weight: 600;
}

.req {
  color: #d92d20;
}

.input {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 0.75rem;
}

.input:focus-within {
  border-color: #7eb0c2;
  box-shadow: 0 0 0 3px rgba(2, 69, 88, 0.12);
  background: #fff;
}

.input input,
.input select {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.85rem 0;
  outline: none;
  min-width: 0;
  color: var(--ink);
}

.input input::placeholder {
  color: #9aabb6;
}

.ico {
  color: #8a9aa5;
  display: inline-flex;
  width: 1.15rem;
  justify-content: center;
  font-weight: 600;
}

.eye {
  border: none;
  background: transparent;
  color: #8a9aa5;
  cursor: pointer;
  padding: 0.25rem;
  display: inline-flex;
}

.mobile-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 0.6rem;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.35rem 0 1.25rem;
  flex-wrap: wrap;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.86rem;
  color: var(--muted);
  cursor: pointer;
}

.check input {
  width: 15px;
  height: 15px;
  accent-color: var(--navy);
}

.forgot {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--link);
  white-space: nowrap;
}

.btn-primary {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  border: none;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary:hover:not(:disabled) {
  background: var(--navy-dark);
}

.btn-primary:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  background: #fff;
  color: var(--navy);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.hint-box {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
  background: #eef6ff;
  color: #3558c7;
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
  font-size: 0.82rem;
  margin: 0.25rem 0 1rem;
}

.footer-link {
  margin: 1.25rem 0 0;
  text-align: center;
  font-size: 0.88rem;
  color: var(--muted);
}

.footer-link a {
  font-weight: 700;
  color: var(--link);
}

.trust {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.trust span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.alert {
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.alert-error {
  background: #fef3f2;
  color: #b42318;
  border: 1px solid #fecdca;
}

.alert-ok {
  background: #ecfdf3;
  color: #027a48;
  border: 1px solid #a6f4c5;
}

.toast {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 10000;
  max-width: min(360px, calc(100vw - 2rem));
  padding: 0.85rem 1.1rem;
  border-radius: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(2, 69, 88, 0.18);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast-show {
  opacity: 1;
  transform: translateY(0);
}

.toast-ok {
  background: #024558;
  color: #fff;
}

.toast-error {
  background: #b42318;
  color: #fff;
}

.credentials {
  margin-top: 1rem;
  background: #e6f8f4;
  border: 1px dashed var(--brand);
  border-radius: 8px;
  padding: 1rem;
  white-space: pre-wrap;
  font-size: 0.88rem;
  line-height: 1.5;
}

/* —— Welcome page —— */
.welcome-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--bg);
}

.welcome-card {
  width: 100%;
  max-width: 520px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(15, 40, 55, 0.08);
  padding: 2rem;
  text-align: center;
}

.welcome-card h1 {
  margin: 0.75rem 0 0.4rem;
}

.welcome-card p {
  color: var(--muted);
  line-height: 1.5;
}

.welcome-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1.5rem;
}

@media (max-width: 520px) {
  .mobile-row {
    grid-template-columns: 1fr;
  }
}

/* —— App shell (Items-inspired library layout) —— */
.app-body {
  margin: 0;
  background: #f3f5f7;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.2s ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 76px 1fr;
}

.app-sidebar {
  background: #eef1f4;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 1.1rem 0.85rem;
  overflow: hidden;
}

.side-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.app-sidebar .side-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.35rem 0.35rem 0.75rem;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  min-width: 0;
  flex: 1;
}

.app-sidebar .side-brand:hover {
  text-decoration: none;
}

.app-sidebar .side-brand .mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
}

.app-sidebar .brand-text {
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}

.sidebar-toggle svg {
  width: 18px;
  height: 18px;
  display: block;
}

.sidebar-toggle:hover {
  background: #f8fafb;
  border-color: #c5d0d7;
}

.sidebar-toggle .ico-expand,
.sidebar-toggle .ico-close-mobile {
  display: none;
}

.app-shell.sidebar-collapsed .sidebar-toggle .ico-collapse {
  display: none;
}

.app-shell.sidebar-collapsed .sidebar-toggle .ico-expand {
  display: block;
}

.topbar-sidebar-toggle {
  margin-right: 0.25rem;
}

.sidebar-backdrop {
  display: none;
}

.app-sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}

.app-sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  color: #4a5c66;
  font-weight: 500;
  font-size: 0.92rem;
  text-decoration: none;
  white-space: nowrap;
}

.app-sidebar .nav-ico {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.app-sidebar .nav-ico svg {
  width: 18px;
  height: 18px;
  display: block;
}

.app-sidebar .nav-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar .nav-link:hover {
  background: rgba(2, 69, 88, 0.06);
  text-decoration: none;
}

.app-sidebar .nav-link.active {
  background: #dceaf5;
  color: var(--brand);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--navy);
}

.app-sidebar .nav-link.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.app-sidebar .side-foot {
  margin-top: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
  overflow: hidden;
}

/* Collapsed sidebar: icons only */
.app-shell.sidebar-collapsed .app-sidebar {
  padding: 1rem 0.55rem;
  align-items: stretch;
}

.app-shell.sidebar-collapsed .side-top {
  flex-direction: column;
  align-items: center;
}

.app-shell.sidebar-collapsed .side-brand {
  justify-content: center;
  padding: 0.25rem 0 0.5rem;
  flex: 0;
}

.app-shell.sidebar-collapsed .brand-text,
.app-shell.sidebar-collapsed .nav-text,
.app-shell.sidebar-collapsed .side-foot-text {
  display: none;
}

.app-shell.sidebar-collapsed .nav-link {
  justify-content: center;
  padding: 0.75rem 0.5rem;
  gap: 0;
}

.app-shell.sidebar-collapsed .nav-link.active {
  box-shadow: none;
}

.app-shell.sidebar-collapsed .side-foot {
  justify-content: center;
  padding: 0.75rem 0.4rem;
}

.dot-ok {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #12b76a;
  flex-shrink: 0;
}

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

.app-topbar {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.app-topbar .top-search {
  flex: 1;
  max-width: 520px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.55rem 1rem;
}

.app-topbar .top-search input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 0.9rem;
}

.app-topbar .top-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.app-topbar .icon-btn {
  border: none;
  background: transparent;
  color: #5b6f6e;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.35rem;
}

.app-profile {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
  border-radius: 10px;
  padding: 0.2rem 0.35rem;
  cursor: pointer;
}

.app-profile:hover {
  background: #f0f4f7;
  text-decoration: none;
}

.app-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.app-profile .meta strong {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.app-profile .meta span {
  font-size: 0.75rem;
  color: var(--muted);
}

.app-content {
  padding: 1.35rem 1.6rem 2rem;
  min-width: 0;
  max-width: 100%;
  overflow-x: clip;
}

.crumbs {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
}

.crumbs a {
  color: var(--muted);
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.page-head h1 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.page-head .desc {
  margin: 0;
  color: var(--muted);
  max-width: 36rem;
  line-height: 1.45;
  font-size: 0.92rem;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  text-decoration: none;
}

.btn-outline:hover {
  background: #f8fafb;
  text-decoration: none;
}

.btn-outline:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-navy {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: none;
  background: var(--navy);
  color: #fff;
  border-radius: 8px;
  padding: 0.55rem 0.95rem;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  text-decoration: none;
}

.btn-navy:hover {
  background: var(--navy-dark);
  text-decoration: none;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.stat-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.buyers-kpi-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.invoices-kpi-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.users-kpi-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

@media (max-width: 1100px) {
  .buyers-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .invoices-kpi-grid,
  .users-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .buyers-kpi-grid,
  .invoices-kpi-grid,
  .users-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
  }

  .buyers-kpi-grid .stat-card,
  .invoices-kpi-grid .stat-card,
  .users-kpi-grid .stat-card {
    padding: 0.85rem 0.9rem;
  }

  .buyers-kpi-grid .stat-card .value,
  .invoices-kpi-grid .stat-card .value,
  .users-kpi-grid .stat-card .value {
    font-size: 1.45rem;
  }
}

.summary-toolbar-controls {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  flex-wrap: nowrap;
  min-width: 0;
}

.summary-toolbar-controls input[type='search'] {
  flex: 1 1 auto;
  min-width: 140px;
}

.summary-toolbar-controls .summary-page-size {
  flex: 0 0 auto;
  white-space: nowrap;
}

.stat-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.15rem 1.25rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 6px 18px rgba(15, 40, 55, 0.04);
}

.stat-card .label {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 0.35rem;
}

.stat-card .value {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-card .sub {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: #027a48;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.stat-card .sub.muted {
  color: var(--muted);
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #e8f1fb;
  color: #2f6fed;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.library-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(15, 40, 55, 0.04);
  overflow: hidden;
}

.library-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.library-toolbar .left,
.library-toolbar .right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.library-toolbar select,
.library-toolbar input[type='search'] {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  background: #fff;
  outline: none;
}

.library-toolbar input[type='search'] {
  min-width: 200px;
  width: min(260px, 100%);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.data-table,
.library-panel table {
  width: 100%;
}

.buyers-table-wrap {
  overflow-x: auto;
  max-width: 100%;
}

.buyers-library {
  width: max-content;
  min-width: 100%;
}

.buyers-library th,
.buyers-library td {
  white-space: nowrap;
}

.buyers-library th:last-child,
.buyers-library td:last-child {
  position: sticky;
  right: 0;
  background: #fff;
  z-index: 1;
  box-shadow: -6px 0 8px -6px rgba(15, 40, 55, 0.12);
  min-width: 7.5rem;
}

.buyers-library thead th:last-child {
  background: var(--navy);
  z-index: 2;
  box-shadow: none;
}

.buyers-library tr:hover td:last-child {
  background: #f8fbfd;
}

table.library {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.library th {
  background: var(--navy);
  color: #fff;
  text-align: left;
  padding: 0.85rem 1rem;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
  white-space: nowrap;
}

table.library td {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

table.library tr:last-child td {
  border-bottom: none;
}

table.library tr:hover td {
  background: #f8fbfd;
}

table.library .name-cell {
  font-weight: 700;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #e8f1fb;
  color: #2f6fed;
}

.pill-ok {
  background: #ecfdf3;
  color: #027a48;
}

.pill-warn {
  background: #fffaeb;
  color: #b54708;
}

.chip {
  display: inline-flex;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  border: 1px solid #b7d4f5;
  color: #2f6fed;
  font-size: 0.8rem;
  font-weight: 600;
  background: #f5f9ff;
}

.library-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.pager {
  display: flex;
  gap: 0.35rem;
}

.pager button {
  min-width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
}

.pager button.active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

.pager button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.row-actions-inline {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  white-space: nowrap;
  min-width: max-content;
  gap: 0.4rem;
  align-items: center;
}

/* Keep View / Edit / Delete on one horizontal line in sticky Actions col */
.buyers-library td:last-child .row-actions,
.buyers-library td:last-child .row-actions-inline {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  min-width: max-content;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  flex-shrink: 0;
}

.btn-icon svg {
  width: 15px;
  height: 15px;
  display: block;
}

.btn-icon:hover {
  background: #f8fafb;
  text-decoration: none;
}

.btn-icon-view {
  border-color: #c5d0d7;
  color: #345;
}

.btn-icon-view:hover {
  background: #f3f6f8;
}

.btn-icon-download {
  border-color: #c5d0d7;
  color: #345;
}

.btn-icon-download:hover {
  background: #f3f6f8;
}

.btn-icon-download:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-icon-edit {
  border-color: #9eb8c4;
  background: var(--navy);
  color: #fff;
}

.btn-icon-edit:hover {
  background: var(--navy-dark);
  border-color: var(--navy-dark);
}

.btn-icon-danger {
  border-color: #fecdca;
  background: #fef3f2;
  color: #b42318;
}

.btn-icon-danger:hover {
  background: #fee4e2;
}

.btn-icon-danger:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid #fecdca;
  background: #fef3f2;
  color: #b42318;
  border-radius: 8px;
  padding: 0.55rem 0.95rem;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
}

.btn-danger:hover {
  background: #fee4e2;
}

.btn-success {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid #a6f4c5;
  background: #ecfdf3;
  color: #027a48;
  border-radius: 8px;
  padding: 0.55rem 0.95rem;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
}

.btn-success:hover {
  background: #d1fadf;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 47, 58, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
  padding: 1.35rem 1.4rem 1.2rem;
}

.modal-card h3 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
}

.modal-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.92rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 1.25rem;
}

.import-hint {
  margin-top: 0.65rem;
  padding: 0.85rem 0.95rem;
  border-radius: 10px;
  background: #eef6fb;
  border: 1px solid #d0e6f2;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.45;
}

.import-hint p {
  color: inherit;
}

.import-errors {
  margin-top: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  background: #fef3f2;
  border: 1px solid #fecdca;
  color: #b42318;
  font-size: 0.86rem;
  max-height: 160px;
  overflow: auto;
}

.import-errors ul {
  margin: 0;
  padding-left: 1.1rem;
}

.empty-row {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1rem !important;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.status-note {
  margin: 0 0 0.35rem;
  padding: 0.75rem 1rem;
  background: #f0f9f6;
  border: 1px solid #c6ebe0;
  border-radius: 10px;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.45;
}

.form-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(15, 40, 55, 0.04);
  padding: 1.25rem 1.35rem 1.35rem;
}

.company-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem 1.15rem;
}

.company-form-grid .span-2 {
  grid-column: 1 / -1;
}

.input-textarea {
  align-items: flex-start;
  padding-top: 0.55rem;
  padding-bottom: 0.55rem;
}

.input-textarea textarea {
  flex: 1;
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  resize: vertical;
  min-height: 4.5rem;
  font: inherit;
  color: var(--ink);
  line-height: 1.45;
}

.form-footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 1.15rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
}

.form-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}

.form-section-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.field-hint-inline {
  font-weight: 500;
  color: #2f6fed;
  font-size: 0.78rem;
  text-transform: none;
  letter-spacing: 0;
}

.address-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.35rem;
}

.field-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.status-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-left: 0.75rem;
}

.status-tab {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.status-tab.active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

.invoice-detail-page {
  min-width: 0;
  max-width: 100%;
}

.invoice-detail-page .form-panel {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.invoice-detail-page .company-form-grid {
  min-width: 0;
  width: 100%;
}

.invoice-detail-page .company-form-grid .field {
  min-width: 0;
  max-width: 100%;
}

.invoice-detail-page .field .input {
  min-width: 0;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
}

.invoice-detail-page .field .input input,
.invoice-detail-page .field .input select {
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

.invoice-items-panel {
  overflow: hidden;
}

.invoice-items-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

table.invoice-items {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  table-layout: auto;
}

table.invoice-items th {
  text-align: left;
  padding: 0.55rem 0.45rem;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

table.invoice-items td {
  padding: 0.45rem;
  vertical-align: middle;
  white-space: nowrap;
}

table.invoice-items select,
table.invoice-items input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.5rem;
  min-width: 88px;
  background: #fff;
  font: inherit;
}

table.invoice-items select.inv-item {
  min-width: 180px;
}

table.invoice-items .inv-readonly {
  color: var(--ink);
  font-weight: 600;
  padding: 0.45rem 0.55rem;
  background: #f8fafb;
  border-radius: 8px;
  border: 1px solid #e8eef2;
  min-width: 90px;
}

.invoice-summary-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1rem;
  align-items: start;
}

.invoice-totals {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.tot-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

.tot-row:last-child {
  border-bottom: none;
}

.tot-grand {
  background: #e8f4f8;
  font-size: 1rem;
}

@media (max-width: 960px) {
  .invoice-summary-grid {
    grid-template-columns: 1fr;
  }
}

.lookup-row {
  display: flex;
  gap: 0.55rem;
  align-items: stretch;
}

.lookup-row .input {
  flex: 1;
  min-width: 0;
}

.uom-box {
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafb;
  padding: 0.65rem 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.uom-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.muted-hint {
  color: var(--muted);
  font-size: 0.86rem;
}

.serial-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84rem;
  background: #f3f6f8;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}

.hs-lookup-backdrop {
  z-index: 1100;
  align-items: stretch;
  justify-content: center;
  padding: 1.25rem;
}

.hs-lookup-modal {
  width: min(1100px, 100%);
  max-height: calc(100vh - 2.5rem);
  margin: auto;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hs-lookup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.15rem;
  background: var(--navy);
  color: #fff;
}

.hs-lookup-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.hs-lookup-close {
  border: none;
  background: transparent;
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}

.hs-lookup-close:hover {
  background: rgba(255, 255, 255, 0.12);
}

.hs-lookup-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.hs-lookup-hint {
  color: var(--muted);
  font-size: 0.86rem;
}

.hs-lookup-toolbar input[type='search'] {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  min-width: min(280px, 100%);
  outline: none;
}

.hs-lookup-table-wrap {
  flex: 1;
  overflow: auto;
  min-height: 220px;
}

.hs-lookup-table-wrap .hs-desc {
  max-width: 420px;
  font-size: 0.82rem;
  color: #334;
  line-height: 1.35;
}

.hs-lookup-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.85rem;
}

.btn-select-hs {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.detail-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(15, 40, 55, 0.04);
  overflow: hidden;
}

.detail-card h2 {
  margin: 0;
  padding: 0.95rem 1.15rem;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--line);
  background: #f8fafb;
}

.detail-card .body {
  padding: 1rem 1.15rem 1.2rem;
}

.kv {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.55rem 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid #eef2f5;
  font-size: 0.9rem;
}

.kv:last-child {
  border-bottom: none;
}

.kv .k {
  color: var(--muted);
  font-weight: 500;
}

.kv .v {
  font-weight: 600;
  word-break: break-word;
}

.summary-filter-panel .summary-filter-grid {
  margin-bottom: 0.85rem;
}

.summary-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.preset-chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.preset-chip:hover {
  background: #f5f8fa;
}

.preset-chip.active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

.summary-tabs-bar {
  align-items: center;
  gap: 0.75rem;
}

.summary-status-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.status-tab {
  border: 1px solid var(--line);
  background: #f5f7f9;
  color: var(--ink);
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.status-tab:hover {
  background: #eef2f5;
}

.status-tab.active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

.dash-page {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.dash-kpi-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.dash-kpi-grid .stat-card {
  min-width: 0;
}

.dash-kpi-grid .stat-card .value {
  word-break: break-word;
}

.dash-main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(260px, 0.85fr);
  gap: 1rem;
  align-items: start;
  width: 100%;
}

.dash-side-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.dash-chart-panel,
.dash-quick-panel,
.dash-month-panel {
  min-width: 0;
  width: 100%;
}

.dash-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.dash-panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--navy);
}

.dash-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 0.9rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.dash-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.dash-legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dash-legend .leg-sales {
  background: #024558;
}

.dash-legend .leg-tax {
  background: #027a48;
}

.dash-chart-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.dash-chart-wrap {
  position: relative;
  height: 320px;
  width: 100%;
  min-width: 0;
}

.dash-quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.dash-quick-btn {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.75rem 0.75rem;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.86rem;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.dash-quick-btn:hover {
  background: #f3f7f9;
  border-color: #c5d0d7;
  text-decoration: none;
}

.dash-quick-btn .dq-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #e8f1fb;
  color: var(--navy);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.dash-month-stats {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.dash-month-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  font-size: 0.9rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--line);
}

.dash-month-row span {
  color: var(--muted);
  flex-shrink: 0;
}

.dash-month-row strong {
  color: var(--ink);
  text-align: right;
  word-break: break-word;
}

.dash-recent-panel {
  width: 100%;
  margin-top: 1rem;
  max-width: 100%;
}

.dash-recent-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.dash-recent-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
}

.dash-recent-table th,
.dash-recent-table td {
  padding: 0.7rem 0.85rem;
  font-size: 0.88rem;
  white-space: nowrap;
}

.dash-recent-table .pill {
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .dash-main-grid {
    grid-template-columns: 1fr;
  }

  .dash-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dash-side-col {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 1rem;
    align-items: start;
  }
}

/* —— Tablet & phone: drawer nav + fluid content —— */
@media (max-width: 960px) {
  body.nav-open {
    overflow: hidden;
  }

  .app-shell,
  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 190;
    background: rgba(11, 47, 58, 0.42);
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
  }

  .sidebar-backdrop[hidden] {
    display: none !important;
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 86vw);
    z-index: 200;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 28px rgba(15, 40, 55, 0.18);
    padding: 1rem 0.9rem;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .app-shell.sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  /* Drawer always shows full labels (ignore desktop collapsed mode) */
  .app-shell.sidebar-collapsed .app-sidebar {
    display: flex;
    padding: 1rem 0.9rem;
    align-items: stretch;
  }

  .app-shell.sidebar-collapsed .side-top {
    flex-direction: row;
    align-items: flex-start;
  }

  .app-shell.sidebar-collapsed .side-brand {
    justify-content: flex-start;
    padding: 0.35rem 0.35rem 0.75rem;
    flex: 1;
  }

  .app-shell.sidebar-collapsed .brand-text,
  .app-shell.sidebar-collapsed .nav-text,
  .app-shell.sidebar-collapsed .side-foot-text {
    display: inline;
  }

  .app-shell.sidebar-collapsed .nav-link {
    justify-content: flex-start;
    padding: 0.7rem 0.8rem;
    gap: 0.65rem;
  }

  .app-shell.sidebar-collapsed .nav-link.active {
    box-shadow: inset 3px 0 0 var(--navy);
  }

  .app-shell.sidebar-collapsed .side-foot {
    justify-content: flex-start;
    padding: 0.75rem 0.85rem;
  }

  .app-sidebar nav {
    flex-direction: column;
    flex-wrap: nowrap;
  }

  .sidebar-toggle .ico-collapse,
  .sidebar-toggle .ico-expand {
    display: none !important;
  }

  .app-sidebar .sidebar-toggle .ico-close-mobile {
    display: block;
  }

  .app-topbar {
    padding: 0.65rem 0.9rem;
    position: sticky;
    top: 0;
    z-index: 50;
  }

  .app-profile .meta {
    display: none;
  }

  .app-content {
    padding: 1rem 0.9rem 1.75rem;
  }

  .page-head {
    flex-direction: column;
    align-items: stretch;
  }

  .page-head h1 {
    font-size: 1.4rem;
  }

  .page-actions {
    width: 100%;
  }

  .page-actions .btn-outline,
  .page-actions .btn-navy {
    flex: 1 1 auto;
    justify-content: center;
  }

  /* Invoice detail: keep top Back button compact */
  .page-actions.invoice-top-actions {
    width: auto;
    align-self: flex-start;
  }

  .page-actions.invoice-top-actions .btn-outline,
  .page-actions.invoice-top-actions .btn-navy {
    flex: 0 0 auto;
    width: auto;
    padding: 0.45rem 0.75rem;
    font-size: 0.86rem;
  }

  .stat-grid:not(.dash-kpi-grid):not(.buyers-kpi-grid):not(.invoices-kpi-grid):not(.users-kpi-grid),
  .stat-grid-3:not(.users-kpi-grid),
  .detail-grid,
  .company-form-grid:not(.summary-filter-grid),
  .invoice-summary-grid {
    grid-template-columns: 1fr;
  }

  .users-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Summary filters: Company full width; From + To side by side */
  .summary-filter-panel .summary-filter-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  .summary-filter-panel .summary-filter-company,
  .summary-filter-panel .summary-filter-actions {
    grid-column: 1 / -1;
  }

  /* Summary table toolbar: tabs on top; search + page size on one row */
  .summary-tabs-bar.library-toolbar {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .summary-tabs-bar .left,
  .summary-tabs-bar .right {
    width: 100%;
  }

  .summary-tabs-bar .right.summary-toolbar-controls {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: stretch;
    gap: 0.65rem;
  }

  .summary-tabs-bar .right input[type='search'] {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
  }

  .summary-tabs-bar .summary-page-size {
    flex: 0 0 auto;
  }

  /* Buyers / shared wide tables: Actions column scrolls with table on tablet+phone */
  .buyers-library th:last-child,
  .buyers-library td:last-child {
    position: static;
    box-shadow: none;
    min-width: 7.5rem;
  }

  .buyers-library thead th:last-child {
    background: var(--navy);
    box-shadow: none;
  }

  .buyers-library tr:hover td:last-child {
    background: inherit;
  }

  .kv {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  /* Tablet: keep Show/entries + search on one row (HS Codes & list pages) */
  .library-toolbar {
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.75rem;
  }

  .library-toolbar .left {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
  }

  .library-toolbar .right {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    justify-content: flex-end;
  }

  .library-toolbar select {
    width: auto;
    min-width: 4.5rem;
    flex: 0 0 auto;
  }

  .library-toolbar input[type='search'] {
    min-width: 0;
    width: 100%;
    flex: 1 1 auto;
  }

  .form-footer-actions {
    flex-wrap: wrap;
  }

  .form-footer-actions .btn-outline,
  .form-footer-actions .btn-navy {
    flex: 1 1 auto;
    justify-content: center;
  }

  .lookup-row {
    flex-direction: column;
  }

  .hs-lookup-backdrop {
    padding: 0.5rem;
  }

  .hs-lookup-modal {
    max-height: calc(100vh - 1rem);
    border-radius: 12px;
  }

  .hs-lookup-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .dash-page-actions {
    width: 100%;
  }

  .dash-page-actions .btn-outline,
  .dash-page-actions .btn-navy {
    flex: 1 1 calc(50% - 0.35rem);
    justify-content: center;
    text-align: center;
  }

  .dash-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dash-side-col {
    grid-template-columns: 1fr 1fr;
  }

  .dash-quick-grid {
    grid-template-columns: 1fr 1fr;
  }

  .dash-chart-wrap {
    height: 280px;
  }

  .toast {
    top: auto;
    bottom: 1rem;
    right: 0.75rem;
    left: 0.75rem;
    max-width: none;
  }

  table.invoice-items select.inv-item {
    min-width: 150px;
  }

  table.invoice-items select.inv-sro,
  table.invoice-items input.inv-sro {
    min-width: 160px;
  }

  .invoice-detail-page .form-section-head {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.45rem 0.75rem;
  }

  .invoice-detail-page .form-section-head .muted-hint,
  .invoice-detail-page .form-section-head .pill {
    flex: 1 1 100%;
  }

  .invoice-detail-page .form-footer-actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
  }

  .invoice-detail-page .form-footer-actions .btn-outline,
  .invoice-detail-page .form-footer-actions .btn-navy,
  .invoice-detail-page .form-footer-actions a {
    flex: 1 1 calc(50% - 0.3rem);
    width: auto;
    min-width: 0;
    justify-content: center;
    text-align: center;
    box-sizing: border-box;
  }

  .auth-card {
    padding: 1.5rem 1.15rem 1.35rem;
  }

  .auth-top {
    padding: 1rem 1rem 0;
  }
}

@media (max-width: 640px) {
  .library-toolbar:not(.summary-tabs-bar) {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: wrap;
  }

  .library-toolbar:not(.summary-tabs-bar) .left,
  .library-toolbar:not(.summary-tabs-bar) .right {
    width: 100%;
    flex-wrap: wrap;
  }

  .library-toolbar:not(.summary-tabs-bar) input[type='search'],
  .library-toolbar:not(.summary-tabs-bar) select {
    min-width: 0;
    width: 100%;
    flex: 1 1 100%;
  }

  .summary-tabs-bar .right.summary-toolbar-controls {
    flex-wrap: nowrap;
  }

  .summary-tabs-bar .right input[type='search'] {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
  }

  .app-content {
    padding: 0.85rem 0.7rem 1.5rem;
  }

  .page-head h1 {
    font-size: 1.25rem;
  }

  .page-head .desc {
    font-size: 0.86rem;
  }

  .crumbs {
    font-size: 0.75rem;
    overflow-wrap: anywhere;
  }

  .dash-page-head h1 {
    font-size: 1.2rem;
  }

  .dash-page-actions {
    flex-direction: column;
  }

  .dash-page-actions .btn-outline,
  .dash-page-actions .btn-navy {
    flex: 1 1 auto;
    width: 100%;
  }

  .dash-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
  }

  .dash-kpi-grid .stat-card {
    padding: 0.8rem 0.75rem;
    flex-direction: column;
    gap: 0.55rem;
  }

  .dash-kpi-grid .stat-card .value {
    font-size: 1.05rem !important;
  }

  .dash-kpi-grid .stat-card .label {
    font-size: 0.65rem;
  }

  .dash-kpi-grid .stat-card .sub {
    font-size: 0.72rem;
  }

  .dash-kpi-grid .stat-icon {
    width: 34px;
    height: 34px;
    font-size: 0.95rem;
    align-self: flex-end;
  }

  .dash-side-col {
    grid-template-columns: 1fr;
  }

  .dash-panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .dash-chart-wrap {
    height: 240px;
    min-width: 520px;
  }

  .dash-quick-btn {
    font-size: 0.8rem;
    padding: 0.65rem 0.55rem;
  }

  .dash-month-row {
    font-size: 0.86rem;
  }

  .dash-recent-table th,
  .dash-recent-table td {
    font-size: 0.82rem;
    padding: 0.6rem 0.7rem;
  }

  .stat-card .value {
    font-size: 1.45rem;
  }

  .stat-card {
    padding: 0.95rem 1rem;
  }

  .btn-outline,
  .btn-navy,
  .btn-secondary {
    padding: 0.55rem 0.75rem;
    font-size: 0.84rem;
  }

  #logoutBtn {
    padding: 0.45rem 0.65rem;
    font-size: 0.8rem;
  }

  .form-panel {
    padding: 0.9rem;
  }

  .company-form-grid .span-2 {
    grid-column: auto;
  }

  .status-tabs,
  .summary-status-tabs,
  .summary-presets {
    width: 100%;
  }

  .status-tab,
  .preset-chip {
    flex: 1 1 auto;
    text-align: center;
    justify-content: center;
  }

  .app-avatar {
    width: 32px;
    height: 32px;
  }

  /* Invoice detail: keep form + items table inside the viewport */
  .invoice-detail-page {
    overflow-x: clip;
  }

  .invoice-general-panel,
  .invoice-items-panel,
  .invoice-summary-panel {
    overflow-x: clip;
  }

  .invoice-detail-page .company-form-grid {
    grid-template-columns: 1fr;
    gap: 0.7rem;
  }

  .invoice-detail-page .field .input {
    padding: 0 0.65rem;
  }

  .invoice-detail-page .field .input input,
  .invoice-detail-page .field .input select {
    padding: 0.75rem 0;
    font-size: 0.9rem;
    text-overflow: ellipsis;
  }

  .invoice-detail-page .field .input .pill {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .invoice-items-panel #addLineBtn {
    width: 100%;
    box-sizing: border-box;
  }

  .invoice-items-wrap {
    margin: 0 -0.15rem;
    border-radius: 8px;
  }

  .invoice-items-wrap::after {
    content: 'Swipe sideways to see all columns';
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    padding: 0.4rem 0.65rem 0.55rem;
    background: #f8fafb;
    border-top: 1px solid var(--line);
    position: sticky;
    left: 0;
  }

  table.invoice-items {
    font-size: 0.8rem;
  }

  table.invoice-items th {
    font-size: 0.68rem;
    padding: 0.5rem 0.4rem;
  }

  table.invoice-items td {
    padding: 0.4rem;
  }

  table.invoice-items select,
  table.invoice-items input {
    min-width: 96px;
    font-size: 0.8rem;
    padding: 0.4rem 0.45rem;
  }

  table.invoice-items select.inv-item {
    min-width: 160px;
  }

  table.invoice-items select.inv-sro,
  table.invoice-items input.inv-sro {
    min-width: 140px;
  }

  .invoice-summary-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .invoice-detail-page .form-footer-actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .invoice-detail-page .form-footer-actions .btn-outline,
  .invoice-detail-page .form-footer-actions .btn-navy,
  .invoice-detail-page .form-footer-actions a {
    flex: 1 1 calc(50% - 0.25rem);
    min-width: 0;
    font-size: 0.86rem;
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }

  .tot-row {
    font-size: 0.86rem;
    padding: 0.55rem 0.75rem;
  }

  .welcome-card {
    padding: 1.35rem 1.1rem;
  }

  .trust {
    gap: 0.75rem;
    font-size: 0.74rem;
  }
}

@media (max-width: 400px) {
  .app-topbar .top-right {
    gap: 0.4rem;
  }

  #logoutBtn {
    padding: 0.4rem 0.5rem;
  }
}

