/* AlamKitab AI Essay Builder — scoped stylesheet.
   The builder root carries BOTH classes: <div class="ak-essay ak-builder">. */

.ak-builder { min-height: 60vh; }
.ak-builder .ak-b-wrap { max-width: 900px; margin: 0 auto; padding-inline: 16px; padding-block: 20px 56px; display: flex; flex-direction: column; gap: 20px; }
.ak-builder h1.ak-pagetitle, .ak-builder h1.ak-paged-title { font-size: clamp(1.45rem, 3.2vw, 2rem); }
.ak-builder h2 { font-size: 1.25rem; }
.ak-builder .ak-lede { max-width: 64ch; }

/* Top bar */
.ak-builder .ak-b-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding-bottom: 14px; border-bottom: 1px solid var(--ak-rule); }
.ak-builder .ak-b-back { font-family: var(--ak-display); font-size: .9rem; color: var(--ak-ink); text-decoration: none; white-space: nowrap; }
.ak-builder .ak-b-title { flex: 1 1 220px; min-width: 0; font-family: var(--ak-display); font-weight: 700; font-size: 1.1rem; color: var(--ak-ink); background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 6px 8px; }
.ak-builder .ak-b-title:hover, .ak-builder .ak-b-title:focus { border-color: var(--ak-rule); background: var(--ak-sheet); }
.ak-builder .ak-b-save { white-space: nowrap; }
.ak-builder .ak-b-save.saved::before { content: "✓ "; color: var(--ak-ok); }
.ak-builder .ak-b-save.error, .ak-builder .ak-b-save.auth { color: var(--ak-pen); }

/* Workspace grid + step rail */
.ak-builder .ak-workspace-grid { display: flex; flex-direction: column; gap: 24px; align-items: start; }
.ak-builder .ak-workspace-sidebar { align-self: stretch; min-width: 0; margin-bottom: 8px; }
.ak-builder .ak-workspace-main { min-width: 0; width: 100%; }
.ak-builder .ak-steprail { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.ak-builder .ak-step { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--ak-rule); border-radius: 999px; background: var(--ak-sheet); color: var(--ak-muted); font-family: var(--ak-display); font-size: .93rem; text-align: left; cursor: pointer; transition: all .2s; }
.ak-builder .ak-step .num { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-family: var(--ak-mono); font-size: .78rem; background: var(--ak-paper); border: 1px solid var(--ak-rule); }
.ak-builder .ak-step:hover:not(:disabled) { border-color: var(--ak-brand); color: var(--ak-ink); }
.ak-builder .ak-step:disabled { cursor: default; opacity: .55; }
.ak-builder .ak-step.done { color: var(--ak-ink); }
.ak-builder .ak-step.done .num { background: var(--ak-brand); border-color: var(--ak-brand); color: var(--ak-ink); }
.ak-builder .ak-step.current { border-color: var(--ak-deep); color: var(--ak-ink); font-weight: 600; box-shadow: 0 0 0 2px var(--ak-deep-soft); }
.ak-builder .ak-step.current .num { background: var(--ak-deep); border-color: var(--ak-deep); color: var(--ak-on-deep); }

