/* Visual language adapted from the supplied Stitch screens.
   Keep this file presentational: application state and controls stay in app.js/index.html. */
:root {
  color-scheme: light;
  --ink: #10253b;
  --muted: #526477;
  --line: #dbe5f3;
  --paper: #ffffff;
  --canvas: #f7f8ff;
  --green: #006b62;
  --green-dark: #00564f;
  --green-soft: #dcf7f1;
  --orange: #a45a08;
  --orange-soft: #fff1d6;
  --red: #b4232f;
  font-family: "Atkinson Hyperlegible Next", "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body,
.auth-screen { background: var(--canvas); }

h1, h2, h3, .brand, .medicine-title, .medicine-name {
  font-family: "Atkinson Hyperlegible Next", "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.sidebar {
  background: #eff4ff;
  border-color: #d8e4f5;
  box-shadow: 1px 0 10px rgb(16 37 59 / 4%);
}

.topbar {
  background: rgb(255 255 255 / 88%);
  border-color: var(--line);
  backdrop-filter: blur(12px);
}

.nav-link { border-radius: 12px; }
.nav-link.active {
  color: #fff;
  background: var(--green);
}
.nav-link.active .nav-icon { color: #fff; }
.nav-link:hover:not(.active) { color: var(--green-dark); background: #e4edf9; }

.space-switcher,
.botiquin-switcher-menu,
.settings-card,
.inventory-panel,
.overview-panel,
.calendar-panel,
.treatment-card,
.treatment-empty,
.care-profile-card,
.medicine-row,
.profile-management,
.members-management,
.summary-card {
  border-color: var(--line);
  border-radius: 20px;
  box-shadow: 0 5px 20px rgb(26 55 88 / 6%);
}

.content-wrap { width: 100%; max-width: 1600px; }
.settings-grid { max-width: none; }
.page-heading { margin-bottom: 24px; }
h1 { color: var(--ink); letter-spacing: -.035em; }
.eyebrow { color: #526477; }
.page-intro { color: var(--muted); }

.button { min-height: 44px; border-radius: 14px; }
.button-primary {
  color: #fff;
  background: var(--green);
  box-shadow: 0 4px 12px rgb(0 107 98 / 18%);
}
.button-primary:hover { background: var(--green-dark); }
.inventory-cima-button { min-width: 190px; min-height: 48px; box-shadow: 0 5px 14px rgb(0 107 98 / 22%); }
.inventory-cima-button:hover { box-shadow: 0 7px 17px rgb(0 107 98 / 28%); transform: translateY(-1px); }
.button-secondary {
  color: #334b62;
  border-color: var(--line);
  background: #fff;
}
.button-secondary:hover { border-color: #9eb6d2; background: #f4f7ff; }

input:not([type="checkbox"]), select, textarea {
  border-color: #c8d7eb;
  border-radius: 12px;
}
input:not([type="checkbox"]):focus, select:focus, textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgb(0 107 98 / 13%);
}

.inventory-panel, .overview-panel, .calendar-panel, .settings-card,
.profile-management, .treatment-card, .treatment-empty {
  background: var(--paper);
}
.inventory-list, .table-head, .filter-tabs, .inventory-bulk-bar,
.calendar-toolbar, .panel-footer {
  background: #f5f7ff;
  border-color: var(--line);
}
.medicine-row, .care-profile-card, .calendar-day, .upcoming-take,
.overview-entry, .members-management,
.profile-management form {
  border-color: var(--line);
  border-radius: 16px;
  box-shadow: 0 3px 12px rgb(26 55 88 / 5%);
}
.medicine-row:hover, .care-profile-card:hover, .calendar-day:hover,
.upcoming-take:hover, .overview-entry:hover { border-color: #9fb8d7; }
.filter-tab.selected { color: #fff; background: var(--green); border-color: var(--green); }
.filter-tab.selected span { color: inherit; }
.nav-icon, .active .nav-icon { color: var(--green); }
.nav-link.active .nav-icon { color: #fff; }

.summary-low-stock, .overview-metric-blue {
  color: #154f9e;
  background: #e8f0ff;
  border-color: #c9daf8;
}
.summary-expiring, .overview-metric-orange {
  color: #8a4b08;
  background: #fff2db;
  border-color: #f2d4a5;
}
html:not([data-theme="dark"]) .summary-low-stock :is(.summary-caption, .summary-label) { color: #24548d; }
html:not([data-theme="dark"]) .summary-expiring :is(.summary-caption, .summary-label) { color: #834606; }
html:not([data-theme="dark"]) .overview-metric-blue small { color: #24548d; }
html:not([data-theme="dark"]) .overview-metric-orange small { color: #834606; }
html:not([data-theme="dark"]) .summary-low-stock .low-icon { color: #174f9f; background: #d4e4ff; }
html:not([data-theme="dark"]) .summary-expiring .expiry-icon { color: #995107; background: #ffe1b3; }
html:not([data-theme="dark"]) .summary-low-stock.is-selected { box-shadow: 0 0 0 1px #84afea, 0 8px 20px rgb(26 55 88 / 10%); }
html:not([data-theme="dark"]) .summary-expiring.is-selected { box-shadow: 0 0 0 1px #e7b675, 0 8px 20px rgb(26 55 88 / 10%); }
html:not([data-theme="dark"]) .summary-low-stock:focus-visible { outline-color: #17569e; }
html:not([data-theme="dark"]) .summary-expiring:focus-visible { outline-color: #995107; }
.summary-primary, .overview-metric-green {
  color: #2f3c51;
  background: #ebeef2;
  border-color: #d4d9e2;
}
.summary-primary :is(.summary-trend, .summary-label) { color: #3b4a64; }
.summary-primary .inventory-icon { color: #36445c; background: #d7dce4; }
.summary-primary .summary-decoration { color: #b1b9c7; }
.summary-primary.is-selected { box-shadow: 0 0 0 1px #d1d7e1, 0 8px 20px rgb(26 55 88 / 10%); }
.summary-primary:hover { border-color: #485a7a; box-shadow: 0 9px 20px rgb(48 60 81 / 0.25); }
.summary-primary.is-selected:hover { box-shadow: 0 9px 20px rgb(48 60 81 / 0.25); }
.summary-primary:focus-visible { outline-color: #6a80a7; }
.overview-metric-green small { color: #3b4a64; }
.overview-metric-sage {
  color: #554071;
  background: #f0eafa;
  border-color: #ddcfed;
}
.overview-metric-sage small { color: #715b8b; }
.overview-metric-sage:focus-visible { outline-color: #8c73aa; }
.overview-metric { transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease; }
.overview-metric-green:hover { border-color: #485a7a; box-shadow: 0 10px 22px rgb(48 60 81 / 0.25); }
.overview-metric-blue:hover { border-color: #194d87; box-shadow: 0 10px 22px rgb(36 93 155 / 25%); }
.overview-metric-orange:hover { border-color: #8e390a; box-shadow: 0 10px 22px rgb(168 70 13 / 25%); }
.overview-metric-sage:hover { border-color: #8c73aa; box-shadow: 0 10px 22px rgb(74 52 102 / 22%); }
.overview-metric-green:focus-visible { outline-color: #485a7a; }
.overview-metric-blue:focus-visible { outline-color: #194d87; }
.overview-metric-orange:focus-visible { outline-color: #8e390a; }
.overview-metric-sage:focus-visible { outline-color: #8c73aa; }

.dialog-content, dialog, .lot-dialog {
  border-color: var(--line);
  border-radius: 22px;
  box-shadow: 0 18px 48px rgb(16 37 59 / 18%);
}
#presentation-dialog.lot-dialog { width: min(1440px, calc(100vw - 40px)); max-height: min(94dvh, 1120px); }
#presentation-dialog.lot-dialog form { padding: 32px; }
#presentation-dialog .cima-search-results { max-height: min(440px, 44dvh); }
#presentation-dialog .cima-search-controls input,
#presentation-dialog .cima-search-controls .button { min-height: 104px; font-size: 16px; }
#presentation-dialog .cima-search-controls input { min-height: 104px; height: 104px !important; font-size: 16px; }
#presentation-dialog .manual-entry-fields > input,
#presentation-dialog .initial-stock-fields input,
#presentation-dialog .initial-stock-fields select { min-height: 46px; font-size: 14px; }
#treatment-dialog.treatment-dialog { width: min(1120px, calc(100vw - 32px)); max-height: min(92vh, 960px); }
#treatment-dialog #treatment-form { padding: 32px; }
#treatment-dialog .field-label,
#treatment-dialog .weekday-fieldset legend { font-size: 13px; }
#treatment-dialog input:not([type="checkbox"]),
#treatment-dialog select { min-height: 48px; font-size: 14px; }
#treatment-dialog textarea { min-height: 110px; padding: 12px; font-size: 14px; }
#treatment-dialog .weekday-options { gap: 10px; }
#treatment-dialog .weekday-options span { width: 46px; height: 46px; font-size: 13px; }
#treatment-dialog .field-help,
#treatment-dialog .essential-toggle small { font-size: 12px; }
#treatment-dialog .dialog-actions .button { min-height: 48px; }

@media (max-width: 620px) {
  .inventory-search-row { flex-wrap: wrap; }
  .inventory-search-row .search-box { flex: 1 1 100%; }
  .inventory-cima-button { width: 100%; min-height: 44px; }
  #presentation-dialog.lot-dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  #presentation-dialog.lot-dialog form { padding: 18px; }
  #presentation-dialog .cima-search-results { max-height: min(34dvh, 250px); }
  #treatment-dialog.treatment-dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  #treatment-dialog #treatment-form { padding: 18px; }
  #treatment-dialog .weekday-options { gap: 7px; }
  #treatment-dialog .weekday-options span { width: 40px; height: 40px; }
}

@media (max-width: 850px) {
  .topbar { background: rgb(255 255 255 / 94%); }
  .content-wrap { padding-top: 28px; }
  .button { min-height: 46px; }
}

@media (max-width: 620px) {
  body { font-size: 15px; }
  .content-wrap { padding: 22px 16px calc(88px + env(safe-area-inset-bottom)); }
  .page-heading { gap: 14px; }
  .page-heading h1 { font-size: clamp(25px, 7vw, 32px); }
  .heading-actions { flex-wrap: wrap; }
  .summary-grid { gap: 10px; }
  .summary-card, .overview-panel, .calendar-panel, .treatment-card,
  .treatment-empty, .profile-management { border-radius: 18px; }
  .main-nav { border-color: var(--line); background: #fff; }
}

html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #ecf2ff;
  --muted: #b5c3d7;
  --line: #34445a;
  --paper: #182536;
  --canvas: #101a28;
  --green: #19a99a;
  --green-dark: #42c8b7;
  --green-soft: #163d3c;
  --orange: #f3ae50;
  --orange-soft: #49351f;
  --red: #ff8c91;
}

html[data-theme="dark"] body,
html[data-theme="dark"] .auth-screen { color: var(--ink); background: var(--canvas); }
html[data-theme="dark"] :is(.sidebar, .topbar, .auth-card, .settings-card, .inventory-panel, .overview-panel, .calendar-panel, .treatment-card, .treatment-empty, .care-profile-card, .medicine-row, .botiquin-switcher-menu, .dialog-content, dialog, .lot-detail-row, .movement-row, .calendar-take, .overview-entry, .profile-management, .auth-session, .auth-account-heading) {
  color: var(--ink);
  background: var(--paper);
  border-color: var(--line);
}
html[data-theme="dark"] :is(.sidebar, .filter-tabs, .inventory-list, .inventory-bulk-bar, .panel-footer, .table-head, .calendar-toolbar, .calendar-day-panel, .main-nav, .create-botiquin-form, .help-card, .search-box, .space-switcher, .botiquin-switcher-choice, .profile-avatar-button, .overview-empty) {
  color: var(--ink);
  background: #202f43;
  border-color: var(--line);
}
html[data-theme="dark"] :is(.nav-link.active, .filter-tab.selected) { color: #fff; background: #087d74; }
html[data-theme="dark"] :is(.nav-link.active .nav-icon, .filter-tab.selected span) { color: #fff; }
html[data-theme="dark"] :is(.button-secondary, .filter-tab, .calendar-nav-button, .calendar-today-button, .mobile-settings-link) {
  color: #e5edfb;
  background: #26374d;
  border-color: #455a74;
}
html[data-theme="dark"] :is(input:not([type="checkbox"]), select, textarea) {
  color: var(--ink);
  background: #111e2e;
  border-color: #526a88;
}
html[data-theme="dark"] :is(.calendar-profile-trigger, .calendar-profile-options) { color: var(--ink); background: #202f43; border-color: var(--line); }
html[data-theme="dark"] .calendar-profile-option:hover,
html[data-theme="dark"] .calendar-profile-option[aria-selected="true"] { color: #e5edfb; background: #2b4462; }
html[data-theme="dark"] :is(h1, h2, h3, .medicine-title, .medicine-name, .summary-number, .stock-cell strong) { color: #f1f5ff; }
html[data-theme="dark"] :is(.page-intro, .eyebrow, .summary-label, .field-label, .cell-caption, .breadcrumbs, .nav-label) { color: #b5c3d7; }
html[data-theme="dark"] :is(.summary-low-stock, .overview-metric-blue) { color: #dbe9ff; background: #1b365a; border-color: #355b8d; }
html[data-theme="dark"] :is(.summary-expiring, .overview-metric-orange) { color: #ffdfae; background: #49351f; border-color: #79542b; }
html[data-theme="dark"] :is(.summary-primary, .overview-metric-green) { color: #eceef2; background: #222b3a; border-color: #38465f; }
html[data-theme="dark"] .summary-primary :is(.summary-trend, .summary-label) { color: #d3d9e2; }
html[data-theme="dark"] .summary-primary .inventory-icon { color: #eceef2; background: #35435b; }
html[data-theme="dark"] .summary-primary .summary-decoration { color: #54698e; }
html[data-theme="dark"] .summary-primary.is-selected { box-shadow: 0 0 0 1px #4a5e7f, 0 8px 20px #0005; }
html[data-theme="dark"] .summary-low-stock.is-selected { box-shadow: 0 0 0 1px #86aee4, 0 8px 20px #0005; }
html[data-theme="dark"] .summary-expiring.is-selected { box-shadow: 0 0 0 1px #d18c4b, 0 8px 20px #0005; }
html[data-theme="dark"] .summary-primary:hover { border-color: #8390a6; box-shadow: 0 9px 20px #0005; }
html[data-theme="dark"] .summary-primary.is-selected:hover { box-shadow: 0 9px 20px #0005; }
html[data-theme="dark"] .overview-metric-green small { color: #d3d9e2; }
html[data-theme="dark"] .overview-metric-blue small { color: #c4d9fa; }
html[data-theme="dark"] .overview-metric-orange small { color: #f4c98f; }
html[data-theme="dark"] .overview-metric-sage { color: #f0e8fa; background: #382d48; border-color: #5a486e; }
html[data-theme="dark"] .overview-metric-sage small { color: #d5c5e8; }
html[data-theme="dark"] .overview-metric-sage:hover { background: #443654; border-color: #b39acb; box-shadow: 0 10px 22px #0005; }
html[data-theme="dark"] .overview-metric-sage:focus-visible { outline-color: #b59bd1; }
html[data-theme="dark"] .overview-metric-green:hover { border-color: #8390a6; box-shadow: 0 10px 22px #0005; }
html[data-theme="dark"] .overview-metric-blue:hover { border-color: #86aee4; box-shadow: 0 10px 22px #0005; }
html[data-theme="dark"] .overview-metric-orange:hover { border-color: #d18c4b; box-shadow: 0 10px 22px #0005; }
html[data-theme="dark"] .overview-metric-green:focus-visible { outline-color: #8390a6; }
html[data-theme="dark"] .overview-metric-blue:focus-visible { outline-color: #86aee4; }
html[data-theme="dark"] .overview-metric-orange:focus-visible { outline-color: #d18c4b; }

.person-detail-header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin: 0 0 18px; padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); box-shadow: 0 6px 18px rgb(16 37 59 / 6%); }
.treatment-detail-navigation { padding-block: 12px; }
.treatment-card.is-detail { grid-column: 1 / -1; }
.profile-management #create-profile-form { order: 0; }
.profile-management .users-list-title { order: 1; margin: 4px 0 0; font-size: 18px; }
.profile-management #profile-management-list { order: 2; }
.profile-management .members-management { order: 3; }
.profile-management #profile-management-message { order: 4; }
.person-detail-header > div { flex: 1; min-width: 160px; }
.person-detail-header h2 { margin: 3px 0 0; }
.profile-open-button { margin-left: auto; white-space: nowrap; }
.care-profile-card .profile-caregiver-controls .text-button { font-weight: 700; }
.care-profile-identity { gap: 12px; flex-wrap: wrap; }
.treatment-group-heading { grid-column: 1 / -1; margin: 12px 0 0; color: var(--ink); font-size: 16px; }
.treatment-card.is-compact .treatment-schedule,
.treatment-card.is-compact .treatment-instructions,
.treatment-card.is-compact .treatment-card-actions { display: none; }
.treatment-card.is-compact .treatment-schedule-row { display: none; }
.treatment-card.is-compact, .care-profile-card { cursor: pointer; }
.treatment-open-button { margin-top: 14px; }
.take-status { display: inline-block; padding: 7px 10px; border-radius: 8px; color: var(--muted); background: var(--canvas); font-weight: 700; }
html[data-theme="dark"] .person-detail-header { background: #202f43; border-color: #455a74; }
html[data-theme="dark"] .take-status { background: #26374d; }
@media (max-width: 650px) {
  .person-detail-header { align-items: stretch; }
  .person-detail-header > div { order: -1; flex-basis: 100%; }
  .person-detail-header > .button { flex: 1; }
  .profile-open-button { width: 100%; }

  .care-profile-heading { display: grid; grid-template-columns: 56px minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
  .care-profile-identity { display: contents; }
  .care-profile-identity strong { grid-column: 2 / -1; grid-row: 1; }
  .care-profile-identity .profile-open-button { grid-column: 2; grid-row: 2; width: 100%; min-height: 44px; min-width: 0; margin: 0; padding-inline: 7px; white-space: normal; }
  .care-profile-heading > .remove-profile-button { grid-column: 3; grid-row: 2; width: 100%; min-height: 44px; min-width: 0; padding: 6px; border-radius: 14px; font-size: 10px; }
  .treatment-schedule-row { align-items: flex-start; flex-wrap: wrap; gap: 12px; }
  .treatment-schedule { flex-basis: 100%; }
  .treatment-card-actions { width: 100%; }
  .treatment-card-actions > .button { min-width: 0; flex: 1; padding-inline: 8px; }
}
html[data-theme="dark"] :is(.medicine-row:hover, .care-profile-card:hover, .calendar-day:hover, .upcoming-take:hover, .overview-entry:hover, .nav-link:hover:not(.active)) { background: #26374d; }

/* Inventario compacto: controles visibles y filtros adaptables. */
.inventory-search-row { padding: 10px 22px; }
.inventory-counter-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 9px 22px; border-bottom: 1px solid var(--line); }
.inventory-counter { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 38px; padding: 6px 13px; border: 1px solid var(--line); border-radius: 11px; color: var(--ink); background: var(--paper); box-shadow: 0 2px 8px rgb(26 55 88 / 5%); cursor: pointer; font: 700 12px/1.2 "Atkinson Hyperlegible Next", sans-serif; }
.inventory-counter strong { display: inline-grid; min-width: 23px; min-height: 23px; place-items: center; border-radius: 7px; color: var(--green-dark); background: #e9ecf0; font-size: 12px; }
.inventory-counter:hover, .inventory-counter:focus-visible { border-color: var(--green); box-shadow: 0 3px 12px rgb(0 107 98 / 13%); }
.inventory-counter.is-selected { color: #fff; border-color: var(--green); background: var(--green); }
.inventory-counter.is-selected strong { color: var(--green-dark); background: #fff; }
html[data-theme="dark"] .inventory-counter { color: var(--ink); background: #26374d; border-color: #455a74; }
html[data-theme="dark"] .inventory-counter.is-selected { color: #fff; background: #087d74; border-color: #087d74; }
html[data-theme="dark"] .inventory-counter strong { color: #e7f6f3; background: #365d59; }
html[data-theme="dark"] .inventory-counter.is-selected strong { color: #00564f; background: #fff; }
@media (max-width: 620px) {
  .inventory-search-row { padding: 10px 14px; }
  .inventory-counter-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; padding: 8px 12px; }
  .inventory-counter { min-width: 0; min-height: 50px; flex-direction: column; gap: 2px; padding: 6px 3px; text-align: center; font-size: 10px; }
  .inventory-counter strong { min-width: 19px; min-height: 19px; font-size: 10px; }
}

/* La lista de escritorio comparte una sola cuadrícula con sus encabezados. */
.medicine-meta-row { display: contents; }
@media (min-width: 851px) {
  .inventory-list { display: block; padding: 0; background: var(--paper); }
  .table-head, .medicine-row { grid-template-columns: 24px minmax(0, 1fr) repeat(3, 130px); column-gap: 18px; padding-inline: 18px; }
  .table-head { min-height: 42px; color: #253244; background: #fff; border-bottom: 1px solid #dbe5f3; letter-spacing: .2px; }
  .status-cell { justify-self: stretch; align-items: center; }
  .medicine-row { height: 70px; min-height: 70px; border: 0; border-bottom: 1px solid #e5eaf1; border-radius: 0; background: #fff; box-shadow: none; transform: none; }
  .medicine-row:last-of-type { border-bottom: 0; }
  .medicine-row:hover { border-color: #dbe5f3; background: #f8faff; box-shadow: none; transform: none; }
  .medicine-symbol { color: #536171; background: #edf0f4; }
  .medicine-copy { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; }
  .medicine-title-wrap { grid-column: 1; grid-row: 1; }
  .medicine-actions { grid-column: 2; grid-row: 1; flex-wrap: nowrap; margin-right: 38px; white-space: nowrap; }
  .medicine-name-button small, .leaflet-link { color: #253244; background: #fff; border-color: #cbd3dd; box-shadow: none; }
  .medicine-name-button:hover small, .medicine-name-button:focus-visible small, .leaflet-link:hover { color: #101b28; background: #eef1f5; border-color: #9daab9; box-shadow: none; }
}
@media (min-width: 851px) and (max-width: 1170px) {
  .table-head, .medicine-row { grid-template-columns: 24px minmax(200px, 1fr) repeat(3, minmax(90px, 115px)); column-gap: 12px; }
  .medicine-copy { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
  .medicine-actions { flex-wrap: nowrap; margin-right: 0; }
  .medicine-row { height: 84px; min-height: 84px; }
}
@media (max-width: 850px) {
  .inventory-list { display: grid; gap: 7px; padding: 7px; }
  .medicine-row { height: auto; min-height: 82px; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 3px 12px rgb(26 55 88 / 5%); }
}
html[data-theme="dark"] .inventory-list { background: #202f43; }
@media (max-width: 620px) {
  .topbar .breadcrumbs, .topbar .local-simulator-banner { display: none; }
  .topbar-actions { width: 100%; justify-content: flex-end; }
  .topbar .notification-button { margin-right: auto; }
}
@media (max-width: 620px) {
  .medicine-row {
    grid-template-columns: 22px 32px minmax(0, 1fr) 72px;
    column-gap: 6px;
    row-gap: 7px;
    min-height: 0;
    padding: 10px 8px;
  }
  .medicine-select { grid-column: 1; grid-row: 1; }
  .medicine-name-cell, .medicine-copy { display: contents; }
  .medicine-symbol { grid-column: 2; grid-row: 1; align-self: start; }
  .medicine-title-wrap { grid-column: 3; grid-row: 1; align-self: start; }
  .stock-cell { grid-column: 4; grid-row: 1; }
  .medicine-meta-row { display: flex; grid-column: 2 / -1; grid-row: 2; align-items: center; gap: 6px; min-width: 0; }
  .medicine-actions { flex: 0 0 auto; flex-wrap: nowrap; gap: 4px; white-space: nowrap; }
  .medicine-name-button small, .leaflet-link { padding-inline: 6px; }
  .mobile-status { display: flex; flex: 1 1 auto; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 3px; min-width: 0; margin: 0; }
  .mobile-status .cell-caption { display: none; }
  .mobile-status .status-badge { padding-inline: 5px; font-size: 10px; }
  .expiry-cell { grid-column: 2 / -1; grid-row: 3; flex-direction: row; align-items: baseline; flex-wrap: wrap; gap: 4px 7px; }
}
@media (min-width: 851px) {
  html[data-theme="dark"] .table-head { color: #e6edf5; background: #202f43; border-color: #455a74; }
  html[data-theme="dark"] .medicine-row { background: #202f43; border-color: #394c63; box-shadow: none; }
  html[data-theme="dark"] .medicine-row:hover { background: #26374d; }
  html[data-theme="dark"] .medicine-symbol { color: #d0dbe8; background: #34475c; }
  html[data-theme="dark"] .medicine-format, html[data-theme="dark"] .stock-cell span { color: #b7c6d7; }
  html[data-theme="dark"] .expiry-cell strong { color: #eef4fa; }
  html[data-theme="dark"] .medicine-name-button small, html[data-theme="dark"] .leaflet-link { color: #e5edfb; background: #26374d; border-color: #52667e; box-shadow: none; }
  html[data-theme="dark"] .medicine-name-button:hover small, html[data-theme="dark"] .leaflet-link:hover { color: #fff; background: #344b65; border-color: #9bb0c8; }
}

/* Controles táctiles legibles en todas las vistas. */
.button { font-size: 14px; line-height: 1.25; text-align: center; }
.heading-actions .button, .page-heading .button { min-height: 48px; font-size: 14px; }
.take-action { min-height: 36px; font-size: 12px; }
.medicine-name-button small, .leaflet-link { min-height: 31px; font-size: 11px; }
.cima-result strong { font-size: 13px; }
.inventory-search-row .search-box { height: 64px; gap: 12px; }
.inventory-search-row .search-box > span { display: grid; flex: 0 0 48px; width: 48px; height: 48px; place-items: center; border-radius: 12px; color: var(--green); background: #eaedf1; font-size: 31px; transform: none; }
.inventory-search-row .search-box input { height: 100%; font-size: 17px; }
.inventory-cima-button { min-height: 52px; font-size: 15px; }
.delete-selected-button { min-height: 44px; padding-inline: 14px; font-size: 14px; }
.inventory-counter { font-size: 13px; }
.table-head > span:not(:empty) { width: auto; padding: 0; border: 0; border-radius: 0; color: #344153; background: transparent; box-shadow: none; font-size: 11px; letter-spacing: .2px; }
.table-head > span:nth-child(2) { margin-left: 49px; }
.table-head > span:last-child { justify-self: center; }
.notification-button { min-height: 44px; font-size: 13px; }
.remove-profile-button { min-height: 34px; font-size: 12px; }
.notification-button .notification-mark i { background: #c94c4c; }
.notification-button.is-enabled .notification-mark i { background: #40516e; }
.care-profile-card .profile-caregiver-list li { font-size: 12px; }
.care-profile-card .profile-caregiver-list li span { min-width: 0; overflow-wrap: anywhere; font-weight: 700; }
.care-profile-card .profile-caregiver-list li .text-button,
.care-profile-card .profile-caregiver-controls .text-button { font-size: 12px; font-weight: 700; }
.sidebar-bottom #settings-nav-link {
  min-height: 42px;
  margin: 0;
  padding: 4px 8px;
  border: 0;
  border-radius: 12px;
  color: #526477;
  background: transparent;
  box-shadow: none;
}
.sidebar-bottom #settings-nav-link .nav-icon {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  color: var(--green-dark);
  background: #e8eaef;
  box-shadow: 0 2px 7px rgb(48 60 81 / 0.12);
  font-size: 16px;
}
.sidebar-bottom #settings-nav-link:hover,
.sidebar-bottom #settings-nav-link:focus-visible {
  color: var(--green-dark);
  background: #f1f3f6;
  box-shadow: 0 3px 10px rgb(48 60 81 / 0.1);
  transform: none;
}
.sidebar-bottom #settings-nav-link.active {
  color: var(--green-dark);
  background: #eceef2;
  box-shadow: 0 3px 10px rgb(48 60 81 / 0.1);
}
@media (min-width: 851px) {
  .sidebar { padding: 30px 18px 22px; }
  .sidebar .brand { gap: 12px; margin: 3px 0 34px 7px; font-size: 25px; }
  .sidebar .brand-mark { width: 36px; height: 36px; border-radius: 11px; }
  .sidebar .brand-mark span:first-child { top: 5px; left: 15px; width: 6px; height: 26px; }
  .sidebar .brand-mark span:last-child { top: 15px; left: 5px; width: 26px; height: 6px; }
  .sidebar .botiquin-switcher-wrap { margin-bottom: 30px; }
  .sidebar .space-switcher { min-height: 68px; gap: 12px; padding: 11px; border-radius: 15px; }
  .sidebar .space-avatar { width: 40px; height: 40px; border-radius: 13px; font-size: 15px; }
  .sidebar .space-copy strong { font-size: 14px; }
  .sidebar .space-copy small { font-size: 11px; }
  .sidebar .chevron { font-size: 19px; }
  .sidebar .nav-label { margin: 0 0 12px 12px; font-size: 10px; }
  .sidebar .main-nav { gap: 6px; }
  .sidebar .main-nav .nav-link { min-height: 48px; gap: 14px; padding-inline: 13px; border-radius: 13px; font-size: 14px; }
  .sidebar .main-nav .nav-icon { width: 22px; font-size: 21px; }
  .sidebar-bottom { gap: 9px; }
  .sidebar-bottom #settings-nav-link { min-height: 48px; gap: 12px; padding-inline: 7px; font-size: 14px; }
  .sidebar-bottom #settings-nav-link .nav-icon { width: 34px; height: 34px; border-radius: 10px; font-size: 18px; }
  .sidebar-bottom .account-row { gap: 11px; padding-left: 7px; }
  .sidebar-bottom .account-row .person-avatar { width: 36px; height: 36px; font-size: 13px; }
  .sidebar-bottom .account-row strong { font-size: 13px; }
  .sidebar-bottom .account-row small { font-size: 11px; }
}
@media (min-width: 621px) {
  .care-profile-heading.with-remove-profile { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .care-profile-heading.with-remove-profile .care-profile-identity { display: contents; }
  .care-profile-heading.with-remove-profile .existing-profile-avatar { grid-column: 1; grid-row: 1; }
  .care-profile-heading.with-remove-profile .care-profile-identity strong { grid-column: 1 / -1; grid-row: 1; align-self: center; margin-left: 52px; }
  .care-profile-heading.with-remove-profile .profile-open-button,
  .care-profile-heading.with-remove-profile > .remove-profile-button { grid-row: 2; width: 100%; min-width: 0; min-height: 44px; margin: 0; padding: 8px; border-radius: 14px; font-size: 14px; line-height: 1.2; text-align: center; white-space: normal; }
  .care-profile-heading.with-remove-profile .profile-open-button { grid-column: 1; }
  .care-profile-heading.with-remove-profile > .remove-profile-button { grid-column: 2; }
  .care-profile-heading.with-remove-profile + .profile-caregiver-list,
  .care-profile-card:has(.with-remove-profile) .profile-caregiver-controls { margin-left: 0; }
}
.calendar-nav-button, .calendar-today-button { min-width: 44px; min-height: 44px; }
.calendar-today-button, .calendar-profile-trigger { font-size: 14px; }
.calendar-profile-trigger { min-height: 44px; }
.calendar-profile-option { min-height: 44px; font-size: 14px; }
html[data-theme="dark"] .inventory-search-row .search-box > span { color: #c8cfdb; background: #30465a; }
html[data-theme="dark"] .table-head > span:not(:empty) { color: #e3ebf5; background: transparent; border: 0; }
@media (max-width: 620px) {
  .inventory-search-row .search-box > span { flex-basis: 44px; width: 44px; height: 44px; font-size: 28px; }
  .delete-selected-button { min-height: 48px; font-size: 14px; }
  .medicine-meta-row { display: grid; grid-column: 1 / -1; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
  .medicine-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); min-width: 0; gap: 4px; white-space: normal; }
  .medicine-actions > :only-child { grid-column: 1 / -1; }
  .medicine-actions .medicine-name-button, .medicine-actions .medicine-name-button small, .medicine-actions .leaflet-link { width: 100%; min-width: 0; max-width: 100%; justify-content: center; text-align: center; white-space: normal; line-height: 1.15; }
  .mobile-status { width: 100px; flex: none; }
  .main-nav .nav-link { font-size: 11px; }
  .calendar-month-controls h2 { min-width: 0; font-size: 16px; }
}

@media (max-width: 620px) {
  .sidebar { gap: 8px; padding-inline: 12px; }
  .sidebar .brand { flex: 0 0 auto; gap: 9px; font-size: clamp(21px, 5.9vw, 24px); letter-spacing: -.05em; }
  .sidebar .brand-mark { flex: 0 0 auto; width: clamp(30px, 8vw, 34px); height: clamp(30px, 8vw, 34px); border-radius: 10px; }
  .sidebar .brand-mark span:first-child { top: 15%; left: 41%; width: 18%; height: 70%; }
  .sidebar .brand-mark span:last-child { top: 41%; left: 15%; width: 70%; height: 18%; }
  .sidebar .botiquin-switcher-wrap { flex: 1 1 0; width: auto; max-width: 230px; min-width: 0; margin-left: auto; }
  .sidebar .space-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .overview-grid { grid-auto-rows: 1fr; }
  .overview-metric { min-width: 0; min-height: 132px; padding: 14px; }
  .overview-metric span { font-size: 13px; line-height: 1.3; }
  .overview-metric strong { font-size: 30px; }
  .overview-metric small { margin-top: 6px; font-size: 12px; line-height: 1.25; white-space: normal; }
  .inventory-counter-row { align-items: stretch; }
  .inventory-counter { height: 100%; min-height: 68px; justify-content: flex-start; gap: 5px; padding-block: 8px 6px; line-height: 1.1; }
  .inventory-counter strong { min-width: 28px; min-height: 28px; border-radius: 8px; font-size: 16px; font-weight: 800; }
  .care-profile-heading { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; gap: 8px; }
  .care-profile-heading .existing-profile-avatar { grid-column: 1; grid-row: 1; }
  .care-profile-identity strong { grid-column: 1 / -1; grid-row: 1; align-self: center; margin-left: 56px; }
  .care-profile-identity .profile-open-button,
  .care-profile-heading > .remove-profile-button { grid-row: 2; width: 100%; min-height: 48px; margin: 0; padding: 7px; border-radius: 14px; font-size: 13px; line-height: 1.2; text-align: center; }
  .care-profile-identity .profile-open-button { grid-column: 1; }
  .care-profile-heading > .remove-profile-button { grid-column: 2; }
  .care-profile-card .profile-caregiver-list,
  .care-profile-card .profile-caregiver-controls { margin-left: 0; }
  .care-profile-card .profile-caregiver-list li { padding-inline: 0; }
  .care-profile-card .profile-caregiver-list li span { padding-left: 3px; }
  .care-profile-card .profile-caregiver-list li .text-button { margin-right: 3px; }
  .topbar .notification-button,
  .topbar .notification-button:hover { min-height: 44px; height: auto; padding: 0 6px; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
  .topbar .notification-button:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 8px; }
}

/* En móvil apaisado la navegación lateral puede desplazarse dentro de su propia columna. */
@media (orientation: landscape) and (max-height: 600px) and (pointer: coarse) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 180px;
    height: 100vh;
    height: 100dvh;
    gap: 7px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    scrollbar-width: thin;
  }
  .sidebar .brand { margin: 0 0 5px 3px; font-size: 19px; }
  .sidebar .brand-mark { width: 27px; height: 27px; }
  .sidebar .botiquin-switcher-wrap { width: 100%; max-width: none; margin: 0 0 5px; }
  .sidebar .space-switcher { min-height: 40px; gap: 7px; padding: 5px; }
  .sidebar .space-avatar { width: 27px; height: 27px; }
  .sidebar .space-copy strong { font-size: 10px; }
  .sidebar .space-copy small { font-size: 9px; }
  .sidebar .nav-label { margin: 2px 0 4px 7px; font-size: 8px; }
  .sidebar .main-nav { position: static; display: flex; flex: 0 0 auto; flex-direction: column; gap: 3px; overflow: visible; padding: 0; border: 0; background: transparent; box-shadow: none; backdrop-filter: none; }
  .sidebar .main-nav .nav-link { min-height: 36px; flex-direction: row; justify-content: flex-start; gap: 9px; padding: 5px 8px; border-radius: 9px; font-size: 11px; }
  .sidebar .nav-icon,
  .sidebar #treatments-nav-link .nav-icon,
  .sidebar-bottom #settings-nav-link .nav-icon { width: 18px; height: 18px; flex: 0 0 18px; font-size: 16px; line-height: 1; }
  .sidebar .nav-label { display: block; }
  .sidebar .sidebar-bottom { display: grid; gap: 6px; margin-top: auto; }
  .sidebar-bottom #settings-nav-link { min-height: 38px; margin: 5px 0 0; padding-inline: 8px; font-size: 11px; }
  .sidebar-bottom .account-row { gap: 7px; padding-left: 4px; }
  .sidebar-bottom .account-row .person-avatar { width: 27px; height: 27px; }
  .sidebar-bottom .account-row strong { font-size: 10px; }
  .sidebar-bottom .account-row small { font-size: 9px; }
  .main-content { margin-left: 180px; }
  .topbar { padding-inline: 18px; }
  .content-wrap { padding: 22px 18px 30px; }
}
