:root {
  --bg: #f6f6f6;
  --panel: #ffffff;
  --muted: #e9e9e9;
  --line: #e3e3e3;
  --line-soft: #eeeeee;
  --text: #101010;
  --sub: #4b5563;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
}

.shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 176px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 12px 10px;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--green);
  color: white;
  font-size: 16px;
  flex: 0 0 auto;
}

.brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  object-fit: contain;
  background: white;
  border: 1px solid var(--line-soft);
  flex: 0 0 auto;
}

.brand span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav {
  display: grid;
  gap: 4px;
}

.session-box {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 12px;
  display: grid;
  gap: 5px;
  border-top: 1px solid var(--line-soft);
  padding-top: 10px;
}

.session-box span {
  color: var(--sub);
  font-size: 11px;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 30px;
  border: 0;
  border-radius: 7px;
  padding: 6px 8px;
  background: transparent;
  color: #374151;
  text-align: left;
}

.nav button.active {
  background: var(--green-soft);
  color: #008a3d;
}

.nav-icon {
  width: 17px;
  text-align: center;
  font-size: 16px;
}

.content {
  margin-left: 176px;
  padding: 18px 32px 40px;
}

.page {
  max-width: 768px;
  margin: 0 auto;
}

.page.wide {
  max-width: 980px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  margin: 18px 0 8px;
}

.sub {
  color: var(--sub);
  font-size: 12px;
  margin-top: 3px;
}

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

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

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

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

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

.metric-title {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--sub);
  font-size: 12px;
}

.metric {
  margin-top: 6px;
  font-size: 22px;
  font-weight: 700;
}

.metric.big {
  font-size: 30px;
}

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

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

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

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

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

thead {
  background: var(--muted);
  color: #374151;
  text-transform: uppercase;
  font-size: 10px;
}

th,
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

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

th {
  font-weight: 500;
}

.left {
  text-align: left;
}

.right {
  text-align: right;
}

.center {
  text-align: center;
}

.link {
  color: #009a49;
  font-weight: 600;
  border: 0;
  background: transparent;
  padding: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
}

.badge.green {
  background: var(--green-soft);
  color: var(--green);
}

.badge.red {
  background: var(--red-soft);
  color: var(--red);
}

.badge.amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 12px;
  font-weight: 700;
  font-size: 12px;
  background: var(--green);
  color: white;
}

.btn:hover {
  filter: brightness(0.96);
}

.btn.secondary {
  background: #f3f4f6;
  color: #111827;
  border-color: var(--line-soft);
}

.btn.ghost {
  background: var(--panel);
  color: #111827;
  border-color: var(--line-soft);
  font-weight: 600;
}

.btn.danger {
  background: var(--red-soft);
  color: var(--red);
}

.btn.info {
  background: var(--blue);
  color: white;
  box-shadow: 0 6px 14px rgb(37 99 235 / 0.16);
}

.btn.warn {
  background: #f59e0b;
  color: white;
  box-shadow: 0 6px 14px rgb(245 158 11 / 0.16);
}

.btn.mini {
  min-height: 24px;
  padding: 4px 8px;
  font-size: 11px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.progress {
  height: 8px;
  border-radius: 99px;
  background: #eeeeee;
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  width: var(--w, 0%);
  max-width: 100%;
  background: var(--green);
  border-radius: 99px;
}

.progress > span.low {
  background: #f59e0b;
}

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

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}

.row:last-child {
  border-bottom: 0;
}

.soft-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 6px;
  border: 1px solid var(--line-soft);
  background: var(--panel);
  font-size: 12px;
}

.soft-row.warn {
  background: #fff7ed;
  border-color: #ffedd5;
}

.empty {
  padding: 30px;
  text-align: center;
  color: var(--sub);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 24px;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  width: min(410px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 20px 45px rgb(0 0 0 / 0.18);
  padding: 20px;
}

.modal.wide {
  width: min(760px, 100%);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.close {
  border: 0;
  background: transparent;
  font-size: 20px;
  color: #6b7280;
}

.form-grid {
  display: grid;
  gap: 13px;
}

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

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

.field.full {
  grid-column: 1 / -1;
}

label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 0;
  border-radius: 5px;
  background: #f1f1f1;
  min-height: 30px;
  padding: 7px 10px;
  outline: none;
  color: #111827;
}

input:focus,
select:focus,
textarea:focus {
  box-shadow: inset 0 0 0 2px #111827;
  background: #f7f7f7;
}

textarea {
  min-height: 64px;
  resize: vertical;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #111;
  color: white;
  border-radius: 5px;
  padding: 13px 18px;
  min-width: 260px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 10px 26px rgb(0 0 0 / 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 80;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -4px);
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: min(390px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 12px 35px rgb(0 0 0 / 0.08);
}

.login-brand {
  margin-bottom: 18px;
}

.login-logo-full {
  display: block;
  width: min(230px, 82%);
  height: auto;
  margin: 0 auto 16px;
}

.login-error {
  margin-top: 12px;
  border-radius: 6px;
  background: var(--red-soft);
  color: var(--red);
  padding: 10px;
  font-size: 12px;
  font-weight: 700;
}

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

.download-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
}

.action-stack {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 16px 0;
}

.segmented button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  padding: 8px 11px;
  font: inherit;
  font-weight: 700;
  color: var(--muted);
}

