/* ID lock so a stale class rule cannot leave #secondaryTools in normal flow. */
#secondaryTools {
  position: fixed;
  z-index: 1000;
  display: none;
  box-sizing: border-box;
  overflow: auto;
  background: #fffdf5;
  min-width: 0;
  width: 240px;
  height: 132px;
  max-width: 240px;
  max-height: 132px;
}
body.secondary-tools-collapsed #secondaryTools {
  display: none !important;
}
body:not(.secondary-tools-collapsed) #secondaryTools {
  display: grid !important;
}
#secondaryTools .drawer-grid,
#secondaryTools .menu-group {
  min-width: 0;
  max-width: 100%;
}
@media (max-width: 520px) {
  #secondaryTools {
    width: calc(50vw - 1px);
    height: calc(50vh - 1px);
    min-width: calc(50vw - 1px);
    min-height: calc(50vh - 1px);
    max-width: calc(50vw - 1px);
    max-height: calc(50vh - 1px);
  }
}

:root {
  --corn: #f7c948;
  --corn-deep: #b7791f;
  --husk: #2f855a;
  --husk-dark: #22543d;
  --ink: #1f2933;
  --muted: #617080;
  --cream: #fff8df;
  --field: #f3ead0;
  --panel: #fffdf5;
  --line: #ded2aa;
  --shadow: 0 18px 45px rgba(74, 50, 12, .14);
  --radius: 8px;
  --paper-width: 8.5in;
  --paper-height: 11in;
  --paper-margin: .7in;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 12%, rgba(247, 201, 72, .28), transparent 26rem),
    linear-gradient(135deg, #fffaf0 0%, #f4edd5 45%, #edf7ed 100%);
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="text"],
input[type="color"] {
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

button {
  min-height: 2.35rem;
  padding: .55rem .75rem;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

button:hover,
button:focus-visible,
a:focus-visible,
input:focus,
textarea:focus,
select:focus {
  outline: 3px solid rgba(247, 201, 72, .45);
  outline-offset: 2px;
}

button:hover {
  border-color: var(--corn-deep);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .8rem clamp(1rem, 3vw, 2rem);
  background: rgba(255, 253, 245, .92);
  border-bottom: 1px solid rgba(183, 121, 31, .25);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 2.5rem;
  height: 2.5rem;
  place-items: center;
  border-radius: 50%;
  color: #233d21;
  font-weight: 900;
  background:
    linear-gradient(90deg, transparent 44%, rgba(255, 255, 255, .42) 44% 56%, transparent 56%),
    var(--corn);
  border: 2px solid var(--husk);
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.eyebrow,
.panel-note,
.template-card span,
.app-footer {
  color: var(--muted);
}

.top-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .35rem;
}

.top-nav a {
  padding: .45rem .7rem;
  color: var(--ink);
  text-decoration: none;
  border-radius: 999px;
}

.top-nav a:hover {
  background: rgba(247, 201, 72, .24);
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: min(1580px, calc(100% - 2rem));
  margin: 0 auto;
}


.start-section {
  margin: .75rem 0 1rem;
  border: 1px solid rgba(183, 121, 31, .22);
  border-radius: var(--radius);
  background: rgba(255, 253, 245, .92);
  box-shadow: 0 10px 26px rgba(74, 50, 12, .08);
}

.start-section > summary {
  list-style: none;
  font-size: 1rem;
}

.start-section > summary::-webkit-details-marker {
  display: none;
}

.start-section > summary::before {
  content: "▸ ";
  color: var(--husk-dark);
}

.start-section[open] > summary::before {
  content: "▾ ";
}

.start-section .hero,
.start-section .template-band {
  padding-left: .9rem;
  padding-right: .9rem;
}

.start-section .template-band {
  padding-bottom: 1rem;
}


.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
  padding: 1rem 0 .75rem;
}

.hero h1 {
  max-width: 820px;
  margin: .15rem 0 .25rem;
  font-size: clamp(1.45rem, 3vw, 2.4rem);
  line-height: 1.08;
}

.hero p {
  max-width: 720px;
  margin: 0;
  color: #3c4856;
  font-size: .98rem;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 800;
  font-size: .78rem;
}

.status-card {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-width: 210px;
  padding: .65rem;
  border: 1px solid rgba(183, 121, 31, .22);
  border-radius: var(--radius);
  background: rgba(255, 253, 245, .9);
  box-shadow: var(--shadow);
}

.status-card span {
  font-weight: 700;
}

.template-band {
  display: grid;
  gap: 1rem;
  padding: 1rem 0 1.25rem;
}

.section-heading h2 {
  margin: .15rem 0 0;
  font-size: 1.6rem;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .75rem;
}

.template-card {
  display: grid;
  gap: .35rem;
  min-height: 7rem;
  align-content: start;
  padding: 1rem;
  text-align: left;
  background: rgba(255, 253, 245, .86);
}

.template-card strong {
  font-size: 1.05rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(215px, 250px) minmax(0, 1fr) minmax(215px, 245px) minmax(215px, 245px);
  gap: 1rem;
  align-items: start;
  padding-bottom: 2rem;
}

.side-panel {
  position: sticky;
  top: 5.2rem;
  z-index: 12;
  display: grid;
  gap: .75rem;
}

details {
  border: 1px solid rgba(183, 121, 31, .22);
  border-radius: var(--radius);
  background: rgba(255, 253, 245, .92);
  box-shadow: 0 10px 26px rgba(74, 50, 12, .08);
}

summary {
  padding: .8rem .9rem;
  font-weight: 800;
  cursor: pointer;
}

details > label,
details > input,
details > select,
details > button,
.panel-note {
  width: calc(100% - 1.6rem);
  margin: 0 .8rem .7rem;
}

label {
  display: grid;
  gap: .3rem;
  color: #344054;
  font-size: .9rem;
}

input[type="text"],
select {
  width: 100%;
  min-height: 2.35rem;
  padding: .45rem .55rem;
  background: #fff;
}

input[type="color"] {
  width: 2.4rem;
  height: 2.1rem;
  padding: .15rem;
  background: #fff;
}

.toggle {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: .55rem;
}

.toggle input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--husk);
}

