/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f8fafc;
  color: #1a202c;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Nav ──────────────────────────────────────────────────────────────────── */
.nav {
  background: white;
  border-bottom: 1px solid #e2e8f0;
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 2rem;
}
.nav-inner {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-brand {
  font-weight: 600;
  font-size: 0.95rem;
  color: #1a365d;
  text-decoration: none;
  letter-spacing: 0.01em;
}
.nav-brand:hover { text-decoration: underline; }
.nav-links {
  display: flex;
  gap: 1.5rem;
  align-items: center;
}
.nav-link {
  font-size: 0.875rem;
  color: #4a5568;
  text-decoration: none;
  font-weight: 500;
}
.nav-link:hover { color: #1a365d; text-decoration: none; }

.nav-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: #718096;
}

/* ── Content wrappers ─────────────────────────────────────────────────────── */
.content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem;
}
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

/* ── Flash messages ───────────────────────────────────────────────────────── */
.flashes {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
  width: 100%;
}
.flash {
  padding: 0.7rem 1rem;
  border-left: 4px solid transparent;
  border-radius: 4px;
  font-size: 0.875rem;
}
.flash-error   { background: #fff5f5; border-color: #c53030; color: #9b2c2c; }
.flash-success { background: #f0fff4; border-color: #276749; color: #276749; }
.flash-info    { background: #ebf8ff; border-color: #2b6cb0; color: #2c5282; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: opacity 0.15s;
  line-height: 1;
}
.btn:hover { opacity: 0.88; }
.btn-primary { background: #1a365d; color: white; }
.btn-danger  { background: #c53030; color: white; }
.btn-sm      { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-full    { width: 100%; margin-top: 0.25rem; padding: 0.6rem 1rem; }

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  padding: 2rem;
}
.login-card { width: 100%; max-width: 360px; }

/* ── Form elements ────────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 1rem;
}
label {
  font-size: 0.875rem;
  font-weight: 500;
  color: #4a5568;
}
input[type="text"],
input[type="password"] {
  padding: 0.5rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: white;
  color: #1a202c;
}
input:focus {
  border-color: #2c5282;
  box-shadow: 0 0 0 3px rgba(44,82,130,0.12);
}

/* ── Typography ───────────────────────────────────────────────────────────── */
.login-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: #1a365d;
  margin-bottom: 1.5rem;
}
h1 { font-size: 1.4rem; font-weight: 600; color: #1a365d; margin-bottom: 0.5rem; }
.subtitle { color: #718096; margin-bottom: 0.5rem; }
.meta { font-size: 0.9rem; color: #4a5568; margin-top: 0.75rem; }

/* ── Select ───────────────────────────────────────────────────────────────── */
select {
  padding: 0.5rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  width: 100%;
  outline: none;
  background: white;
  color: #1a202c;
  cursor: pointer;
}
select:focus {
  border-color: #2c5282;
  box-shadow: 0 0 0 3px rgba(44,82,130,0.12);
}

/* ── Links ────────────────────────────────────────────────────────────────── */
a { color: #2c5282; }
a:hover { text-decoration: underline; }

/* ── Wide content wrapper (editor layout) ─────────────────────────────────── */
.content-wide { max-width: 1500px; }

/* ── Prompt 2: Companies CRUD ─────────────────────────────────────────────── */

/* Page header: title on left, action button on right */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}
.page-header h1 { margin-bottom: 0; }
.muted-text { font-size: 0.85rem; color: #718096; margin-top: 0.25rem; }

/* Companies table */
.table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  font-size: 0.9rem;
}
.table th {
  text-align: left;
  padding: 0.65rem 1rem;
  background: #f7fafc;
  font-size: 0.8rem;
  font-weight: 600;
  color: #4a5568;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #e2e8f0;
}
.table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f0f4f8;
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f7fafc; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: #718096;
}

/* Form layout */
.form-wrap {
  max-width: 680px;
}
.form-section {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  padding: 1.5rem 1.75rem;
  margin-bottom: 1.25rem;
}
.form-section h2 {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #718096;
  margin-bottom: 1.25rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid #e2e8f0;
}
.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}
.form-row:last-child { margin-bottom: 0; }
.help-text {
  font-size: 0.8rem;
  font-style: italic;
  color: #a0aec0;
  line-height: 1.4;
}
.required-mark { color: #c53030; }

/* Actions bar at bottom of form */
.actions-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.spacer { flex: 1; }

/* Secondary outline button */
.btn-secondary-outline {
  background: transparent;
  border: 1px solid #e2e8f0;
  color: #4a5568;
}
.btn-secondary-outline:hover { background: #f7fafc; opacity: 1; }

/* Confirm delete page */
.confirm-delete-wrap {
  max-width: 480px;
}

/* ── Prompt 5: Letter history + lists ────────────────────────────────────── */

/* Letter composer header eyebrow */
.letter-eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #a0aec0;
  margin-bottom: 0.2rem;
}

/* Draft badge in letter lists */
.draft-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #a0aec0;
  background: #f0f4f8;
  border: 1px solid #e2e8f0;
  border-radius: 3px;
  padding: 0.1rem 0.4rem;
  margin-left: 0.4rem;
  vertical-align: middle;
}

/* Filter bar for global letter list */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  margin-bottom: 0.25rem;
}
.filter-bar input[type="text"],
.filter-bar input[type="date"],
.filter-bar select {
  padding: 0.4rem 0.65rem;
  font-size: 0.85rem;
}
.filter-sep {
  font-size: 0.8rem;
  color: #a0aec0;
  flex-shrink: 0;
}

/* toolbar-meta in letter_preview.css */
.toolbar-meta {
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(20,20,20,0.45);
  margin-left: 8px;
  white-space: nowrap;
}

/* ── Prompt 3: Branding + Live Preview ────────────────────────────────────── */

/* Textarea */
textarea {
  padding: 0.5rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: white;
  color: #1a202c;
  resize: vertical;
  line-height: 1.5;
}
textarea:focus {
  border-color: #2c5282;
  box-shadow: 0 0 0 3px rgba(44,82,130,0.12);
}
textarea.mono {
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Mono', Consolas, monospace;
  font-size: 0.78rem;
}

/* Number input */
input[type="number"] {
  padding: 0.5rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: white;
  color: #1a202c;
}
input[type="number"]:focus {
  border-color: #2c5282;
  box-shadow: 0 0 0 3px rgba(44,82,130,0.12);
}

/* Color picker + text input row */
.color-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.color-input-row input[type="color"] {
  width: 40px;
  height: 36px;
  padding: 2px 3px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  background: white;
}
.color-input-row input[type="text"] {
  flex: 1;
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 0.83rem;
}

/* Swatch row */
.swatch-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.swatch {
  width: 26px;
  height: 26px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.14);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s, box-shadow 0.12s;
}
.swatch:hover {
  transform: scale(1.18);
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}

/* Current logo preview above upload */
.logo-preview {
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.logo-preview img {
  max-height: 80px;
  width: auto;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 4px;
  background: white;
}
.btn-xs {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
}

/* Two-column editor layout */
.editor-layout {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}
.editor-form-col {
  width: 480px;
  flex-shrink: 0;
}
.editor-preview-col {
  flex: 1;
  min-width: 0;
  position: sticky;
  top: 1.5rem;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 2rem;
}
@media (max-width: 1200px) {
  .editor-layout { flex-direction: column; }
  .editor-form-col { width: 100%; max-width: 680px; }
  .editor-preview-col {
    min-width: unset;
    width: 100%;
    position: static;
    max-height: none;
    overflow: visible;
  }
}

/* Preview column header */
.preview-col-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #a0aec0;
  margin-bottom: 0.75rem;
}

/* Preview scale wrapper */
.preview-scale-wrapper {
  transform: scale(0.82);
  transform-origin: top left;
  /* Element still occupies its full 816px layout width, but visual is 669px.
     Negative margins collapse the excess so the column doesn't over-expand. */
  margin-right:  calc(816px * -0.18);
  margin-bottom: -120px;
}

/* No-preview state (new company page) */
.preview-unavailable {
  background: #f7fafc;
  border: 1px dashed #e2e8f0;
  border-radius: 6px;
  padding: 2rem;
  text-align: center;
  color: #a0aec0;
  font-size: 0.875rem;
}

/* Color swatches in companies list and page header */
.theme-swatches {
  display: flex;
  gap: 4px;
  align-items: center;
}
.theme-dot {
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}
.theme-dot-sm { width: 12px; height: 12px; }
.theme-dot-lg { width: 20px; height: 20px; }

/* Page header with swatches */
.page-header-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.3rem;
}

/* ── Prompt 5.1: Letter composer two-column layout ─────────────────────────── */

.composer-layout {
  display: grid;
  grid-template-columns: 480px 1fr;
  gap: 32px;
  align-items: start;
}

@media (max-width: 1199px) {
  .composer-layout {
    grid-template-columns: 1fr;
  }
}

.composer-form-col {
  min-width: 0;
}

.composer-preview-wrapper {
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.composer-preview-scale {
  transform: scale(0.75);
  transform-origin: top left;
  margin-right: calc(816px * -0.25);
  margin-bottom: calc(-11in * 0.25);
  pointer-events: none;
}

/* Font size slider control */
.font-size-control label {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.font-size-display {
  font-family: monospace;
  font-size: 13px;
  color: #4a5568;
  padding: 2px 8px;
  background: #edf2f7;
  border-radius: 4px;
}

.font-size-control .reset-link {
  margin-left: auto;
  font-size: 11px;
  color: #2c5282;
  background: none;
  border: 0;
  cursor: pointer;
  text-decoration: underline;
}

.font-size-control input[type="range"] {
  width: 100%;
  margin-top: 8px;
}
