:root {
  --ink: #1d2733;
  --muted: #5b6b7c;
  --line: #c9d3dd;
  --accent: #0b6e6e;
  --accent-soft: #e6f2f2;
  --paper: #ffffff;
  --bg: #eef1f4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, "Noto Sans Bengali", sans-serif;
}

/* ---------- Toolbar ---------- */
.toolbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 10px 16px;
  background: #fff; border-bottom: 1px solid var(--line);
}
.toolbar .hint { color: var(--muted); font-size: 13px; flex: 1; min-width: 200px; }
.toolbar .actions { display: flex; flex-wrap: wrap; gap: 8px; }
button {
  font: inherit; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 6px 12px; border-radius: 6px;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- A4 page ---------- */
.page {
  width: 210mm; min-height: 297mm;
  margin: 20px auto; padding: 14mm 14mm 10mm;
  background: var(--paper);
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
  display: flex; flex-direction: column;
}

/* Editable placeholders */
[contenteditable] { outline: none; border-radius: 3px; min-width: 2ch; }
[contenteditable]:hover { background: #f6f9fb; }
[contenteditable]:focus { background: var(--accent-soft); }
[contenteditable]:empty::before { content: attr(data-ph); color: #a3afbb; }

/* ---------- Header ---------- */
.rx-header {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: center;
  padding-bottom: 10px; border-bottom: 3px solid var(--accent);
}
.rx-header h1 { margin: 0; font-size: 22px; color: var(--accent); }
.rx-header h2 { margin: 0; font-size: 16px; }
.rx-header p { margin: 1px 0; font-size: 13px; }
.degrees { font-weight: 600; }
.speciality, .reg { color: var(--muted); }
.chamber { text-align: right; }
.logo svg { fill: var(--accent); opacity: .85; display: block; }

/* ---------- Patient ---------- */
.patient {
  display: flex; flex-wrap: wrap; gap: 6px 18px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.field { display: flex; align-items: baseline; gap: 6px; }
.field.grow { flex: 1 1 220px; }
.field label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.field .val { flex: 1; border-bottom: 1px dotted var(--line); min-width: 60px; font-weight: 600; }
.field .val.short { min-width: 40px; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; }

/* ---------- Body ---------- */
.rx-body { display: grid; grid-template-columns: 32% 1fr; flex: 1; }
.clinical { padding: 12px 14px 12px 0; border-right: 1px solid var(--line); }
.rx { padding: 12px 0 12px 16px; display: flex; flex-direction: column; gap: 14px; }

.block h3 {
  margin: 0 0 4px; font-size: 12px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--accent);
}
.block + .block { margin-top: 14px; }
.rx .block + .block { margin-top: 0; }
.area { min-height: 3.2em; white-space: pre-wrap; }
.vitals { list-style: none; margin: 0 0 4px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; font-size: 13px; }

.rx-symbol { font-size: 40px; line-height: 1; font-family: Georgia, serif; color: var(--accent); }

/* Medicines table */
.meds { width: 100%; border-collapse: collapse; }
.meds th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); border-bottom: 1px solid var(--line); padding: 4px 6px;
}
.meds td { padding: 6px; border-bottom: 1px dashed var(--line); vertical-align: top; }
.meds .n { width: 22px; color: var(--muted); }
.med-name { font-weight: 600; }
.med-generic { font-size: 12px; color: var(--muted); }
.meds select {
  font: inherit; font-size: 13px; border: none; background: transparent; color: var(--ink);
  padding: 0; cursor: pointer; appearance: none; -webkit-appearance: none;
}
.meds select:hover, .meds select:focus { background: var(--accent-soft); outline: none; }
.del { border: none; color: #b33; font-size: 18px; padding: 0 6px; line-height: 1; }

.inline { display: inline-block; min-width: 3ch; border-bottom: 1px dotted var(--line); font-weight: 600; }
.followup p { margin: 0; }

/* ---------- Footer ---------- */
.rx-footer {
  display: flex; justify-content: space-between; align-items: flex-end;
  padding-top: 12px; border-top: 1px solid var(--line);
}
.verify { display: flex; gap: 10px; align-items: center; font-size: 11px; color: var(--muted); }
.verify p { margin: 0; }
.qr {
  width: 56px; height: 56px; border: 1px dashed var(--line);
  display: grid; place-items: center; font-size: 11px; color: var(--muted);
}
.signature { text-align: center; width: 180px; }
.sign-line { border-bottom: 1px solid var(--ink); height: 36px; }
.signature p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.disclaimer { margin: 8px 0 0; font-size: 10.5px; color: var(--muted); text-align: center; }

/* ---------- Small screens ---------- */
@media (max-width: 860px) {
  .page { width: auto; min-height: 0; margin: 12px; padding: 16px; }
  .rx-header { grid-template-columns: 1fr; }
  .chamber { text-align: left; }
  .logo { display: none; }
  .rx-body { grid-template-columns: 1fr; }
  .clinical { border-right: none; border-bottom: 1px solid var(--line); padding-right: 0; }
  .rx { padding-left: 0; }
}

/* ---------- Print ---------- */
@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .page { margin: 0; box-shadow: none; width: 210mm; min-height: 297mm; }
  [contenteditable]:empty::before { content: ""; }
  [contenteditable]:hover, [contenteditable]:focus { background: none; }
  .meds tr { break-inside: avoid; }
}
