:root {
  --it9-red: #ff4438;
  --it9-red-dark: #d9322b;
  --it9-navy: #000d3e;
  --it9-blue: #045cb4;
  --ink: #202226;
  --muted: #667085;
  --line: #e6e8ed;
  --paper: #ffffff;
  --soft: #f6f7f9;
  --ok: #13795b;
  --warn: #a15c07;
  --info: #22577a;
  --shadow: 0 18px 50px rgba(18, 25, 38, .12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: #eef1f5;
  font-family: Arial, Helvetica, Verdana, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(255, 68, 56, .20), transparent 32%),
    linear-gradient(315deg, rgba(4, 92, 180, .32), transparent 38%),
    var(--it9-navy);
}

.login-shell {
  width: min(820px, 100%);
  min-height: 430px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  overflow: hidden;
  background: var(--paper);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .36);
}

.brand-panel {
  display: grid;
  align-content: center;
  gap: 28px;
  padding: 34px;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(255, 68, 56, .18), transparent 50%),
    linear-gradient(315deg, rgba(4, 92, 180, .42), transparent 56%),
    var(--it9-navy);
  border-right: 1px solid rgba(255, 255, 255, .12);
}

.product-logo {
  width: 64px;
  height: 64px;
  display: block;
  object-fit: cover;
  object-position: left center;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(18, 25, 38, .12);
}

