/* ─── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f0f2f5;
}

/* ─── Header ────────────────────────────────────────────────────────────── */
.app-header {
  height: 48px;
  background: linear-gradient(90deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
  flex-shrink: 0;
  color: white;
}
.brand {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: linear-gradient(90deg, #e0c3fc, #8ec5fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ─── Quill toolbar ─────────────────────────────────────────────────────── */
.quill-toolbar {
  background: #fff;
  border-bottom: 1px solid #dee2e6;
  flex-shrink: 0;
  padding: 4px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
}
#toolbar.ql-toolbar.ql-snow { border: none; padding: 4px 8px; }

/* ─── Main 3-column layout ──────────────────────────────────────────────── */
.main-layout {
  flex: 1 1 0;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ─── Side panels ───────────────────────────────────────────────────────── */
.side-panel {
  width: 260px;
  min-width: 260px;
  background: #f8f9fb;
  overflow-y: auto;
  flex-shrink: 0;
  border: none;
}
.side-panel-left  { border-right: 1px solid #dee2e6; }
.side-panel-right { border-left:  1px solid #dee2e6; }

.panel-body { padding: 12px; }

.panel-section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e9ecef;
}
.panel-section:last-child { border-bottom: none; margin-bottom: 0; }

.panel-collapse-btn { background: none; border: none; padding: 2px 4px; cursor: pointer; line-height: 1; }
.collapse-chevron { font-size: 11px; color: #adb5bd; transition: transform 0.2s ease; display: inline-block; }
.panel-collapse-btn[aria-expanded="false"] .collapse-chevron { transform: rotate(180deg); }

.section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6c757d;
  margin-bottom: 8px;
}

.form-label-sm {
  font-size: 11px;
  color: #555;
  margin-bottom: 3px;
  display: block;
}

/* ─── Editor area ───────────────────────────────────────────────────────── */
.editor-area {
  flex: 1 1 0;
  overflow: auto;
  padding: 32px 24px;
  background: #e0e3ec;
  display: flex;
  justify-content: center;
}

/* ─── Page (A4 default) ─────────────────────────────────────────────────── */
.page-container {
  background: #fff;
  box-shadow:
    0 1px 3px rgba(0,0,0,.12),
    0 4px 16px rgba(0,0,0,.10),
    0 16px 48px rgba(0,0,0,.07);
  width: 210mm;
  min-height: 297mm;
  padding: 25.4mm;
  position: relative;
  align-self: flex-start;
  flex-shrink: 0;
  transition: background-color 0.3s ease;
}
.page-container.size-letter { width: 215.9mm; min-height: 279.4mm; }
.page-container.size-legal  { width: 215.9mm; min-height: 355.6mm; }
.page-container.margin-narrow { padding: 12.7mm; }
.page-container.margin-wide   { padding: 38.1mm; }

/* ─── Quill editor ──────────────────────────────────────────────────────── */
.ql-container.ql-snow { border: none !important; }
.ql-editor {
  padding: 0 !important;
  font-size: 11pt;
  font-family: 'Times New Roman', Times, serif;
  line-height: 1.65;
  min-height: 200mm;
  transition: font-family 0.2s, font-size 0.2s, color 0.2s;
}
.ql-editor.ql-blank::before {
  font-style: normal;
  color: #bbb;
}

/* ─── Watermark overlay ─────────────────────────────────────────────────── */
.watermark-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  overflow: hidden;
}
.wm-text-item {
  position: absolute;
  white-space: nowrap;
  user-select: none;
  pointer-events: none;
  transform-origin: center center;
}
.wm-image {
  position: absolute;
  pointer-events: none;
}

/* ─── Theme categories ──────────────────────────────────────────────────── */
.theme-category {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #adb5bd;
  margin: 10px 0 5px;
  padding-bottom: 3px;
  border-bottom: 1px solid #e9ecef;
}
.theme-category:first-of-type { margin-top: 0; }

/* ─── Theme grid ────────────────────────────────────────────────────────── */
.theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.theme-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border: 1.5px solid #dee2e6;
  border-radius: 8px;
  background: #fff;
  font-size: 11px;
  font-weight: 500;
  color: #333;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.theme-chip:hover {
  border-color: #adb5bd;
  box-shadow: 0 2px 6px rgba(0,0,0,.1);
  transform: translateY(-1px);
}
.theme-chip.active {
  border-color: #6c5ce7;
  box-shadow: 0 0 0 2px rgba(108,92,231,.25);
  background: #f5f3ff;
}

.theme-swatch {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,.1);
}

/* ─── Color controls ────────────────────────────────────────────────────── */
.color-row {
  display: flex;
  gap: 8px;
  justify-content: space-around;
}
.color-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.color-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid #dee2e6;
  padding: 2px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}
.color-dot:hover { transform: scale(1.1); border-color: #adb5bd; }
.color-dot-label {
  font-size: 10px;
  color: #6c757d;
  font-weight: 500;
}

/* ─── Page background presets ───────────────────────────────────────────── */
.page-bg-presets { flex: 1; }
.bg-preset {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1.5px solid #dee2e6;
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s, border-color 0.1s;
}
.bg-preset:hover { transform: scale(1.2); border-color: #adb5bd; }

/* ─── Result cards ──────────────────────────────────────────────────────── */
.result-card {
  border: 1px solid #dee2e6;
  border-radius: 6px;
  overflow: hidden;
}
.result-card-header {
  background: #f1f3f5;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #dee2e6;
}
.result-card-body {
  padding: 8px 10px;
  font-size: 12px;
  max-height: 180px;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.5;
}

/* ─── Micro buttons ─────────────────────────────────────────────────────── */
.btn-xs {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-xs.btn-success {
  background: #198754; color: #fff; border-color: #198754;
}
.btn-xs.btn-outline-secondary {
  background: transparent; color: #6c757d; border-color: #6c757d;
}

/* ─── Loading overlay on buttons ────────────────────────────────────────── */
.btn-loading { opacity: .65; pointer-events: none; }

/* ─── Scrollbars ────────────────────────────────────────────────────────── */
.side-panel::-webkit-scrollbar,
.editor-area::-webkit-scrollbar { width: 5px; }
.side-panel::-webkit-scrollbar-thumb,
.editor-area::-webkit-scrollbar-thumb { background: #c5cae9; border-radius: 3px; }

/* ─── Page Break ─────────────────────────────────────────────────────────── */
.ql-page-break {
  display: block;
  position: relative;
  border-top: 2px dashed #adb5bd;
  margin: 1.5em 0;
  height: 16px;
  cursor: default;
  user-select: none;
}
.ql-page-break::after {
  content: 'Page Break';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  padding: 0 8px;
  font-size: 9px;
  color: #adb5bd;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  white-space: nowrap;
}

/* Toolbar page-break button sizing matches other ql buttons */
.ql-pagebreak-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px !important;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  color: #444;
  border-radius: 3px;
}
.ql-pagebreak-btn:hover { background: #f0f0f0; }

/* ─── Layout Images (banner / sidebar) ─────────────────────────────────── */
.ql-layout-image { display: block; margin: 0.8em 0; }
.ql-layout-image img { border-radius: 4px; display: block; }
.ql-layout-image[data-layout="banner"] img { width: 100%; }
.ql-layout-image[data-layout="sidebar"] {
  float: right;
  width: 36%;
  margin: 0 0 1em 1.5em;
}
.ql-layout-image[data-layout="sidebar"] img { width: 100%; }

/* ─── Raw HTML embed (tables, cards) ────────────────────────────────────── */
.ql-raw-html { margin: 0.5em 0; }
.ql-raw-html table { border-collapse: collapse; width: 100%; }

/* ─── Card tables ────────────────────────────────────────────────────────── */
/* Cards are plain <table> elements — all colours are inline so they survive
   copy-paste and export without extra CSS. These rules only handle editor UX. */

/* Prevent Quill's global table reset from flattening card tables */
.ql-editor table { border-spacing: 0; }

/* Subtle focus ring on the active cell so it's clear where you're typing */
.ql-editor td:focus,
.ql-editor th:focus { outline: 2px dashed rgba(99,102,241,.5); outline-offset: -2px; }

/* Keep the header row from being selectable as text accidentally */
.ql-editor th { user-select: text; }

/* ─── Print ─────────────────────────────────────────────────────────────── */
@media print {
  .side-panel, .quill-toolbar, .app-header, .toast-container { display: none !important; }
  body { overflow: visible; display: block; }
  .main-layout { display: block; overflow: visible; }
  .editor-area { padding: 0; background: none; display: block; }
  .page-container {
    box-shadow: none;
    width: 100% !important;
    min-height: auto !important;
    margin: 0;
    padding: 15mm !important;
  }
  .watermark-overlay { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .ql-page-break {
    break-before: page;
    page-break-before: always;
    border: none;
    height: 0;
    margin: 0;
  }
  .ql-page-break::after { display: none; }
}
