:root {
  --expired: #c0392b;
  --warning: #d68910;
  --ok: #1e8449;
}

.site-header {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

.site-clock {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 0.45rem 0.55rem;
  padding: 0.45rem 0.75rem;
  border-radius: 0.5rem;
  background: #f4f7fa;
  color: #243140;
  font-size: 0.95rem;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}

.site-clock-date {
  font-weight: 600;
}

.site-clock-time {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.site-clock-sep {
  color: #8a97a6;
}

.site-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.site-header h1 {
  margin: 0;
}

.drug-title {
  margin: 0 0 0.75rem;
}

.user-corner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  white-space: nowrap;
}

.user-corner form {
  margin: 0;
}

.user-corner button,
.user-corner select {
  width: auto;
  margin: 0;
}

.dept-switch {
  margin: 0;
}

.dept-switch label {
  margin: 0;
}

.dept-switch select {
  max-width: 14rem;
  padding: 0.25rem 0.5rem;
}

nav.app-nav {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0;
}

nav.app-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

nav.app-nav a {
  display: inline-block;
  padding: 0.32rem 0.72rem;
  border-radius: 999px;
  background: #e7f1fb;
  color: #0b3a66;
  text-decoration: none;
  line-height: 1.35;
  font-size: 0.95rem;
}

nav.app-nav a:hover {
  background: #d3e6f8;
  color: #0b3a66;
}

nav.app-nav a.is-current {
  background: #0b3a66;
  color: #fff;
}

nav.app-nav-admin a {
  background: #f3f5f7;
  color: #3d4c5c;
}

nav.app-nav-admin a:hover {
  background: #e6eaee;
  color: #243140;
}

nav.app-nav-admin a.is-current {
  background: #3d4c5c;
  color: #fff;
}

.badge-expired,
.badge-warning,
.badge-today {
  color: #9b1c1c;
  font-weight: 700;
  font-size: 1.05rem;
  background: #fde8e8;
  border-radius: 0.35rem;
  padding: 0.15rem 0.5rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  padding: 1rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
}

a.stat-card-link {
  display: block;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

a.stat-card-link:hover {
  border-color: var(--pico-primary-border);
}

.stat-value {
  font-size: 1.6rem;
  margin: 0;
}

.stat-note {
  margin: 0.25rem 0 0;
  color: var(--pico-muted-color);
  font-size: 0.9rem;
}

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

.stats-filters button,
.stats-filters a[role="button"] {
  width: auto;
  margin-right: 0.5rem;
}

.hidden {
  display: none !important;
}

table.compact td,
table.compact th {
  padding: 0.35rem 0.5rem;
}

table.compact form {
  margin: 0;
}

table.compact button {
  width: auto;
  margin: 0;
  padding: 0.2rem 0.55rem;
}

details batch-row {
  margin-left: 1rem;
}

.msg-ok {
  color: var(--ok);
}

.msg-err {
  color: var(--expired);
}

.box-preview {
  font-weight: 600;
  margin-top: 0.5rem;
}

.issue-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 1rem;
}

.issue-actions form,
.issue-actions button,
.issue-actions a {
  width: auto;
  margin: 0;
}

.qty-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.15rem 0 0.75rem;
}

.qty-presets button {
  width: auto;
  margin: 0;
  padding: 0.2rem 0.75rem;
}

.qty-presets button.preset-on,
.qty-presets button.preset-on:hover,
.qty-presets button.preset-on:focus {
  --pico-background-color: #e7f1fb;
  --pico-border-color: #1d6fb8;
  --pico-color: #0b3a66;
  background-color: #e7f1fb;
  border-color: #1d6fb8;
  color: #0b3a66;
  font-weight: 700;
}

.med-search-wrap {
  position: relative;
  margin-bottom: 1rem;
}

.med-search-field {
  position: relative;
}

.med-search-field input {
  padding-right: 2.6rem;
}

.search-clear {
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.8rem;
  height: 1.8rem;
  margin: 0;
  padding: 0;
  line-height: 1;
}

tr.row-link {
  cursor: pointer;
}

tr.row-link:hover td {
  background: var(--pico-table-row-stripped-background, rgba(0, 0, 0, 0.03));
}

