: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);
}

body[data-page="admin"] main {
  max-width: 1180px;
  padding: 16px 12px 36px;
}

.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;
}

.session-bar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.session-bar span {
  color: rgba(255, 255, 255, 0.86);
  font-size: 14px;
  font-weight: 800;
}

.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;
}

.login-shell {
  align-items: flex-start;
  display: flex;
  min-height: 100dvh;
  padding: 16px;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: 0 auto;
  max-width: 440px;
  padding: 18px;
  width: 100%;
}

.login-brand {
  align-items: flex-start;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 22px;
}

.login-brand .brand-logo {
  height: 62px;
  width: 62px;
}

.login-brand h1 {
  color: var(--ink);
  font-size: 25px;
  line-height: 1.12;
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-error {
  color: var(--danger);
  font-size: 14px;
  min-height: 20px;
  margin: 0;
}

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

.admin-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(15, 78, 141, 0.08);
  overflow: hidden;
  padding: 14px;
}

.admin-card .section-head {
  margin-bottom: 12px;
}

.admin-card h2 {
  font-size: 22px;
}

.admin-user-form {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.admin-user-form input,
.admin-user-form select,
.admin-edit,
.admin-password {
  min-width: 0;
  width: 100%;
}

.admin-table-wrap {
  box-shadow: none;
  margin-left: -14px;
  margin-right: -14px;
  width: calc(100% + 28px);
}

.admin-table-wrap table {
  min-width: 720px;
}

.admin-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  flex-wrap: wrap;
  gap: 8px;
}

.toggle-label {
  align-items: center;
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.toggle-label input {
  width: auto;
}

.admin-lists {
  display: grid;
  gap: 16px;
}

.admin-lists h3 {
  font-size: 16px;
  margin: 0 0 10px;
}

.admin-list-item {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 4px;
  padding: 10px 0;
}

.admin-list-item strong {
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.admin-list-item:last-child {
  border-bottom: 0;
}

.admin-list-item span,
.muted-small {
  color: var(--muted);
  font-size: 13px;
}

.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: 78px 138px 150px auto;
  min-width: 470px;
}

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

.add-medicine-form {
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  grid-template-columns: 120px 170px minmax(240px, 1fr) 120px 145px 120px 135px minmax(160px, 1fr) auto;
  margin-bottom: 16px;
  padding: 16px;
}

.add-medicine-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: 1580px;
}

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

.request-history-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: 1220px;
}

.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;
  }

  .add-medicine-form {
    grid-template-columns: 1fr;
  }

  body[data-page="admin"] .session-bar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  body[data-page="admin"] .session-bar span {
    grid-column: 1 / -1;
  }

  body[data-page="admin"] .nav-link {
    padding: 0 10px;
    width: 100%;
  }

  body[data-page="admin"] .summary-item {
    min-width: 0;
    padding: 10px;
    white-space: normal;
  }
}

@media (min-width: 761px) {
  .login-shell {
    align-items: center;
    padding: 24px;
  }

  .login-card {
    padding: 28px;
  }

  .login-brand {
    align-items: center;
    flex-direction: row;
    margin-bottom: 24px;
  }

  .login-brand .brand-logo {
    height: 76px;
    width: 76px;
  }

  .login-brand h1 {
    font-size: 28px;
  }

  .admin-card {
    padding: 22px;
  }

  body[data-page="admin"] main {
    padding: 28px clamp(16px, 4vw, 40px) 48px;
  }

  .admin-summary {
    display: flex;
  }

  .admin-table-wrap {
    margin-left: 0;
    margin-right: 0;
    width: 100%;
  }

  .admin-user-form {
    grid-template-columns: 1.2fr 1fr 1fr 1fr auto;
    align-items: end;
  }

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

/* ───────────── Pedidos agrupados por sala + mes (Control) ───────────── */
#pedidos-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.pedido-card {
  display: grid;
  gap: 8px;
  text-align: left;
  background: var(--panel, #fff);
  border: 1px solid var(--line, #d7e3ec);
  border-left: 4px solid var(--primary, #0f4e8d);
  border-radius: 10px;
  box-shadow: var(--shadow, 0 10px 28px rgba(15,78,141,.08));
  padding: 14px 16px;
  cursor: pointer;
  min-height: auto;
  color: var(--ink, #102f4d);
  transition: transform .12s ease, box-shadow .12s ease;
}
.pedido-card:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(15,78,141,.16); }
.pedido-card-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pedido-card-row strong { font-size: 1.05rem; }
.pedido-card-mes { color: var(--muted, #5f7890); font-weight: 700; font-size: .9rem; text-transform: capitalize; }
.pedido-card-sub { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted, #5f7890); font-size: .85rem; font-weight: 700; }
.pedido-count { color: var(--primary, #0f4e8d); }
.pedido-badge {
  font-size: .72rem; font-weight: 900; letter-spacing: .04em;
  padding: 4px 10px; border-radius: 999px; text-transform: uppercase;
}
.pedido-badge.abierto { background: #e6f7ec; color: #1f8a4c; border: 1px solid #b7e4c7; }
.pedido-badge.cerrado { background: #eef1f4; color: #6c7480; border: 1px solid #d7dde4; }
.pedido-detail-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.pedido-detail-head h2 { margin: 0; font-size: 1.2rem; }
#pedido-back { min-height: 40px; }
@media (min-width: 700px) {
  #pedidos-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1050px) {
  #pedidos-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
