/* --- Global & Browser Reset --- */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f0f2f5;
  color: #222;
}

/* --- Buttons --- */
.btn {
  padding: 10px 20px;
  border: 1px solid #c7ccd4;
  border-radius: 6px;
  background: #fff;
  color: #222;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: #eef1f5; }
.btn-primary { background: #0073e6; border-color: #0073e6; color: #fff; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.btn-primary:hover { background: #005bb5; }

/* --- Footer and ad slot (screen only) --- */
.site-footer { text-align: center; padding: 20px 16px 32px; color: #666; font-size: 14px; }
.site-footer nav { margin-bottom: 6px; }
.site-footer a { color: #0066cc; text-decoration: none; margin: 0 4px; }
.site-footer a:hover { text-decoration: underline; }
.ad-slot { display: none; max-width: 970px; margin: 16px auto; text-align: center; }
.ad-slot.is-live { display: block; min-height: 90px; }
.ad-slot .adsbygoogle { display: block; }

/* --- Screen UI --- */
.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 32px;
  background: #fff;
  border-bottom: 1px solid #dde1e7;
}
.app-bar h1 { font-size: 20px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; }
.brand-logo { width: 36px; height: 36px; flex: none; display: block; }
.app-bar { flex-wrap: wrap; }
@media (max-width: 700px) { .app-bar { padding: 12px 16px; } .app-bar .brand { flex-basis: 100%; } .top-nav { margin-right: 0; } }
.top-nav { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-right: auto; }
.top-nav a { padding: 8px 12px; border-radius: 6px; color: #333; font-weight: 600; font-size: 15px; text-decoration: none; }
.top-nav a:hover { background: #eef1f5; }
.top-nav a[aria-current=page] { background: #e6f0fc; color: #005bb5; }

.editor {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 40px;
  padding: 48px 20px 24px;
}
.card-slot { --preview-zoom: 1.4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.slot-header {
  display: flex;
  align-items: center;
  justify-content: center; /* label + button sit together, centered over the card */
  gap: 14px;
}
.btn-sm { padding: 5px 16px; font-size: 14px; }
.slot-label { font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: #666; }

/* Show the real 3.5x2in card larger on screen */
.preview { zoom: var(--preview-zoom); box-shadow: 0 2px 10px rgba(0,0,0,0.2); }

.hint { max-width: 640px; margin: 8px auto 40px; padding: 0 20px; text-align: center; font-size: 13px; color: #666; line-height: 1.5; }

/* --- Card Styles (shared by screen preview and print sheets) --- */
.card {
  position: relative;
  width: 3.5in;
  height: 2in;
  overflow: hidden;
  background-color: var(--bg, #fff);
  color: var(--fg, #333);
}
.card-content {
  padding: 0.2in;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.card h2 { font-size: var(--name-size, 18px); color: var(--fg); margin-bottom: 1px; }
.card .title { font-size: 11px; color: var(--accent, #0073e6); font-weight: 600; text-transform: uppercase; margin-bottom: 6px; }
.front-content { padding: 0.15in 0.2in; justify-content: flex-start; }
.card .contacts {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr; /* overridden by the "First column width" setting */
  grid-auto-flow: column; /* fill column 1 top-to-bottom, then column 2 */
  gap: 4px 8px;
}
.card .contacts-top { grid-template-columns: 1fr; grid-auto-flow: row; }
/* Top block: name/title at the top; email and phone sit at its bottom edge, so with a QR code
   the lower block can start one normal row-gap below the phone and still clear the QR. */
.card-top { display: flex; flex-direction: column; }
.card-top .contacts-top { margin-top: auto; }
.card .contacts-lower {
  margin-top: 4px;
  grid-template-columns: calc(var(--col1) * 1fr) calc((100 - var(--col1)) * 1fr);
  grid-template-rows: repeat(var(--rows), auto);
}
.card .contacts li { display: flex; align-items: center; gap: 4px; min-width: 0; font-size: var(--item-size, 9.5px); color: var(--fg); }
.card .contacts li.filler { visibility: hidden; }
.card .contacts span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .icon { flex: none; width: 1.25em; height: 1.15em; color: var(--accent, #0073e6); }

.qr { position: absolute; right: 0.15in; top: 0.15in; background: #fff; line-height: 0; }
.qr { width: var(--qr-size); height: var(--qr-size); }
.qr-middle { top: 50%; transform: translateY(-50%); }
.qr-bottom { top: auto; bottom: 0.15in; }
.qr svg { display: block; width: 100%; height: 100%; }
.card-top.beside-qr { margin-right: calc(var(--qr-size) + 0.05in); min-height: var(--qr-size); }
.front-content.clear-qr { padding-right: calc(var(--qr-size) + 0.25in); }
.back-content { align-items: center; }
.back-content { gap: 8px; justify-content: center; }
.back-art { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
.back-art-box { width: var(--art-size); height: var(--art-size); max-width: 100%; max-height: 100%; }
.back-img { display: block; width: 100%; height: 100%; object-fit: contain; }
.back-bleed { padding: 0; }
.back-bleed .back-img { object-fit: cover; }
.back-logo .back-art, .back-logo-text .back-art { width: 100%; }
.logo { font-size: var(--text-size, 18px); font-weight: bold; letter-spacing: 2px; text-align: center; }

/* --- Modal --- */
dialog {
  margin: auto;
  width: min(680px, calc(100vw - 32px));
  border: none;
  border-radius: 10px;
  padding: 20px 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
/* Docked panel: fixed to the side opposite the card being edited */
dialog[open] { position: fixed; top: 84px; margin: 0; max-height: calc(100vh - 100px); width: min(620px, calc(100vw - 32px)); box-shadow: 0 8px 32px rgba(0,0,0,0.28); border: 1px solid #dde1e7; }
dialog.dock-right[open] { right: 16px; left: auto; }
dialog.dock-left[open]  { left: 16px; right: auto; }
@media (max-width: 899px) {
  /* narrow windows: centered (selectors match the dock rules' specificity so they win) */
  dialog[open], dialog.dock-right[open], dialog.dock-left[open] { left: 50%; right: auto; transform: translateX(-50%); }
}
@media (max-width: 560px) {
  dialog[open] { top: 8px; max-height: calc(100dvh - 16px); width: calc(100vw - 16px); padding: 16px; }
  #edit-form { max-height: calc(100dvh - 90px); }
}
dialog h3 { margin-bottom: 12px; font-size: 18px; }

#edit-form { display: flex; flex-direction: column; max-height: calc(100vh - 142px); }
#modal-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  overflow-y: auto; /* only kicks in on very short screens */
  /* Room for the 3px focus ring (2px outline + 1px offset), which overflow would otherwise clip.
     The negative margin cancels the padding so nothing shifts. */
  padding: 4px;
  margin: -4px;
}
.field { display: block; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field span { display: block; margin-bottom: 3px; font-size: 12px; font-weight: 600; color: #444; }
.field input[type="text"], .field input[type="email"], .field input[type="tel"] {
  width: 100%; padding: 7px 10px; border: 1px solid #c7ccd4; border-radius: 6px; font-size: 14px;
}
.field select { width: 100%; padding: 7px 10px; border: 1px solid #c7ccd4; border-radius: 6px; font-size: 14px; background: #fff; }
.field-num { display: flex; align-items: center; gap: 6px; }
.field-num span { margin: 0; }
.field-num input { width: 64px; padding: 5px 6px; border: 1px solid #c7ccd4; border-radius: 6px; font-size: 14px; }
.field-num select { padding: 4px 6px; border: 1px solid #c7ccd4; border-radius: 6px; font-size: 14px; background: #fff; width: auto; }
.field-num input[type="checkbox"] { width: 18px; height: 18px; }
.field-num .unit { font-weight: 400; color: #666; }
.file-row { display: flex; align-items: center; gap: 10px; }
.file-row input[type="file"] { flex: 1; min-width: 0; font-size: 13px; }
.field .file-name { margin: 3px 0 0; font-weight: 400; color: #666; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
[hidden] { display: none !important; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(520px, calc(100vw - 32px)); padding: 12px 18px; background: #222; color: #fff; border-radius: 8px; font-size: 14px; z-index: 10; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.field input:focus, .field select:focus { outline: 2px solid #0073e6; outline-offset: 1px; }

.color-row { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px 24px; padding-top: 4px; }
.qr-fieldset { margin: 0; min-width: 0; padding: 6px 12px 10px; border: 1px solid #c7ccd4; border-radius: 8px; align-items: center; }
.qr-fieldset legend { padding: 0 6px; font-size: 12px; font-weight: 600; color: #4a5260; }
.field-color { display: flex; align-items: center; gap: 8px; }
.field-color span { margin: 0; }
.field-color input { width: 40px; height: 28px; padding: 0; border: 1px solid #c7ccd4; border-radius: 6px; background: none; cursor: pointer; }

.fit-note { grid-column: 1 / -1; font-size: 13px; color: #1f6f3a; background: #eaf6ee; border-radius: 6px; padding: 6px 10px; }
.fit-note.warn { color: #8a4b00; background: #fff3e0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* Narrow screens: single column */
@media (max-width: 560px) {
  #modal-fields { grid-template-columns: 1fr; }
}

/* --- Print sheets: hidden on screen, shown only in print --- */
#print-area { display: none; }

.page {
  background: white;
  width: 8.5in;
  height: 11in;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 3.5in);
  grid-template-rows: repeat(5, 2in);
}

@media print {
  @page { size: letter portrait; margin: 0; }

  body { background: transparent; }
  .app-bar, .account-bar, .editor, .hint, dialog, #toast, .ad-slot, .site-footer { display: none !important; }
  #print-area { display: block; }

  .page {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    break-inside: avoid;
  }
  .page:not(:last-child) { break-after: page; page-break-after: always; }

  /* Light cut guides */
  .card { outline: 1px dashed rgba(0, 0, 0, 0.15); }
}

/* --- Welcome modal (first visit) --- */
.welcome-dialog[open] { width: min(460px, calc(100vw - 32px)); padding: 28px 28px 24px; }
.welcome-screen { margin: 0; }
.welcome-intro { text-align: center; }
.welcome-lead { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 24px; line-height: 1.2; }
.welcome-line { font-size: 22px; color: #333; }
.welcome-free { font-size: 52px; font-weight: 800; letter-spacing: 3px; color: var(--accent, #0073e6); }
.welcome-ever { font-size: 30px; font-weight: 700; letter-spacing: 2px; color: #333; }
.welcome-form-title { font-size: 20px; font-weight: 700; margin-bottom: 16px; text-align: left; }
.welcome-dialog label { display: grid; gap: 4px; margin-bottom: 12px; font-size: 14px; font-weight: 600; text-align: left; }
.welcome-dialog input { font: inherit; font-weight: 400; padding: 9px 10px; border: 1px solid #c7ccd4; border-radius: 6px; width: 100%; }
.welcome-dialog input:focus { outline: 2px solid #0073e6; outline-offset: 1px; }
.welcome-note { font-size: 13px; color: #666; margin: -4px 0 16px; text-align: left; }
.welcome-actions { margin-top: 20px; text-align: center; }
.welcome-actions .btn-primary { min-width: 180px; padding: 12px 24px; font-size: 16px; }
@media (max-width: 480px) {
  .welcome-free { font-size: 42px; }
  .welcome-ever { font-size: 26px; }
  .welcome-actions .btn-primary { width: 100%; }
}

/* --- Back: bullet list --- */
.back-bullets { justify-content: center; }
.bullet-list { list-style: none; width: 100%; display: grid; grid-template-columns: 1fr; gap: 3px 14px; }
.bullet-list.multi-col { grid-auto-flow: column; grid-template-columns: repeat(var(--bcols, 2), minmax(0, auto)); grid-template-rows: repeat(var(--brows, 1), auto); justify-content: start; }
.bullet-list li { display: flex; align-items: baseline; gap: 6px; min-width: 0; font-size: var(--bsize, 10px); line-height: 1.3; color: var(--fg, #fff); }
.bullet-list .bullet-mark { flex: none; }
.bullet-list .bullet-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Bullet-list editor (Back modal) */
.bullet-editor textarea { width: 100%; min-height: 92px; font: inherit; font-weight: 400; padding: 8px 10px; border: 1px solid #c7ccd4; border-radius: 6px; resize: vertical; }
.bullet-palette { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.bullet-palette .btn { min-width: 34px; font-size: 15px; line-height: 1; padding: 6px 8px; }
.bullet-hint { font-size: 12px; color: #666; margin-top: 6px; line-height: 1.4; }