.med-suggestions {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  max-height: 14rem;
  overflow-y: auto;
  margin: 0.25rem 0 0;
  padding: 0;
  list-style: none;
  background: var(--pico-background-color);
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.med-suggestions li {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
}

.med-suggestions li:hover,
.med-suggestions li:focus {
  background: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
  outline: none;
}

.med-selected-hint {
  font-size: 0.9rem;
  margin: 0.35rem 0 0;
  color: var(--pico-muted-color);
}

.med-create-panel {
  margin: 0.75rem 0 1rem;
  padding: 1rem 1.1rem 0.25rem;
  border: 1px solid #b7dfc4;
  background: #f3faf5;
  border-radius: var(--pico-border-radius);
}

.med-create-panel h3 {
  margin: 0 0 0.25rem;
  font-size: 1.15rem;
}

.receipt-lead {
  margin-top: -0.35rem;
  color: var(--pico-muted-color);
}

.receipt-block h2 {
  font-size: 1.15rem;
  margin: 0 0 0.55rem;
}

.med-picked {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid #b7dfc4;
  background: #f3faf5;
  border-radius: var(--pico-border-radius);
}

.med-picked p {
  margin: 0.15rem 0 0;
}

.med-picked button {
  width: auto;
  margin: 0;
}

.med-suggestions li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.med-suggestions li span {
  color: var(--pico-muted-color);
}

.med-suggestions li:hover span,
.med-suggestions li:focus span,
.suggest-new {
  color: inherit;
}

.suggest-new {
  font-weight: 600;
  border-top: 1px solid var(--pico-muted-border-color);
}

fieldset,
.choice-grid,
.grid,
.qty-fields,
.table-scroll {
  min-width: 0;
  max-width: 100%;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
  gap: 0.6rem;
  border: 0;
  padding: 0;
  margin: 0 0 0.85rem;
}

.choice-grid > legend {
  margin-bottom: 0.35rem;
}

.choice-grid > label {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  margin: 0;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  min-width: 0;
  white-space: normal;
  overflow: visible;
}

.choice-grid > label input[type="radio"] {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 1.25rem;
  margin: 0.2rem 0 0;
}

.choice-grid > label span {
  display: block;
  min-width: 0;
}

.choice-grid > label small {
  display: block;
  color: var(--pico-muted-color);
  white-space: normal;
}

.choice-grid > label:has(input:disabled) {
  opacity: 0.5;
}

.choice-grid > label:has(input:checked) {
  background: #e7f1fb;
  border-color: var(--pico-primary);
  box-shadow: inset 0 0 0 2px var(--pico-primary);
}

.qty-fields input[type="number"] {
  font-size: 1.35rem;
  font-weight: 700;
}

.field-hint {
  margin: 0 0 0.35rem;
  color: var(--pico-muted-color);
  font-size: 0.9rem;
}

.qty-result {
  margin: 0.2rem 0 1rem;
  padding: 0.85rem 1rem;
  background: #f3faf5;
  border: 1px solid #b7dfc4;
  border-radius: var(--pico-border-radius);
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.qty-result small {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--pico-muted-color);
}

.msg-warn {
  background: #fff6e0;
  color: #7a4e00;
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.35;
  border: 2px solid #e6c36a;
  border-radius: 0.4rem;
  padding: 0.8rem 1rem;
  margin: 0.2rem 0 1rem;
}

.msg-alert {
  background: #fde8e8;
  color: #9b1c1c;
  font-weight: 700;
  font-size: 1.08rem;
  line-height: 1.35;
  border: 2px solid #e7b2b2;
  border-radius: 0.4rem;
  padding: 0.8rem 1rem;
  margin: 0.6rem 0 1rem;
}

tr.stock-toggle {
  cursor: pointer;
}

tr.stock-toggle:hover td {
  background: var(--pico-table-row-stripped-background, rgba(0, 0, 0, 0.03));
}

tr.stock-toggle .chevron::before {
  content: "▸";
  display: inline-block;
  width: 1rem;
}

tr.stock-toggle.is-open .chevron::before {
  content: "▾";
}

.stock-batches td {
  background: #f7f7f5;
}

@media (max-width: 900px) {
  .site-top {
    flex-direction: column;
    align-items: stretch;
  }

  .user-corner {
    margin-left: 0;
    white-space: normal;
    flex-wrap: wrap;
    width: 100%;
  }

  .dept-switch,
  .dept-switch select {
    width: 100%;
    max-width: 100%;
  }

  nav.app-nav a {
    padding: 0.45rem 0.8rem;
  }

  .choice-grid,
  .grid {
    grid-template-columns: 1fr;
  }

  .med-picked,
  .issue-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .issue-actions button,
  .issue-actions a,
  .med-picked button {
    width: 100%;
  }

  .col-optional {
    display: none;
  }
}

.stock-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin: 0 0 0.35rem;
}

.stock-tools input,
.stock-tools button {
  margin: 0;
  width: auto;
}

.stock-tools input {
  max-width: 7.5rem;
}

@media (max-width: 600px) {
  main.container {
    padding-left: 0.8rem;
    padding-right: 0.8rem;
  }

  h1 {
    font-size: 1.45rem;
  }
}
