/* ───────────────────────────────────────────
   TABLET BREAKPOINT (≤980px)
   ─────────────────────────────────────────── */
@media (max-width: 980px) {
  .app {
    padding: 18px;
    height: auto;
    overflow: visible;
  }

  .topbar,
  .tools,
  .workspace {
    grid-template-columns: 1fr;
  }

  .modeSwitch:not([hidden]) {
    grid-column: auto;
  }

  .workspace {
    flex: none;
    min-height: auto;
    align-items: start;
  }

  .topbar {
    display: grid;
  }

  .limit {
    width: 100%;
    flex: none;
  }

  .tableWrap {
    max-height: none;
  }

  .summary {
    position: static;
    height: auto;
    overflow: visible;
  }

  .summary .outputPreview {
    flex: none;
    min-height: 300px;
  }
}

/* ───────────────────────────────────────────
   MOBILE BREAKPOINT (≤600px)
   Card layout, floating bar, touch targets
   ─────────────────────────────────────────── */
@media (max-width: 600px) {

  /* ── iOS auto-zoom fix: inputs must be ≥16px ── */
  input,
  select,
  textarea {
    font-size: 16px;
  }

  /* ── Tools section tighter ── */
  .tools {
    gap: 10px;
  }

  .categoryGroup > .controlLabel,
  .categoryChips {
    display: none;
  }

  .categorySelectLabel {
    display: block;
  }

  /* ── Limit panel compact ── */
  .limit {
    padding: 14px 16px;
  }

  .limitLine {
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 1px 8px;
  }

  .limitLine strong {
    font-size: 18px;
  }

  .limitLine span {
    font-size: 10px;
  }

  .limitLine small {
    font-size: 10px;
  }

  .meter {
    height: 10px;
    margin-top: 10px;
  }

  /* ── Table → Cards ── */
  table thead {
    display: none;
  }

  table, tbody, tr {
    display: block;
    width: 100%;
  }

  table {
    min-width: 0 !important;
  }

  .tableWrap {
    border: none;
    box-shadow: none;
    background: transparent;
    padding: 0;
    overflow-x: hidden;
    border-radius: 0;
  }

  /* Card layout: name on top, metadata below, qty on the right */
  tbody tr[hidden] {
    display: none !important;
  }

  tbody tr:not(.categoryHeaderRow) {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto;
    gap: 4px 10px;
    padding: 14px;
    margin: 0 0 10px 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--panel) !important;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
  }

  tbody tr.selectedRow {
    border-color: var(--success);
    background-color: var(--success-light) !important;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.1);
  }

  tbody tr.selectedRow td:first-child {
    box-shadow: none;
  }

  td {
    display: block;
    padding: 0 !important;
    border-bottom: none !important;
    text-align: left !important;
  }

  /* Row 1: Name (full width left), QTY (right, spanning rows) */
  td.name {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
  }

  .nameCell {
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 10px;
  }

  .productThumb {
    width: 36px;
    height: 36px;
    border-radius: 6px;
  }

  td.qtyCell {
    grid-column: 2 / 3;
    grid-row: 1 / 3;
    align-self: center;
    justify-self: end;
  }

  /* Row 2: Code as subtle badge */
  td.code {
    grid-column: 1 / 2;
    grid-row: 2 / 3;
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
  }

  /* Row 3: Metadata line – weight, producer, copay */
  td.weight-cell {
    grid-column: 1 / 2;
    grid-row: 3 / 4;
    margin-top: 2px;
    font-size: 12px;
    color: var(--ink);
  }

  td.producer {
    grid-column: 1 / 2;
    grid-row: 4 / 5;
    text-align: left !important;
    width: auto;
    margin-top: 2px;
  }

  td.copay-cell {
    grid-column: 2 / 3;
    grid-row: 3 / 4;
    justify-self: end;
    text-align: right !important;
    margin-top: 0;
    font-size: 12px;
  }

  td.purchasePrice {
    grid-column: 1 / 2;
    grid-row: 6 / 7;
    justify-self: start;
    text-align: left !important;
    margin-top: 2px;
    font-size: 12px;
  }

  /* Pseudo labels */
  td.weight-cell::before {
    content: "Váha: ";
    color: var(--muted);
    font-weight: 500;
  }

  td.copay-cell::before {
    content: "Doplatok: ";
    color: var(--muted);
    font-weight: 500;
  }

  td.purchasePrice::before {
    content: "Moja cena: ";
    color: var(--muted);
    font-weight: 500;
    display: inline;
  }

  td.purchasePrice strong,
  td.purchasePrice small {
    display: inline !important;
    font-size: 12px;
  }

  /* ── Category headers prominent ── */
  .categoryHeaderRow td {
    display: block;
    background: transparent;
    border: none !important;
    border-top: none !important;
    padding: 20px 0 6px;
    font-size: 12px;
    color: var(--accent);
    font-weight: 800;
    letter-spacing: 0.06em;
    border-bottom: 2px solid var(--accent) !important;
  }

  .categoryHeaderRow {
    margin-bottom: 10px;
  }

  /* ── QTY buttons bigger touch targets ── */
  .qty {
    grid-template-columns: 44px 36px 44px;
    gap: 3px;
    padding: 3px;
  }

  .qty button {
    min-height: 44px;
    height: 44px;
    width: 44px;
    touch-action: manipulation;
  }

  .qty output {
    font-size: 14px;
  }

  /* ── Summary panel compact ── */
  .summary .outputPreview {
    min-height: 160px;
    max-height: 280px;
  }

  /* ── Image modal mobile fix ── */
  .imageModal {
    padding: 12px;
    max-width: 94vw;
    border-radius: var(--radius-md);
  }

  .closeModal {
    top: 8px;
    right: 8px;
    width: 44px;
    height: 44px;
    min-height: 44px;
    box-shadow: none;
  }

  /* ── Intro dialog mobile ── */
  .introPanel {
    padding: 24px 20px;
    gap: 14px;
  }

  .introPanel h2 {
    font-size: 22px;
  }

  #introEnterButton {
    width: 100%;
  }

  /* ── Pad bottom for floating bar ── */
  .app {
    padding-bottom: 80px;
  }
}

