@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600;700&family=IBM+Plex+Mono:wght@400;600&display=swap");

:root {
  --bg: #f5f3ef;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-strong: rgba(255, 255, 255, 0.95);
  --ink: #1c1b18;
  --muted: #5d5a53;
  --line: rgba(21, 19, 15, 0.14);
  --accent: #ff6a1f;
  --accent-deep: #df4f04;
  --safe: #157f52;
  --warn: #bf3f0f;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", "Avenir Next", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% -8%, rgba(255, 150, 98, 0.45), transparent 36%),
    radial-gradient(circle at 95% 8%, rgba(255, 211, 77, 0.35), transparent 30%),
    linear-gradient(125deg, #fbf9f4 0%, #f0ebe3 100%);
}

.background-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    -35deg,
    rgba(36, 33, 29, 0.015) 0,
    rgba(36, 33, 29, 0.015) 1px,
    transparent 1px,
    transparent 10px
  );
}

.app-shell {
  position: relative;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 18px 42px;
}

.auth-shell {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.auth-card {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 26px rgba(23, 21, 18, 0.08);
}

.auth-card h1 {
  margin: 0;
  font-size: clamp(1.3rem, 3vw, 1.8rem);
}

.auth-card p {
  margin: 8px 0 14px;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 16, 12, 0.45);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 18px;
  box-shadow: 0 18px 40px rgba(18, 14, 10, 0.24);
}

.modal-card h2 {
  margin: 0 0 8px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.7rem, 4vw, 2.6rem);
  letter-spacing: 0.01em;
}

.topbar p {
  margin: 8px 0 16px;
  color: var(--muted);
}

.banner {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.84);
  font-size: 0.9rem;
  color: var(--ink);
}

.banner-warning {
  border-color: rgba(167, 117, 0, 0.42);
  background: rgba(255, 223, 141, 0.25);
  color: #7a5400;
}

.banner-critical {
  border-color: rgba(191, 63, 15, 0.38);
  background: rgba(255, 120, 78, 0.18);
  color: #902f09;
}

.session-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.shop-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.shop-switcher span {
  white-space: nowrap;
}

.shop-switcher select {
  min-width: 190px;
  padding: 8px 10px;
  font-size: 0.84rem;
}

.inline-input-action {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-input-action input {
  flex: 1;
}

.inline-input-action button {
  white-space: nowrap;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tabbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.tab-btn {
  background: rgba(255, 255, 255, 0.84);
}

.tab-btn.active {
  border-color: transparent;
  background: linear-gradient(140deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #fff;
}

.tab-panel {
  margin-top: 20px;
}

.actions a,
button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 15px;
  background: var(--surface-strong);
  color: var(--ink);
  text-decoration: none;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

button:hover,
.actions a:hover {
  transform: translateY(-1px);
  border-color: rgba(21, 19, 15, 0.3);
}

.primary {
  border-color: transparent;
  background: linear-gradient(140deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #fff;
}

.ghost {
  background: transparent;
}

.danger {
  color: var(--warn);
  border-color: rgba(191, 63, 15, 0.28);
  background: rgba(191, 63, 15, 0.06);
}

.grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
  margin-top: 16px;
}

.seller-grid {
  grid-template-columns: 2fr 1fr;
}

.inventory-grid {
  grid-template-columns: 1fr 1fr;
}

.dashboard {
  margin-top: 14px;
}

.receipts-grid {
  grid-template-columns: 1fr;
  margin-top: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 26px rgba(23, 21, 18, 0.05);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.kpi-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.7);
}

.kpi-value {
  margin: 4px 0 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.card-wide {
  min-width: 0;
}

.sale-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.sale-item-row {
  display: grid;
  grid-template-columns: 1fr 120px auto;
  gap: 8px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.87rem;
  color: var(--muted);
  margin-bottom: 9px;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.86);
  padding: 10px 11px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.95rem;
  color: var(--ink);
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin: 8px 0 12px;
}

legend {
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0 6px;
}

input:focus,
select:focus {
  outline: 2px solid rgba(255, 106, 31, 0.35);
  border-color: rgba(255, 106, 31, 0.6);
}

.two-up {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  margin-bottom: 10px;
}

.compact-inline {
  margin: 0;
  font-size: 0.84rem;
  gap: 8px;
}

.checkbox-row input {
  width: auto;
}

.credit-fields {
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 11px;
  margin-bottom: 10px;
}

.hidden {
  display: none;
}

.sale-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 12px;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.total {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.status {
  min-height: 1.3em;
  margin: 10px 0 0;
  font-size: 0.88rem;
  color: var(--safe);
}

.status.error {
  color: var(--warn);
}

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 14px 0;
}

h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 9px 7px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

td.debtor-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}

td.debtor-actions > button {
  padding: 6px 10px;
  font-size: 0.78rem;
}

.admin-note {
  margin-top: 4px;
  font-size: 0.74rem;
}

.warn-text {
  color: var(--warn);
}

.muted-inline {
  color: var(--muted);
  font-size: 0.78rem;
}

.inventory-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

td.inventory-actions {
  display: table-cell;
  white-space: nowrap;
}

td.inventory-actions > button {
  margin-right: 6px;
}

td.inventory-actions > button:last-child {
  margin-right: 0;
}

.inventory-actions button {
  padding: 6px 10px;
  font-size: 0.76rem;
}

#inventory-products-table input[type="text"],
#inventory-products-table input[type="number"] {
  padding: 7px 9px;
  font-size: 0.85rem;
}

