/* ==========================================================================
   styles/layout.css
   The app shell: title bar, ribbon, the two panes, status bar.

   Grid rows, top to bottom:
       title bar   - file name and file actions
       ribbon      - the tools, grouped and labelled
       split       - preview | gutter | source
       status bar  - counts and the issue tally

   The frontmatter is not a row here. It lives in the publish panel, which
   floats over this shell - see styles/panel.css for why.
   ========================================================================== */

.app {
  display: grid;
  grid-template-rows:
    var(--bar-h) var(--menu-h) var(--tab-h) var(--toolbar-h) minmax(0, 1fr) var(--status-h);
  position: relative;
  height: 100vh;
}

/* --------------------------------------------------------------------------
   Title bar
   -------------------------------------------------------------------------- */

.titlebar {
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px; position: relative;
  background: var(--panel);
  border-bottom: 1px solid var(--line-soft);
}

/* The brand is centred on the window, not on whatever is left over between
   the two clusters of buttons - so it stays put as they change width. */
.brand {
  position: absolute; inset-inline-start: 50%; top: 50%;
  transform: translate(50%, -50%);
  display: flex; align-items: center; gap: 9px;
  pointer-events: none;
  white-space: nowrap;
}

/* The mark is inlined by ui/logo.js and inherits currentColor, so it follows
   the theme. A CSS mask was tried first and renders nothing at all when the
   file is missing - the worst failure for the one element that identifies
   the tool. */
/* The mark takes the text colour, not the accent - so it is near-black on the
   light themes, the way the site prints it, and turns pale on the dark ones.
   It always matches the word beside it. */
.brand__mark {
  width: 30px; height: 30px; flex-shrink: 0;
  display: grid; place-items: center;
  color: var(--fg);
}
.brand__mark svg { width: 100%; height: 100%; display: block; }
.brand__name { font-size: 0.88rem; font-weight: 700; letter-spacing: -0.01em; }

.titlebar__file {
  display: flex; align-items: center; gap: 7px;
  margin-inline: 10px auto; min-width: 0;
}
.titlebar__name {
  font-family: var(--font-mono); font-size: 0.78rem; color: var(--fg);
  direction: ltr; unicode-bidi: isolate;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40ch;
}
.titlebar__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.titlebar__actions { display: flex; align-items: center; gap: 3px; }

/* --------------------------------------------------------------------------
   Panes
   -------------------------------------------------------------------------- */

/* --- split panes -------------------------------------------------------- */

.split {
  display: grid;
  grid-template-columns: var(--preview-w, 1fr) 6px var(--source-w, 1fr);
  min-width: 0; min-height: 0;
}
/* One visible pane means one column. Keeping three definitions here put the
   surviving pane into the first, zero-width column - which is exactly why
   the "متن" view came up blank. */
.app.view-source .split,
.app.view-preview .split { grid-template-columns: 1fr; }
.app.view-source .pane--preview,
.app.view-source .gutter,
.app.view-preview .pane--source,
.app.view-preview .gutter { display: none; }

.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--paper); }
.pane--source { border-inline-start: 1px solid var(--line); }

.pane__head {
  height: 32px; flex-shrink: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px;
  font-size: 0.76rem; color: var(--fg-dim);
  background: var(--panel); border-bottom: 1px solid var(--line-soft);
}
.pane__head .spacer { margin-inline-start: auto; }

.pane__body { flex: 1; min-height: 0; overflow: auto; }
/* Nothing written yet means nothing to scroll to. */
.pane__body.is-empty { overflow: hidden; }
/* The preview reserves 40vh of trailing space so the last line can sit at a
   comfortable height. With nothing written, that space is just a scrollbar. */
.pane__body.is-empty .preview { padding: 0; height: 100%; max-width: none; }
.pane--source .pane__body { overflow: hidden; }

.gutter { cursor: col-resize; background: var(--line-soft); transition: background var(--fast); }
.gutter:hover, .gutter.is-dragging { background: var(--accent); }

/* --------------------------------------------------------------------------
   Issues drawer
   Readability first: this is where mistakes get explained, so it gets real
   line height, a wide message column, and colour only where it means something.
   -------------------------------------------------------------------------- */

.issues {
  position: absolute; inset-inline: 0; inset-block-end: var(--status-h);
  max-height: min(46vh, 460px); overflow: auto;
  background: var(--panel);
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 60;
}

.issues__head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  font-size: 0.82rem; font-weight: 600;
}
.issues__head .spacer { margin-inline-start: auto; }