/* Steps (Claude's original styling) */
.ak-builder .ak-b-step { display: flex; flex-direction: column; gap: 16px; }
.ak-builder .ak-b-topicline { font-size: .95rem; background: var(--ak-sheet); border: 1px solid var(--ak-rule); border-radius: 10px; padding: 10px 14px; }
.ak-builder .ak-b-topicline .ak-eyebrow { margin-right: 8px; }
.ak-builder .ak-b-field { display: flex; flex-direction: column; gap: 6px; }
.ak-builder .ak-b-field label { display: flex; justify-content: space-between; gap: 8px; font-family: var(--ak-display); font-weight: 600; font-size: .92rem; }
.ak-builder .ak-b-field label .ak-mono { font-weight: 400; font-size: .78rem; }
.ak-builder .ak-b-hint { font-size: .85rem; color: var(--ak-muted); }
.ak-builder textarea, .ak-builder input[type="text"], .ak-builder select { font: inherit; color: var(--ak-ink); background: var(--ak-paper); border: 1px solid var(--ak-rule); border-radius: 8px; padding: 10px 12px; width: 100%; }
.ak-builder textarea { resize: vertical; line-height: 1.6; font-family: var(--ak-body); }
.ak-builder textarea:focus, .ak-builder input:focus, .ak-builder select:focus { outline: 2px solid var(--ak-brand); outline-offset: 1px; border-color: var(--ak-brand); }
.ak-builder .ak-b-error { color: var(--ak-pen); background: var(--ak-pen-soft); border-radius: 8px; padding: 8px 12px; font-size: .92rem; }
.ak-builder .ak-b-nav { justify-content: space-between; padding-top: 8px; border-top: 1px dashed var(--ak-rule); }
.ak-builder .ak-b-copy { font-family: var(--ak-display); font-size: .8rem; border: 1px solid var(--ak-rule); background: var(--ak-sheet); color: var(--ak-ink); border-radius: 999px; padding: 4px 12px; cursor: pointer; white-space: nowrap; align-self: flex-start; }
.ak-builder .ak-b-copy:hover { border-color: var(--ak-brand); }
.ak-builder .ak-b-x { flex: none; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--ak-rule); background: var(--ak-sheet); color: var(--ak-muted); font-size: 1.1rem; line-height: 1; cursor: pointer; }
.ak-builder .ak-b-x:hover:not(:disabled) { color: var(--ak-pen); border-color: var(--ak-pen); }
.ak-builder .ak-b-x:disabled { opacity: .4; cursor: default; }

/* Step 1 */
.ak-builder .ak-b-topiclist { display: flex; flex-wrap: wrap; gap: 8px; }
.ak-builder .ak-b-topic { font-family: var(--ak-body); font-size: .9rem; text-align: left; border: 1px solid var(--ak-rule); background: var(--ak-paper); color: var(--ak-ink); border-radius: 10px; padding: 8px 12px; cursor: pointer; max-width: 100%; }
.ak-builder .ak-b-topic:hover { border-color: var(--ak-brand); }
.ak-builder .ak-b-topic.on { border-color: var(--ak-deep); background: var(--ak-deep-soft); font-weight: 600; }
.ak-builder .ak-b-warn { border-color: var(--ak-warn); background: var(--ak-warn-soft); }
.ak-builder .ak-b-warn ul { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 4px; }
.ak-builder .ak-b-angles { display: grid; gap: 8px; }
.ak-builder .ak-b-angle { display: flex; flex-direction: column; gap: 4px; text-align: left; font: inherit; color: var(--ak-ink); background: var(--ak-paper); border: 1px solid var(--ak-rule); border-radius: 10px; padding: 12px 14px; cursor: pointer; }
.ak-builder .ak-b-angle:hover { border-color: var(--ak-brand); }
.ak-builder .ak-b-angle.on { border-color: var(--ak-ok); background: var(--ak-ok-soft); }
.ak-builder .ak-b-angle .strength { font-size: .75rem; letter-spacing: 2px; color: var(--ak-brand-ink); }
.ak-builder .ak-b-angle .use { font-size: .82rem; }

/* Scores */
.ak-builder .ak-b-score { display: grid; grid-template-columns: 150px minmax(0, 1fr) 44px; gap: 10px; align-items: center; font-size: .9rem; }
.ak-builder .ak-b-score .ak-mono { text-align: right; font-size: .82rem; }
.ak-builder .ak-b-scorehint { grid-column: 1 / -1; font-size: .82rem; color: var(--ak-muted); margin-top: -4px; }
.ak-builder .ak-b-bar { display: block; height: 8px; background: var(--ak-paper); border: 1px solid var(--ak-rule); border-radius: 999px; overflow: hidden; }
.ak-builder .ak-b-bar i { display: block; height: 100%; background: var(--ak-brand); }
.ak-builder .ak-b-bar i.mid { background: var(--ak-warn); }
.ak-builder .ak-b-bar i.low { background: var(--ak-pen); }

