/* =================================================================
   خط نویس — application styles
   The entire interface is RTL.  Urdu *content* uses the chosen Nastaleeq
   family; interface chrome uses a plain sans stack so controls stay legible.
   ================================================================= */

:root {
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --paper: #ffffff;
  --canvas: #eef1f5;
  --panel: #f7f8fa;
  --line: #dbe2ea;
  --line-strong: #c3cedb;
  --accent: #0f766e;
  --accent-soft: #e6f2f1;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, .10);
  --shadow-lg: 0 18px 50px rgba(15, 23, 42, .18);
  --radius: 10px;
  --radius-lg: 16px;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;

  /* Letter typography — driven live by the settings panel */
  --page-w: 210mm;
  --page-h: 297mm;
  --pad-x: 18mm;
  --pad-y: 16mm;
  --urdu-font: "Noto Nastaliq Urdu", serif;
  --urdu-size: 26px;
  --urdu-leading: 2.4;
  --urdu-align: justify;
  --urdu-color: #111827;
  --block-gap: .35em;
  --zoom: 1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--ui-font);
  direction: rtl;
}

body { overflow: hidden; }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }

.app { display: flex; flex-direction: column; height: 100dvh; min-height: 100vh; }

/* ------------------------------ ٹاپ بار ------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  /* above the canvas bar and the sheets, so the command menu is never drawn
     underneath them */
  z-index: 60;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(140deg, var(--accent), #0b5f59);
  color: #fff;
  font-family: "Noto Nastaliq Urdu", serif;
  font-size: 20px;
  line-height: 1;
  padding-bottom: 6px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 16px; }
.brand-text small { color: var(--muted); font-size: 11.5px; }

.topbar-actions { display: flex; align-items: center; gap: 6px; }

/* ---------------- ہیڈر کا کمانڈ مینو ---------------- */

.menu-wrap { position: relative; display: inline-flex; z-index: 1; }

.menu {
  position: absolute;
  /* anchored to the button, so the extra offset clears the header's border */
  top: calc(100% + 12px);
  inset-inline-end: 0;
  z-index: 70;
  min-width: 232px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.menu[hidden] { display: none; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  color: var(--ink);
  text-align: right;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--accent-soft); color: var(--accent); outline: none; }
.menu-item .menu-glyph { font-size: 15px; width: 20px; text-align: center; flex: 0 0 auto; opacity: .85; }
.menu-item kbd {
  margin-inline-start: auto;
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
  direction: ltr;
}
.menu-item .badge { margin-inline-start: auto; }
.menu-sep { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }

/* ------------------------------ بٹن ------------------------------ */

.btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: var(--radius);
  padding: 8px 13px;
  font-size: 14px;
  line-height: 1.2;
  transition: background .14s, border-color .14s, transform .05s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #0b5f59; color: #fff; }

.btn-icon { padding: 8px 10px; min-width: 38px; justify-content: center; }
.btn-small { padding: 6px 10px; font-size: 13px; }
.btn-wide { width: 100%; justify-content: center; }
.btn-danger { color: var(--danger); border-color: #e6b3ae; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn[disabled] { opacity: .5; pointer-events: none; }

.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  padding: 1px 7px;
  line-height: 1.6;
}

/* ------------------------------ بنیادی گرڈ ------------------------------ */

.body {
  flex: 1;
  display: grid;
  /* One column while the settings are hidden.  The canvas is pinned to the
     last column explicitly: with auto-placement it would fall into the
     collapsed first track and end up 0px wide. */
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
  transition: grid-template-columns .18s ease;
}
body.settings-open .body { grid-template-columns: 330px minmax(0, 1fr); }
.canvas { grid-column: -2 / -1; }
body.settings-open .canvas { grid-column: 2; }
/* Removed from layout when closed, not merely squeezed: an overflowing grid
   item is not clipped by its track, so it would still be painted. */
.sidebar.sidebar-settings { display: none; }
body.settings-open .sidebar.sidebar-settings { display: flex; grid-column: 1; }

