:root {
  --protocol-drawer-width: 460px;
  --ink: #17211d;
  --muted: #68756f;
  --line: #dde5e1;
  --soft: #f3f7f5;
  --paper: #fbfcfb;
  --white: #fff;
  --green: #176b52;
  --green-dark: #0d4f3b;
  --green-pale: #e5f2ed;
  --amber: #a96812;
  --shadow: 0 18px 50px rgba(25, 48, 39, .09);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { width: 100%; max-width: 100%; overflow-x: hidden; }
body { margin: 0; padding-top: 92px; color: var(--ink); background: var(--paper); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.app-shell {
  display: grid; grid-template-columns: 292px minmax(0, 1fr); min-height: calc(100vh - 92px);
  background: linear-gradient(165deg, #123f32, #0b2e25 72%) left top / 292px 100% no-repeat;
}
.sidebar {
  position: fixed; top: 92px; bottom: 0; left: 0; z-index: 6;
  width: 292px; height: auto; display: flex; flex-direction: column;
  padding: 24px 18px 16px; color: #edf7f2;
  background: linear-gradient(165deg, #123f32, #0b2e25 72%);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 24px; }
.sidebar > .brand { display: none; }
.brand-mark {
  width: 38px; height: 58px; display: block;
  object-fit: contain; background: transparent;
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; letter-spacing: .01em; }
.brand span { margin-top: 3px; color: #a9c8bb; font-size: 12px; }
.search { position: relative; display: block; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 14px; }
.mode-switch button { border: 1px solid rgba(255,255,255,.12); border-radius: 9px; padding: 9px; color: #9fbaaf; background: transparent; font-size: 12px; font-weight: 700; }
.mode-switch button.active { color: #143b30; background: #bfe5d5; }
.mobile-protocol-toggle { display: none; }
.search span { position: absolute; left: 13px; top: 9px; color: #9ab8ac; font-size: 19px; }
.search input {
  width: 100%; border: 1px solid rgba(255,255,255,.12); border-radius: 11px;
  padding: 10px 12px 10px 38px; color: white; outline: none; background: rgba(255,255,255,.07);
}
.search input::placeholder { color: #91ada2; }
.search input:focus { border-color: #83bda7; background: rgba(255,255,255,.1); }
.library-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin: 15px 0 10px; padding: 4px; border-radius: 10px; background: rgba(0,0,0,.13); }
.library-switch button {
  min-height: 58px;
  border: 0;
  border-radius: 7px;
  padding: 8px;
  color: #9fbaaf;
  background: transparent;
  font-size: 12px;
  line-height: 1.2;
}
.library-switch button.active { color: #133b2f; background: #dcece5; font-weight: 700; }
.library-switch span { display: block; margin-top: 3px; opacity: .7; }
.protocol-list { min-height: 0; overflow-y: auto; margin-right: -6px; padding-right: 6px; }
.protocol-row { position: relative; }
.protocol-row.has-error { display: grid; grid-template-columns: minmax(0,1fr) 30px; gap: 4px; align-items: center; }
.protocol-item {
  width: 100%; display: block; border: 0; border-radius: 10px; padding: 10px 11px;
  color: #d6e7df; text-align: left; background: transparent;
}
.protocol-item:hover { background: rgba(255,255,255,.07); }
.protocol-item.active { color: white; background: rgba(163, 220, 196, .17); box-shadow: inset 3px 0 #86d0b1; }
.protocol-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.protocol-item small { display: block; margin-top: 4px; color: #8faea1; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.protocol-error-delete {
  width: 30px; height: 30px; border: 1px solid rgba(255,164,151,.25); border-radius: 8px;
  color: #efb2aa; background: rgba(145,45,35,.18); font-size: 20px; line-height: 1;
}
.protocol-error-delete:hover { color: white; background: #8f392f; }
.sidebar-foot { margin-top: auto; padding: 14px 6px 0; color: #8dac9f; font-size: 11px; }
.sidebar-foot button { width: 100%; margin-bottom: 13px; border: 1px solid rgba(255,255,255,.12); border-radius: 8px; padding: 8px; color: #bdd2c9; background: transparent; font-size: 11px; }
.sidebar-author { color: #bdd2c9; line-height: 1.45; }
.sidebar-action { width: 100%; margin: 0 0 9px; border: 1px solid rgba(180,230,208,.25); border-radius: 9px; padding: 9px; color: #dff3ea; background: rgba(125,196,166,.12); font-weight: 700; font-size: 12px; }
.sidebar-action.service-offline { border-color: #c9a35a; color: #f1d49b; }
.workspace { grid-column: 2; min-width: 0; }
body.protocol-info-open .workspace {
  margin-right: var(--protocol-drawer-width);
}
.topbar {
  position: static; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  min-height: 92px; padding: 20px 34px; border-bottom: 1px solid var(--line); background: rgba(251,252,251,.94); backdrop-filter: blur(12px);
}
body[data-mode="calculator"] .editor-topbar { display: none; }
.editor-topbar {
  min-height: 70px;
  padding: 12px 24px;
  gap: 18px;
}
.eyebrow { margin-bottom: 5px; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
h1 { margin: 0; font-family: Georgia, serif; font-size: 27px; font-weight: 500; letter-spacing: -.02em; }
.top-actions { display: flex; align-items: center; gap: 9px; }
.calculator-actionbar {
  min-height: 70px;
  padding: 12px 24px;
  gap: 18px;
}
.calculator-actionbar > div:first-child {
  flex: 1;
  min-width: 0;
  max-width: none;
}
.calculator-actionbar .eyebrow {
  margin-bottom: 3px;
  font-size: 9px;
}
.calculator-actionbar h1 {
  font-size: 20px;
  line-height: 1.15;
  white-space: normal;
}
.editor-topbar .eyebrow {
  margin-bottom: 3px;
  font-size: 9px;
}
.editor-topbar h1 {
  font-size: 20px;
  line-height: 1.15;
}
.editor-topbar .button {
  font-size: 11px;
}
.editor-topbar .change-state {
  font-size: 11px;
}
.calculator-top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.calculator-top-actions .button {
  padding: 8px 12px;
  white-space: nowrap;
  font-size: 11px;
}
.change-state { margin-right: 8px; color: var(--muted); font-size: 12px; }
.change-state.dirty { color: var(--amber); font-weight: 700; }
.button { border: 1px solid transparent; border-radius: 10px; padding: 10px 16px; font-weight: 700; font-size: 13px; }
.button:disabled { cursor: default; opacity: .42; }
.button.primary { color: white; background: var(--green); box-shadow: 0 7px 18px rgba(23,107,82,.17); }
.button.primary:hover:not(:disabled) { background: var(--green-dark); }
.button.secondary { border-color: #ced9d4; color: #34453e; background: white; }
.button.ghost { color: var(--green); background: transparent; }
.button.danger { border-color: #eccfca; color: #9c382f; background: #fff8f7; }
.empty-state { max-width: 520px; margin: 18vh auto; text-align: center; }
.empty-symbol { width: 76px; height: 76px; display: grid; place-items: center; margin: auto; border: 1px solid #c9ddd4; border-radius: 24px; color: var(--green); background: var(--green-pale); font-family: Georgia, serif; font-size: 26px; }
.empty-state h2 { margin: 22px 0 8px; font-family: Georgia, serif; font-size: 25px; font-weight: 500; }
.empty-state p { color: var(--muted); line-height: 1.65; }
.hidden { display: none !important; }
.editor { padding: 0 34px 54px; }
.calculator { max-width: 1180px; padding: 28px 34px 54px; }
#calculator-result, #calculator-result.with-preview { width: 100%; }
.calculator-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 20px; align-items: start; }
.calculator-stack { display: grid; gap: 20px; }
.schema-box { white-space: pre-wrap; border-radius: 10px; padding: 15px; color: #3f564c; background: #eff6f3; line-height: 1.55; font-size: 13px; }
.drawer-overlay {
  position: fixed; inset: 92px 0 0; z-index: 40;
  pointer-events: none;
}
.protocol-info-drawer {
  width: var(--protocol-drawer-width); height: 100%; margin-left: auto; overflow-y: auto;
  pointer-events: auto; padding: 22px; border-left: 1px solid var(--line);
  background: var(--paper); box-shadow: -10px 0 28px rgba(25, 48, 39, .10);
}
.drawer-head {
  position: sticky; top: -22px; z-index: 2; display: flex; align-items: center;
  justify-content: space-between; gap: 18px; margin: -22px -22px 18px; padding: 17px 22px;
  border-bottom: 1px solid var(--line); background: rgba(251,252,251,.97);
}
.drawer-head h2 { margin: 0; font-family: Georgia, serif; font-size: 21px; font-weight: 500; }
.drawer-close {
  width: 34px; height: 34px; border: 1px solid #ced9d4; border-radius: 9px;
  color: #52645c; background: white; font-size: 23px; line-height: 1;
}
.drawer-close:hover { color: var(--green-dark); border-color: #8eb7a6; }
.protocol-info-content .card { margin: 0; }
.backup-settings {
  margin-top: 24px; border: 1px solid var(--line); border-radius: 13px;
  padding: 18px; background: var(--soft);
}
.backup-settings .section-head { margin-bottom: 14px; padding-bottom: 13px; }
.backup-components {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 18px;
}
.backup-components .check-line { margin: 0; padding: 8px 10px; border-radius: 8px; background: white; }
.backup-components .backup-all {
  grid-column: 1 / -1; color: var(--green-dark); background: var(--green-pale); font-weight: 800;
}
.backup-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 15px; }
.backup-status { margin-top: 13px; }
.form-stack { display: grid; gap: 14px; }
.date-input-wrap { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 46px; gap: 7px; }
.date-input-wrap > input[type="text"] { width: 100%; }
.calendar-button {
  border: 1px solid #c9d9d2; border-radius: 9px; color: var(--green);
  background: var(--green-pale); font-size: 19px; font-weight: 800;
}
.calendar-button:hover { border-color: #70a992; background: #d9eee5; }
.native-date-picker {
  position: absolute; right: 4px; bottom: 0; width: 1px; height: 1px;
  padding: 0; border: 0; opacity: 0; pointer-events: none;
}
.check-line { display: flex; align-items: center; gap: 9px; color: #485a52; font-size: 13px; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.protocol-preview { max-height: 540px; overflow: auto; white-space: pre-wrap; border-radius: 9px; padding: 15px; background: #f6f8f7; font-family: "Segoe UI", sans-serif; font-size: 13px; line-height: 1.55; }
.prescription-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.prescription-table td { border: 1px solid var(--line); padding: 7px; white-space: pre-wrap; }
.download-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 16px; }
.save-file-rows { display: grid; gap: 10px; margin-top: 16px; }
.result-save-card { width: 100%; }
.next-patient-button { width: 100%; margin-top: 16px; }
.web-result-documents { display: grid; gap: 20px; margin-top: 18px; }
.web-document-card { overflow: hidden; }
.web-document-card .section-head { gap: 16px; }
.web-protocol-editor {
  width: 100%; min-height: 360px; resize: vertical; border: 1px solid var(--line); border-radius: 10px;
  padding: 16px; color: #273b33; background: #fbfdfc; font-family: "Segoe UI", sans-serif;
  font-size: 14px; line-height: 1.6; white-space: pre-wrap;
}
.web-prescription-document {
  width: 267mm; max-width: none; min-height: 180mm; margin: 0;
  margin-left: max(0px, calc((100% - 267mm) / 2)); border: 1px solid var(--line);
  border-radius: 4px; padding: 0; color: #000; background: white; font-family: Arial, sans-serif;
  font-size: 9pt; line-height: 1.15;
}
.web-prescription-body {
  max-height: min(78vh, 900px); overflow: auto; overscroll-behavior: contain;
  scrollbar-gutter: stable both-edges;
}
.web-editable { outline: 0; }
.web-editable:hover, .web-editable:focus { background: #fff7d6; box-shadow: 0 0 0 2px #efd879; }
.web-document-readonly:hover, .web-document-readonly:focus { background: inherit; box-shadow: none; }
.web-protocol-editor.web-document-readonly { cursor: default; background: #fbfdfc; }
.word-title-table, .word-prescription-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.word-title-table td, .word-title-table th,
.word-prescription-table td, .word-prescription-table th {
  border: .75pt solid #000; padding: 1.3mm 1mm; color: #000; background: #fff;
  font-weight: 400; vertical-align: top; white-space: pre-wrap; overflow-wrap: anywhere;
}
.word-title-table .word-institution-cell { width: 52.38%; line-height: 1.2; }
.word-title-table .word-form-identity { width: 47.62%; text-align: center; line-height: 1.25; }
.word-title-table .word-document-title { padding: 2mm 1mm; text-align: center; font-weight: 700; }
.word-execution-title { padding: 2.2mm 1mm 1.7mm; text-align: center; font-weight: 700; }
.word-prescription-table col { width: 4.7619%; }
.word-prescription-table th { text-align: left; }
.word-prescription-table td, .word-prescription-table th { height: 7mm; padding: .8mm .65mm; }
.word-prescription-table .word-drug-cell { vertical-align: middle; }
.word-prescription-table .word-role-cell { vertical-align: middle; text-align: center; }
.word-prescription-table .word-mark-cell { vertical-align: middle; text-align: center; font-weight: 700; }
.word-table-spacer { height: 4mm; }
.word-prescription-table-wrap { width: 100%; overflow: visible; }
.web-prescription-comments {
  margin-top: 4mm; white-space: pre-wrap; line-height: 1.3;
}
.save-file-row {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(140px, .45fr);
  gap: 10px; align-items: center;
}
.save-file-row .button { text-align: center; }
.tabs { display: flex; gap: 26px; border-bottom: 1px solid var(--line); }
.tabs button { position: relative; border: 0; padding: 18px 1px 15px; color: var(--muted); background: transparent; font-size: 13px; font-weight: 700; }
.tabs button.active { color: var(--green); }
.tabs button.active::after { content: ""; position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; background: var(--green); }
.tabs span { display: inline-block; min-width: 18px; margin-left: 4px; border-radius: 10px; padding: 1px 5px; background: #e7eeeb; font-size: 10px; }
.tab-panel { max-width: 1180px; padding-top: 26px; }
.section-card { margin-bottom: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--white); box-shadow: 0 6px 22px rgba(27,50,41,.04); }
.section-head { display: flex; align-items: center; justify-content: space-between; padding: 17px 20px; border-bottom: 1px solid var(--line); }
.section-head h2 { margin: 0; font-family: Georgia, serif; font-size: 18px; font-weight: 500; }
.section-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.section-body { padding: 20px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 17px; }
.field-grid .wide { grid-column: 1 / -1; }
.field label, .mini-label { display: block; margin-bottom: 7px; color: #506159; font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.field input, .field textarea, .field select, .cell-input {
  width: 100%; border: 1px solid #d5dfda; border-radius: 9px; padding: 10px 11px; outline: none; color: var(--ink); background: #fdfefd;
}
.field textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.field input:focus, .field textarea:focus, .cell-input:focus { border-color: #66a88f; box-shadow: 0 0 0 3px rgba(65,145,114,.1); }
.field input.invalid { border-color: #bd4f45; background: #fff3f1; box-shadow: 0 0 0 3px rgba(189,79,69,.1); }
.required-mark { color: #a43c33; }
.path-picker { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: stretch; }
.path-picker .button { white-space: nowrap; }
.setup-notice {
  display: flex; gap: 8px; align-items: center; margin: 14px 0;
  border-left: 4px solid #4b9b7d; border-radius: 9px; padding: 12px 14px;
  color: #345349; background: #edf7f3;
}
.setup-notice span { color: #5d7169; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { padding: 9px 8px; color: var(--muted); text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.data-table td { padding: 7px 8px; border-top: 1px solid #edf1ef; vertical-align: top; }
.data-table .cell-input { min-width: 110px; padding: 8px; border-color: transparent; background: transparent; }
.data-table .cell-input:hover, .data-table .cell-input:focus { border-color: #d5dfda; background: white; }
.row-number { width: 32px; padding-top: 16px !important; color: #8c9993; font-size: 11px; }
.icon-button { border: 0; border-radius: 8px; padding: 7px 9px; color: #708078; background: transparent; }
.icon-button:hover { color: #9c382f; background: #faeeec; }
.add-button { border: 1px dashed #adc8bd; border-radius: 9px; padding: 8px 12px; color: var(--green); background: #f5faf8; font-size: 12px; font-weight: 700; }
.notice { border-left: 3px solid #7baf9b; border-radius: 0 10px 10px 0; padding: 12px 15px; color: #496158; background: #eef6f2; font-size: 12px; line-height: 1.5; }
.notice.error { border-left-color: #b84b40; color: #8f3028; background: #fff1ef; }
.logic-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.logic-tree { display: grid; gap: 9px; }
.subsection { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line); }
.subsection-heading { margin-bottom: 16px; }
.subsection-heading h3 { margin: 0 0 6px; font-family: Georgia, serif; font-size: 25px; font-weight: 500; }
.subsection-heading p { margin: 0; color: var(--muted); }
.legacy-document-editor {
  overflow: hidden; border: 1px solid #cfddd7; border-radius: 14px;
  background: #fbfdfc; box-shadow: inset 0 1px 0 rgba(255,255,255,.8);
}
.legacy-document-row {
  display: block; width: 100%; min-height: 48px; overflow: hidden; resize: none;
  border: 0; border-bottom: 1px solid #e6eeea; padding: 13px 16px;
  outline: none; color: #273b33; background: transparent;
  font-family: "Segoe UI", Arial, sans-serif; font-size: 14px; line-height: 1.65;
  white-space: pre-wrap; field-sizing: content;
}
.legacy-document-row:last-child { border-bottom: 0; }
.legacy-document-row:hover { background: #f5faf8; }
.legacy-document-row:focus { position: relative; z-index: 1; background: white; box-shadow: inset 3px 0 0 #63a88e; }
.legacy-document-row.invalid { color: #8f3029; background: #fff3f1; box-shadow: inset 3px 0 0 #bd4f45; }
.legacy-document-row[readonly] { color: #65756e; background: #f1f5f3; cursor: default; }
.legacy-copy-notice { margin-top: 14px; }
.node {
  border: 1px solid #dae3df; border-radius: 11px; background: white; overflow: hidden;
}
.node > summary { display: flex; align-items: center; gap: 10px; padding: 11px 13px; cursor: pointer; list-style: none; }
.node > summary::-webkit-details-marker { display: none; }
.node > summary::before { content: "›"; width: 16px; color: #789087; font-size: 20px; transition: transform .15s; }
.node[open] > summary::before { transform: rotate(90deg); }
.node-type { border-radius: 6px; padding: 3px 7px; color: var(--green-dark); background: var(--green-pale); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.node-summary { overflow: hidden; color: #51625a; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.node-body { padding: 8px 14px 14px 38px; border-top: 1px solid #eef2f0; }
.property { display: grid; grid-template-columns: 130px minmax(0,1fr); gap: 10px; align-items: start; margin-top: 9px; }
.property-name { padding-top: 8px; color: #6d7b75; font-size: 11px; font-weight: 700; }
.array-items { display: grid; gap: 7px; }
.primitive { display: flex; gap: 6px; align-items: center; }
.primitive input, .primitive select, .primitive textarea { flex: 1; min-width: 0; border: 1px solid #d8e1dd; border-radius: 7px; padding: 7px 8px; background: #fbfdfc; }
.primitive textarea { min-height: 65px; resize: vertical; }
.global-statusbar {
  position: fixed; left: 0; right: 0; top: 0; z-index: 40;
  height: 92px; display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 9px 20px; border-bottom: 1px solid rgba(255,255,255,.1);
  color: #d8e9e1; background: rgba(11,46,37,.97); box-shadow: 0 -8px 28px rgba(12,37,29,.12);
  backdrop-filter: blur(12px); font-size: 12px;
}
.statusbar-brand, .statusbar-links { display: flex; align-items: center; gap: 9px; }
.statusbar-brand { min-width: 390px; gap: 15px; white-space: nowrap; }
.statusbar-brand img { width: 54px; height: 72px; object-fit: contain; }
.statusbar-brand strong, .statusbar-brand > div > span { display: block; }
.statusbar-brand strong { color: white; font-size: 24px; line-height: 1.1; letter-spacing: .01em; }
.statusbar-brand > div > span { margin-top: 7px; color: #a9c8bb; font-size: 15px; }
.brand-version { display: inline; margin-left: 7px; color: #bfe5d5; font-size: 14px; font-weight: 700; }
.statusbar-links { justify-content: flex-end; flex-wrap: wrap; }
.statusbar-links a {
  border-radius: 7px; padding: 5px 8px; color: #c3ddd2; text-decoration: none;
}
.statusbar-links a:hover { color: white; background: rgba(255,255,255,.09); }
.statusbar-links .social-icon-link { width: 34px; height: 34px; display: grid; place-items: center; padding: 4px; }
.social-icon-link img { width: 24px; height: 24px; display: block; object-fit: contain; }
.social-icon-link span { white-space: nowrap; }
.statusbar-links .social-icon-link:has(span:not([hidden])) { width: auto; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: 420px; border-radius: 11px; padding: 13px 17px; color: white; background: #183e31; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #8c342d; }
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; background: rgba(10,27,21,.48); backdrop-filter: blur(3px); }
.modal-card { width: min(460px,100%); border-radius: 16px; padding: 25px; background: white; box-shadow: var(--shadow); }
.modal-card.settings-card { width: min(980px, 96vw); max-height: 90vh; overflow: auto; }
.field-grid.single { grid-template-columns: 1fr; margin-top: 20px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.settings-grid textarea { min-height: 110px; }
.section-head.compact { margin-top: 18px; padding-inline: 0; }
.drug-library-list { display: grid; gap: 8px; }
.library-drug { display: grid; grid-template-columns: 2fr 1fr 1fr 38px; gap: 8px; }
.library-solvent { display: grid; grid-template-columns: 2fr 2fr 38px; gap: 8px; }
.library-launchers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 22px; }
.library-launchers .button { min-height: 58px; }
.modal-card.library-card { width: min(1120px, 96vw); max-height: 92vh; overflow: auto; }
.library-card > .modal-actions {
  position: sticky; bottom: -25px; z-index: 5; margin-inline: -25px;
  padding: 14px 25px 25px; background: linear-gradient(to top, #fff 72%, rgba(255,255,255,.92));
  border-top: 1px solid var(--border);
}
.library-modal-content { display: grid; gap: 14px; margin-top: 16px; }
.library-drug-card { border: 1px solid var(--border); border-radius: 16px; padding: 18px; background: #fff; }
.library-drug-card .field-grid { margin-top: 0; }
.library-search { width: 100%; min-height: 58px; }
.library-drug-results { display: grid; gap: 8px; }
.library-drug-result {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 16px 18px; border: 1px solid var(--border); border-radius: 13px;
  background: #fff; color: var(--text); text-align: left; cursor: pointer;
}
.library-drug-result:hover { border-color: var(--accent); background: var(--soft); }
.library-drug-result strong { font-size: 1.05rem; }
.library-drug-result span { color: var(--muted); text-align: right; }
.library-composite-components { display: grid; gap: 8px; margin-top: 12px; }
.library-composite-component {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.medication-toolbar {
  display: grid; grid-template-columns: auto minmax(200px, 1fr) auto minmax(220px, 1fr);
  gap: 9px; align-items: stretch; width: min(100%, 1040px);
}
.composite-medication-children {
  display: grid; gap: 10px; margin: 4px 0 16px; padding: 12px;
  border: 1px solid #d9e7e1; border-radius: 12px; background: #f6faf8;
}
.composite-medication-children > .node { background: white; }
.composite-inline-fields { border-top: 1px solid var(--border); padding-top: 14px; }
.library-detail-navigation { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.library-list-textarea { width: 100%; min-height: 52vh; resize: vertical; }
.schema-generate-button { align-self: flex-start; margin-top: 10px; }
.drag-handle {
  cursor: grab; user-select: none; color: var(--muted); font-size: 1.15rem;
  padding: 5px 8px; margin: -5px 0 -5px -5px; border-radius: 8px;
}
.drag-handle:active { cursor: grabbing; }
.node.dragging { opacity: .45; }
.node.drag-target { border-color: var(--accent); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.composite-section { margin-top: 26px; padding-top: 8px; border-top: 1px solid var(--border); }
.composite-components { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.composite-component { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.cycle-comments-section { margin-top: 26px; padding-top: 8px; border-top: 1px solid var(--border); }
.cycle-comments-textarea { width: 100%; min-height: 190px; resize: vertical; }
.comment-toolbar {
  display: grid; grid-template-columns: minmax(220px, 1fr) auto minmax(150px, .6fr) minmax(110px, .35fr) auto;
  gap: 9px; align-items: stretch; margin-bottom: 12px;
}
.comment-toolbar select, .comment-toolbar button { min-height: 48px; }
.modal-card h2 { margin: 0 0 8px; font-family: Georgia, serif; font-weight: 500; }
.modal-card p { color: var(--muted); line-height: 1.55; }
.account-register-fields { display: contents; }
.account-sync-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }
.account-protocol-list { max-height: 280px; overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.account-protocol-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.account-protocol-row:last-child { border-bottom: 0; }
.account-delete-section { margin-top: 24px; padding-top: 20px; border-top: 1px solid #efc9c4; }
.account-delete-section h3 { margin: 0 0 8px; color: #9f382f; }
.account-delete-section .field { margin: 14px 0; }
.admin-account-section { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
.admin-account-section h3 { margin: 0 0 5px; }
.admin-account-section h4 { margin: 18px 0 8px; }
.admin-account-section .section-head { align-items: center; }
.admin-user-list { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.admin-user-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 12px; border-bottom: 1px solid var(--border); }
.admin-user-row:last-child { border-bottom: 0; }
.admin-user-details { min-width: 0; }
.admin-user-details strong, .admin-user-details span { display: block; }
.admin-user-details span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.admin-user-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }
.prescription-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
@media (max-width: 850px) {
  .path-picker { grid-template-columns: 1fr; }
  .setup-notice { align-items: flex-start; flex-direction: column; }
  .library-launchers { grid-template-columns: 1fr; }
  .library-drug-result { align-items: flex-start; flex-direction: column; }
  .library-drug-result span { text-align: left; }
  .backup-components { grid-template-columns: 1fr; }
  .backup-components .backup-all { grid-column: auto; }
  .composite-components { grid-template-columns: 1fr; }
  .comment-toolbar { grid-template-columns: 1fr; }
  .account-sync-actions { grid-template-columns: 1fr; }
  .admin-user-row { align-items: stretch; flex-direction: column; }
  .admin-user-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .medication-toolbar { grid-template-columns: 1fr; }
  body { padding-top: 126px; }
  .app-shell {
    width: 100%; max-width: 100%; grid-template-columns: minmax(0, 1fr); min-height: calc(100vh - 126px);
    background: var(--paper);
  }
  body.protocol-info-open .workspace { margin-right: 0; }
  .drawer-overlay { top: 126px; }
  .protocol-info-drawer { width: min(var(--protocol-drawer-width), 92vw); }
  .sidebar, .workspace { width: 100%; max-width: 100%; min-width: 0; }
  .workspace { grid-column: 1; }
  .sidebar { position: static; height: auto; max-height: 340px; }
  .sidebar-foot { display: none; }
  .topbar { position: static; align-items: flex-start; gap: 15px; padding: 18px; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .calculator-top-actions { flex-wrap: wrap; justify-content: flex-start; }
  .editor { padding: 0 18px 35px; }
  .calculator { padding: 20px 18px 35px; }
  #calculator-result, #calculator-result.with-preview { width: 100%; }
  .calculator-layout, .result-grid { grid-template-columns: 1fr; }
  .save-file-row { grid-template-columns: 1fr; }
  .result-save-card { width: 100%; }
  .tabs { overflow-x: auto; gap: 20px; }
  .tabs button { white-space: nowrap; }
  .field-grid { grid-template-columns: 1fr; }
  .property { grid-template-columns: 1fr; gap: 2px; }
  .global-statusbar { height: 126px; align-items: center; flex-wrap: wrap; gap: 3px 10px; padding: 7px 12px; }
  .statusbar-brand { min-width: 0; flex: 1; }
  .statusbar-brand img { width: 43px; height: 58px; }
  .statusbar-brand strong { font-size: 18px; }
  .statusbar-brand > div > span { margin-top: 4px; font-size: 12px; }
  .brand-version { font-size: 11px; }
  .statusbar-links { justify-content: flex-end; gap: 3px; }
  .statusbar-links a { padding: 4px 6px; }
  .toast { right: 12px; bottom: 12px; }
}

@media (max-width: 480px) {
  body { padding-top: 88px; }
  .app-shell { min-height: calc(100vh - 88px); }
  .global-statusbar {
    height: 88px; flex-wrap: nowrap; gap: 6px; padding: 6px 9px;
  }
  .statusbar-brand { min-width: 0; gap: 7px; white-space: normal; }
  .statusbar-brand img { width: 32px; height: 48px; flex: 0 0 auto; }
  .statusbar-brand > div { min-width: 0; }
  .statusbar-brand strong {
    overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap;
  }
  .statusbar-brand > div > span, .brand-version { display: none; }
  .statusbar-links { flex: 0 0 auto; flex-wrap: nowrap; gap: 1px; }
  .statusbar-links .social-icon-link { width: 27px; height: 27px; padding: 3px; }
  .social-icon-link img { width: 19px; height: 19px; }
  .sidebar { max-height: none; padding: 16px 12px 14px; }
  .mobile-protocol-toggle {
    width: 100%; display: block; margin-bottom: 10px; border: 1px solid rgba(180,230,208,.25);
    border-radius: 9px; padding: 9px; color: #dff3ea; background: rgba(125,196,166,.12);
    font-size: 12px; font-weight: 700;
  }
  .protocol-list { max-height: min(210px, 28vh); }
  .sidebar.mobile-protocols-collapsed .search,
  .sidebar.mobile-protocols-collapsed .library-switch,
  .sidebar.mobile-protocols-collapsed .sidebar-action,
  .sidebar.mobile-protocols-collapsed .protocol-list { display: none; }
  .mode-switch { margin-bottom: 10px; }
  .library-switch { margin-top: 10px; }
  .empty-state { max-width: none; margin: 9vh 16px; }
  .empty-state h2 { font-size: 22px; }
  .empty-state p { font-size: 14px; }
  .topbar { padding: 14px 12px; }
  .editor { padding: 0 12px 30px; }
  .calculator { width: 100%; padding: 16px 12px 30px; }
  #calculator-form { scroll-margin-top: 96px; }
  .section-head, .section-body { padding: 14px; }
  .web-document-card .section-head { align-items: stretch; flex-direction: column; }
  .web-document-card .section-head .button { width: 100%; }
  .web-protocol-editor { min-height: 300px; padding: 12px; }
  .web-prescription-document { margin: 0; }
  .web-prescription-body { max-height: 72vh; }
  .web-document-card .section-body { overflow-x: auto; }
  .modal { padding: 10px; }
  .modal-card, .modal-card.settings-card, .modal-card.library-card {
    width: 100%; max-width: 100%; padding: 18px 14px;
  }
  .drawer-overlay { top: 88px; }
  .protocol-info-drawer { width: 100vw; padding: 16px; }
  .toast { left: 10px; right: 10px; max-width: none; }
}

@media print {
  @page { size: A4 landscape; margin: 15mm 15mm 18mm; }
  html, body { background: white !important; }
  body.print-web-prescription { min-height: 100%; padding: 0 !important; background: white !important; }
  body.print-web-prescription > * { display: none !important; }
  body.print-web-prescription > .web-prescription-document {
    display: block !important; position: static; width: 267mm; max-width: none; margin: 0;
    border: 0; border-radius: 0; padding: 0; background: white !important; box-shadow: none;
  }
  body.print-web-prescription .web-editable { background: transparent !important; box-shadow: none !important; }
  body.print-web-prescription .table-wrap { overflow: visible; }
  body.print-web-prescription .prescription-table { break-inside: auto; }
  body.print-web-prescription .prescription-table tr { break-inside: avoid; break-after: auto; }
  body.print-web-prescription .word-prescription-table-wrap { overflow: visible; }
  body.print-web-prescription .word-prescription-table { break-inside: auto; }
  body.print-web-prescription .word-prescription-table thead { display: table-header-group; }
  body.print-web-prescription .word-prescription-table tbody { display: table-row-group; }
  body.print-web-prescription .word-prescription-table tr { break-inside: avoid; break-after: auto; }
}
