/* App page (/app). Values come from tokens.css (see DESIGN.md). */

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-4);
  height: 60px; padding: 0 var(--gutter);
  background: var(--navy-950); color: #fff;
  border-bottom: 1px solid rgb(255 255 255 / .08);
}
.brand { display: inline-flex; align-items: center; gap: var(--s-3); color: #fff; text-decoration: none; font: 600 16px/1 var(--font-sans); }
.brand img { display: block; }
.topbar-tag { font-size: var(--fs-small); color: rgb(255 255 255 / .6); }
@media (max-width: 560px) { .topbar-tag { display: none; } }

/* ---- layout ---- */
.layout {
  display: grid; grid-template-columns: minmax(320px, 400px) 1fr; gap: var(--s-6);
  max-width: 1320px; margin: 0 auto; padding: var(--s-6) var(--gutter) var(--s-8);
  align-items: start;
}
@media (max-width: 960px) { .layout { grid-template-columns: 1fr; padding-top: var(--s-5); } }

/* ---- left panel ---- */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1); position: sticky; top: 84px; overflow: hidden;
}
@media (max-width: 960px) { .panel { position: static; } }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-1); padding: var(--s-1); margin: var(--s-4) var(--s-4) 0; background: var(--surface-2); border-radius: var(--r-md); }
.tab {
  height: 38px; border: 0; border-radius: var(--r-sm); background: transparent; cursor: pointer;
  font: 600 14px/1 var(--font-sans); color: var(--text-muted);
  transition: background-color .15s, color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.dot { display: inline-block; width: 7px; height: 7px; margin-left: 4px; border-radius: 50%; background: var(--brass); vertical-align: 2px; }

.tab-body { padding: var(--s-5); display: flex; flex-direction: column; gap: var(--s-4); }
label { display: flex; flex-direction: column; gap: 6px; min-width: 0; font: 600 var(--fs-small)/1.4 var(--font-sans); }
label small, .small { font-weight: 400; color: var(--text-muted); font-size: 13px; margin: 0; }
.opt { font-weight: 400; color: var(--text-muted); }
input, textarea {
  width: 100%; min-width: 0;
  font: 400 15px/1.4 var(--font-sans); color: var(--text);
  padding: 10px 12px; min-height: 44px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: .7; }
input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
textarea { resize: vertical; }
label.check { flex-direction: row; align-items: center; gap: var(--s-2); font-weight: 400; }
label.check input { width: 18px; min-height: 0; height: 18px; accent-color: var(--primary); }
fieldset { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s-4); margin: 0; display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }
legend { font: 600 var(--fs-small)/1 var(--font-sans); padding: 0 6px; }
.grid2, .grid3 { display: grid; gap: var(--s-3); }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: 1fr 64px 1fr; }
@media (max-width: 400px) { .grid2 { grid-template-columns: 1fr; } }
.row { display: flex; gap: var(--s-2); }

.btn-block { width: 100%; height: 48px; font-size: 16px; }
.btn-sm { height: 36px; padding: 0 var(--s-4); font-size: 14px; }
button.link { border: 0; background: none; color: var(--error); padding: 0; font: 500 14px var(--font-sans); text-decoration: underline; cursor: pointer; }

.upload input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.upload span {
  display: flex; align-items: center; justify-content: center; gap: var(--s-2);
  padding: var(--s-5) var(--s-4); text-align: center;
  border: 1.5px dashed var(--border); border-radius: var(--r-md);
  color: var(--primary); font-weight: 600; cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.upload span::before {
  content: ""; width: 18px; height: 18px; flex: none; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 16V4M7 9l5-5 5 5M5 20h14'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 16V4M7 9l5-5 5 5M5 20h14'/%3E%3C/svg%3E") center / contain no-repeat;
}
.upload span:hover { border-color: var(--primary); background: var(--surface-2); }
.upload:focus-within span { border-color: var(--primary); background: var(--surface-2); outline: 2px solid var(--primary); outline-offset: 2px; }
#crop-canvas { max-width: 100%; border: 1px solid var(--border); border-radius: var(--r-sm); cursor: crosshair; touch-action: none; background: #fff; }
.sig-saved { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-3); background: #fff; border: 1px solid var(--border); border-radius: var(--r-sm); }
.sig-saved img { max-height: 52px; max-width: 220px; }

.note { margin: 0; font-size: 13px; color: var(--text-muted); }
.note:empty { display: none; }
.note.warn { background: var(--warning-bg); color: var(--warning); padding: var(--s-3); border-radius: var(--r-sm); }
.note.err { color: var(--error); }
.note.ok { color: var(--success); }

/* ---- preview ---- */
.preview-col { min-width: 0; }
.preview-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-4); color: var(--text-muted); font-size: var(--fs-small); }
.page-wrap { position: relative; }

