:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --ink: #071b3b;
  --muted: #64748b;
  --line: #d8e1ec;
  --brand: #06265a;
  --brand-dark: #031735;
  --accent: #ff7a00;
  --cyan: #08a8f5;
  --warn: #a13737;
  --soft: #e8f5ff;
  --shadow: 0 12px 32px rgba(3, 23, 53, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: #fff;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  padding-top: 0;
  padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px));
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.request-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 18px calc(env(safe-area-inset-bottom, 0px) + 18px);
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  backdrop-filter: blur(4px);
}

.request-progress[hidden] {
  display: none;
}

.request-progress-box {
  width: min(88vw, 320px);
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 24px 18px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 22px 54px rgba(3, 23, 53, 0.18);
  text-align: center;
}

.request-progress strong {
  display: block;
  font-size: 1.02rem;
  font-weight: 700;
}

.request-progress span {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.request-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(255, 255, 255, 0.24);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.request-progress-bar {
  width: 100%;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef6;
}

.request-progress i {
  display: block;
  width: var(--progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--accent));
  transition: width 0.22s ease;
}

body.request-busy {
  overflow: hidden;
  touch-action: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 86px;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #fff;
  box-shadow: 0 6px 18px rgba(3, 23, 53, 0.28);
}

.brand-logo {
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  border-radius: 14px;
  object-fit: cover;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
}

.brand-logo-title {
  width: min(230px, calc(100vw - 92px));
  height: 70px;
  padding: 3px;
  border-radius: 14px;
  object-fit: contain;
  background: #fff;
}

