/* PMP Draft drafting tool. Mike's original design, with the font changed to
   Source Sans 3 and nothing sticky, so the whole page scrolls together.
   The sidebar and form text is slightly larger and darker than the original. */

  :root {
    --bg: #f8f9fa;
    --surface: #ffffff;
    --surface2: #f1f3f5;
    --border: #dde2e8;
    --accent: #1a56db;
    --accent-dim: #e8f0fe;
    --text: #111827;
    --text-muted: #6b7280;
    --text-secondary: #4b5563;
    --success: #0a8a4a;
    --warning: #b45309;
    --danger: #dc2626;
    --mono: 'Source Sans 3', 'Segoe UI', sans-serif;
    --sans: 'Source Sans 3', 'Segoe UI', sans-serif;
    --sidebar-w: 220px;
    --sticky-header-height: 116px;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }

  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-weight: 300;
    min-height: 100vh;
    display: flex;
  }

  /* SIDEBAR */
  .sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
  }

  /* Coffee box, saved count and site links: held in the bottom-left corner of the window
     while the page scrolls, and resting at the bottom of the sidebar at the end of the page. */
  .sidebar-bottom {
    margin-top: auto;
    position: sticky;
    bottom: 0;
    background: var(--surface);
  }

  a.sidebar-header { display: block; text-decoration: none; }
  a.sidebar-header:hover { color: var(--accent); }

  .sidebar-header {
    font-family: var(--mono);
    font-size: 0.73rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 1.2rem 1rem 0.8rem;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-folder {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--border);
  }

  .btn-folder {
    width: 100%;
    padding: 0.45rem 0.6rem;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px dashed var(--accent);
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.73rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    text-align: center;
    transition: background 0.2s;
  }

  .btn-folder:hover { background: var(--accent); color: #fff; border-style: solid; }

  .folder-connected {
    font-family: var(--mono);
    font-size: 0.73rem;
    color: var(--success);
    display: flex;
    align-items: center;
    gap: 0.4rem;
  }

  .folder-name-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
  }

  .btn-change-folder {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.12rem;
    padding: 0;
    flex-shrink: 0;
    line-height: 1;
    font-family: var(--mono);
  }

  .btn-change-folder:hover { color: var(--accent); }


  .sidebar-how {
    margin: 0.6rem 0.8rem 0;
    padding: 0.4rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.73rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    width: calc(100% - 1.6rem);
    text-align: center;
    transition: color 0.15s, border-color 0.15s;
  }

  .sidebar-how:hover { color: var(--accent); border-color: var(--accent); }

  .sidebar-new {
    margin: 0.5rem 0.8rem 0.8rem;
    padding: 0.5rem;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid var(--accent-dim);
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    width: calc(100% - 1.6rem);
    text-align: center;
    transition: background 0.2s;
  }

  .sidebar-new:hover { background: var(--accent); color: #fff; }

  .project-list { padding: 0.5rem 0; }

  .project-item {
    padding: 0.6rem 1rem;
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: background 0.15s, border-color 0.15s;
    position: relative;
  }

  .project-item:hover { background: var(--surface2); }
  .project-item.active { border-left-color: var(--accent); background: var(--surface2); }

  .project-item-title {
    font-family: var(--mono);
    font-size: 0.81rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .project-item-meta {
    font-size: 0.76rem;
    color: var(--text-secondary);
    margin-top: 0.2rem;
  }

  .project-item-delete {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--danger);
    font-size: 0.9rem;
    cursor: pointer;
    opacity: 0;
    padding: 0.2rem 0.3rem;
    transition: opacity 0.15s;
  }

  .project-item:hover .project-item-delete { opacity: 1; }

  .sidebar-bmc {
    padding: 0.9rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
    flex-shrink: 0;
    background: var(--surface);
  }

  .sidebar-bmc p {
    font-size: 0.78rem;
    color: var(--text);
    line-height: 1.4;
  }

  .btn-bmc-small {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--accent);
    color: #fff;
    font-size: 0.84rem;
    font-weight: 600;
    padding: 0.45rem 0.9rem;
    border-radius: 5px;
    text-decoration: none;
    transition: opacity 0.15s;
    white-space: nowrap;
    align-self: stretch;
    justify-content: center;
  }

  .btn-bmc-small:hover { opacity: 0.85; text-decoration: none; }

  .sidebar-footer {
    padding: 0.8rem 1rem;
    border-top: 1px solid var(--border);
    font-family: var(--mono);
    font-size: 0.73rem;
    color: var(--text-secondary);
    flex-shrink: 0;
  }

  .sidebar-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 0.8rem;
    padding: 0.8rem 1rem 1rem;
    border-top: 1px solid var(--border);
  }

  .sidebar-links a {
    font-family: var(--mono);
    font-size: 0.81rem;
    color: var(--text-secondary);
    text-decoration: none;
  }

  .sidebar-links a:hover { color: var(--accent); text-decoration: underline; }

  /* Sidebar, title block and form: regular weight for readability. */
  .sidebar, .form-header-sticky, .form-panel { font-weight: 400; }

  /* MAIN GRID: [title | output] / [form | output] */
  .main {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
    align-items: start;
  }

  /* ROW 1: title and progress (left) */
  .form-header-sticky {
    grid-column: 1;
    grid-row: 1;
    background: var(--surface);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 1.5rem 2rem 1rem;
    align-self: stretch;
  }

  /* ROW 2: form (left) */
  .form-panel {
    grid-column: 1;
    grid-row: 2;
    padding: 1.5rem 2rem 2rem;
    background: var(--surface);
    border-right: 1px solid var(--border);
    align-self: start;
  }

  /* Output (right), beside the title and the form */
  .output-panel {
    grid-column: 2;
    grid-row: 1 / 3;
    padding: 1.5rem 2rem 2rem;
    background: var(--bg);
    align-self: start;
  }

  .header {
    border-left: 3px solid var(--accent);
    padding-left: 1rem;
    margin-bottom: 1rem;
  }

  .header h1 {
    font-family: var(--mono);
    font-size: 1.23rem;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .header p {
    font-size: 0.92rem;
    color: var(--text-secondary);
    margin-top: 0.3rem;
    font-family: var(--mono);
  }

  .progress-bar { background: var(--border); height: 2px; margin-bottom: 0.5rem; }
  .progress-fill { height: 100%; background: var(--accent); transition: width 0.4s ease; width: 0%; }

  .progress-label {
    font-family: var(--mono);
    font-size: 0.93rem;
    color: var(--text-secondary);
    text-align: right;
    margin-bottom: 0;
  }

  /* First section-divider in form panel needs no top margin/border */
  .form-panel > .section-divider:first-child {
    margin-top: 0;
    border-top: none;
    padding-top: 0;
  }

  .field-group { margin-bottom: 1.4rem; }

  label {
    display: block;
    font-family: var(--mono);
    font-size: 0.94rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.3rem;
  }

  .field-hint {
    font-size: 0.97rem;
    color: var(--text);
    margin-bottom: 0.4rem;
    line-height: 1.4;
  }

  input, textarea, select {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--sans);
    font-size: 1.07rem;
    font-weight: 400;
    padding: 0.55rem 0.75rem;
    border-radius: 4px;
    outline: none;
    transition: border-color 0.2s;
    resize: vertical;
  }

  input:focus, textarea:focus, select:focus { border-color: var(--accent); }
  textarea { min-height: 65px; }
  select option { background: var(--surface); }

  .row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
  .row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

  .section-divider {
    font-family: var(--mono);
    font-size: 0.97rem;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    border-top: 1px solid var(--border);
    padding-top: 0.8rem;
    margin: 1.8rem 0 1.2rem;
  }

  .btn-row { display: flex; gap: 0.8rem; margin-top: 1.8rem; flex-wrap: wrap; }

  button {
    font-family: var(--mono);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 0.6rem 1.3rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
  }

  button:active { transform: scale(0.98); }
  .btn-primary { background: var(--accent); color: #ffffff; position: relative; overflow: hidden; }
  .btn-primary:hover:not(:disabled) { opacity: 0.88; }
  .btn-primary:disabled { cursor: not-allowed; opacity: 1; background: var(--accent); }

  .btn-cooldown-bar {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    background: rgba(255,255,255,0.25);
    width: 100%;
    transform-origin: left;
    pointer-events: none;
  }
  .btn-secondary { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
  .btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
  .btn-success { background: var(--success); color: #ffffff; }
  .btn-success:hover { opacity: 0.88; }

  .error-msg {
    font-family: var(--mono);
    font-size: 0.84rem;
    color: var(--danger);
    margin-top: 0.5rem;
    display: none;
  }
  .error-msg.visible { display: block; }

  /* OUTPUT PANEL */
  .output-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
  }

  .output-header-title {
    border-left: 3px solid var(--success);
    padding-left: 1rem;
  }

  .output-header h2 {
    font-family: var(--mono);
    font-size: 1.23rem;
    font-weight: 600;
    color: var(--success);
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }

  .output-header p {
    font-family: var(--mono);
    font-size: 0.92rem;
    color: var(--text-secondary);
    margin-top: 0.3rem;
  }

  .output-header-actions {
    display: none;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.4rem;
    flex-shrink: 0;
  }

  .output-header-actions.visible {
    display: flex;
  }

  .output-header-btns {
    display: flex;
    gap: 0.5rem;
  }

  .output-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    color: var(--text-muted);
    font-family: var(--mono);
    font-size: 0.78rem;
    text-align: center;
    border: 1px dashed var(--border);
    border-radius: 6px;
    padding: 2rem;
    line-height: 1.8;
  }

  .output-empty-icon {
    font-size: 1.8rem;
    margin-bottom: 1rem;
    opacity: 0.4;
  }

  .output-fields { display: none; }
  .output-fields.visible { display: block; }

  .output-field { margin-bottom: 1.2rem; }

  .output-field-title {
    font-family: var(--mono);
    font-size: 0.94rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.3rem;
  }

  .output-text {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.65rem 0.75rem;
    font-size: 0.84rem;
    line-height: 1.6;
    white-space: pre-wrap;
  }

  .word-count {
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: right;
    margin-bottom: 1rem;
  }

  .word-count.over { color: var(--warning); }
  .word-count.good { color: var(--success); }

  .loading {
    display: none;
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    padding: 3rem 1rem;
  }

  .loading.visible { display: block; }

  .dot-anim::after {
    content: '';
    animation: dots 1.2s steps(4, end) infinite;
  }

  @keyframes dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
  }

  .empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    font-family: var(--mono);
    font-size: 0.8rem;
  }

  .toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--success);
    color: #ffffff;
    font-family: var(--mono);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.6rem 1.2rem;
    border-radius: 4px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
    z-index: 100;
  }
  .toast.show { opacity: 1; transform: translateY(0); }

  /* ── How it works modal ─────────────────────────────────────── */
  .modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.45);
    z-index: 200;
    align-items: center;
    justify-content: center;
  }
  .modal-overlay.open { display: flex; }

  .modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 560px;
    max-width: calc(100vw - 2rem);
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    padding: 2rem;
    position: relative;
  }

  .modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.2rem 0.5rem;
    font-family: var(--mono);
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
  }

  .modal-close:hover { color: var(--text); transform: none; }

  .modal h2 {
    font-family: var(--mono);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-left: 3px solid var(--accent);
    padding-left: 0.8rem;
    margin-bottom: 1.5rem;
  }

  .modal-section { margin-bottom: 1.4rem; }

  .modal-section h3 {
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.5rem;
  }

  .modal-section p {
    font-size: 0.84rem;
    color: var(--text-muted);
    line-height: 1.65;
    margin-bottom: 0.4rem;
  }

  .modal-section ul {
    padding-left: 1.2rem;
    margin-top: 0.3rem;
  }

  .modal-section li {
    font-size: 0.84rem;
    color: var(--text-muted);
    line-height: 1.65;
    margin-bottom: 0.3rem;
  }

  .modal-section code {
    font-family: var(--mono);
    font-size: 0.78rem;
    background: var(--surface2);
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    color: var(--accent);
  }

  .modal hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.2rem 0;
  }

  /* Phone and narrow tablet: one column. Desktop layout above is unchanged. */
  @media (max-width: 900px) {
    body { flex-direction: column; }
    .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
    .sidebar-bottom { position: static; }
    .main { grid-template-columns: minmax(0, 1fr); }
    .form-header-sticky, .form-panel, .output-panel { grid-column: 1; grid-row: auto; border-right: none; }
    .form-header-sticky { padding: 1.25rem 1rem 1rem; }
    .form-panel { padding: 1.25rem 1rem 1.5rem; }
    .output-panel { padding: 1.5rem 1rem; }
    .row-3 { grid-template-columns: 1fr 1fr; }
  }

  @media (max-width: 560px) {
    .row-2, .row-3 { grid-template-columns: 1fr; }
    .output-header { flex-wrap: wrap; }
  }