.panel-note {
  font-size: .84rem;
  line-height: 1.45;
}

.editor-frame {
  position: relative;
  min-width: 0;
}

.toolbar,
.preview-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
  padding: .65rem;
  border: 1px solid rgba(183, 121, 31, .22);
  background: #fffdf5;
}

.toolbar-shell {
  position: relative;
  z-index: 10;
  background: transparent;
}

#editor {
  scroll-margin-top: 4.75rem;
}

.toolbar {
  position: sticky;
  top: 4.75rem;
  z-index: 16;
  border-radius: var(--radius) var(--radius) 0 0;
  background: #fffdf5;
}

.toolbar button,
.toolbar select {
  min-height: 2.1rem;
  padding: .38rem .58rem;
}

.primary-tool {
  color: #233d21;
  border-color: rgba(47, 133, 90, .45);
  background: linear-gradient(180deg, #fff8df, #f7c948);
  font-weight: 800;
}

.more-tools {
  position: relative;
}

.tools-menu {
  position: fixed;
  top: calc(100% + .35rem);
  right: 0;
  left: auto;
  z-index: 1000;
  display: grid;
  gap: .65rem;
  box-sizing: border-box;
  /* Wide menus are an explicit box, not max-content. 240×132 = 31,680,
     under the phone half-cap area (~56k) and shorter than that panel. */
  width: 240px;
  height: 132px;
  min-width: 0;
  max-width: 240px;
  max-height: 132px;
  padding: .7rem;
  border: 1px solid rgba(183, 121, 31, .28);
  border-radius: var(--radius);
  background: #fffdf5;
  box-shadow: 0 16px 36px rgba(74, 50, 12, .18);
  overflow: auto;
}

.drawer-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}


.drawer-heading strong,
.drawer-heading span {
  display: block;
}

.drawer-heading span {
  color: var(--muted);
  font-size: .86rem;
}

.drawer-heading button {
  min-height: 2rem;
  padding: .35rem .65rem;
}

.tools-menu .drawer-grid {
  display: grid;
  grid-template-columns: minmax(0, max-content);
  gap: .65rem;
  min-width: 0;
  max-width: 100%;
}

.tools-menu .menu-group {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: .4rem;
  align-content: start;
  min-width: 0;
  max-width: 100%;
}

.menu-group strong {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  gap: .45rem;
  color: var(--husk-dark);
  font-size: .9rem;
}

.tools-menu .menu-group button,
.tools-menu .menu-group .color-tool {
  width: 100%;
}

