:root {
  color-scheme: light;
  --bg: #f3f7fa;
  --panel: #ffffff;
  --ink: #102f4d;
  --muted: #5f7890;
  --line: #d7e3ec;
  --primary: #0f4e8d;
  --primary-dark: #11487c;
  --primary-soft: #e7f1fa;
  --accent: #6f9fbe;
  --danger: #a73838;
  --danger-bg: #fff0f0;
  --soft: #eaf3f9;
  --shadow: 0 18px 45px rgba(15, 78, 141, 0.11);
  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(--ink);
}

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

.topbar {
  align-items: center;
  background: linear-gradient(135deg, #0f4e8d 0%, #123f6c 100%);
  color: white;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 56px);
}

.brand {
  align-items: center;
  display: flex;
  gap: 16px;
  min-width: 0;
}

.brand-logo {
  background: white;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(5, 26, 45, 0.18);
  height: 76px;
  object-fit: contain;
  padding: 8px;
  width: 76px;
}

.eyebrow {
  color: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 4px;
  opacity: 0.72;
  text-transform: uppercase;
}

h1,
h2 {
  letter-spacing: 0;
  line-height: 1.1;
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
}

h2 {
  font-size: clamp(24px, 3vw, 34px);
}

main {
  margin: 0 auto;
  max-width: 1240px;
  padding: 28px clamp(16px, 4vw, 40px) 48px;
}

body[data-page="control"] main {
  max-width: none;
  padding-left: clamp(12px, 2vw, 28px);
  padding-right: clamp(12px, 2vw, 28px);
}

.tabs,
.actions,
.filters,
.summary,
.control-tabs {
  display: flex;
  gap: 10px;
}

.tabs {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 4px;
}

.tab,
button,
.nav-link {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 800;
  min-height: 42px;
  padding: 0 18px;
}

.nav-link {
  align-items: center;
  background: white;
  color: var(--primary);
  display: inline-flex;
  justify-content: center;
  text-decoration: none;
}

.tab {
  background: transparent;
  color: white;
}

.tab.is-active {
  background: white;
  color: var(--primary);
}

.control-tabs {
  margin: 0 0 16px;
}

.control-tab {
  background: #edf4f9;
  color: var(--ink);
}

.control-tab.is-active {
  background: var(--primary);
  color: white;
}

.control-panel {
  display: none;
}

.control-panel.is-active {
  display: block;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.section-head {
  align-items: end;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.section-head .eyebrow {
  color: var(--primary);
}

.status-pill,
.summary-item {
  background: var(--primary-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--primary-dark);
  font-weight: 800;
  margin: 0;
  padding: 10px 14px;
  white-space: nowrap;
}

.form-grid,
.filters,
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.form-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 22px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 800;
  gap: 7px;
}

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

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 78, 141, 0.16);
  outline: none;
}

.span-2 {
  grid-column: span 2;
}

.actions {
  align-items: center;
  justify-content: flex-end;
}

button {
  background: var(--primary);
  color: white;
}

button:hover {
  background: var(--primary-dark);
}

button.secondary {
  background: #edf4f9;
  color: var(--ink);
}

button.secondary:hover {
  background: #dceaf4;
}

button.danger {
  background: var(--danger-bg);
  color: var(--danger);
}

button.danger:hover {
  background: #ffdede;
}

.compact button {
  min-height: 38px;
}

.stock-head {
  align-items: end;
  margin-top: 6px;
}

.stock-search {
  min-width: min(360px, 100%);
}

.stock-entry-form {
  display: grid;
  gap: 8px;
  grid-template-columns: 86px 142px auto;
  min-width: 320px;
}

.stock-entry-form button {
  min-height: 44px;
  padding: 0 12px;
}

.filters {
  align-items: end;
  box-shadow: none;
  display: grid;
  grid-template-columns: 180px 180px minmax(220px, 1fr);
  margin-bottom: 16px;
  padding: 16px;
}

.summary {
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.table-wrap {
  overflow-x: auto;
  width: 100%;
}

table {
  border-collapse: collapse;
  min-width: 980px;
  width: 100%;
}

body[data-page="control"] table {
  min-width: 1280px;
}

#stock-panel table {
  min-width: 1500px;
}

#history-panel table {
  min-width: 1180px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f7fbfd;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.medicine-cell {
  min-width: 340px;
}

.state-select {
  min-width: 128px;
}

.delivery-date {
  min-width: 142px;
}

.delivery-qty {
  min-width: 96px;
}

#stock-panel .medicine-cell {
  min-width: 420px;
}

#stock-panel th:nth-child(9),
#stock-panel td:nth-child(9) {
  background: #f3f9fd;
  color: var(--primary-dark);
  font-weight: 900;
}

#history-panel th:nth-child(8),
#history-panel td:nth-child(8) {
  background: #f3f9fd;
  color: var(--primary-dark);
  font-weight: 900;
}

.entries-head {
  margin-top: 24px;
}

.entries-wrap table {
  min-width: 980px;
}

.empty-row {
  color: var(--muted);
  padding: 28px 12px;
  text-align: center;
}

.toast {
  background: #0f4e8d;
  border-radius: 8px;
  bottom: 18px;
  color: white;
  left: 50%;
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.site-footer {
  display: flex;
  justify-content: center;
  padding: 0 clamp(16px, 4vw, 40px) 28px;
}

.credit-widget {
  align-items: center;
  background: white;
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 10px 26px rgba(15, 78, 141, 0.09);
  color: var(--muted);
  display: inline-flex;
  font-size: 13px;
  font-weight: 800;
  gap: 9px;
  padding: 8px 14px 8px 8px;
}

.credit-mark {
  align-items: center;
  background: var(--primary);
  border-radius: 999px;
  color: white;
  display: inline-flex;
  font-size: 12px;
  height: 28px;
  justify-content: center;
  width: 28px;
}

@media (max-width: 760px) {
  .topbar,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .brand {
    align-items: center;
  }

  .brand-logo {
    height: 58px;
    width: 58px;
  }

  .tabs {
    width: 100%;
  }

  .tab {
    flex: 1;
  }

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

  .span-2 {
    grid-column: span 1;
  }

  .actions {
    flex-direction: column-reverse;
  }

  .actions button {
    width: 100%;
  }

  .control-tabs {
    flex-direction: column;
  }

  .stock-entry-form {
    grid-template-columns: 1fr;
    min-width: 190px;
  }
}
