:root {
  color-scheme: light;
  --ink: #111;
  --muted: #6f6f6f;
  --line: #dedbd5;
  --paper: #faf9f7;
  --panel: #fff;
  --accent: #9a7b49;
  --danger: #9f2d2d;
  --ok: #276749;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.sidebar {
  background: #111;
  color: #fff;
  padding: 28px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 40;
}

.sidebar-backdrop {
  display: none;
}

.brandmark {
  letter-spacing: 0.16em;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}

.sidebar-user {
  margin-bottom: 18px;
  padding: 10px 0 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.28);
  border-bottom: 1px solid rgba(255, 255, 255, 0.36);
}

.sidebar-user span {
  display: block;
  margin-bottom: 4px;
  color: rgba(255, 255, 255, 0.45);
  font-family: "Roboto Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sidebar-user strong {
  display: block;
  color: rgba(255, 255, 255, 0.9);
  font-size: 13px;
  line-height: 1.25;
  word-break: break-word;
}

.sidebar-user-link,
.topbar-user-link {
  text-decoration: none;
}

.sidebar-user-link:hover,
.topbar-user-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.nav {
  display: grid;
  gap: 0;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 12px;
}

.nav a,
.logout-button {
  border: 0;
  background: transparent;
  color: #eee;
  display: block;
  width: 100%;
  padding: 6px 10px;
  border-radius: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.32);
  text-align: left;
  line-height: 1.08;
  font: inherit;
  cursor: pointer;
}

.nav a:hover,
.nav a.active,
.logout-button:hover {
  background: #242424;
}

.sidebar-stamps {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.42);
  color: rgba(255, 255, 255, 0.68);
  font-family: "Roboto Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.stamp-title {
  margin-bottom: 10px;
  color: rgba(255, 255, 255, 0.45);
  font-weight: 700;
}

.stamp-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  padding: 4px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.22);
}

