:root {
  --app-ink: #2d6a62;
  --app-ink-hover: #245750;
  --app-muted: #6b7280;
  --app-line: #d7dde3;
  --app-focus: rgba(45, 106, 98, 0.22);
  --bs-primary: #2d6a62;
  --bs-primary-rgb: 45, 106, 98;
  --bs-link-color: #2d6a62;
  --bs-link-hover-color: #245750;
  --bs-focus-ring-color: rgba(45, 106, 98, 0.22);
}

html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

a {
  color: var(--app-ink);
}

.btn-primary {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--app-ink);
  --bs-btn-border-color: var(--app-ink);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--app-ink-hover);
  --bs-btn-hover-border-color: var(--app-ink-hover);
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: var(--app-ink-hover);
  --bs-btn-active-border-color: var(--app-ink-hover);
  --bs-btn-disabled-color: #fff;
  --bs-btn-disabled-bg: var(--app-ink);
  --bs-btn-disabled-border-color: var(--app-ink);
}

.btn-outline-primary {
  --bs-btn-color: var(--app-ink);
  --bs-btn-border-color: var(--app-ink);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--app-ink);
  --bs-btn-hover-border-color: var(--app-ink);
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: var(--app-ink-hover);
  --bs-btn-active-border-color: var(--app-ink-hover);
  --bs-btn-disabled-color: var(--app-ink);
  --bs-btn-disabled-border-color: var(--app-ink);
}

.btn-outline-secondary {
  --bs-btn-color: #4b5563;
  --bs-btn-border-color: #d7dde3;
  --bs-btn-hover-color: var(--app-ink);
  --bs-btn-hover-bg: #f3f7f6;
  --bs-btn-hover-border-color: #c5ccd3;
  --bs-btn-active-color: var(--app-ink);
  --bs-btn-active-bg: #e8f0ee;
  --bs-btn-active-border-color: #c5ccd3;
}

.btn:focus,
.btn:active:focus,
.form-control:focus,
.form-check-input:focus {
  border-color: #9aa3ad;
  box-shadow: 0 0 0 0.2rem var(--app-focus);
}

.form-check-input:checked {
  background-color: var(--app-ink);
  border-color: var(--app-ink);
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}

.login-page {
  min-height: 100vh;
  margin: 0;
  background: #f4f6f8;
  color: #1f2933;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 32px;
  background: #fff;
  border: 1px solid #e4e7eb;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(31, 41, 51, 0.06);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.login-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--app-ink);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.3;
}

.login-brand p {
  margin: 2px 0 0;
  color: #6b7280;
  font-size: 0.9rem;
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
}

.login-field .form-control {
  min-height: 42px;
  border-color: #d7dde3;
  border-radius: 8px;
}

.login-field .form-control:focus {
  border-color: var(--app-ink);
}

.login-alert.validation-summary-valid {
  display: none;
}

.login-alert.validation-summary-errors {
  margin-bottom: 16px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fef2f2;
  color: #b42318;
  font-size: 0.875rem;
}

.login-alert ul {
  margin: 0;
  padding-left: 1.1rem;
}

.login-remember {
  margin: 4px 0 20px;
  font-size: 0.9rem;
  color: #4b5563;
}

.login-submit {
  min-height: 42px;
  width: 100%;
  border-radius: 8px;
  font-weight: 500;
}

.app-page {
  min-height: 100vh;
  margin: 0;
  background: #f4f6f8;
  color: #1f2933;
}

.app-header {
  background: #fff;
  border-bottom: 1px solid #e4e7eb;
}

.app-nav {
  width: 100%;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #1f2933;
  text-decoration: none;
  font-weight: 600;
}

.app-brand:hover {
  color: #1f2933;
}

.app-brand .login-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 11px;
}

.app-nav-links {
  display: flex;
  gap: 8px;
}

.app-nav-link {
  padding: 6px 10px;
  border-radius: 8px;
  color: #4b5563;
  text-decoration: none;
  font-size: 0.92rem;
}

.app-nav-link.active,
.app-nav-link:hover {
  background: #f4f6f8;
  color: #1f2933;
}

.app-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #6b7280;
  font-size: 0.9rem;
}

.app-logout {
  border: 0;
  background: transparent;
  color: #4b5563;
  padding: 0;
  font-size: 0.9rem;
}

.app-logout:hover {
  color: #1f2933;
}

.app-main {
  width: 100%;
  padding: 28px 24px 48px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 20px;
}

.page-head h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 650;
}

.page-head p {
  margin: 4px 0 0;
  color: #6b7280;
}

.page-meta {
  display: flex;
  gap: 8px;
  color: #6b7280;
  font-size: 0.85rem;
}

.page-meta span {
  background: #fff;
  border: 1px solid #e4e7eb;
  border-radius: 999px;
  padding: 4px 10px;
}

.panel {
  background: #fff;
  border: 1px solid #e4e7eb;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(31, 41, 51, 0.04);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  font-weight: 600;
}

.panel h3 {
  margin: 20px 0 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #4b5563;
}

.panel-note {
  margin: -4px 0 16px;
  color: var(--app-muted);
  font-size: 0.85rem;
}

.settings-form .btn {
  margin-top: 8px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
  margin-bottom: 12px;
}

.settings-grid label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: #374151;
}

.settings-wide {
  grid-column: 1 / -1;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  align-items: end;
}

