/* CharterPro Kit Generator — premium understated, navy on cream */

:root {
  --navy: #0B3C66;
  --navy-light: #1d5588;
  --navy-faded: rgba(11, 60, 102, 0.08);
  --cream: #faf8f4;
  --paper: #ffffff;
  --border: #e5e2dc;
  --border-strong: #d4d0c7;
  --text: #1a1a1a;
  --text-soft: #6b6b6b;
  --danger: #b00020;
  --success: #1e7e34;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--cream);
  color: var(--text);
  font-family: 'Helvetica Neue', 'DejaVu Sans', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.app { max-width: 1280px; margin: 0 auto; padding: 32px 24px 64px; }

header { border-bottom: 1px solid var(--border); padding-bottom: 20px; margin-bottom: 28px; }
header h1 {
  font-family: 'Georgia', 'DejaVu Serif', serif;
  font-size: 28px; font-weight: 400;
  color: var(--navy); margin: 0 0 6px; letter-spacing: 0.2px;
}
header .subtitle { color: var(--text-soft); margin: 0; font-size: 14px; }

main {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 32px;
}
@media (max-width: 900px) { main { grid-template-columns: 1fr; } }

/* ============ FORM ============ */

.form-panel {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 24px 28px;
}

fieldset { border: none; padding: 0; margin: 0 0 24px; }
fieldset legend {
  font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--navy); font-weight: 600;
  padding: 0; margin-bottom: 14px;
}
fieldset legend .opt {
  font-weight: 400; color: var(--text-soft);
  text-transform: none; letter-spacing: 0;
}

.field-help { font-size: 12px; color: var(--text-soft); margin: 0 0 8px; }
.field-help code {
  background: var(--navy-faded); padding: 1px 5px; border-radius: 2px;
  font-size: 11px; color: var(--navy);
}

label { display: block; margin-bottom: 12px; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.lbl { font-size: 12px; font-weight: 600; color: var(--text); }
.hint { font-size: 11px; color: var(--text-soft); font-style: italic; }

input[type="text"], textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 3px;
  font-size: 13px; font-family: inherit;
  background: var(--paper); color: var(--text);
  transition: border-color 0.15s ease;
}
input[type="text"]:focus, textarea:focus { outline: none; border-color: var(--navy); }

textarea {
  resize: vertical;
  font-family: 'Menlo', 'DejaVu Sans Mono', monospace;
  font-size: 12px;
}

/* ============ BUTTONS ============ */

.actions {
  display: flex; gap: 12px; margin-top: 24px;
  padding-top: 20px; border-top: 1px solid var(--border);
}

button {
  padding: 10px 18px; border-radius: 3px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: inherit; letter-spacing: 0.3px;
  transition: all 0.15s ease;
  display: inline-flex; align-items: center; gap: 6px;
}

.btn-primary { background: var(--navy); color: white; border: 1px solid var(--navy); }
.btn-primary:hover { background: var(--navy-light); border-color: var(--navy-light); }
.btn-primary:disabled { opacity: 0.5; cursor: wait; }

.btn-secondary { background: transparent; color: var(--navy); border: 1px solid var(--navy); }
.btn-secondary:hover { background: var(--navy-faded); }

.status { margin-top: 14px; font-size: 12px; min-height: 18px; }
.status.error { color: var(--danger); }
.status.success { color: var(--success); }
.status.loading { color: var(--text-soft); font-style: italic; }

/* ============ PREVIEW ============ */

.preview-panel {
  background: var(--paper); border: 1px solid var(--border); border-radius: 4px;
  padding: 24px 28px; position: sticky; top: 24px; align-self: start;
}
.preview-header h2 {
  font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--navy); font-weight: 600; margin: 0 0 4px;
}
.preview-url {
  font-size: 11px; color: var(--text-soft);
  font-family: 'Menlo', 'DejaVu Sans Mono', monospace;
  word-break: break-all; margin: 0 0 18px; min-height: 14px;
}
.preview-stage {
  background: var(--cream); border: 1px solid var(--border); border-radius: 4px;
  padding: 24px; display: flex; align-items: center; justify-content: center;
  aspect-ratio: 1; min-height: 360px;
}
.preview-stage svg { max-width: 100%; max-height: 100%; width: 100%; height: auto; }
.preview-placeholder { color: var(--text-soft); font-style: italic; font-size: 13px; text-align: center; }

/* ============ RESULTS PANEL (FILE LIST) ============ */

.results-panel {
  margin-top: 32px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 24px 28px;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.results-header h2 {
  font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--navy); font-weight: 600; margin: 0 0 4px;
}

.results-meta {
  font-size: 12px; color: var(--text-soft); margin: 0;
  font-family: 'Menlo', 'DejaVu Sans Mono', monospace;
  word-break: break-all;
}

.results-footnote {
  font-size: 11px; color: var(--text-soft);
  margin: 16px 0 0; font-style: italic;
}

/* File row */

.files-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--paper);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.file-row:hover {
  border-color: var(--navy);
  background: var(--cream);
}

.file-icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  background: var(--cream);
  color: var(--navy);
}

.file-icon svg { width: 22px; height: 22px; }

.file-meta {
  flex: 1;
  min-width: 0;  /* allow text-overflow */
}

.file-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-sub {
  font-size: 12px;
  color: var(--text-soft);
  margin: 0;
}

.file-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-download {
  padding: 8px 16px;
  background: var(--paper);
  color: var(--navy);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-download:hover {
  background: var(--navy);
  color: white;
  border-color: var(--navy);
}

footer {
  margin-top: 48px; padding-top: 18px;
  border-top: 1px solid var(--border);
  text-align: center; font-size: 11px; color: var(--text-soft);
}
footer code {
  background: var(--navy-faded); padding: 1px 6px; border-radius: 2px;
  font-size: 10px; color: var(--navy);
}

/* ============ MODAL (PREVIEW) ============ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 25, 35, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  animation: fadeIn 0.15s ease-out;
}

/* CRITICAL: the HTML [hidden] attribute must actually hide the modal,
   overriding the display:flex above. Without this rule the modal stays
   visible (and blocks clicks on the page). */
.modal-overlay[hidden] {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-card {
  background: var(--paper);
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--cream);
}

.modal-titles { min-width: 0; }

.modal-header h3 {
  font-family: 'Georgia', 'DejaVu Serif', serif;
  font-size: 18px;
  font-weight: 400;
  color: var(--navy);
  margin: 0 0 3px;
  word-break: break-word;
}

.modal-sub {
  font-size: 11px;
  color: var(--text-soft);
  margin: 0;
  font-family: 'Menlo', 'DejaVu Sans Mono', monospace;
  word-break: break-all;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-soft);
  font-size: 26px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  border-radius: 3px;
  height: 30px;
  width: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover { color: var(--navy); background: var(--navy-faded); }

.modal-body {
  flex: 1;
  overflow: auto;
  padding: 22px;
  background: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
}

.modal-body .modal-loading {
  color: var(--text-soft);
  font-style: italic;
}

/* Specific content renderers */

.modal-image {
  max-width: 100%;
  max-height: 70vh;
  border: 1px solid var(--border);
  background: white;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}

.modal-pdf {
  width: 100%;
  height: 75vh;
  border: 1px solid var(--border);
  background: white;
}

.modal-text {
  width: 100%;
  max-height: 70vh;
  overflow: auto;
  background: white;
  border: 1px solid var(--border);
  padding: 16px 20px;
  font-family: 'Menlo', 'DejaVu Sans Mono', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.modal-unsupported {
  text-align: center;
  color: var(--text-soft);
  padding: 40px 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: var(--paper);
}