/* Step 3 rows */
.ak-builder .ak-b-row { display: grid; grid-template-columns: 22px minmax(0, 1fr) 30px; gap: 8px; align-items: start; }
.ak-builder .ak-b-rownum { padding-top: 10px; color: var(--ak-muted); font-size: .8rem; }
.ak-builder .ak-b-rowmain { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ak-builder .ak-b-rowfb { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: .86rem; }
.ak-builder .ak-b-counter { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 30px; gap: 8px; align-items: start; }
.ak-builder .ak-b-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ak-builder .ak-b-list li { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding-top: 10px; border-top: 1px solid var(--ak-rule); }
.ak-builder .ak-b-list li:first-child { border-top: 0; padding-top: 0; }
.ak-builder .ak-b-quote { font-family: var(--ak-body); font-style: italic; }
.ak-builder .ak-b-term { font-weight: 600; }

/* Step 5 paragraphs + suggestion panel */
.ak-builder .ak-paragraph-block { border-left: 3px solid var(--ak-brand); }
.ak-builder .ak-b-blockhead { display: flex; justify-content: space-between; align-items: center; }
.ak-builder .ak-b-feedback { display: flex; flex-direction: column; gap: 12px; padding-top: 12px; border-top: 1px dashed var(--ak-rule); }
.ak-builder .ak-b-parts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0; }
.ak-builder .ak-b-parts div { background: var(--ak-paper); border: 1px solid var(--ak-rule); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.ak-builder .ak-b-parts dt { font-family: var(--ak-mono); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ak-muted); margin-bottom: 4px; }
.ak-builder .ak-b-parts dd { margin: 0; font-size: .93rem; }
.ak-builder .ak-b-overall { background: var(--ak-deep-soft); border-radius: 8px; padding: 10px 12px; }
.ak-builder .ak-b-suggest { border: 1px solid var(--ak-rule); border-radius: 10px; overflow: hidden; background: var(--ak-sheet); }
.ak-builder .ak-suggestion-tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--ak-rule); background: var(--ak-paper); scrollbar-width: thin; }
.ak-builder .ak-suggestion-tab { flex: none; border: 0; border-bottom: 2px solid transparent; background: none; padding: 10px 14px; font-family: var(--ak-display); font-size: .88rem; color: var(--ak-muted); cursor: pointer; }
.ak-builder .ak-suggestion-tab .ak-mono { font-size: .72rem; margin-left: 4px; }
.ak-builder .ak-suggestion-tab.on { color: var(--ak-ink); border-bottom-color: var(--ak-brand); font-weight: 600; }
.ak-builder .ak-b-sugglist { list-style: none; margin: 0; padding: 0 14px; }
.ak-builder .ak-suggestion-item { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--ak-rule); }
.ak-builder .ak-suggestion-item:first-child { border-top: 0; }
.ak-builder .ak-suggestion-item p { margin: 0 0 2px; }
.ak-builder .ak-verify-chip { display: inline-block; margin-top: 4px; font-family: var(--ak-mono); font-size: .68rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--ak-warn-soft); color: var(--ak-warn); border: 1px solid var(--ak-warn); }
.ak-builder .ak-b-none, .ak-builder .ak-b-fine { padding: 12px 14px; font-size: .86rem; }

/* Step 7 */
.ak-builder .ak-b-checks { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .92rem; }
.ak-builder .ak-b-checks .ok { color: var(--ak-ok); }
.ak-builder .ak-b-checks .miss { color: var(--ak-muted); }
.ak-builder .ak-b-total { border-top: 4px solid var(--ak-brand); }
.ak-builder .ak-b-totalrow { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ak-builder .ak-b-totalrow .num { font-family: var(--ak-display); font-weight: 700; font-size: 3.2rem; line-height: 1; letter-spacing: -.03em; }
.ak-builder .ak-b-passbar { position: relative; height: 12px; background: var(--ak-paper); border: 1px solid var(--ak-rule); border-radius: 999px; overflow: hidden; }
.ak-builder .ak-b-passbar i { position: absolute; inset: 0 auto 0 0; background: var(--ak-brand); }
.ak-builder .ak-b-passbar b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ak-pen); }
.ak-builder .ak-b-table { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 0; }
.ak-builder .ak-b-table th, .ak-builder .ak-b-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--ak-rule); }
.ak-builder .ak-b-table td:nth-child(2) { white-space: nowrap; }
.ak-builder .ak-b-table td:nth-child(3) { width: 40%; }
.ak-builder .ak-b-issues { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 12px; }
.ak-builder .ak-b-issues .ak-chip { margin-left: 8px; }
.ak-builder .ak-b-rewrite { background: var(--ak-deep-soft); }