#inventory-products-table input[type="checkbox"] {
  width: auto;
}

#admin-shops-table input[type="text"],
#admin-shops-table input[type="datetime-local"],
#admin-shops-table select {
  min-width: 140px;
  padding: 7px 8px;
  font-size: 0.84rem;
}

#admin-shops-table th:last-child,
#admin-shops-table td:last-child {
  position: sticky;
  right: 0;
  background: var(--surface-strong);
}

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

.platform-shop-select {
  min-width: 220px;
  min-height: 84px;
  margin-top: 6px;
  font-size: 0.82rem;
}

.platform-shop-checks {
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  max-height: 140px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.stock-low {
  color: var(--warn);
  font-weight: 700;
}

.prediction-risk-critical {
  color: var(--warn);
  font-weight: 700;
}

.prediction-risk-warning {
  color: #a06b05;
  font-weight: 700;
}

.prediction-risk-ok {
  color: var(--safe);
  font-weight: 600;
}

.prediction-risk-no_data {
  color: var(--muted);
}

.stack {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stack li {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px;
  background: rgba(255, 255, 255, 0.7);
}

.stack.compact li {
  padding: 9px 10px;
  font-size: 0.92rem;
}

/* Bottom navigation - mobile */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--surface-strong);
  border-top: 1px solid var(--line);
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(18, 14, 10, 0.08);
}

.bottom-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  font-size: 0.7rem;
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
  min-width: 0;
}

.bottom-nav-btn.active {
  color: var(--accent);
  font-weight: 600;
}

.bottom-nav-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.bottom-nav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Home layout - responsive grid */
.home-layout {
  display: grid;
  gap: 20px;
  margin-top: 0;
}

.today-summary-card .kpi-compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.kpi-compact .kpi-box {
  padding: 8px;
}

.kpi-compact .kpi-value {
  font-size: 0.95rem;
}

.payment-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.payment-chips .chip {
  font-size: 0.8rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
}

.quick-actions {
  margin: 0;
}

.quick-actions-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.quick-actions-row > .quick-action-btn {
  width: 100%;
  min-width: 0;
  padding: 10px 16px;
  font-size: 0.9rem;
  text-align: center;
  white-space: nowrap;
}

.sell-layout,
.debtors-layout,
.more-layout {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sell-layout .quick-actions h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
  line-height: 1.2;
}