.segmented button.active {
  color: var(--green);
  background: var(--green-soft);
  border-color: transparent;
}

.inventory-filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.inventory-filters button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 12px;
  color: #111827;
  box-shadow: 0 8px 18px rgb(0 0 0 / 0.04);
}

.inventory-filters button span {
  display: grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  border-radius: 99px;
  background: #f3f4f6;
  color: var(--sub);
  font-weight: 800;
}

.inventory-filters button.active {
  background: #0f5132;
  color: white;
  border-color: transparent;
  box-shadow: 0 12px 24px rgb(15 81 50 / 0.2);
}

.inventory-filters button.active span {
  background: white;
  color: #0f5132;
}

.choice-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 10px;
  background: #fafafa;
}

.medicine-lines {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.medicine-line {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #fafafa;
}

.sale-lines {
  display: grid;
  gap: 8px;
}

.sale-line {
  display: grid;
  grid-template-columns: minmax(110px, 0.7fr) minmax(0, 1fr) minmax(0, 1fr) minmax(92px, 0.6fr);
  gap: 8px;
  align-items: end;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #fafafa;
}

.line-total {
  text-align: right;
  font-weight: 800;
  color: var(--green);
}

.summary-box {
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #fafafa;
  padding: 10px;
  font-weight: 800;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-weight: 600;
}

.check-row input {
  width: auto;
  min-height: auto;
}

@media (max-width: 840px) {
  body {
    font-size: 13px;
  }

  .sidebar {
    width: 100%;
    height: auto;
    inset: auto 0 0;
    border-right: 0;
    border-top: 1px solid var(--line);
    padding: 8px;
    background: rgb(255 255 255 / 0.96);
    backdrop-filter: blur(10px);
  }

  .brand {
    display: none;
  }

  .login-brand {
    display: flex;
  }

  .session-box {
    display: none;
  }

  .nav {
    display: flex;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav button {
    min-width: 74px;
    flex: 0 0 auto;
    justify-content: center;
    flex-direction: column;
    gap: 2px;
    font-size: 10.5px;
    line-height: 1.1;
    padding: 7px 8px;
    white-space: nowrap;
  }

  .content {
    margin-left: 0;
    padding: 14px 10px 92px;
  }

  .page,
  .page.wide {
    max-width: none;
    width: 100%;
  }

  h1 {
    font-size: 20px;
  }

  h2 {
    font-size: 15px;
  }

  .grid.cards-5,
  .grid.two,
  .grid.three,
  .grid.four,
  .grid[style*="grid-template-columns"],
  .form-grid.two-col,
  .form-grid.three,
  .inventory-filters,
  .choice-list,
  .medicine-line,
  .sale-line,
  .downloads {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 12px;
  }

  .row {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .row .right {
    text-align: left;
  }

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

  table.mobile-cards,
  table.mobile-cards thead,
  table.mobile-cards tbody,
  table.mobile-cards tr,
  table.mobile-cards th,
  table.mobile-cards td {
    display: block;
    width: 100%;
  }

  table.mobile-cards {
    border-collapse: separate;
    border-spacing: 0;
  }

  table.mobile-cards thead {
    display: none;
  }

  table.mobile-cards tbody {
    display: grid;
    gap: 10px;
  }

  table.mobile-cards tr {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    box-shadow: 0 8px 18px rgb(0 0 0 / 0.035);
  }

  table.mobile-cards td {
    display: grid;
    grid-template-columns: minmax(92px, 38%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 8px 0;
    border-bottom: 1px solid var(--line-soft);
    text-align: left;
    overflow-wrap: anywhere;
  }

  table.mobile-cards td:last-child {
    border-bottom: 0;
  }

  table.mobile-cards td::before {
    content: attr(data-label);
    color: var(--sub);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
  }

  table.mobile-cards td.center,
  table.mobile-cards td.right {
    text-align: left;
  }

  .action-stack {
    justify-content: flex-start;
  }

  .action-stack .btn,
  .page-head > .btn {
    width: 100%;
  }

  .inventory-filters button {
    min-height: 44px;
  }

  .sale-head {
    display: none;
  }

  .line-total {
    text-align: left;
  }

  .page-head {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

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

  .modal-backdrop {
    align-items: stretch;
    justify-content: stretch;
    padding: 10px;
  }

  .modal,
  .modal.wide {
    width: 100%;
    max-height: calc(100vh - 20px);
    padding: 16px;
  }

  .modal-actions {
    position: sticky;
    bottom: -16px;
    background: var(--panel);
    padding-top: 10px;
  }

  .modal-actions .btn {
    flex: 1;
  }

  .toast {
    left: 10px;
    right: 10px;
    bottom: 82px;
    min-width: 0;
    transform: none;
  }

  .toast.show {
    transform: translateY(-4px);
  }
}

@media (max-width: 480px) {
  .nav button {
    min-width: 68px;
    font-size: 10px;
  }

  table.mobile-cards td {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .btn {
    min-height: 34px;
  }

  .login-card {
    padding: 18px;
  }
}
