:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4f;
  --text: #e7edf5;
  --muted: #8b9cb3;
  --accent: #3d9cf5;
  --accent-dim: #2b7ac4;
  --danger: #f0677a;
  --ok: #4cd0a8;
  --warn: #e6b35a;
  --radius: 10px;
  --input-fill: #1a2433;
  font-family: "Segoe UI", system-ui, sans-serif;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0.75rem clamp(1rem, 2vw, 1.75rem);
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}
.nav {
  display: flex;
  gap: 0.5rem;
  flex: 1;
}
.nav a {
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  color: var(--muted);
}
.nav a:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
}
.nav a.active {
  color: var(--text);
  background: rgba(61, 156, 245, 0.15);
}

.logout-form {
  margin: 0;
}

.main {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 1.25rem clamp(1rem, 2vw, 1.75rem);
  box-sizing: border-box;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}
.flash-ok,
.flash-success {
  background: rgba(76, 208, 168, 0.12);
  border-color: var(--ok);
  color: #b8f0dd;
}
.flash-error {
  background: rgba(240, 103, 122, 0.12);
  border-color: var(--danger);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}
.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
}
.card-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}
.h-sub {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
}
.muted {
  color: var(--muted);
  font-size: 0.92rem;
}
.empty {
  color: var(--muted);
  padding: 1rem;
}

.toolbar {
  margin-bottom: 1rem;
}
.toolbar-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem 1.5rem;
}
.toolbar-hint {
  flex: 1 1 100%;
  margin: 0.35rem 0 0;
  font-size: 0.86rem;
}
.toolbar-hint strong {
  color: var(--text);
  font-weight: 600;
}
.company-select,
.per-page-select {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.company-select span,
.per-page-select span {
  color: var(--muted);
  font-size: 0.9rem;
}
select,
input[type="text"],
input[type="search"],
input[type="date"],
input[type="password"] {
  background: var(--input-fill);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  font-size: 0.95rem;
  min-width: 0;
}

/* Kalendarz: wyraźniejsze pole + ikona z odstępem od prawej krawędzi; własna ikona (WebKit/Blink) */
input[type="date"],
input[type="datetime-local"] {
  color-scheme: dark;
  background-color: #243044;
  border-color: #3d516f;
  color: var(--text);
  padding-right: 0.7rem;
}
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  width: 1.15rem;
  height: 1.15rem;
  margin: 0 0.35rem 0 0.15rem;
  opacity: 1;
  background: center / contain no-repeat
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23c8d7ea' d='M19 4h-1V2h-2v2H8V2H6v2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V10h14v10zM7 12h2v2H7v-2zm4 0h2v2h-2v-2zm4 0h2v2h-2v-2zM19 8H5V6h14v2z'/%3E%3C/svg%3E");
}
input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover {
  filter: brightness(1.12);
}

select {
  color-scheme: dark;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding: 0.45rem 2.35rem 0.45rem 0.65rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23b8c9db' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.68rem center;
  background-size: 1.1rem;
  background-color: var(--input-fill);
}
select::-ms-expand {
  display: none;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem 1rem;
  margin-bottom: 0.75rem;
}
.filters-form label,
.row-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.filters-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.filters-grid .filters-actions {
  grid-column: 1 / -1;
}
.row-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.92rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover {
  background: rgba(255, 255, 255, 0.07);
  text-decoration: none;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent-dim);
  color: #0a1628;
}
.btn.primary:hover {
  filter: brightness(1.08);
}
.btn.subtle {
  background: transparent;
  color: var(--muted);
}
.btn.wide {
  width: 100%;
}

.table-actions {
  margin-bottom: 0.75rem;
}

.table-actions-end {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.75rem;
  margin-bottom: 0.5rem;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.25rem;
}
.invoice-table {
  width: 100%;
  min-width: 1100px;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.invoice-table th,
.invoice-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 0.5rem;
  text-align: left;
  vertical-align: top;
}
.invoice-row {
  cursor: pointer;
}
.invoice-row:hover td {
  background: rgba(255, 255, 255, 0.03);
}
.invoice-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.invoice-table th.th-sortable {
  padding: 0;
  vertical-align: bottom;
}
.th-sort {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem 0.5rem;
  color: inherit;
  font-weight: inherit;
  font-size: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  border-radius: 4px;
  text-decoration: none;
  line-height: 1.2;
}
.th-sort:hover {
  color: var(--accent);
  background: rgba(61, 156, 245, 0.12);
  text-decoration: none;
}
.th-sort.is-active {
  color: var(--text);
}
.th-sort .sort-arrow {
  font-size: 0.65rem;
  opacity: 0.95;
}
.th-check {
  width: 2rem;
}
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.mono {
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  word-break: break-all;
}
.inline-form {
  margin: 0;
}
.inline-form select {
  max-width: 140px;
  font-size: 0.82rem;
  padding: 0.25rem 2rem 0.25rem 0.4rem;
  background-position: right 0.5rem center;
  background-size: 0.95rem;
}

.desktop-only {
  display: table;
}