.eyebrow {
  margin: 0 0 4px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.panel h2,
.dialog-head h2 {
  margin: 0;
  line-height: 1.1;
}

main {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 14px 12px 88px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.summary-grid article {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.summary-grid span {
  display: block;
  font-size: 1.45rem;
  font-weight: 800;
}

.summary-grid small,
.muted {
  color: var(--muted);
}

.tabs {
  position: sticky;
  top: 75px;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 0 10px;
  background: var(--bg);
}

.tab,
.secondary,
.primary {
  min-height: 42px;
  border-radius: 8px;
  font-weight: 700;
}

.tab {
  color: var(--muted);
  background: #ece7dc;
}

.tab.active {
  color: #fff;
  background: var(--brand-dark);
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0 12px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel h2 {
  font-size: 1.05rem;
}

.primary {
  padding: 0 14px;
  color: #fff;
  background: var(--accent);
}

.secondary {
  padding: 0 14px;
  color: var(--brand);
  background: var(--soft);
}

.compact {
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.88rem;
}

.list {
  display: grid;
  gap: 10px;
}

.load-more-btn {
  width: 100%;
  margin-top: 2px;
}

.card {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 18px rgba(22, 33, 31, 0.06);
}

.product-card {
  grid-template-columns: minmax(96px, 30%) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 136px;
}

.product-photo,
.photo-placeholder {
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  border: 1px solid #e2e8f0;
  border-radius: 7px;
  object-fit: cover;
  object-position: center;
  background: #e8dfd0;
}

.photo-placeholder {
  display: grid;
  place-items: center;
  color: #85644f;
  font-weight: 800;
}

.card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.product-info {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 9px;
  min-width: 0;
}

.product-info h3 {
  overflow-wrap: anywhere;
}

.product-info .card-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  width: 100%;
  align-self: stretch;
  justify-content: flex-end;
  gap: 6px;
}

.product-info .card-actions .compact {
  width: 100%;
  min-height: 34px;
  padding: 0 8px;
}

.card p {
  margin: 0;
  color: var(--muted);
}

.meta-row,
.card-actions,
.order-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.price {
  color: var(--brand);
  font-weight: 800;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #efe5d9;
  color: #5f4b38;
  font-size: 0.78rem;
  font-weight: 800;
}

.badge.open {
  background: #dff3ff;
  color: #075985;
}

.badge.cancel {
  background: #f1dddd;
  color: #8c2b2b;
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
  font-weight: 900;
}

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.ghost {
  color: var(--muted);
  background: transparent;
}

.danger {
  color: #fff;
  background: var(--warn);
}

dialog {
  width: min(560px, calc(100% - 24px));
  max-height: calc(100vh - 28px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(13, 29, 26, 0.54);
}

dialog form {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.picker-view {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.notifications-view {
  display: grid;
  gap: 12px;
  padding: 14px;
  min-width: min(92vw, 420px);
}

.notification-list {
  display: grid;
  gap: 10px;
}

.notification-card {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
}

.notification-card.read {
  background: #f8fafc;
}

.notification-card h3 {
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
}

.notification-card time,
.notification-card p {
  margin: 0;
  color: var(--muted);
}

.notification-actions {
  justify-content: flex-start;
  margin-top: 4px;
}

.picker-card {
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  text-align: left;
}

.picker-actions {
  justify-content: flex-start;
  margin-top: 8px;
}

.picker-card:active {
  transform: scale(0.99);
}

.photo-dialog {
  background: #111916;
}

.photo-viewer {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.photo-viewer .dialog-head {
  color: #fff;
}

#largeProductPhoto {
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border-radius: 8px;
  background: #0b100e;
}

.dialog-head,
.dialog-actions,
.items-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dialog-head,
.items-head {
  justify-content: space-between;
}

.dialog-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.spacer {
  flex: 1;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.form-status {
  min-height: 22px;
  margin: 0 0 12px;
  color: var(--muted);
  font-weight: 700;
}

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

.form-status.success {
  color: #0f8f5b;
}

.api-user-card {
  display: grid;
  gap: 8px;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.api-user-card span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

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

.choice-group {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.choice-group legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.choice-group label {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 7px 8px;
  border-radius: 8px;
  background: #f8fbff;
}

.choice-group input {
  width: auto;
  min-height: 0;
}

.setup-dialog {
  width: min(440px, calc(100% - 24px));
}

.setup-head {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  align-items: center;
}

.setup-head img {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  object-fit: contain;
  background: #fff;
}

.setup-head h2,
.setup-head p {
  margin: 0;
}

.setup-head p {
  margin-top: 5px;
  color: var(--muted);
}

.search-field {
  margin-bottom: 12px;
}

.search-field input {
  padding-left: 14px;
  border-color: #cfc7b9;
  background: #fffdfa;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.inline-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.filter-field {
  min-width: 140px;
}

.photo-preview {
  width: min(180px, 100%);
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.order-item-row {
  display: grid;
  grid-template-columns: 1fr 78px 42px;
  gap: 8px;
  margin-bottom: 8px;
}

.stock-warning {
  grid-column: 1 / -1;
  color: #9a3412;
  font-size: 0.82rem;
  font-weight: 700;
}

.order-item-row.stock-low select,
.order-item-row.stock-low input {
  border-color: #f97316;
  background: #fff7ed;
}

.empty {
  padding: 18px;
  border: 1px dashed #cabfad;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: rgba(255, 255, 255, 0.55);
}

.receipt {
  min-height: 240px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.receipt-logo {
  display: block;
  width: 86px;
  height: 86px;
  margin: 0 auto 10px;
  border-radius: 18px;
  object-fit: cover;
}

.receipt h3,
.receipt h4 {
  margin: 0 0 8px;
}

.receipt table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
}

.receipt th,
.receipt td {
  padding: 8px 4px;
  border-bottom: 1px solid #e8e1d6;
  text-align: left;
  vertical-align: top;
}

.receipt .right {
  text-align: right;
}

@media (max-width: 520px) {
  .tabs {
    top: 72px;
  }

  .tab {
    min-height: 40px;
    font-size: 0.78rem;
  }

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

  .product-card {
    grid-template-columns: 98px minmax(0, 1fr);
    min-height: 128px;
  }

  .product-photo,
  .photo-placeholder {
    width: 100%;
    min-height: 0;
  }

  .product-info .card-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
  }
}

/* Android safe spacing refinement */
.app-header {
  align-items: flex-start;
  min-height: 138px;
  padding-top: calc(54px + env(safe-area-inset-top, 0px));
  background: var(--brand);
}

.summary-grid {
  margin-top: 14px;
}

.tabs {
  top: 138px;
}

.bottom-nav {
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  min-height: 60px;
}

.bottom-tab,
.bottom-add {
  min-height: 44px;
}

.bottom-add {
  margin-top: -14px;
}

@media (max-width: 520px) {
  .tabs {
    top: 138px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-header,
  .summary-grid,
  .tabs,
  .panel:not(#reportsPanel),
  .panel-head,
  .panel-actions,
  #reportOrder,
  #reportOrder + *,
  .field {
    display: none !important;
  }

  main {
    width: 100%;
    padding: 0;
  }

  #reportsPanel,
  .receipt {
    display: block;
    border: 0;
    padding: 0;
    box-shadow: none;
  }
}

/* Dashboard visual polish inspired by the provided reference */
body {
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
}

.app-header {
  min-height: 96px;
  padding: 12px 14px 20px;
  background: var(--brand);
}

.brand-logo-title {
  width: 48px;
  height: 48px;
  padding: 2px;
  border-radius: 12px;
}

.welcome {
  display: grid;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.welcome strong {
  color: #fff;
  font-size: 0.96rem;
}

.welcome span {
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.78rem;
}

.welcome .app-version {
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.68rem;
  line-height: 1.1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.round-action,
.profile-action {
  position: relative;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
}

.round-action svg,
.profile-action svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.round-action small {
  position: absolute;
  top: -3px;
  right: -1px;
  display: grid;
  width: 17px;
  height: 17px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
}

.profile-action {
  background: #fff;
  color: var(--brand);
}

main {
  padding: 14px 12px 20px;
}

.summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: -28px;
}

.summary-grid article {
  display: grid;
  gap: 3px;
  justify-items: center;
  min-height: 92px;
  padding: 10px 6px;
  box-shadow: 0 8px 24px rgba(3, 23, 53, 0.08);
}

.summary-grid span {
  font-size: 1rem;
}

.summary-icon {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  font-style: normal;
  font-weight: 900;
}

.products-icon {
  color: #0b74ff;
  background: #e8f2ff;
}

.clients-icon {
  color: #10b981;
  background: #e8fbf3;
}

.orders-icon {
  color: var(--accent);
  background: #fff1e4;
}

.sales-icon {
  color: #6554ff;
  background: #eeeeff;
}

.tabs {
  top: 96px;
  padding: 8px;
  margin-bottom: 12px;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(3, 23, 53, 0.06);
}

.tab {
  background: transparent;
}

.tab.active {
  background: var(--brand);
}

.panel-head {
  margin: 14px 0 12px;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 12px;
}

.search-row .search-field {
  margin-bottom: 0;
}

.filter-button {
  min-width: 86px;
  align-self: end;
}

.card {
  box-shadow: 0 7px 22px rgba(3, 23, 53, 0.07);
}

.product-card {
  grid-template-columns: 94px minmax(0, 1fr);
  min-height: 132px;
}

.product-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.product-title-row h3 {
  margin: 0;
}

.product-info .card-actions {
  grid-template-columns: repeat(3, minmax(38px, 1fr));
}

.icon-only {
  min-width: 38px;
  font-size: 1rem;
}

.danger-soft {
  color: var(--warn);
  background: #fff1f1;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  width: min(920px, 100%);
  min-height: 64px;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -8px 24px rgba(3, 23, 53, 0.09);
}

.bottom-tab,
.bottom-add {
  min-height: 48px;
  color: var(--muted);
  background: transparent;
  font-size: 0.72rem;
  font-weight: 800;
}

.bottom-tab.active {
  color: #0b74ff;
}

.bottom-add {
  width: 52px;
  height: 52px;
  min-height: 52px;
  justify-self: center;
  border-radius: 999px;
  color: #fff;
  background: #0b74ff;
  box-shadow: 0 8px 18px rgba(11, 116, 255, 0.32);
  font-size: 1.7rem;
}

.more-menu-grid {
  display: grid;
  gap: 10px;
}

.more-menu-grid button {
  justify-content: center;
  width: 100%;
}

.master-list {
  margin-top: 12px;
}

@media (max-width: 520px) {
  .tabs {
    top: 96px;
  }

  .summary-grid {
    gap: 7px;
  }

  .summary-grid small {
    font-size: 0.66rem;
  }
}

/* Final spacing for Android system bars */
.app-header {
  align-items: flex-start;
  min-height: 112px;
  padding-top: calc(28px + env(safe-area-inset-top, 0px));
  background: var(--brand);
}

.summary-grid {
  margin-top: -18px;
}

.tabs {
  top: 112px;
}

.bottom-nav {
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  min-height: 60px;
}

.bottom-tab,
.bottom-add {
  min-height: 44px;
}

.bottom-add {
  margin-top: -14px;
}

@media (max-width: 520px) {
  .tabs {
    top: 112px;
  }
}

/* Final Android top correction: no white gap above header */
body {
  padding-top: 0;
}

.app-header {
  min-height: 96px;
  padding: 12px 14px 20px;
  background: var(--brand);
}

.app-header .brand-logo,
.app-header .welcome,
.app-header .header-actions {
  transform: translateY(16px);
}

.tabs {
  top: 96px;
}

@media (max-width: 520px) {
  .tabs {
    top: 96px;
  }
}