.stamp-row strong {
  color: rgba(255, 255, 255, 0.9);
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

.main {
  padding: 28px;
}

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

.topbar-heading {
  display: grid;
  gap: 4px;
}

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.sidebar-toggle-icon {
  display: grid;
  gap: 4px;
}

.sidebar-toggle-icon span {
  display: block;
  width: 15px;
  height: 2px;
  background: #fff;
  border-radius: 999px;
}

.sidebar-toggle-text {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

h1 {
  font-size: 24px;
  margin: 0;
}

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

.grid {
  display: grid;
  gap: 16px;
}

.kpis {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.kpi-value {
  font-size: 26px;
  margin-top: 8px;
}

.kpi-value small {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.kpi-divider {
  height: 1px;
  margin: 16px 0 12px;
  background: var(--line);
}

.kpi-subrow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-top: 2px;
}

.kpi-subtitle {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-family: "Roboto Mono", "SFMono-Regular", Consolas, monospace;
}

.kpi-subvalue {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.kpi-subvalue small {
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
}

.kpi-debug {
  margin-top: 10px;
  color: var(--muted);
  font-family: "Roboto Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  line-height: 1.35;
  letter-spacing: 0.04em;
  overflow-wrap: anywhere;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
  min-height: 40px;
  font: inherit;
  color: var(--ink);
}

button,
.button {
  min-height: 40px;
  border: 1px solid #111;
  border-radius: 6px;
  padding: 10px 14px;
  background: #111;
  color: #fff;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.link-button {
  min-height: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: #111;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-button:hover {
  background: transparent;
  color: var(--accent);
}

.danger-link {
  color: var(--danger);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.row-actions form {
  margin: 0;
}

.receipt-matching-form {
  display: grid;
  gap: 10px;
  width: 100%;
}

.receipt-matching-bottom {
  display: grid;
  gap: 10px;
  align-items: end;
}

.receipt-matching-bottom {
  grid-template-columns: 140px 110px minmax(220px, 1fr) 190px auto;
}

.receipt-matching-bottom--full {
  grid-template-columns: 160px 120px 110px minmax(220px, 1fr) 190px auto;
}

.receipt-matching-form label {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.receipt-matching-form label span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.receipt-matching-form input {
  min-width: 0;
  width: 100%;
}

.receipt-matching-cell {
  padding-top: 12px;
  padding-bottom: 14px;
  background: #fcfbf8;
}

.receipt-matching-detail-row td {
  border-bottom: 1px solid var(--line);
}

.receipt-matching-rate {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8f6f1;
  min-height: 40px;
}

.receipt-matching-rate span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: "Roboto Mono", "SFMono-Regular", Consolas, monospace;
}

.receipt-matching-rate strong {
  font-family: "Roboto Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  color: #111;
}

.receipt-matching-meta {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.receipt-attachment-link::before {
  content: "▣";
  font-size: 11px;
  line-height: 1;
}

.receipt-lightbox-panel {
  width: min(980px, 100%);
}

.receipt-lightbox-body {
  display: grid;
  place-items: center;
  background: #f6f4ef;
}

.receipt-lightbox-body img {
  max-width: 100%;
  max-height: min(72vh, 820px);
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.18);
}

.button.secondary,
button.secondary {
  background: #fff;
  color: #111;
}

.danger-zone {
  border-color: rgba(159, 45, 45, 0.35);
}

.flush-form {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 14px;
  border: 1px solid rgba(159, 45, 45, 0.28);
  border-radius: 8px;
  background: #fffafa;
}

.flush-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--danger);
  font-weight: 700;
}

.danger-button {
  border-color: var(--danger);
  background: var(--danger);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.pagination-summary {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.pagination-pages {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.pagination-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #111;
  font-size: 13px;
  line-height: 1;
  font-weight: 600;
}

.pagination-item:hover {
  border-color: #111;
}

.pagination-item.is-active {
  border-color: #111;
  background: #111;
  color: #fff;
}

.pagination-item.is-disabled,
.pagination-item.is-gap {
  color: #9b9b9b;
  background: #f5f4f1;
  border-color: #ebe7df;
  cursor: default;
}

.pagination-item.is-gap {
  min-width: 28px;
  padding: 0 4px;
  background: transparent;
  border-color: transparent;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(17, 17, 17, 0.58);
}

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

.modal-panel {
  width: min(1120px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.28);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.modal-close {
  width: 34px;
  min-height: 34px;
  padding: 0;
  justify-content: center;
  border-color: var(--line);
  background: #fff;
  color: #111;
  font-size: 22px;
}

.modal-body {
  overflow: auto;
  padding: 18px 20px 20px;
}

.modal-table-wrap table {
  min-width: 760px;
}

.modal-table-wrap td {
  vertical-align: top;
}

.import-row-data {
  min-width: 420px;
  max-width: 620px;
  color: #333;
  font-size: 12px;
}

.import-row-data div + div {
  margin-top: 3px;
}

.issue-summary {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.issue-summary-title {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.issue-summary-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.issue-summary-item summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  cursor: pointer;
}

.issue-summary-item summary span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.issue-summary-item summary strong {
  min-width: 52px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #111;
  color: #fff;
  text-align: center;
}

.issue-summary-detail {
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
}

.issue-summary-table {
  border-radius: 6px;
}

.issue-summary-table table {
  min-width: 520px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}

th,
td {
  padding: 12px 14px 12px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #f4f2ee;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.table-wrap td > a:not(.pagination-item),
.table-wrap td .row-actions a,
.table-wrap td button.secondary,
.table-wrap td form button,
.table-action {
  min-height: 32px;
  border: 1px solid #111;
  border-radius: 6px;
  padding: 6px 10px;
  background: #fff;
  color: #111;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  line-height: 1;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.table-wrap td > a:not(.pagination-item):hover,
.table-wrap td .row-actions a:hover,
.table-wrap td button.secondary:hover,
.table-wrap td form button:hover,
.table-action:hover {
  background: #f4f2ee;
}

.status {
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #eee;
}

.status.ok {
  color: var(--ok);
}

.status.risk {
  color: var(--danger);
}

.status.warn {
  color: #9a7b49;
}

.status.muted {
  color: var(--muted);
}

.flash {
  border: 1px solid var(--line);
  background: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.form-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.compact-list {
  margin: 10px 0 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
}

.heat-badge,
.quantity-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.quantity-badge {
  min-width: 38px;
  background: #111;
}

.season-list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
}

.season-list li {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.season-list li:last-child {
  border-bottom: 0;
}

.permission-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 172px;
}

.permission-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.permission-badge.is-allowed {
  background: #111;
  color: #fff;
}

.permission-badge.is-blocked {
  background: #e5e7eb;
  color: #7b8088;
}

.user-access-cell {
  padding: 0;
  background: #faf9f7;
}

.user-access-log {
  padding: 10px 14px 14px;
}

.user-access-log summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  font-size: 12px;
  font-weight: 700;
}

.user-access-log summary::-webkit-details-marker {
  display: none;
}

.user-access-log summary strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #111;
  color: #fff;
  font-size: 11px;
}

.user-access-table {
  width: 100%;
  min-width: 0;
  margin-top: 12px;
  border-collapse: collapse;
  table-layout: fixed;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.user-access-table th,
.user-access-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
}

.user-access-table th {
  position: static;
  background: #f8f7f4;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.user-access-table tbody tr:last-child td {
  border-bottom: 0;
}

.user-access-table td:nth-child(3),
.user-access-table td:nth-child(4),
.user-access-table td:nth-child(5) {
  font-family: "Roboto Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  overflow-wrap: anywhere;
}

.user-access-table td:nth-child(1) {
  width: 168px;
}

.user-access-table td:nth-child(2) {
  width: 132px;
}

.user-access-table td:nth-child(5) {
  width: 132px;
}

.user-access-empty {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.user-access-empty {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.stock-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stock-summary-card {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.stock-summary-card span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stock-summary-card strong {
  font-size: 22px;
  font-weight: 700;
}

.fifo-stat-card {
  position: relative;
}

.fifo-stat-card.is-active {
  border-color: #111;
  box-shadow: 0 0 0 1px rgba(17, 17, 17, 0.08);
}

.fifo-stat-meta {
  color: var(--muted);
  font-family: "Roboto Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  letter-spacing: 0.04em;
}

.age-bucket {
  display: inline-flex;
  min-width: 54px;
  justify-content: flex-end;
  padding: 3px 7px;
  border-radius: 999px;
  background: #f1f1f1;
}

.age-bucket.is-highlighted {
  background: #111;
  color: #fff;
}

.dashboard-chart-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}

.dashboard-chart-filters {
  flex: 1 1 auto;
}

.chart-toggles {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin: 0;
  padding-top: 4px;
}

.chart-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #4b5563;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.chart-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: #111;
  flex: 0 0 16px;
}

.chart-toggle span {
  display: inline-block;
  white-space: nowrap;
}

#dashboard-chart {
  width: 100%;
  height: 390px;
  display: block;
  background: #fff;
}

@media (max-width: 1100px) {
  .dashboard-chart-toolbar {
    flex-direction: column;
  }

  .chart-toggles {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 700px) {
  .chart-toggle {
    width: calc(50% - 5px);
    justify-content: center;
  }
}

@media (max-width: 560px) {
  .chart-toggle {
    width: 100%;
  }
}

.ajax-table.is-loading {
  opacity: 0.55;
  pointer-events: none;
}

.inline-price {
  width: 110px;
  min-height: 34px;
  padding: 6px 8px;
}

.inline-price.is-saved {
  border-color: var(--ok);
  box-shadow: 0 0 0 2px rgba(39, 103, 73, 0.12);
}

.match-product {
  width: 260px;
  max-width: 34vw;
}

.money,
.number {
  white-space: nowrap;
  text-align: right;
  padding-right: 18px;
}

.date {
  white-space: nowrap;
  text-align: center;
}

.zero-money {
  color: #a8a8a8;
}

.is-excluded-row {
  opacity: 0.5;
}

.excluded-icon {
  display: inline-flex;
  margin-right: 6px;
  font-size: 14px;
  vertical-align: middle;
}

.stock-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}

.stock-empty {
  background: #e5e7eb;
  color: #4b5563;
}

.stock-low {
  background: #b42318;
  color: #fff;
}

.stock-decreasing {
  background: #f59e0b;
  color: #2f1900;
}

.stock-sufficient {
  background: #16803f;
  color: #fff;
}

.coefficient-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 12px;
  white-space: nowrap;
}

.coefficient-empty {
  background: #e5e7eb;
  color: #4b5563;
}

.coefficient-low {
  background: #b42318;
  color: #fff;
}

.coefficient-mid {
  background: #f59e0b;
  color: #2f1900;
}

.coefficient-ok {
  background: #16803f;
  color: #fff;
}

.turnover-status-cell {
  padding: 0;
  width: 92px;
}

.turnover-legend {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.turnover-legend-row {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.turnover-legend-row p {
  margin: 0;
}

.turnover-status {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 96px;
  padding: 8px 7px;
  border-radius: 0;
  text-align: center;
  font-weight: 700;
  font-size: 11px;
  line-height: 1.12;
  white-space: normal;
  overflow-wrap: anywhere;
}

.turnover-fast {
  background: #7ed957;
  color: #10220b;
}

.turnover-healthy {
  background: #0f6b3f;
  color: #fff;
}

.turnover-watch {
  background: #b42318;
  color: #fff;
}

.forecast-toolbar label,
.forecast-toolbar input[type="date"],
.forecast-toolbar select {
  min-width: 0;
}

.forecast-metrics-cell {
  min-width: 170px;
}

.forecast-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.forecast-metric {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 6px 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f7f4;
  text-align: center;
}

.forecast-metric small {
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.forecast-metric strong {
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
}

.forecast-status-cell {
  padding: 0;
  width: 118px;
}

.forecast-status {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 8px 7px;
  border-radius: 0;
  text-align: center;
  font-weight: 700;
  font-size: 11px;
  line-height: 1.12;
  white-space: normal;
  overflow-wrap: anywhere;
}

.forecast-status-risk {
  background: #b42318;
  color: #fff;
}

.forecast-status-warn {
  background: #f59e0b;
  color: #2f1900;
}

.forecast-status-ok {
  background: #0f6b3f;
  color: #fff;
}

.forecast-status-muted {
  background: #e5e7eb;
  color: #4b5563;
}

.chart-wrap {
  position: relative;
}

.chart-tooltip {
  position: absolute;
  display: none;
  pointer-events: none;
  background: #111;
  color: #fff;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  z-index: 5;
  white-space: nowrap;
}

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

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(82vw, 320px);
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 18px 0 48px rgba(0, 0, 0, 0.22);
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: block;
    background: rgba(17, 17, 17, 0.42);
  }

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

  .sidebar-stamps {
    margin-top: 18px;
  }

  .main {
    padding: 78px 16px 16px;
  }

  .topbar {
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 18px;
  }

  .topbar-heading {
    position: static;
  }

  .topbar-user {
    display: none;
  }

  .sidebar-toggle {
    display: inline-flex;
    position: fixed;
    top: 10px;
    right: 16px;
    z-index: 35;
    min-height: 40px;
    min-width: 40px;
    padding: 8px 10px;
    border-radius: 10px;
    border-color: rgba(17, 17, 17, 0.78);
    background: rgba(17, 17, 17, 0.72);
    color: #fff;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.16);
  }

  h1 {
    font-size: 22px;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .toolbar > * {
    width: 100%;
    min-width: 0;
  }

  label {
    width: 100%;
    min-width: 0;
    overflow: hidden;
  }

  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea,
  button,
  .button {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  input[type="date"] {
    display: block;
    inline-size: 100%;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding-right: 8px;
  }

  select[multiple] {
    min-height: 132px;
  }

  .chart-toggles {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  #dashboard-chart {
    height: 280px;
  }

  .sales-panels,
  .season-grid {
    grid-template-columns: 1fr !important;
  }

  .turnover-legend-row {
    grid-template-columns: 120px minmax(0, 1fr);
    gap: 10px;
  }

  .turnover-toolbar {
    grid-template-columns: 1fr;
  }

  .turnover-toolbar label,
  .turnover-toolbar input[type="date"],
  .turnover-toolbar select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .stock-summary {
    grid-template-columns: 1fr;
  }

  .forecast-toolbar {
    grid-template-columns: 1fr;
  }

  .forecast-toolbar label,
  .forecast-toolbar input[type="date"],
  .forecast-toolbar select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .permission-badges {
    min-width: 0;
  }

  .user-access-log {
    padding: 10px 12px 12px;
  }

  .user-access-table {
    display: block;
    overflow-x: auto;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .table-wrap table.is-responsive-ready,
  .table-wrap table.is-responsive-ready thead,
  .table-wrap table.is-responsive-ready tbody,
  .table-wrap table.is-responsive-ready tr,
  .table-wrap table.is-responsive-ready th,
  .table-wrap table.is-responsive-ready td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .table-wrap table.is-responsive-ready {
    border-collapse: separate;
    min-width: 0;
  }

  .table-wrap table.is-responsive-ready thead {
    display: none;
  }

  .table-wrap table.is-responsive-ready tr {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
  }

  .table-wrap table.is-responsive-ready td {
    display: grid;
    grid-template-columns: minmax(96px, 42%) minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
  }

  .table-wrap table.is-responsive-ready td:last-child {
    border-bottom: 0;
  }

  .table-wrap table.is-responsive-ready td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    justify-self: start;
  }

  .table-wrap table.is-responsive-ready td.money,
  .table-wrap table.is-responsive-ready td.number,
  .table-wrap table.is-responsive-ready td.date {
    justify-items: end;
    padding-right: 12px;
  }

  .table-wrap table.is-responsive-ready td.money::before,
  .table-wrap table.is-responsive-ready td.number::before,
  .table-wrap table.is-responsive-ready td.date::before {
    justify-self: start;
  }

  .table-wrap table.is-responsive-ready td.forecast-metrics-cell {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .table-wrap table.is-responsive-ready td.forecast-metrics-cell::before {
    margin-bottom: 2px;
  }

  .table-wrap table.is-responsive-ready td.forecast-status-cell {
    grid-template-columns: 1fr;
    padding: 0;
  }

  .table-wrap table.is-responsive-ready td.forecast-status-cell::before {
    padding: 10px 12px 0;
  }

  .table-wrap table.is-responsive-ready td.forecast-status-cell .forecast-status {
    max-width: none;
  }

  .table-wrap table.is-responsive-ready td.has-row-actions,
  .table-wrap table.is-responsive-ready td[data-label="Akce"] {
    justify-items: stretch;
  }

  .table-wrap table.is-responsive-ready td.has-row-actions .row-actions,
  .table-wrap table.is-responsive-ready td[data-label="Akce"] .row-actions {
    flex-wrap: wrap;
    white-space: normal;
  }

  .receipt-matching-form {
    grid-template-columns: 1fr;
  }

  .receipt-matching-top,
  .receipt-matching-bottom {
    grid-template-columns: 1fr;
  }

  .receipt-matching-bottom--full {
    grid-template-columns: 1fr;
  }

  .receipt-matching-form label,
  .receipt-matching-rate {
    grid-template-columns: 1fr;
    gap: 5px;
    align-items: start;
  }

  .receipt-matching-meta {
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .row-actions {
    flex-wrap: wrap;
    white-space: normal;
  }

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

  .pagination-pages {
    justify-content: flex-start;
  }
}