/* A US Letter page at 96 px/in: 8.5in wide, 1in margins, Times New Roman 12pt. */
.page {
  width: 100%; max-width: 816px; min-height: 1056px; margin: 0 auto;
  padding: 48px 96px 96px;
  background: var(--paper); color: #000; border-radius: 3px;
  box-shadow: var(--shadow-paper);
  font: 16px/1.15 var(--font-memo);
  transition: opacity .3s, filter .3s;
}
.page.dim { opacity: .35; filter: blur(1.5px); pointer-events: none; }
@media (max-width: 700px) { .page { padding: 28px 22px 48px; min-height: 0; font-size: 14px; } }
.page p { margin: 0 0 16px; }
.letterhead { position: relative; text-align: center; color: #355e93; min-height: 96px; margin-bottom: 40px; padding-top: 6px; }
.letterhead .seal { position: absolute; left: -48px; top: 0; width: 96px; height: 96px; }
.lh-text { font-family: "Copperplate Gothic Bold", Copperplate, "Times New Roman", serif; font-size: 13px; line-height: 1.25; }
.lh-text .lh-big { font-size: 16px; }
@media (max-width: 700px) { .letterhead .seal { position: static; width: 56px; height: 56px; } .letterhead { min-height: 0; } }
.page .date { text-align: right; }
.body { margin: 0 0 16px; padding-left: 0; list-style: none; counter-reset: para; }
.body li { counter-increment: para; margin: 16px 0 0; white-space: pre-wrap; } /* pre-wrap shows the two spaces between sentences */
.body li::before { content: counter(para) ".  "; }
.sigblock { margin: 56px 0 0 53.85%; position: relative; }
.sigblock img { position: absolute; bottom: 100%; left: 0; max-width: 100%; margin-bottom: 4px; }

.page [contenteditable] { border-radius: 2px; outline: none; transition: background-color .15s; }
.page [contenteditable]:hover { background: #eef4ff; }
.page [contenteditable]:focus { background: #e2ecff; box-shadow: 0 0 0 1px #9bb8e8; }

/* ---- loader: a small memo types itself over the page while the AI writes ---- */
.loader {
  position: absolute; z-index: 5; left: 50%; top: 140px; transform: translateX(-50%);
  width: min(400px, calc(100% - 32px));
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: var(--s-6) var(--s-5) var(--s-5);
  background: var(--navy-950); color: #fff; border-radius: var(--r-lg);
  box-shadow: 0 30px 80px -20px rgb(10 22 40 / .6);
  animation: loader-in .25s ease-out;
}
.loader-paper {
  width: 100%; min-height: 128px; padding: 18px 20px; margin-bottom: var(--s-5);
  background: var(--paper); color: #111; border-radius: 3px; text-align: left;
  font: 13.5px/1.45 var(--font-memo);
}
.loader-lines p { margin: 0 0 6px; white-space: pre-wrap; }
.loader-title { margin: 0; font: 500 20px/1.3 var(--font-serif); }
.loader-msg { margin: var(--s-2) 0 0; font-size: var(--fs-small); color: rgb(255 255 255 / .62); min-height: 1.5em; }
@keyframes loader-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---- review dialog ---- */
.dialog {
  max-width: 480px; width: calc(100% - 32px);
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-6);
  background: var(--surface); color: var(--text);
  box-shadow: 0 30px 80px -20px rgb(10 22 40 / .5);
}
.dialog::backdrop { background: rgb(10 22 40 / .6); }
.dialog h2 { margin: 0 0 var(--s-3); font: 500 24px/1.25 var(--font-serif); }
.dialog p { margin: 0 0 var(--s-3); }
.dialog ul { margin: 0 0 var(--s-4); padding-left: 20px; }
.dialog li { margin-bottom: var(--s-1); }
.dialog label.check { margin: var(--s-4) 0 var(--s-5); font-weight: 600; align-items: flex-start; }
.dialog label.check input { margin-top: 2px; flex: none; }
.dialog-actions { justify-content: flex-end; flex-wrap: wrap; }

.site-footer { max-width: 1320px; margin: 0 auto; padding: 0 var(--gutter) var(--s-7); color: var(--text-muted); font-size: 12px; text-align: center; }
.topbar :focus-visible { outline-color: #fff; }