.filter-grid label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: #374151;
}

.filter-grid .form-control,
.filter-grid .form-select,
.filter-grid .form-control.flatpickr-input {
  min-height: 42px;
  border-color: #d7dde3;
  border-radius: 8px;
}

.flatpickr-calendar {
  border: 1px solid #e4e7eb;
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(31, 41, 51, 0.12);
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
  background: var(--app-ink);
  border-color: var(--app-ink);
}

.flatpickr-day.today {
  border-color: var(--app-ink);
}

.filter-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}

.filter-check .form-check-label {
  display: inline;
  margin: 0;
  font-weight: 500;
  color: #374151;
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
}

.filter-actions .btn,
.table-toolbar .btn {
  min-height: 42px;
  border-radius: 8px;
  font-weight: 500;
}

.btn-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 118px;
}

.btn-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}

.btn-loading.is-loading .btn-spinner {
  display: inline-block;
}

.btn-loading.is-loading {
  pointer-events: none;
  opacity: 0.8;
}

@keyframes btn-spin {
  to {
    transform: rotate(360deg);
  }
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.table-wrap {
  overflow: auto;
}

.app-table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  border: 1px solid #e4e7eb;
}

.app-table th,
.app-table td {
  padding: 7px 10px;
  border: 1px solid #eef1f4;
  vertical-align: middle;
}

.app-table th {
  font-size: 0.78rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.app-table tbody tr:last-child td {
  border-bottom: 0;
}

.invoice-row.is-return td {
  background: #fff8f1;
}

.invoice-row.is-expanded td {
  border-bottom-color: transparent;
}

.line-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.line-toggle .chevron {
  width: 8px;
  height: 8px;
  border-right: 1.5px solid #6b7280;
  border-bottom: 1.5px solid #6b7280;
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}

.line-toggle[aria-expanded="true"] .chevron {
  transform: rotate(45deg);
}

.invoice-lines td {
  padding: 0 10px 10px 46px;
  background: #f8fafb;
}

.line-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid #e4e7eb;
  border-radius: 8px;
  overflow: hidden;
}

.line-table th,
.line-table td {
  padding: 5px 10px;
  border: 1px solid #eef1f4;
  font-size: 0.86rem;
}

.line-table th {
  font-size: 0.72rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #f8fafb;
}

.line-table tbody tr:last-child td {
  border-bottom: 0;
}

.status-return {
  background: #fff6ed;
  color: #b54708;
  margin-right: 4px;
}

.col-check {
  width: 36px;
}

.col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}

.row-actions {
  display: inline-flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}

.json-pop {
  position: fixed;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  min-width: 180px;
  padding: 6px;
  background: #fff;
  border: 1px solid #e4e7eb;
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(31, 41, 51, 0.16);
}

.json-pop[hidden] {
  display: none;
}

.json-pop-item {
  border: 0;
  background: transparent;
  text-align: left;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.86rem;
  color: #1f2933;
}

.json-pop-item:hover {
  background: #f3f7f6;
}

.json-meta {
  margin-bottom: 10px;
}

.json-meta strong {
  margin-right: 6px;
}

.json-meta span {
  word-break: break-all;
}

.json-box {
  margin: 0;
  padding: 14px 16px;
  border-radius: 8px;
  background: #1f2933;
  color: #e8eef2;
  font-size: 0.8rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

#jsonModal .modal-title,
#userModal .modal-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.inline-form {
  display: inline;
  margin: 0;
}

#userModal .modal-content {
  border: 1px solid #e4e7eb;
  border-radius: 12px;
}

#userModal .modal-body .login-field:last-child {
  margin-bottom: 0;
}

.contact-check-btn.is-loading,
.send-invoice-btn.is-loading {
  pointer-events: none;
}

.contact-check-btn.is-loading .btn-spinner,
.send-invoice-btn.is-loading .btn-spinner {
  display: inline-block;
}

.contact-check-btn.is-loading svg,
.send-invoice-btn.is-loading svg {
  display: none;
}

.btn-icon {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.tip {
  position: relative;
  display: inline-flex;
}

.tip::after {
  content: attr(data-tip);
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  padding: 4px 8px;
  border-radius: 6px;
  background: #1f2933;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
}

.tip:hover::after,
.tip:focus-within::after {
  opacity: 1;
}

.cell-strong {
  font-weight: 600;
}

.app-table small {
  display: block;
  margin-top: 1px;
  color: #6b7280;
}

.empty-state {
  padding: 36px 8px;
  text-align: center;
  color: #6b7280;
}

.status {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.status-ok {
  background: #ecfdf3;
  color: #067647;
}

.status-wait {
  background: #f3f4f6;
  color: #4b5563;
}

.app-alert {
  margin-bottom: 16px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.app-alert-ok {
  background: #ecfdf3;
  color: #067647;
}

.app-alert-err {
  background: #fef2f2;
  color: #b42318;
}

.result-list {
  margin: 0;
  padding-left: 1.1rem;
}

.result-list .is-ok {
  color: #067647;
}

.result-list .is-err {
  color: #b42318;
}

@media (max-width: 768px) {
  .page-head,
  .table-toolbar,
  .app-nav {
    flex-wrap: wrap;
  }

  .filter-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .filter-actions {
    justify-content: stretch;
  }

  .filter-actions .btn {
    width: 100%;
  }
}