.sidebar { background: var(--panel); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.sidebar-settings { border-inline-end: 1px solid var(--line); }

.panel-head { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); background: #fff; }
.panel-head h2 { margin: 0 0 2px; font-size: 15px; }
.panel-head .hint { color: var(--muted); font-size: 11.5px; }
.panel-head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* Leaving a sheet on a phone needs an obvious, thumb-sized target. */
.panel-close {
  display: none;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13.5px;
  line-height: 1;
  flex: 0 0 auto;
}
.panel-close:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.panel-close span { font-size: 12.5px; }

/* Tapping the letter behind a sheet closes it. */
.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .28);
  z-index: 45;
}
.panel-backdrop[hidden] { display: none; }

.sidebar-scroll { overflow-y: auto; overscroll-behavior: contain; padding: 12px; flex: 1; }
.panel-foot { padding: 10px 12px; border-top: 1px solid var(--line); background: #fff; }

.group {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 12px;
  margin-bottom: 12px;
}
.group h3 { margin: 0 0 10px; font-size: 13.5px; color: var(--ink-soft); }

.field { display: block; margin-bottom: 11px; }
.field > span { display: block; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 5px; }
.field > span output { color: var(--accent); font-weight: 600; }
.field:last-child { margin-bottom: 0; }

input[type="text"], input[type="file"], select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 7px 9px;
  background: #fff;
  font-size: 13.5px;
}
input[type="text"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="color"] { width: 46px; height: 32px; padding: 2px; border-radius: 8px; border: 1px solid var(--line-strong); background: #fff; }
input[type="file"] { font-size: 12px; padding: 5px; }

textarea {
  font-family: "Noto Nastaliq Urdu", serif;
  font-size: 17px;
  line-height: 2.2;
  min-height: 96px;
  resize: vertical;
}

input[type="range"] { width: 100%; accent-color: var(--accent); }

.segmented { display: flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.segmented button {
  flex: 1;
  border: 0;
  background: #fff;
  padding: 7px 4px;
  font-size: 12.5px;
  border-inline-start: 1px solid var(--line);
}
.segmented button:first-child { border-inline-start: 0; }
.segmented button.is-active { background: var(--accent); color: #fff; }

.row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.row:last-child { margin-bottom: 0; }
.row > input[type="text"] { flex: 1; }

.note { font-size: 11.5px; color: var(--muted); margin: 8px 0 0; line-height: 1.7; }
.note.ok { color: var(--accent); }
.note.warn { color: #b45309; }

/* ------------------------------ متن کے خانے ------------------------------ */

.block-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 9px;
  overflow: hidden;
  transition: border-color .14s, box-shadow .14s;
}
.block-card:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.block-card.is-linked { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.block-card-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 6px;
  background: #fbfcfd;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.block-card-head select {
  flex: 1 1 118px;
  min-width: 108px;
  border: 0;
  background: transparent;
  font-size: 12.5px;
  color: var(--ink-soft);
  padding: 3px 2px;
}
.block-card-head select:focus { box-shadow: none; }
.block-card-tools { display: flex; gap: 1px; flex: 0 0 auto; }
.block-card-tools button {
  border: 0;
  background: transparent;
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 12px;
  color: var(--muted);
}
.block-card-tools button:hover { background: var(--accent-soft); color: var(--accent); }
.block-card-tools button.danger:hover { background: var(--danger-soft); color: var(--danger); }

.block-card-format {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  flex-wrap: wrap;
}
.block-font-select {
  flex: 1 1 118px;
  min-width: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 6px;
  font-size: 12px;
  color: var(--ink-soft);
  background: #fff;
}
.block-font-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.align-group { display: flex; gap: 2px; flex: 0 0 auto; }
.align-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  border-radius: 7px;
  padding: 5px 7px;
  font-size: 11.5px;
  line-height: 1.2;
  min-width: 32px;
}
.align-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.align-btn.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
/*
 * Each alignment button draws three ruled lines arranged the way the text will
 * sit.  The bars are deliberately wide (18px) and the short line is a full
 * 40% narrower than the long one — at phone size the four buttons must be
 * tellable apart without a legend.
 */
/*
 * Alignment buttons.  Each option draws a different shape so the four are
 * distinguishable at phone size without a legend:
 *   right   3 bars, flushed right (ragged left edge)
 *   center  2 bars, centred
 *   justify 4 full bars (a solid block)
 *   left    3 bars, flushed left (ragged right edge)
 */
/*
 * These mock-ups are laid out with LTR so "flex-start" always means the visual
 * left.  Inside the RTL interface the roles would otherwise be mirrored and the
 * بائیں/دائیں buttons would show each other's picture.
 */
.align-bars { display: flex; flex-direction: column; gap: 2.5px; width: 18px; direction: ltr; }
.align-bars i { display: block; height: 2px; border-radius: 1px; background: currentColor; width: 100%; }
.align-bars-right { align-items: flex-end; }
.align-bars-right i:nth-child(2) { width: 55%; }
.align-bars-center { align-items: center; }
.align-bars-center i:nth-child(1) { width: 100%; }
.align-bars-center i:nth-child(2) { width: 62%; }
.align-bars-left { align-items: flex-start; }
.align-bars-left i:nth-child(2) { width: 55%; }
.align-bars-justify i { width: 100%; }
.align-auto { min-width: 46px; }

.block-card-preview {
  padding: 8px;
  cursor: text;
  white-space: pre-wrap;
  max-height: 132px;
  overflow: auto;
}
.block-empty { color: #94a3b8; }

/* ------------------------------ ترتیب پٹی (footer) ------------------------------ */

.formatbar {
  background: #fff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 10px rgba(15, 23, 42, .05);
  z-index: 30;
  flex: 0 0 auto;
}
.formatbar-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 7px 14px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}
.fb-group { display: flex; align-items: center; gap: 7px; flex: 0 0 auto; }
.fb-group + .fb-group { border-inline-start: 1px solid var(--line); padding-inline-start: 14px; }
.fb-label { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.fb-label output { color: var(--accent); font-weight: 600; }

.fb-select {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 5px 7px;
  font-size: 12.5px;
  background: #fff;
  color: var(--ink);
  max-width: 190px;
}
.fb-select-wide { max-width: 240px; }
.fb-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.fb-select:disabled { opacity: .5; }

.fb-size { min-width: 168px; }
.fb-size input[type="range"] { width: 108px; }
.fb-align button { padding: 5px 7px; }
.fb-align button:disabled { opacity: .45; }

.fb-buttons { display: flex; gap: 3px; }
.fb-buttons button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 13px;
  line-height: 1.2;
  min-width: 32px;
}
.fb-buttons button:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.fb-buttons button.danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.fb-status { margin-inline-start: auto; flex: 0 0 auto; }

/* the line the toolbar is pointed at */
.page .blk.is-active { background: rgba(15, 118, 110, .07); box-shadow: 0 0 0 1.5px rgba(15, 118, 110, .3); }

/* ------------------------------ مدد ------------------------------ */

.help-body { line-height: 1.85; }
.help-section { margin-bottom: 20px; }
.help-section:last-child { margin-bottom: 0; }
.help-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--accent);
  border-bottom: 1px solid var(--line);
  padding-bottom: 5px;
}
.help-section ul, .help-section ol { margin: 0; padding-inline-start: 20px; }
.help-section li { margin-bottom: 5px; font-size: 13.5px; color: var(--ink-soft); }
.help-section p { margin: 0 0 8px; font-size: 13.5px; color: var(--ink-soft); }
.help-dim { color: var(--muted) !important; font-size: 12.5px !important; }
.help-keys { border-collapse: collapse; font-size: 13px; }
.help-keys td { padding: 3px 10px 3px 0; color: var(--ink-soft); }
.help-keys kbd {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  direction: ltr;
  display: inline-block;
}
.sidebar-note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.8;
  background: var(--accent-soft);
  border: 1px solid #bfe0dd;
  border-radius: 10px;
  padding: 9px 11px;
  margin: 0 0 12px;
}