/* Draft list */
.ak-builder .ak-b-listhead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.ak-builder .ak-b-drafts { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.ak-builder .ak-b-draft { gap: 10px; }
.ak-builder .ak-b-draftitle { font-family: var(--ak-display); font-weight: 700; font-size: 1.05rem; color: var(--ak-ink); background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 4px 6px; margin: -4px -6px 0; width: calc(100% + 12px); }
.ak-builder .ak-b-draftitle:hover, .ak-builder .ak-b-draftitle:focus { border-color: var(--ak-rule); background: var(--ak-paper); }
.ak-builder .ak-b-empty { align-items: flex-start; }
.ak-builder .ak-b-howto { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 8px; }

/* Buttons rendered as links */
.ak-builder a.ak-btn { text-decoration: none; }

/* ===== NEW: DATA NOTES ===== */
.ak-builder .ak-b-datanotes { background: var(--ak-paper); border-left: 4px solid var(--ak-brand); padding: 16px; margin-top: 24px; margin-bottom: 24px; }
.ak-builder .ak-b-datanotes-toggle { display: flex; justify-content: space-between; align-items: center; width: 100%; background: none; border: none; cursor: pointer; }
.ak-builder .ak-b-datanotes-content { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--ak-rule); }
.ak-builder .ak-b-note-row { display: grid; grid-template-columns: 100px 1fr 130px 30px; gap: 8px; margin-bottom: 8px; align-items: center; }
.ak-builder .ak-b-note-row select, .ak-builder .ak-b-note-row input { padding: 8px; border: 1px solid var(--ak-rule); border-radius: 6px; font-size: 0.9rem; background: var(--ak-sheet); }

/* ===== NEW: MODAL & COPY VIEW ===== */
.ak-builder .ak-b-modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.7); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 24px; backdrop-filter: blur(4px); }
.ak-builder .ak-b-modal-content { background: var(--ak-sheet); border-radius: 12px; width: 100%; max-width: 800px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 40px rgba(0,0,0,0.2); }
.ak-builder .ak-b-modal-header { padding: 16px 24px; border-bottom: 1px solid var(--ak-rule); display: flex; justify-content: space-between; align-items: center; }
.ak-builder .ak-b-modal-body { padding: 32px; overflow-y: auto; background: var(--ak-paper); }

.ak-builder .ak-b-copy-view { font-family: var(--ak-body); font-size: 1.1rem; line-height: 2.2; color: var(--ak-ink); background-color: var(--ak-sheet); padding: 32px; border-radius: 4px; box-shadow: inset 0 0 0 1px var(--ak-rule); }
.ak-builder .ak-b-copy-view .ak-b-copy-title { font-family: var(--ak-display); font-size: 1.5rem; font-weight: 700; margin-bottom: 24px; line-height: 1.3; }
.ak-builder .ak-b-copy-view .ak-b-copy-section { margin-bottom: 2.2rem; page-break-inside: avoid; }
.ak-builder .ak-b-copy-view .ak-b-copy-text { white-space: pre-wrap; }
.ak-builder .ak-b-copy-view .ak-b-copy-placeholder { color: var(--ak-muted); font-style: italic; }
.ak-builder .ak-b-copy-view .ak-b-copy-outline h4 { margin-bottom: 8px; }
.ak-builder .ak-b-copy-view .ak-b-copy-outline ol { padding-left: 2rem; margin-bottom: 24px; }