/* ───────────────────────────────────────────
   SMALLEST MOBILE (≤520px)
   ─────────────────────────────────────────── */
@media (max-width: 520px) {
  .app {
    padding: 10px;
    padding-bottom: 80px;
  }

  h1 {
    font-size: 22px;
  }

  .introPanel {
    padding: 20px 16px;
    gap: 12px;
  }

  .introPanel h2 {
    font-size: 20px;
  }

  .limitStats {
    gap: 12px;
  }
}

/* ───────────────────────────────────────────
   FLOATING MOBILE BOTTOM BAR
   ─────────────────────────────────────────── */
.mobileBar {
  display: none;
}

@media (max-width: 600px) {
  .mobileBar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .mobileBar[hidden] {
    display: flex;
    transform: translateY(100%);
    pointer-events: none;
  }

  .mobileBar:not([hidden]) {
    transform: translateY(0);
    pointer-events: auto;
  }

}

.mobileBarStats {
  display: flex;
  gap: 16px;
  min-width: 0;
}

.mobileBarStat {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.mobileBarStat span {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.mobileBarStat strong {
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.mobileBarStat strong.over {
  color: var(--danger);
}

#mobileBarCopy {
  flex-shrink: 0;
  min-height: 38px;
  padding: 0 20px;
  background: var(--ink);
  border-color: var(--ink);
  color: white;
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  touch-action: manipulation;
}

#mobileBarCopy:hover:not(:disabled) {
  background: #1e293b;
  border-color: #1e293b;
}

#mobileBarCopy:disabled {
  opacity: 0.4;
}