/* ------------------------------ صفحہ ------------------------------ */

.canvas { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--canvas); }

.canvas-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .72);
  backdrop-filter: blur(6px);
  flex-wrap: wrap;
}
.zoom-group { display: flex; align-items: center; gap: 6px; }
.zoom-value { font-size: 13px; color: var(--ink-soft); min-width: 54px; text-align: center; }
.canvas-bar-right { display: flex; align-items: center; gap: 6px; }

.chip { background: #fff; border: 1px solid var(--line-strong); border-radius: 999px; padding: 4px 11px; font-size: 12px; color: var(--ink-soft); }
.chip-quiet { color: var(--muted); }
.chip.warn { background: #fff7ed; border-color: #fdba74; color: #b45309; }
/* the content-panel toggle lives here to keep the header short */
.btn-panel { border-color: var(--line-strong); }

.page-scroll { flex: 1; overflow: auto; padding: 22px; display: flex; justify-content: center; align-items: flex-start; }
.page-stage { transform-origin: top center; transform: scale(var(--zoom)); position: relative; }

/* Dashed guide showing where the first printed sheet ends. */
.page-limit {
  position: absolute;
  top: var(--page-h);
  left: 0;
  right: 0;
  border-top: 1.5px dashed #f59e0b;
  pointer-events: none;
  display: none;
}
.page-limit span {
  position: absolute;
  inset-inline-end: 6px;
  top: 3px;
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #b45309;
  border-radius: 999px;
  font-family: var(--ui-font);
  font-size: 10.5px;
  padding: 1px 8px;
  direction: rtl;
}
body.has-overflow .page-limit { display: block; }

/* The letter sheet — this exact element is what gets printed. */
.page {
  width: var(--page-w);
  /* A fixed sheet, never sized by its content: the letter must be laid out
     against the real A4 box so the overflow warning means something. */
  height: var(--page-h);
  padding: var(--pad-y) var(--pad-x);
  background: var(--paper);
  box-shadow: var(--shadow-lg);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

/* ------------------------------ خط کے بلاکس ------------------------------ */

.page .blk {
  font-family: var(--urdu-font);
  font-size: var(--urdu-size);
  line-height: var(--urdu-leading);
  color: var(--urdu-color);
  margin: 0 0 var(--block-gap);
  outline: none;
  overflow-wrap: break-word;
  word-break: normal;
  text-align: right;
  padding: 1px 2px;
  border-radius: 3px;
  transition: background .12s;
}
.page .blk:last-child { margin-bottom: 0; }
.page .blk { cursor: text; caret-color: var(--accent); }
.page .blk:hover { background: rgba(15, 118, 110, .035); }
.page .blk:focus { background: rgba(15, 118, 110, .06); box-shadow: 0 0 0 2px rgba(15, 118, 110, .25); }
.page .blk:empty::before { content: "…"; color: #cbd5e1; }

.page .blk-header { text-align: center; font-size: calc(var(--urdu-size) * .60); line-height: 2.2; }
.page .blk-title { text-align: center; font-size: var(--urdu-size); }
.page .blk-subtitle { text-align: center; font-size: var(--urdu-size); }
.page .blk-date {
  text-align: left;
  direction: ltr;
  font-family: "Noto Naskh Arabic", var(--ui-font), serif;
  font-size: calc(var(--urdu-size) * .70);
  line-height: 1.9;
  color: #374151;
}
.page .blk-addressee { text-align: center; font-size: calc(var(--urdu-size) * .96); }
.page .blk-salutation { text-align: center; font-size: var(--urdu-size); }
.page .blk-body { text-align: var(--urdu-align); }
.page .blk-closing { text-align: left; }
.page .blk-signature { text-align: center; font-size: calc(var(--urdu-size) * .84); margin-top: 1.2em; }
.page .blk-signature-line { text-align: center; font-size: calc(var(--urdu-size) * .84); }
.page .blk-signature-address { text-align: center; font-size: calc(var(--urdu-size) * .84); }
.page .blk-custom { text-align: var(--urdu-align); }

.page .blk b, .page .blk strong { font-weight: 700; }
.page .blk i, .page .blk em { font-style: italic; }
.page .blk u { text-decoration: underline; text-underline-offset: 4px; }
.page .blk .has-link { color: inherit; }

/* Per-block manual alignment wins over the role default. */
.page .blk[data-align="right"] { text-align: right; }
.page .blk[data-align="center"] { text-align: center; }
.page .blk[data-align="left"] { text-align: left; }
.page .blk[data-align="justify"] { text-align: justify; }

/* ------------------------------ ڈائیلاگ ------------------------------ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, .45);
  display: grid;
  place-items: center;
  padding: 18px;
}
.modal[hidden] { display: none; }

.modal-card {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(560px, 100%);
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-wide { width: min(760px, 100%); }
.modal-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-card header h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px; overflow-y: auto; }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff; }
.list-item .meta { flex: 1; min-width: 0; }
.list-item .meta strong { display: block; font-size: 14px; }
.list-item .meta small { color: var(--muted); font-size: 11.5px; }
.list-item .preview {
  font-family: "Noto Nastaliq Urdu", serif;
  font-size: 14px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 22px 0; }

/* ------------------------------ ٹوسٹ ------------------------------ */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: var(--shadow-md);
  max-width: min(90vw, 520px);
  text-align: center;
}
.toast[hidden] { display: none; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--accent); }

.print-footer { display: none; }

/* ------------------------------ موبائل ------------------------------ */

@media (max-width: 1100px) {
  .body, body.settings-open .body { grid-template-columns: minmax(0, 1fr); }
  .formatbar-inner { gap: 10px; padding: 6px 10px; }
  .fb-group + .fb-group { padding-inline-start: 10px; }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    width: min(360px, 88vw);
    z-index: 50;
    box-shadow: var(--shadow-lg);
    transition: transform .22s ease;
  }
  .sidebar-content { right: 0; transform: translateX(105%); }
  .sidebar-settings { left: 0; transform: translateX(-105%); }
  body.panel-right-open .sidebar-content { transform: none; }
  body.panel-left-open .sidebar-settings { transform: none; }
  .canvas-bar { padding: 6px 10px; }
  .page-scroll { padding: 12px; }
  .brand-text small { display: none; }
  .panel-close { display: inline-flex; }
  /* on a narrow screen the words chip costs the panel toggle its room */
  #chip-words { display: none; }
  .canvas-bar-right { gap: 4px; }
  /* the floating toolbar can be wider than a phone: let it scroll sideways */
  .floating-toolbar { max-width: calc(100vw - 16px); overflow-x: auto; }
}

@media (max-width: 560px) {
  .topbar { padding: 6px 8px; gap: 6px; }
  .topbar-actions .btn { padding: 7px 9px; font-size: 13px; }
  .btn-icon { min-width: 34px; }
  .menu { min-width: 208px; }
  .brand-text small { display: none; }
}

/* =================================================================
   پرنٹ — صرف صفحہ چھپتا ہے
   ================================================================= */

@media print {
  html, body { background: #fff !important; height: auto; overflow: visible; }
  .topbar, .sidebar, .canvas-bar, .formatbar, .modal, .toast { display: none !important; }
  .app, .body, .canvas { display: block; height: auto; }
  .page-scroll { overflow: visible; padding: 0; display: block; }
  .page-stage { transform: none !important; }
  .page {
    box-shadow: none !important;
    border-radius: 0;
    margin: 0;
    width: var(--page-w);
    /* print keeps the fixed sheet height; a longer letter flows onto the next
       sheet via the @page rule below, keeping the same padding as a margin */
    height: var(--page-h);
    overflow: visible;
    padding: var(--pad-y) var(--pad-x);
  }
  .page .blk:focus { background: transparent; box-shadow: none; }
  .page .blk:empty::before { content: ""; }
  .page-limit { display: none !important; }
  .print-footer {
    display: block;
    position: fixed;
    bottom: 6mm;
    left: var(--pad-x);
    right: var(--pad-x);
    text-align: center;
    font-family: var(--ui-font);
    font-size: 9pt;
    color: #6b7280;
  }
  @page { margin: 0; }
}