/* Mobile: rail becomes a horizontal scroller */
@media (max-width: 860px) {
  .ak-builder .ak-steprail { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 8px; }
  .ak-builder .ak-b-parts { grid-template-columns: 1fr; }
  .ak-builder .ak-b-note-row { grid-template-columns: 1fr; gap: 4px; padding-bottom: 12px; border-bottom: 1px dashed var(--ak-rule); }
}
@media (max-width: 480px) {
  .ak-builder .ak-b-wrap { padding-inline: 12px; }
  .ak-builder .ak-b-score { grid-template-columns: 110px minmax(0, 1fr) 40px; }
  .ak-builder .ak-b-counter { grid-template-columns: 1fr 30px; }
  .ak-builder .ak-b-counter textarea:nth-of-type(2) { grid-column: 1; }
  .ak-builder .ak-b-drafts { grid-template-columns: 1fr; }
  .ak-builder .ak-suggestion-item { flex-direction: column; }
  .ak-builder .ak-b-totalrow .num { font-size: 2.6rem; }
}

/* ===== PRINT STYLES (Download PDF) ===== */
@media print {
  body * { visibility: hidden; }
  .ak-builder .ak-b-modal-body, .ak-builder .ak-b-modal-body * { visibility: visible; }
  .ak-builder .ak-b-modal-body { position: absolute; left: 0; top: 0; width: 100%; padding: 0; overflow: visible; background: none; }
  .ak-builder .ak-b-copy-view { box-shadow: none; padding: 0; background: none; font-size: 12pt; }
  .ak-builder .ak-b-copy-view .ak-b-copy-title { font-size: 18pt; }
  .ak-builder .ak-b-modal-header { display: none; }
}

/* ===== FIX LAYOUT OVERRIDES ===== */

/* Force the step rail to be a horizontal row of pills */
.ak-builder .ak-workspace-sidebar {
  position: static !important;
  width: 100% !important;
  margin-bottom: 24px;
}
.ak-builder .ak-steprail {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: wrap !important;
  gap: 8px !important;
}
.ak-builder .ak-step {
  width: auto !important;
}

/* ===== STICKY NOTES ===== */
.ak-builder .ak-b-datanotes { 
  background: #fffbeb; /* Light yellow sticky note vibe */
  border: 1px solid #fde68a; 
  border-left: 4px solid #f59e0b; 
  padding: 16px; 
  margin-bottom: 24px; 
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}
.ak-builder .ak-b-datanotes-toggle { 
  display: flex; justify-content: space-between; align-items: center; 
  width: 100%; background: none; border: none; cursor: pointer; 
}
.ak-builder .ak-b-datanotes-content { 
  margin-top: 16px; padding-top: 16px; border-top: 1px dashed #fcd34d; 
}
.ak-builder .ak-b-sticky-input {
  flex: 1;
  width: 100%;
  font-family: var(--ak-body) !important; /* 👈 Changed from mono to body font */
  font-size: 1.1rem;
  line-height: 1.8;
  color: var(--ak-ink);
  background: #ffffff;
  border: 1px solid #fcd34d;
  padding: 24px;
  border-radius: 8px;
  resize: none;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

/* ===== FIX MODAL HORIZONTAL SCROLL ===== */
.ak-builder .ak-b-modal-body {
  overflow-x: hidden !important; /* Prevent side scroll */
}
.ak-builder .ak-b-copy-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word; /* Force long words to wrap */
}

/* ===== MODAL OVERRIDES FOR NOTES ===== */
.ak-builder .ak-b-notes-modal {
  max-width: 900px;
  height: 85vh; /* Takes up most of the screen */
}
.ak-builder .ak-b-notes-modal .ak-b-modal-body {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 24px;
}

/* ===== STICKY NOTE TEXTAREA ===== */
.ak-builder .ak-b-sticky-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  height: 100%;
}
.ak-builder .ak-b-sticky-input {
  flex: 1;
  width: 100%;
  font-family: var(--ak-mono) !important; /* Monospace for notes */
  font-size: 1rem;
  line-height: 1.8;
  background: #ffffff;
  border: 1px solid #fcd34d;
  padding: 24px;
  border-radius: 8px;
  resize: none; /* Let the modal handle the sizing */
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}
.ak-builder .ak-b-sticky-input:focus {
  outline: 2px solid #f59e0b;
  border-color: #f59e0b;
}

/* Ensure the copy text wraps in the preview modal */
.ak-builder .ak-b-copy-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}