/* Jeden element ma .cards.mobile-only — nie można dawać .cards { display:flex } globalnie,
   bo nadpisuje .mobile-only { display:none } i lista jest dublowana (tabela + karty). */
.cards.mobile-only {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
}
.inv-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.2);
}
.inv-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.check-label {
  font-weight: 600;
}
.inv-card footer {
  margin-top: 0.5rem;
  display: flex;
  gap: 1rem;
}
.card-pay {
  margin-top: 0.5rem;
}
.inline-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.inline-label select {
  flex: 1;
  min-width: 0;
}
.small {
  font-size: 0.82rem;
}

.badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  font-weight: 600;
}
.badge.ok {
  background: rgba(76, 208, 168, 0.2);
  color: var(--ok);
}
.badge.warn {
  background: rgba(230, 179, 90, 0.2);
  color: var(--warn);
}
.badge.pay-blik {
  background: rgba(125, 211, 252, 0.16);
  color: #9bdcfc;
}
.badge.pay-transfer {
  background: rgba(96, 165, 250, 0.18);
  color: #a8c7fa;
}
.badge.pay-cash {
  background: rgba(52, 211, 153, 0.16);
  color: #86efac;
}
.badge.pay-other {
  background: rgba(167, 139, 250, 0.18);
  color: #d4c4fc;
}
.badge.bad {
  background: rgba(240, 103, 122, 0.2);
  color: var(--danger);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.status-select {
  max-width: 12.5rem;
  font-size: 0.8rem;
}

.note-cell {
  vertical-align: top;
  max-width: 13rem;
}
.note-drawer {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
  overflow: hidden;
}
.note-drawer-summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
  user-select: none;
}
.note-drawer-summary::-webkit-details-marker {
  display: none;
}
.note-drawer-summary:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}
.note-icon {
  font-size: 0.95rem;
  opacity: 0.9;
}
.note-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.note-form {
  padding: 0 0.5rem 0.55rem;
  border-top: 1px solid var(--border);
  margin-top: 0;
  background: rgba(0, 0, 0, 0.12);
}
.note-textarea {
  display: block;
  width: 100%;
  margin-top: 0.45rem;
  padding: 0.45rem 0.55rem;
  font-family: inherit;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--text);
  background: var(--input-fill);
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
  min-height: 3.2rem;
}
.note-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 156, 245, 0.2);
}
.note-save {
  margin-top: 0.45rem;
  font-size: 0.82rem;
  padding: 0.35rem 0.75rem;
}
.note-preview-inline {
  font-weight: 400;
  opacity: 0.85;
}
.note-drawer-card {
  margin-top: 0.65rem;
}
.note-drawer-card .note-form {
  border-top: 1px solid var(--border);
}
.note-drawer-card .note-textarea {
  margin-top: 0.35rem;
}
.note-drawer-card .note-save {
  width: auto;
}
.invoice-items-row[hidden] {
  display: none;
}
.invoice-items-row td {
  padding: 0;
  background: rgba(255, 255, 255, 0.02);
}
.invoice-items-panel,
.invoice-items-mobile {
  padding: 0.8rem 1rem 0.95rem;
}
.invoice-items-mobile {
  margin-top: 0.7rem;
  border-top: 1px solid var(--border);
}
.invoice-items-header,
.invoice-items-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 8rem;
  gap: 0.75rem;
  align-items: start;
}
.invoice-items-header {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border);
}
.invoice-items-list {
  display: flex;
  flex-direction: column;
}
.invoice-items-entry {
  padding: 0.55rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.invoice-items-entry:last-child {
  border-bottom: 0;
}
.invoice-items-name {
  min-width: 0;
}
.invoice-items-amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.invoice-items-loading,
.invoice-items-empty {
  color: var(--muted);
  font-size: 0.85rem;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.job-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}
.job-table th,
.job-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.5rem;
  text-align: left;
  vertical-align: top;
}
.job-table .num {
  white-space: nowrap;
}
.nowrap {
  white-space: nowrap;
}
.job-table .msg {
  max-width: 420px;
}
.err-detail {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  color: var(--danger);
  white-space: pre-wrap;
  word-break: break-word;
}

.page-login .main {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 0px);
  max-width: none;
}
.login-wrap {
  width: 100%;
  max-width: 400px;
  padding: 1rem;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
}
.login-card h1 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
}
.login-hint {
  color: var(--muted);
  margin: 0 0 1.25rem;
  font-size: 0.92rem;
}
.login-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
  font-size: 0.88rem;
  color: var(--muted);
}
.login-form input {
  font-size: 1rem;
  padding: 0.6rem 0.75rem;
}

code {
  background: rgba(0, 0, 0, 0.35);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.88em;
}

@media (max-width: 900px) {
  .desktop-only {
    display: none !important;
  }
  .cards.mobile-only {
    display: flex !important;
  }
  .inv-card {
    cursor: pointer;
  }
  .invoice-items-header,
  .invoice-items-entry {
    grid-template-columns: minmax(0, 1fr) 6.5rem;
  }
  .topbar-inner {
    flex-direction: column;
    align-items: stretch;
  }
  .nav {
    justify-content: center;
  }
}