.issue {
  display: block; width: 100%; text-align: start;
  padding: 14px 18px; border: 0; border-bottom: 1px solid var(--line-soft);
  background: transparent; color: var(--fg); font-family: inherit;
  cursor: pointer; transition: background var(--fast);
}
.issue:last-child { border-bottom: 0; }
.issue:hover { background: var(--panel-2); }

.issue__top { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.issue__tag {
  font-size: 0.66rem; font-weight: 700; line-height: 1;
  padding: 4px 8px; border-radius: 5px; flex-shrink: 0;
}
.issue--error .issue__tag { background: var(--err); color: #fff; }
.issue--warn .issue__tag { background: var(--warn); color: #fff; }
.issue__where { font-size: 0.72rem; color: var(--fg-dim); font-family: var(--font-mono); direction: ltr; }
.issue__rule { font-size: 0.68rem; color: var(--fg-faint); font-family: var(--font-mono); direction: ltr; margin-inline-start: auto; }

.issue__msg { font-size: 0.86rem; line-height: 1.95; color: var(--fg); }

.issue__code {
  font-family: var(--font-mono); font-size: 0.75rem; line-height: 1.9;
  direction: ltr; text-align: left; unicode-bidi: plaintext;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 11px; margin-top: 9px;
  white-space: pre-wrap; word-break: break-word; color: var(--fg-dim);
}
.issue__code--fix { border-color: var(--ok); color: var(--ok); }
.issue__code b { display: block; font-family: var(--font-ui); font-size: 0.7rem;
                 direction: rtl; text-align: right; margin-bottom: 4px; opacity: 0.8; font-weight: 500; }

.issues__empty { padding: 26px 18px; text-align: center; color: var(--fg-dim); font-size: 0.85rem; }

/* --------------------------------------------------------------------------
   Status bar
   -------------------------------------------------------------------------- */

.statusbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px;
  background: var(--panel); border-top: 1px solid var(--line);
  font-size: 0.76rem; color: var(--fg-dim);
}
.statusbar .spacer { margin-inline-start: auto; }
.statusbar button {
  background: none; border: 0; color: inherit; font: inherit; cursor: pointer;
  padding: 4px 8px; border-radius: 5px;
}
.statusbar button:hover { background: var(--panel-2); color: var(--fg); }
.status--ok { color: var(--ok); }
.status--err { color: var(--err); }
.status--warn { color: var(--warn); }

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

.toast {
  position: fixed; inset-block-end: 48px; inset-inline-start: 50%;
  transform: translateX(50%) translateY(10px);
  background: var(--ink); color: #f5f2ea;
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 11px 20px; font-size: 0.84rem;
  opacity: 0; pointer-events: none;
  transition: opacity var(--fast), transform var(--fast);
  z-index: 400; max-width: 80vw;
}
.toast.is-visible { opacity: 1; transform: translateX(50%) translateY(0); }

/* --------------------------------------------------------------------------
   Narrow screens
   -------------------------------------------------------------------------- */

@media (max-width: 820px) {
  .split { grid-template-columns: 1fr; }
  .gutter, .pane--preview { display: none; }
  .app.view-preview .pane--preview { display: flex; }
  .app.view-preview .pane--source { display: none; }
  .brand__name { display: none; }
}

/* --------------------------------------------------------------------------
   Empty state
   When nothing is open, the preview pane carries the house mark. It is the
   one place in the studio with room for it, and it turns a blank rectangle
   into something that says whose tool this is.
   -------------------------------------------------------------------------- */

.welcome {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px; height: 100%; min-height: 0; padding: 24px;
  text-align: center;
}
.welcome__mark {
  width: 148px; height: 148px;
  display: grid; place-items: center;
  color: var(--fg);
}
.welcome__mark svg { width: 100%; height: 100%; display: block; }
/* Mark above, name beneath, a hairline between them. Stacked rather than
   side by side because the horse is tall and a wordmark beside it would
   leave the pair lopsided. */
.welcome__name {
  font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; color: var(--fg);
  padding-top: 16px; position: relative;
}
.welcome__name::before {
  content: ''; position: absolute; top: 0; inset-inline-start: 50%;
  transform: translateX(50%);
  width: 46px; height: 1px; background: var(--line);
}
.welcome__hint { font-size: 0.85rem; color: var(--fg-dim); line-height: 2; max-width: 34ch; }
.welcome__hint kbd {
  display: inline-block; font-family: var(--font-mono); font-size: 0.72rem;
  direction: ltr; unicode-bidi: isolate;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 5px; padding: 2px 6px;
}
