:root {
  --navy: #0b2942;
  --navy-2: #174e73;
  --accent: #e92d72;
  --accent-dark: #c81f5d;
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #132238;
  --muted: #607080;
  --line: #dfe7ef;
  --soft: #eef3f8;
  --success-bg: #e8f7ef;
  --success-text: #166534;
  --danger-bg: #feeceb;
  --danger-text: #991b1b;
  --shadow: 0 8px 24px rgba(15, 35, 55, .08);
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 100%;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.45;
  overscroll-behavior-y: contain;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px max(16px, env(safe-area-inset-left)) 14px max(16px, env(safe-area-inset-right));
  background: var(--navy);
  color: #fff;
  box-shadow: 0 4px 18px rgba(11, 41, 66, .18);
}

.brand {
  display: inline-block;
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.business {
  max-width: 62vw;
  margin-top: 2px;
  font-size: 12px;
  opacity: .82;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout {
  flex: 0 0 auto;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 12px;
  color: #fff;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}

.container {
  width: min(100%, 960px);
  min-height: calc(100vh - 66px);
  min-height: calc(100dvh - 66px);
  margin: 0 auto;
  padding: 16px 14px calc(132px + env(safe-area-inset-bottom));
}

.hero {
  margin-bottom: 14px;
  padding: clamp(18px, 5vw, 28px);
  border-radius: 20px;
  color: #fff;
  background: linear-gradient(135deg, var(--navy), var(--navy-2));
  box-shadow: var(--shadow);
}

.hero .label {
  font-size: 12px;
  letter-spacing: .05em;
  opacity: .82;
}

.hero .value {
  margin-top: 4px;
  font-size: clamp(28px, 9vw, 44px);
  line-height: 1.05;
  font-weight: 800;
  overflow-wrap: anywhere;
}

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

.card,
.form-card {
  min-width: 0;
  border: 1px solid rgba(223, 231, 239, .75);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.card {
  display: block;
  padding: 15px;
  color: var(--ink);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.card:hover,
.btn:hover,
.primary:hover,
.logout:hover {
  filter: brightness(.98);
}

.metric {
  font-size: 13px;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: clamp(18px, 5vw, 23px);
  overflow-wrap: anywhere;
}

.primary,
.btn {
  min-height: 46px;
  border: 0;
  border-radius: 14px;
  font-weight: 800;
  text-decoration: none;
}

.primary {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  padding: 14px 16px;
  background: var(--accent);
  color: #fff;
  text-align: center;
  font-size: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 14px;
  background: var(--navy);
  color: #fff;
}

.btn-light { background: #e8eef4; color: var(--navy); }
.btn-danger { background: #b42318; }
.whatsapp-btn { background: #1f9d55; }

.table-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 11px;
  border-radius: 10px;
  background: var(--soft);
  color: var(--navy);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.section-title {
  margin: 20px 0 10px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 800;
}

.form-card {
  padding: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.product-search-note {
  margin-top: 6px;
}

.pos-card {
  overflow: visible;
}

.pos-add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 10px;
  align-items: end;
}

.pos-add-row .btn {
  grid-column: 1 / -1;
}

.pos-cart {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}

.pos-cart-head,
.pos-line,
.pos-total,
.receipt-top,
.receipt-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pos-cart-head,
.pos-total {
  padding: 12px;
  background: var(--soft);
}

.pos-line {
  padding: 12px;
  border-top: 1px solid #eef2f6;
}

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

.pos-line-actions input {
  width: 86px;
}

.pos-empty {
  padding: 12px;
  border-top: 1px solid #eef2f6;
}

.pos-total strong,
.receipt-total strong {
  font-size: 20px;
}

.receipt-card {
  display: grid;
  gap: 14px;
}

.receipt-buttons,
.backup-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.receipt-buttons .btn,
.backup-grid .btn {
  flex: 1 1 150px;
}

.backup-grid .btn {
  min-width: min(100%, 180px);
}

.admin-form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: end;
}

.subscription-card {
  margin-bottom: 12px;
}

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

.audit-list > div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft);
}

.sale-detail-card {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.sale-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.receipt-top,
.receipt-total {
  padding: 12px;
  border-radius: 12px;
  background: var(--soft);
}

form.grid {
  align-items: end;
}

label {
  display: block;
  margin: 12px 0 5px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  padding: 12px 13px;
  border: 1px solid #d8e0e8;
  border-radius: 12px;
  outline: 0;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}

input[type="checkbox"] {
  width: auto;
  min-height: 0;
  margin-right: 8px;
  transform: translateY(1px);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(233, 45, 114, .12);
}

table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 14px;
  background: #fff;
}

th,
td {
  padding: 12px 11px;
  border-bottom: 1px solid #eef2f6;
  text-align: left;
  font-size: 13px;
  vertical-align: top;
}

th {
  background: var(--soft);
  color: #35475c;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

tr:last-child td { border-bottom: 0; }

.alert {
  margin-bottom: 12px;
  padding: 11px 12px;
  border-radius: 12px;
  font-weight: 700;
}

.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-danger { background: var(--danger-bg); color: var(--danger-text); }

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid #e5eaf0;
  background: rgba(255, 255, 255, .98);
  box-shadow: 0 -10px 30px rgba(15, 35, 55, .08);
}

.admin-nav {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.bottom-nav a {
  min-width: 0;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px 2px;
  border-radius: 12px;
  color: #536575;
  text-align: center;
  text-decoration: none;
  font-size: 11px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.bottom-nav .sell {
  margin-top: -18px;
  padding-top: 13px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(233, 45, 114, .28);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.row > * { min-width: 0; }

.muted {
  color: #738292;
  font-size: 12px;
}

.pill {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--soft);
  font-size: 11px;
  font-weight: 700;
}

.low {
  color: var(--danger-text) !important;
  font-weight: 800;
}

.right { text-align: right; }

@media (min-width: 520px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 760px) {
  .container {
    padding: 22px 22px 136px;
  }

  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

  form.grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  .pos-add-row {
    grid-template-columns: minmax(0, 1fr) 110px 120px;
  }

  .pos-add-row .btn {
    grid-column: auto;
  }

  .bottom-nav {
    right: auto;
    left: 50%;
    width: min(700px, calc(100% - 28px));
    transform: translateX(-50%);
    border: 1px solid #e5eaf0;
    border-bottom: 0;
    border-radius: 18px 18px 0 0;
  }

  .admin-nav {
    width: min(960px, calc(100% - 28px));
  }

  .admin-form-grid {
    grid-template-columns: minmax(180px, 1.2fr) repeat(3, minmax(120px, 1fr)) 90px;
  }
}

@media (max-width: 430px) {
  .topbar { padding-top: 12px; padding-bottom: 12px; }
  .brand { font-size: 18px; }
  .business { max-width: 54vw; }
  .container { padding-left: 10px; padding-right: 10px; }
  .hero, .card, .form-card { border-radius: 14px; }
  .hero { padding: 16px; }
  .row {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .row .btn { margin-left: auto; }
  table { min-width: 520px; }
  .admin-nav {
    grid-template-columns: repeat(7, minmax(78px, 1fr));
    justify-content: start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .admin-nav a {
    white-space: nowrap;
  }
  .backup-grid .btn {
    flex-basis: 100%;
  }
  .pos-line,
  .sale-detail-head,
  .receipt-actions,
  .receipt-top,
  .receipt-total {
    align-items: flex-start;
    flex-direction: column;
  }
  .pos-line-actions {
    width: 100%;
  }
  .pos-line-actions input {
    flex: 1;
  }
}

@media print {
  .topbar,
  .bottom-nav,
  .receipt-actions,
  .primary { display: none !important; }
  .container { width: 100%; padding: 0; }
  .card,
  .form-card,
  .hero { box-shadow: none; }
}