.alerts-card .alerts-content {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.alerts-section {
  padding-bottom: 4px;
}

.alerts-section:last-of-type {
  padding-bottom: 0;
}

.alerts-section h3 {
  margin: 0 0 6px;
  font-size: 0.9rem;
}

.link-cta {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.88rem;
  color: var(--accent);
  text-decoration: none;
}

.link-cta:hover {
  text-decoration: underline;
}

.last-sale-quick {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 0;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.last-sale-label {
  font-size: 0.88rem;
  color: var(--muted);
}

.last-sale-actions {
  margin-left: auto;
}

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

/* New Transaction modal */
.new-transaction-modal .modal-card {
  max-height: 90vh;
  overflow-y: auto;
  width: min(560px, 100%);
}

.debtor-edit-modal .modal-card {
  width: min(520px, 100%);
}

.new-transaction-modal .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-close {
  font-size: 1.5rem;
  line-height: 1;
  padding: 4px 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--muted);
}

.modal-close:hover {
  color: var(--ink);
}

.transaction-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.transaction-tab {
  padding: 8px 14px;
  font-size: 0.9rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  color: var(--muted);
}

.transaction-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.transaction-tab-panel {
  min-height: 120px;
}

/* Debtors filters */
.debtors-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}

.debtors-search {
  flex: 1;
  min-width: 140px;
  max-width: 220px;
}

.filter-btn {
  padding: 6px 12px;
  font-size: 0.84rem;
}

.filter-btn.active {
  background: linear-gradient(140deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #fff;
  border-color: transparent;
}

/* More layout */
.more-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  align-items: center;
}

.more-nav-link {
  padding: 0 8px;
  font-size: 0.95rem;
  line-height: 1.25;
  text-decoration: none;
  color: var(--ink);
}

.more-nav-link:hover {
  color: var(--accent);
}

.more-section {
  margin-top: 0;
}

.inventory-secondary {
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 24px;
  margin-bottom: 32px;
}

#panel-inventory .inventory-prediction-card {
  padding-bottom: 24px;
}

#panel-inventory > .inventory-grid {
  margin-top: 0;
}

#panel-inventory .inventory-secondary .stack {
  margin-top: 10px;
}

#panel-inventory .inventory-secondary .stack li {
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.78);
}

#panel-inventory .inventory-prediction-card .stack.compact {
  gap: 10px;
  margin: 12px 0 14px;
}

#panel-inventory .inventory-prediction-card .stack.compact li {
  line-height: 1.35;
}

#panel-inventory .inventory-prediction-card .actions {
  margin-top: 6px;
  gap: 8px;
}

/* Desktop: 2-column grid for Home */
@media (min-width: 768px) {
  .home-layout {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 20px;
  }

  .today-summary-card {
    grid-column: 1;
    grid-row: 1;
  }

  .home-layout > .quick-actions {
    grid-column: 1;
    grid-row: 2;
    align-self: start;
  }

  .alerts-card {
    grid-column: 1;
    grid-row: 3;
  }

  .recent-activity-card {
    grid-column: 2;
    grid-row: 1 / 4;
  }

  .bottom-nav {
    display: none;
  }

  .tabbar-desktop {
    display: flex;
  }
}

@media (max-width: 767px) {
  .tabbar-desktop {
    display: none;
  }

  .bottom-nav {
    display: flex;
    justify-content: space-around;
  }

  .app-shell {
    padding-bottom: 72px;
  }

  .new-transaction-modal .modal-card {
    max-height: 95vh;
    margin: auto;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .new-transaction-modal .modal-backdrop {
    position: fixed;
  }

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

  .quick-actions-row > .quick-action-btn {
    width: 100%;
    min-width: 0;
  }

  .quick-actions-row .quick-action-btn:last-child {
    grid-column: 1 / -1;
  }
}

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

  .seller-grid {
    grid-template-columns: 1fr;
  }

  .inventory-grid {
    grid-template-columns: 1fr;
  }

  .inventory-secondary {
    grid-template-columns: 1fr;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .kpi-compact {
    grid-template-columns: 1fr 1fr;
  }

  .sale-item-row {
    grid-template-columns: 1fr;
  }

  .two-up {
    grid-template-columns: 1fr;
  }

  .check-grid {
    grid-template-columns: 1fr;
  }

  .inline-input-action {
    flex-direction: column;
    align-items: stretch;
  }
}