.tools-menu .drawer-heading span {
  max-width: 12.5rem;
  white-space: normal;
}

.tools-menu .color-tool {
  flex-wrap: nowrap;
}

.tools-menu .icon-button span,
.tools-menu .color-tool span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap;
}

.group-icon,
.tool-icon {
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.group-icon {
  width: 1rem;
  height: 1rem;
  stroke-width: 2.3;
}

.tool-icon {
  width: 1.08rem;
  height: 1.08rem;
  stroke-width: 2.1;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: .45rem;
  min-height: 2.25rem;
  padding: .45rem .55rem;
  text-align: left;
}

.icon-button span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: break-word;
  line-height: 1.2;
}

.color-tool {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem;
  min-height: 2.1rem;
  padding: .25rem .4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-size: .86rem;
}

.color-tool span {
  flex: 1 1 4.5rem;
}

.color-tool input {
  flex: 0 0 auto;
}

.divider {
  width: 1px;
  height: 1.8rem;
  background: var(--line);
}

.underline {
  text-decoration: underline;
  font-weight: 800;
}

.preview-controls {
  position: relative;
  z-index: 11;
  justify-content: space-between;
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}

.preview-controls .toggle {
  width: auto;
  margin: 0;
  white-space: normal;
}

.paper {
  width: min(100%, var(--paper-width));
  max-width: 100%;
  min-height: var(--paper-height);
  margin: 1rem auto 2.25rem;
  padding: var(--paper-margin);
  color: #111827;
  background: #fff;
  box-shadow: 0 22px 70px rgba(17, 24, 39, .22);
  overflow-wrap: break-word;
}

.paper.letter {
  --paper-width: 8.5in;
  --paper-height: 11in;
}

.paper.legal {
  --paper-width: 8.5in;
  --paper-height: 14in;
}

.paper.a4 {
  --paper-width: 8.27in;
  --paper-height: 11.69in;
}

.paper.landscape.letter {
  --paper-width: 11in;
  --paper-height: 8.5in;
}

.paper.landscape.legal {
  --paper-width: 14in;
  --paper-height: 8.5in;
}

.paper.landscape.a4 {
  --paper-width: 11.69in;
  --paper-height: 8.27in;
}

.paper.margin-normal {
  --paper-margin: .7in;
}

.paper.margin-narrow {
  --paper-margin: .42in;
}

.paper.margin-wide {
  --paper-margin: 1in;
}

.doc-header,
.doc-footer {
  min-height: .35in;
  color: #536173;
  font-size: .78rem;
}

.doc-header {
  position: relative;
  z-index: 0;
  background: #fff;
}

.doc-header {
  padding-bottom: .22in;
  border-bottom: 1px solid #e5e7eb;
}

.doc-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: .28in;
  padding-top: .16in;
  border-top: 1px solid #e5e7eb;
}

.doc-body {
  position: relative;
  z-index: 1;
  min-height: calc(var(--paper-height) - (var(--paper-margin) * 2) - 1in);
  padding: .24in 0;
  line-height: 1.55;
  background: #fff;
}

.doc-body:focus,
.doc-header:focus,
.doc-footer [contenteditable]:focus {
  outline: 2px solid rgba(47, 133, 90, .35);
  outline-offset: 2px;
}

.doc-body h1,
.doc-body h2,
.doc-body h3 {
  line-height: 1.16;
}

.doc-body h1 {
  margin: .1rem 0 .7rem;
  font-size: 2rem;
}

.doc-body h2 {
  margin: 1.2rem 0 .45rem;
  font-size: 1.3rem;
}

.doc-body h3 {
  margin: 1rem 0 .35rem;
}

.doc-body p {
  margin: .5rem 0;
}

.doc-body blockquote {
  margin: .8rem 0;
  padding: .1rem .7rem;
  border-left: 4px solid #f7c948;
  color: #334155;
  background: #fffbeb;
}

.doc-body hr {
  border: 0;
  border-top: 1px solid #cbd5e1;
  margin: 1rem 0;
}

.doc-body table {
  position: relative;
  z-index: 1;
  width: 100%;
  margin: .8rem 0;
  border-collapse: collapse;
  background: #fff;
}

.doc-body th,
.doc-body td {
  min-width: 3.5rem;
  padding: .45rem;
  border: 1px solid #cbd5e1;
  vertical-align: top;
  background: #fff;
}

.doc-body th {
  background: #f8fafc;
}