.product-heading {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo,
.app-brand img {
  width: 100px;
  height: auto;
  padding: 0;
  border-radius: 4px;
  background: transparent;
}

.brand-panel h1,
.login-form h2,
.topbar h2,
.token-dialog h3 {
  margin: 4px 0 0;
  font-weight: 400;
  letter-spacing: 0;
}

.brand-panel h1 {
  max-width: 320px;
  font-size: clamp(1.9rem, 4vw, 2.65rem);
  line-height: 1.05;
}

.brand-copy p:not(.eyebrow) {
  max-width: 360px;
  margin: 14px 0 0;
  color: rgba(255, 255, 255, .78);
  font-size: 1rem;
  line-height: 1.55;
}

.brand-byline {
  display: flex;
  align-items: center;
  gap: 12px;
  color: rgba(255, 255, 255, .72);
  font-size: .82rem;
  font-weight: 700;
}

.brand-byline .brand-logo {
  width: 82px;
  padding: 0;
}

.eyebrow {
  margin: 0;
  color: var(--it9-red);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.login-form {
  display: grid;
  align-content: center;
  gap: 18px;
  padding: 34px;
}

.login-form-header {
  margin-bottom: 4px;
}

.login-form h2 {
  font-size: 1.55rem;
  font-weight: 700;
}

.login-links {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
  font-size: .86rem;
  font-weight: 700;
}

.login-links a {
  color: var(--it9-red-dark);
  text-decoration: none;
}

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

.login-error {
  min-height: 20px;
  margin: -6px 0 0;
  color: #9d251f;
  font-size: .86rem;
  font-weight: 700;
}

#loginError {
  color: #9d251f !important;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cfd5df;
  border-radius: 6px;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid rgba(255, 68, 56, .4);
  outline-offset: 2px;
}

.policy-page {
  min-height: 100vh;
  background: #eef1f5;
}

.policy-shell {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 56px;
}

.policy-header,
.policy-section,
.policy-footer {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.policy-header {
  position: relative;
  margin-bottom: 14px;
  padding: 30px 150px 30px 30px;
}

.policy-brand {
  position: absolute;
  top: 30px;
  right: 30px;
  display: inline-flex;
}

.policy-brand img {
  width: 92px;
  height: auto;
}

.policy-product-title {
  max-width: 680px;
  margin: 0 0 8px;
  color: var(--it9-navy);
  font-size: .98rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0;
  white-space: nowrap;
}

.policy-product-subtitle {
  font-size: .9em;
  font-weight: 700;
}

.policy-page-title {
  max-width: 680px;
  margin: 0 0 16px;
  color: var(--it9-navy);
  font-size: clamp(2.25rem, 5vw, 3.35rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.policy-header p,
.policy-section p,
.policy-section li,
.policy-footer p {
  color: #3f4652;
  line-height: 1.65;
}

.policy-updated {
  margin-bottom: 0;
  font-size: .9rem;
  font-weight: 700;
}

.policy-section {
  margin-top: 10px;
  padding: 24px 30px;
}

.policy-section h2 {
  margin: 0 0 12px;
  color: var(--it9-navy);
  font-size: 1.18rem;
  letter-spacing: 0;
}

.policy-section p {
  margin: 0 0 12px;
}

.policy-section p:last-child {
  margin-bottom: 0;
}

.policy-section ul {
  margin: 0 0 12px;
  padding-left: 22px;
}

.policy-section a {
  color: var(--it9-red-dark);
  font-weight: 700;
}

.policy-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  margin-top: 14px;
  padding: 20px 30px;
}

.policy-footer p {
  margin: 0;
  font-size: .9rem;
}

.policy-footer .ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 150px;
  padding: 9px 14px;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.primary-btn,
.ghost-btn,
.nav-item,
.icon-btn {
  min-height: 42px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-btn {
  color: #fff;
  background: var(--it9-red);
  border-color: var(--it9-red);
}

.primary-btn:hover {
  background: var(--it9-red-dark);
}

.ghost-btn,
.icon-btn {
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.ghost-btn:hover,
.icon-btn:hover {
  border-color: #b8c0cc;
}

.app-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 26px;
  padding: 24px 18px;
  background:
    linear-gradient(180deg, rgba(4, 92, 180, .18), transparent 46%),
    var(--it9-navy);
  overflow: hidden;
}

.app-brand {
  width: fit-content;
}

nav {
  display: grid;
  align-content: start;
  gap: 8px;
}

.nav-item {
  width: 100%;
  padding: 10px 12px;
  color: #d9dde5;
  text-align: left;
  background: transparent;
  border-color: transparent;
}

.nav-item:hover,
.nav-item.active {
  color: #fff;
  background: rgba(255, 255, 255, .08);
}

.nav-item.active {
  border-left: 3px solid var(--it9-red);
}

.sidebar-footer {
  display: grid;
  gap: 10px;
  color: #d9dde5;
  font-size: .86rem;
  overflow-wrap: anywhere;
}

.workspace {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 18px;
}

.topbar h2 {
  font-size: clamp(1.6rem, 3vw, 2.4rem);
}

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

.context-switcher {
  width: auto;
  min-width: 0;
  min-height: 34px;
  padding: 6px 28px 6px 14px;
  color: var(--ok);
  font-size: .82rem;
  font-weight: 700;
  white-space: nowrap;
  background:
    linear-gradient(45deg, transparent 50%, var(--ok) 50%) calc(100% - 20px) 50% / 6px 6px no-repeat,
    linear-gradient(135deg, var(--ok) 50%, transparent 50%) calc(100% - 15px) 50% / 6px 6px no-repeat,
    #e8f5ef;
  border-color: #b7dfcf;
  border-radius: 999px;
  appearance: none;
}

.data-notice {
  margin-bottom: 14px;
  padding: 12px 14px;
  color: var(--info);
  background: #e6f1f7;
  border: 1px solid #bdd8e8;
  border-radius: 8px;
  font-size: .92rem;
  font-weight: 700;
  line-height: 1.45;
}

.data-notice.success {
  color: var(--ok);
  background: #e8f5ef;
  border-color: #b7dfcf;
}

.data-notice.warn {
  color: #5c3b00;
  background: #fff7df;
  border-color: #f1d898;
}

.data-notice.error {
  color: #9d251f;
  background: #ffe8e5;
  border-color: #ffc9c4;
}

.data-notice:empty {
  display: none;
}

.token-status {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 700;
  white-space: nowrap;
}

.token-status.connected {
  color: var(--ok);
  background: #e8f5ef;
}

.token-status.disconnected {
  color: var(--warn);
  background: #fff4df;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metrics article {
  display: grid;
  gap: 8px;
  padding: 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics span {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}

.metrics strong {
  font-size: 1.25rem;
  line-height: 1.2;
}

.tool-band {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 96px 112px 148px 148px auto;
  gap: 6px;
  align-items: end;
  margin-bottom: 18px;
  padding: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tool-band label {
  min-width: 0;
}

.tool-band input,
.tool-band select {
  min-width: 0;
  padding-inline: 8px;
  font-size: .84rem;
}

.filter-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: nowrap;
}

.checkbox-control {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 7px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: .82rem;
  font-weight: 700;
  white-space: nowrap;
}

.filter-actions .primary-btn,
.filter-actions .ghost-btn {
  min-height: 38px;
  padding-inline: 8px;
  font-size: .82rem;
  white-space: nowrap;
}

.checkbox-control input {
  width: 16px;
  min-height: 16px;
  margin: 0;
  accent-color: var(--it9-red);
}

.invoice-groups {
  display: grid;
  gap: 12px;
}

.access-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
  padding: 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.access-toolbar h3 {
  margin: 4px 0 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.context-list {
  display: grid;
  gap: 10px;
}

.admin-user-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.context-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.context-title,
.context-meta {
  display: block;
}

.context-title {
  margin-bottom: 5px;
}

.context-meta {
  color: var(--muted);
  font-size: .86rem;
}

.context-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.invoice-table-panel {
  overflow: hidden;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-heading {
  width: 100%;
  min-height: 54px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--ink);
  background: #fff;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.table-title {
  font-weight: 700;
}

.table-meta {
  color: var(--muted);
  font-size: .88rem;
}

.table-scroll {
  overflow-x: hidden;
}

.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 16px;
  background: #fff;
  border-top: 1px solid var(--line);
}

.pagination-controls {
  min-height: 38px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 700;
}

.pagination-status {
  min-width: 142px;
  color: var(--ink);
}

.page-size-control {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: .84rem;
}

.page-size-select {
  width: 74px;
  min-height: 36px;
  padding: 6px 8px;
}

.pagination-buttons {
  display: flex;
  gap: 6px;
}

.pagination-buttons .ghost-btn {
  width: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
}

.pagination-buttons .ghost-btn:disabled {
  cursor: not-allowed;
  opacity: .48;
}

.export-excel-btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-inline: 14px;
  color: var(--ok);
  border-color: #b7dfcf;
}

.export-excel-btn:hover {
  border-color: var(--ok);
}

.excel-icon {
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 20px;
  color: #fff;
  background: #107c41;
  border-radius: 4px;
  font-size: .72rem;
  font-weight: 700;
  line-height: 1;
}

table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.date-col {
  width: 88px;
}

.type-col {
  width: 12%;
}

.direction-col {
  width: 104px;
}

.party-col {
  width: 18%;
}

.value-col {
  width: 19%;
}

.ksef-col {
  width: 154px;
}

th,
td {
  overflow-wrap: anywhere;
  padding: 10px 5px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: .84rem;
}

th {
  color: var(--muted);
  background: #fafbfc;
  font-size: .76rem;
  text-transform: uppercase;
}

th:first-child,
td:first-child {
  white-space: nowrap;
}

.sort-button {
  width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
  font: inherit;
  font-weight: 700;
  text-align: left;
  text-transform: inherit;
}

.sort-indicator {
  position: relative;
  width: 8px;
  height: 12px;
  flex: 0 0 8px;
  opacity: .38;
}

.sort-indicator::before,
.sort-indicator::after {
  content: "";
  position: absolute;
  left: 0;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}

.sort-indicator::before {
  top: 0;
  border-bottom: 5px solid currentColor;
}

.sort-indicator::after {
  bottom: 0;
  border-top: 5px solid currentColor;
}

.sort-button.active {
  color: var(--ink);
}

.sort-button.active .sort-indicator {
  opacity: 1;
}

.sort-button.active[data-direction="asc"] .sort-indicator::after,
.sort-button.active[data-direction="desc"] .sort-indicator::before {
  opacity: .18;
}

.money-sort {
  justify-content: flex-end;
}

td.money {
  text-align: left;
  font-variant-numeric: tabular-nums;
  filter: blur(6px);
  user-select: none;
}

.show-money td.money {
  filter: none;
  user-select: auto;
}

.value-cell {
  line-height: 1.42;
}

.value-part {
  display: inline-block;
  white-space: nowrap;
}

.cell-clamp,
.ksef-value {
  display: -webkit-box;
  overflow: hidden;
  line-height: 1.35;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
}

.cell-clamp {
  max-height: 2.7em;
  -webkit-line-clamp: 2;
}

.ksef-value {
  max-height: 4.05em;
  -webkit-line-clamp: 3;
}

#metricGross,
#metricSales,
#metricPurchase {
  filter: blur(6px);
  user-select: none;
}

.money-blur {
  display: inline-block;
  filter: blur(6px);
  user-select: none;
}

.show-money #metricGross,
.show-money #metricSales,
.show-money #metricPurchase,
.show-money .money-blur {
  filter: none;
  user-select: auto;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
  white-space: nowrap;
}

.pill.sales {
  color: #9d251f;
  background: #ffe8e5;
}

.pill.purchase {
  color: #22577a;
  background: #e6f1f7;
}

.pill.other {
  color: #475467;
  background: #edf0f4;
}

.pill.ok {
  color: var(--ok);
  background: #e8f5ef;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
  text-align: center;
  background: var(--paper);
  border: 1px dashed #b8c0cc;
  border-radius: 8px;
}

.token-dialog {
  width: min(520px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.token-dialog::backdrop {
  background: rgba(15, 19, 28, .48);
}

.token-dialog form {
  display: grid;
  gap: 16px;
}

.form-note {
  margin: 0;
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.45;
}

.token-dialog header,
.token-dialog footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.icon-btn {
  width: 38px;
  min-height: 38px;
  padding: 0;
}

@media (max-width: 980px) {
  .app-view {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    min-height: auto;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto;
    align-items: center;
  }

  nav {
    display: flex;
    overflow-x: auto;
  }

  .sidebar-footer {
    justify-items: end;
  }

  .metrics,
  .tool-band {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-box,
  .filter-actions {
    grid-column: 1 / -1;
  }

  .filter-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

@media (max-width: 720px) {
  .policy-header {
    padding: 24px 108px 24px 24px;
  }

  .policy-brand {
    top: 24px;
    right: 24px;
  }

  .policy-brand img {
    width: 72px;
  }

  .policy-product-title {
    font-size: .86rem;
  }

  .policy-page-title {
    font-size: 2rem;
  }

  .login-shell {
    grid-template-columns: 1fr;
  }

  .brand-panel {
    min-height: 230px;
    align-items: center;
  }

  .product-heading {
    align-items: flex-start;
  }

  .topbar,
  .topbar-actions,
  .sidebar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    display: grid;
  }

  .access-toolbar,
  .admin-user-form,
  .context-item {
    display: grid;
  }

  .admin-user-form {
    grid-template-columns: 1fr;
  }

  .context-actions {
    justify-content: start;
  }

  .metrics,
  .tool-band {
    grid-template-columns: 1fr;
  }
}
