/*
 * Synaptia's component layer. The shell block below is the CSS Shell used to
 * inline on every render (legacy/synaptia/ui.php at 637058c), moved to a file
 * so it is cached and so a component can rely on it. The component rules after
 * it are this layer's own: they style the classes under src/Infra/Http/View.
 *
 * Loaded after Bootstrap (which is still linked) and before each migrated
 * screen's own stylesheet, so a migrated screen can still override.
 */

/* --- base --------------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--syn-font);
  font-size: 15px;
  line-height: 1.4;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { text-decoration: none; }

/* --- application shell -------------------------------------------------- */
.syn-app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.syn-app-shell button,
.syn-app-shell input,
.syn-app-shell select,
.syn-app-shell textarea {
  font-family: inherit;
}

.syn-app-shell button,
.syn-app-shell .btn,
.syn-app-shell [role="button"] {
  vertical-align: middle;
}

.syn-app-shell .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
}

.syn-global-topbar {
  min-height: 74px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid #d8dee9;
  display: grid;
  grid-template-columns: auto auto minmax(200px, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 10px 22px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.syn-brand {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 52px;
  padding: 0 18px 0 0;
  background: transparent;
  border: 0;
  border-right: 1px solid #d8dee9;
  box-shadow: none;
}

.syn-brand-logo {
  display: block;
  width: 220px;
  height: 52px;
  object-fit: contain;
  object-position: left center;
  border-radius: 0;
}

.syn-topnav {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: max-content;
}

.syn-nav-item {
  min-height: 38px;
  border-radius: 8px;
  padding: 8px 13px;
  color: #24324b;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  line-height: 1.15;
  font-weight: 700;
  white-space: nowrap;
}

.syn-nav-item:hover { color: #071f4f; background: #eef4ff; }
.syn-nav-item.active { color: #084f9a; background: #e4edff; box-shadow: none; }

.syn-main-area {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.syn-global-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-width: 0;
  position: relative;
}

.syn-global-search input {
  width: 100%;
  height: 40px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 0 13px;
  background: #fbfcfe;
  font-size: 14px;
  line-height: 1.2;
}

.syn-global-search input:focus {
  outline: none;
  border-color: #8bb8f5;
  box-shadow: var(--syn-focus);
}

.syn-search-suggestions {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 360px;
  overflow: auto;
  display: none;
  padding: 6px;
  border: 1px solid #d8dee9;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(24, 32, 51, .14);
  z-index: 50;
}

.syn-search-suggestions.show { display: grid; gap: 4px; }

.syn-search-option {
  min-height: 54px;
  padding: 9px 10px;
  border-radius: 9px;
  display: grid;
  gap: 2px;
  color: #24324b;
  text-decoration: none;
}

.syn-search-option:hover,
.syn-search-option:focus { outline: none; background: #eef4ff; color: #084f9a; }
.syn-search-option strong { font-size: 14px; line-height: 1.2; }
.syn-search-option span { color: #667085; font-size: 12px; line-height: 1.25; }
.syn-search-empty { padding: 10px; color: #667085; font-size: 13px; }

.syn-global-context {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 22px;
  background: #f8fafc;
  border-bottom: 1px solid #e5e9f0;
  color: #667085;
  font-size: 13px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.syn-global-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  white-space: nowrap;
}

.syn-global-actions .btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1.15;
}

.syn-global-actions .syn-current-patient {
  background: #168a4b;
  border-color: #168a4b;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 5px 14px rgba(22, 138, 75, .24);
}

.syn-global-actions .syn-current-patient:hover,
.syn-global-actions .syn-current-patient:focus {
  background: #10743d;
  border-color: #10743d;
  color: #fff;
}

.syn-config-menu { position: relative; }

.syn-icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
  color: #344054;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.syn-icon-button:hover { background: #eef4ff; color: #084f9a; border-color: #b7cdf2; }
.syn-icon-button svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.syn-config-menu summary { list-style: none; cursor: pointer; }
.syn-config-menu summary::-webkit-details-marker { display: none; }
.syn-config-menu[open] summary { background: #eef4ff; color: #084f9a; }

.syn-config-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 210px;
  padding: 7px;
  border: 1px solid #d8dee9;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(24, 32, 51, .14);
  display: grid;
  gap: 4px;
  z-index: 160;
}

.syn-config-popover a {
  min-height: 34px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  padding: 7px 9px;
  color: #24324b;
  text-decoration: none;
  font-weight: 650;
}

.syn-config-popover a:hover { background: #f3f7fc; color: #084f9a; }

.syn-config-popover .syn-user-block {
  padding: 8px 9px 9px;
  border-bottom: 1px solid #eef2f7;
  display: grid;
  gap: 2px;
  color: #667085;
  font-size: 12px;
}

.syn-config-popover .syn-user-block strong { color: #182033; font-size: 14px; }
.syn-config-popover a.danger { color: #b42318; background: #fff7f7; }
.syn-config-popover a.danger:hover { color: #991b1b; background: #ffe8e5; }

@media (max-width: 1120px) {
  .syn-global-topbar { grid-template-columns: 1fr; position: static; gap: 10px; }
  .syn-brand { border-right: 0; padding-right: 0; }
  .syn-topnav { overflow-x: auto; padding-bottom: 2px; }
  .syn-global-context { white-space: normal; }
  .syn-global-actions { justify-content: flex-start; flex-wrap: wrap; }
  .syn-search-suggestions { right: 0; }
}

/* --- page scaffold ------------------------------------------------------ */
.syn-main-area { padding: 18px 22px 40px; }

.syn-page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 18px;
}

.syn-page-heading { min-width: 0; }
.syn-page-title { font-size: 1.35rem; font-weight: 700; color: var(--ink); margin: 0; }
.syn-page-subtitle { font-size: 13px; margin-top: 2px; }
.syn-page-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.syn-empty {
  color: var(--muted);
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: var(--syn-radius);
  padding: 18px;
}

.syn-hint { color: var(--muted); font-size: 12px; }

/* --- components --------------------------------------------------------- */
.syn-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1.15;
  vertical-align: middle;
}

.syn-btn--sm { min-height: 32px; }

.syn-badge {
  display: inline-flex;
  align-items: center;
  border-radius: var(--syn-radius-sm);
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
}

.syn-badge--ok { background: var(--green-soft); color: var(--green); border-color: #c8ebda; }
.syn-badge--info { background: var(--blue-soft); color: #084f9a; border-color: #bfdbff; }
.syn-badge--warn { background: var(--amber-soft); color: var(--amber); border-color: #ffd98a; }
.syn-badge--danger { background: var(--red-soft); color: var(--red); border-color: #ffc9c2; }
.syn-badge--neutral { background: #eef2f7; color: #475467; border-color: var(--line); }

.syn-fact {
  min-height: 54px;
  border: 1px solid #e5e9f0;
  border-radius: var(--syn-radius-sm);
  padding: 8px 10px;
  background: #fbfcfe;
}

.syn-fact.missing { border-color: #ffb4a8; background: #fff0ed; box-shadow: inset 4px 0 0 #f04438; }
.syn-fact.missing .fact-label,
.syn-fact.missing .fact-value { color: #9f1f17; }
.syn-fact .fact-label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 3px; }
.syn-fact .fact-value { display: block; font-weight: 700; overflow-wrap: anywhere; }

.syn-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.syn-item {
  border: 1px solid #e5e9f0;
  border-radius: var(--syn-radius-sm);
  padding: 10px;
  background: #fff;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.syn-item__body { min-width: 0; }
.syn-item__title { font-weight: 750; margin-bottom: 2px; }

.syn-definition { width: 100%; border-collapse: collapse; }
.syn-definition th,
.syn-definition td { text-align: left; padding: 8px 0; border-bottom: 1px solid #eef2f7; vertical-align: top; }
.syn-definition th { color: var(--muted); font-size: 12px; font-weight: 700; width: 34%; }
.syn-definition tr:last-child th,
.syn-definition tr:last-child td { border-bottom: 0; }

.syn-avatar {
  width: 58px;
  height: 58px;
  border-radius: var(--syn-radius);
  background: #10294f;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
}

.syn-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.syn-pagination__links { display: flex; gap: 8px; }
/* --- surfaces ----------------------------------------------------------- */
/* The canonical card and panel the components render. A migrated screen
   relies on these instead of its own former block. */
.syn-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--syn-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.syn-card-header {
  min-height: 48px;
  padding: 12px 14px;
  border-bottom: 1px solid #e5e9f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.syn-card-body { padding: 14px; }
.syn-title { margin: 0; font-size: 17px; font-weight: 750; }
.syn-card-heading { min-width: 0; }
.syn-card-subtitle { font-size: 13px; margin-top: 2px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--syn-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  padding: 14px 16px;
  border-bottom: 1px solid #e5e9f0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.panel-head h1,
.panel-head h2 { margin: 0; font-size: 20px; }

.panel-body { padding: 16px; }

/* --- form fields -------------------------------------------------------- */
.syn-field { display: grid; gap: 5px; }
.syn-field label { color: var(--muted); font-size: 12px; font-weight: 750; }
.syn-field input,
.syn-field select,
.syn-field textarea {
  min-height: var(--syn-field-height);
  border: 1px solid #cbd5e1;
  border-radius: var(--syn-radius-sm);
  padding: 0 10px;
  background: #fff;
  width: 100%;
}

.syn-field textarea { min-height: 96px; padding: 8px 10px; }

/* Standalone controls, for a form that composes Input/Select/Textarea directly
   rather than through Field. */
.syn-input,
.syn-select,
.syn-textarea {
  min-height: var(--syn-field-height);
  border: 1px solid #cbd5e1;
  border-radius: var(--syn-radius-sm);
  padding: 0 10px;
  background: #fff;
  width: 100%;
}

.syn-textarea { min-height: 72px; padding: 8px 10px; resize: vertical; }
.missing-input { border-color: #ff9b8e; background: #fff8f6; }

.syn-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.syn-muted { color: var(--muted); }
.syn-small { font-size: 13px; }

/* --- generic scaffold --------------------------------------------------- */
/* These were Shell's inline "port CSS", emitted only for a screen with no
   stylesheet of its own (Home) and used by the migrated screens. */
.syn-app-shell h2 { font-size: 1.05rem; color: #24324b; margin: 24px 0 10px; font-weight: 700; }
.syn-app-shell .cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 18px; }
.syn-app-shell .card { background: #fff; border: 1px solid var(--line); border-radius: var(--syn-radius-lg); padding: 14px 16px; }
.syn-app-shell .card .n { font-size: 1.5rem; font-weight: 800; color: var(--ink); }
.syn-app-shell .card .l { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }
.syn-app-shell .muted { color: var(--muted); }
.syn-app-shell .ok { color: #10743d; }
.syn-app-shell .warn { color: #8a5a00; }
.syn-app-shell .danger { color: #b42318; }
.syn-app-shell .neutral { color: var(--muted); }
.syn-app-shell .pill { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: var(--syn-radius-pill); font-size: .75rem; font-weight: 700; background: #eef4ff; color: #084f9a; }
.syn-app-shell .pill.warn { background: var(--amber-soft); color: var(--amber); }
.syn-app-shell form.search { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.syn-app-shell form.search input,
.syn-app-shell form.search select { min-height: 38px; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--syn-radius-sm); background: #fff; }
.syn-app-shell button { min-height: 38px; }

.syn-alert { border-radius: var(--syn-radius); }
.syn-alert--success { background: var(--green-soft); color: #0f5132; border: 1px solid #badbcc; }
.syn-alert--danger { background: var(--red-soft); color: #842029; border: 1px solid #f5c2c7; }
.syn-alert--warning { background: var(--amber-soft); color: #664d03; border: 1px solid #ffecb5; }
.syn-alert--info { background: var(--blue-soft); color: #055160; border: 1px solid #b6effb; }

.syn-table { margin-bottom: 0; }
.syn-disclosure > summary { list-style: none; cursor: pointer; }
.syn-disclosure > summary::-webkit-details-marker { display: none; }

/* One editor, with a prescription sheet assembled alongside it. */
.rx-composer { display: grid; gap: 24px; margin-top: 24px; }
.rx-composer.is-enhanced { grid-template-columns: minmax(0,1fr) minmax(320px,.9fr); align-items: start; }
.rx-composer-editor,.rx-composer-side { min-width: 0; }
.rx-composer-heading { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.rx-composer-heading h3 { margin: 0 0 4px; font-size: 19px; font-weight: 650; }
.rx-composer-heading p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.rx-step { flex-shrink: 0; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--blue-soft); color: var(--blue-dark); font-size: 12px; font-weight: 700; }
.rx-composer-side { position: sticky; top: 100px; }
.rx-composer-preview { padding: 20px; border-radius: 18px; background: var(--soft); border: 1px solid var(--line); }
.rx-preview-count { margin-left: auto; white-space: nowrap; color: var(--muted); font-size: 12px; font-weight: 600; }
.rx-prescription-paper { padding: 24px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.rx-paper-heading { display: flex; justify-content: space-between; gap: 12px; border-bottom: 2px solid var(--ink); padding-bottom: 16px; margin-bottom: 20px; font-size: 11px; letter-spacing: .08em; color: var(--muted); }
.rx-paper-heading span:first-child { font-weight: 700; color: var(--ink); letter-spacing: .14em; }
.rx-paper-patient { display: block; font-size: 17px; font-weight: 650; }
.rx-paper-meta { margin: 6px 0 16px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.rx-paper-diagnosis { font-size: 13px; border-top: 1px solid var(--line); padding-top: 12px; overflow-wrap: anywhere; }
.rx-preview-empty { min-height: 220px; display: grid; justify-items: center; align-content: center; gap: 10px; text-align: center; color: var(--muted); }
.rx-preview-empty > span { display: grid; place-items: center; height: 44px; width: 44px; border-radius: 50%; background: var(--blue-soft); font-size: 24px; color: var(--blue-dark); }
.rx-preview-empty strong { color: var(--ink); font-size: 14px; font-weight: 600; }
.rx-preview-empty p { margin: 0; max-width: 220px; font-size: 13px; line-height: 1.6; }
.rx-preview-items { list-style: none; margin: 0; padding: 0; }
.rx-preview-item { display: grid; grid-template-columns: 24px minmax(0,1fr); gap: 10px; padding: 20px 0; border-top: 1px solid var(--line); animation: rx-arrive .2s ease-out; }
.rx-item-number { color: var(--blue-dark); font-size: 12px; font-weight: 700; padding-top: 3px; }
.rx-item-content { display: grid; gap: 6px; min-width: 0; }
.rx-item-name { font-size: 15px; font-weight: 650; overflow-wrap: anywhere; }
.rx-item-presentation,.rx-item-quantity { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.rx-item-dosage { font-size: 13px; line-height: 1.5; margin: 4px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.rx-item-actions { display: flex; gap: 16px; }
.rx-item-action { border: 0; padding: 3px 0; min-height: 28px !important; background: transparent; color: var(--blue-dark); font-size: 12px; font-weight: 600; cursor: pointer; }
.rx-item-action[data-rx-remove] { color: var(--red); }
.rx-paper-footer { display: flex; flex-wrap: wrap; gap: 8px 14px; color: var(--muted); font-size: 11px; padding-top: 16px; border-top: 1px solid var(--line); margin-top: 12px; }
.rx-composer-controls { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 20px; margin-top: 16px; border-top: 1px solid var(--line); }
.rx-composer-message { font-size: 13px; color: var(--green); margin: 0 0 12px; }
.rx-composer-message:empty { display: none; }
.rx-composer-message.is-error { color: var(--red); }
.rx-composer-limit { padding: 24px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); line-height: 1.6; }
.rx-composer.is-enhanced .med-card { background: transparent; border: 0; padding: 0; margin: 0; }
.rx-composer.is-enhanced .rx-actions { flex-wrap: wrap; align-items: center; margin-top: 16px; border: 0; padding: 0; }
.rx-composer.is-enhanced .rx-actions > .btn { width: 100%; min-height: 44px; }
.rx-composer [hidden] { display: none !important; }
@keyframes rx-arrive { from { opacity: .4; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .rx-preview-item { animation: none; } }
@media (max-width: 1050px) { .rx-composer.is-enhanced { grid-template-columns: minmax(0,1fr); } .rx-composer-side { position: static; } }
@media (max-width: 600px) { .rx-prescription-paper { padding: 18px; } .rx-composer-preview { padding: 16px; } }

.rehabilitation-actions [hidden] { display: none !important; }
.rehabilitation-actions button.success { color: #18794e; }
.rehabilitation-actions button.danger { color: #b42318; }