.doc-body img {
  max-width: 100%;
  height: auto;
}

.doc-note {
  margin: .8rem 0;
  padding: .7rem .8rem;
  border: 1px solid #f7c948;
  border-left: 5px solid #b7791f;
  background: #fff8df;
}

.signature-line {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) minmax(8rem, .45fr);
  gap: 1rem;
  align-items: end;
  margin: 1.25rem 0 .5rem;
}

.signature-line span {
  display: block;
  padding-top: 1.5rem;
  border-top: 1px solid #111827;
  color: #536173;
  font-size: .8rem;
}

.page-break {
  display: block;
  height: .1in;
  margin: .4in 0;
  border-top: 2px dashed #94a3b8;
  page-break-after: always;
  break-after: page;
}

.page-break::before {
  content: "Page break";
  display: inline-block;
  margin-top: -.7rem;
  padding: 0 .35rem;
  color: #64748b;
  background: #fff;
  font-size: .75rem;
}

.page-number::after {
  content: " 1";
}

.hide-header .doc-header,
.hide-footer .doc-footer,
.hide-numbers .page-number {
  display: none;
}

.hide-formatting-toolbar .toolbar,
.hide-formatting-toolbar .tools-menu {
  display: none;
}

.hide-secondary-menu #toggleSecondaryTools,
.hide-secondary-menu .tools-menu {
  display: none;
}

.secondary-tools-collapsed .tools-menu {
  display: none;
}

.hide-side-panels .workspace {
  grid-template-columns: minmax(0, 1fr);
}

.hide-side-panels .side-panel {
  display: none;
}

.preview-on .paper {
  background:
    linear-gradient(#fff, #fff) padding-box,
    repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--paper-height) - 1px), rgba(47, 133, 90, .45) calc(var(--paper-height) - 1px), rgba(47, 133, 90, .45) var(--paper-height)) border-box;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .45rem .8rem;
  width: calc(100% - 1.6rem);
  margin: 0 .8rem .8rem;
  padding: .75rem;
  border-radius: var(--radius);
  background: #fff;
}

.stats-grid span {
  color: var(--muted);
}

.stats-grid strong {
  text-align: right;
}

.app-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem clamp(1rem, 3vw, 2rem);
  border-top: 1px solid rgba(183, 121, 31, .22);
  background: rgba(255, 253, 245, .8);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .export-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .paper {
    max-width: 100%;
    height: auto;
  }
}

@media (max-width: 520px) {
  .tools-menu {
    box-sizing: border-box;
    overflow: auto;
    min-width: calc(50vw - 1px);
    width: calc(50vw - 1px);
    max-width: calc(50vw - 1px);
    min-height: calc(50vh - 1px);
    height: calc(50vh - 1px);
    max-height: calc(50vh - 1px);
  }

  .tools-menu .drawer-grid,
  .tools-menu .menu-group {
    width: 100%;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr);
  }

  .tools-menu .icon-button span,
  .tools-menu .color-tool span,
  .tools-menu .drawer-heading span {
    min-width: 0;
    max-width: none;
    white-space: normal;
  }
}

@media (max-width: 760px) {
  .app-header,
  .hero,
  .app-footer {
    align-items: stretch;
  }

  .app-header,
  .hero {
    flex-direction: column;
  }

  .app-header {
    position: static;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .template-grid,
  .side-panel,
  .export-panel {
    grid-template-columns: 1fr;
  }

  .top-nav {
    justify-content: flex-start;
  }

  #editor {
    scroll-margin-top: 0;
  }

  .toolbar {
    top: 0;
  }

  .paper {
    padding: .45in;
    transform-origin: top center;
  }
}

@page {
  size: letter portrait;
  margin: 0;
}

@media print {
  body {
    background: #fff;
  }

  .app-header,
  .start-section,
  .hero,
  .template-band,
  .side-panel,
  .toolbar-shell,
  .toolbar,
  .tools-menu,
  .preview-controls,
  .app-footer {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .editor-frame {
    width: auto;
    margin: 0;
    padding: 0;
    display: block;
  }

  .paper {
    width: auto;
    min-height: auto;
    margin: 0;
    padding: var(--paper-margin);
    box-shadow: none;
  }

  .page-break {
    border: 0;
    height: 0;
    margin: 0;
  }

  .page-break::before {
    content: "";
    display: none;
  }
}
