/* ============================================================
   Printable Target Generator — KnowYourRifle Theme
   ============================================================ */

/* --- Base -------------------------------------------------- */
* { box-sizing: border-box; }

:root {
  --amber: #b88d58;
  --amber-hover: #a67b4a;
  --amber-light: #c9a373;
  --surface: #1e232a;
  --surface-dark: #121518;
  --surface-input: #2a303c;
  --surface-border: #3d4452;
  --text-primary: #e5e7eb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
}

/* --- Margin Cross Layout ---------------------------------- */
.margin-cross {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.margin-cross-top,
.margin-cross-bottom {
  width: 80px;
  text-align: center;
}

.margin-cross-middle {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
}

.margin-cross-middle > div:first-child,
.margin-cross-middle > div:last-child {
  flex: 1;
}

.margin-cross-spacer {
  width: 60px;
  height: 40px;
  border: 1px dashed var(--surface-border);
  border-radius: 4px;
  flex-shrink: 0;
}

/* --- Textarea --------------------------------------------- */
textarea.input-field {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
}

/* --- Tab Navigation --------------------------------------- */
.tab-btn {
  flex: 1;
  padding: 10px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text-secondary); }

.tab-btn.active {
  color: var(--amber);
  border-bottom-color: var(--amber);
}

/* --- Tab Panels ------------------------------------------- */
.tab-panel { display: none; animation: fadeIn 0.15s ease; }
.tab-panel.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Field Labels ----------------------------------------- */
.field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.margin-label {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* --- Input Fields ----------------------------------------- */
.input-field {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--surface-input);
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-field:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 2px rgba(184, 141, 88, 0.15);
}

.input-field::placeholder { color: var(--text-muted); }

select.input-field {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { opacity: 1; height: 22px; }

/* --- Color Input ------------------------------------------ */
.color-input {
  width: 100%;
  height: 36px;
  padding: 2px 4px;
  background: var(--surface-input);
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s ease;
}

.color-input:focus { border-color: var(--amber); }
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: none; border-radius: 4px; }

/* --- Toggle Options (Orientation) ------------------------- */
.toggle-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-input);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.toggle-option:first-child { border-right: 1px solid var(--surface-border); }

.toggle-option.active {
  color: #fff;
  background: var(--amber);
}

.toggle-option:hover:not(.active) {
  color: var(--text-secondary);
  background: #323844;
}

/* --- Layout Cards ----------------------------------------- */
.layout-card {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  background: var(--surface-input);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.layout-card:hover { border-color: #555d6b; }

.layout-card:has(input:checked) {
  border-color: var(--amber);
  background: rgba(184, 141, 88, 0.08);
}

.layout-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.layout-card-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* --- Checkbox Row ----------------------------------------- */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--amber);
  cursor: pointer;
  flex-shrink: 0;
}

/* --- Overlay Cards (collapsible) -------------------------- */
.overlay-card {
  background: var(--surface-input);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  margin-bottom: 10px;
  overflow: hidden;
}

.overlay-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}

.overlay-card-header:hover { background: rgba(255,255,255,0.02); }

.overlay-card-header input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--amber);
  cursor: pointer;
  flex-shrink: 0;
}

.overlay-card-body {
  display: none;
  padding: 0 12px 12px 12px;
  border-top: 1px solid var(--surface-border);
}

.overlay-card:has(input:checked) .overlay-card-body {
  display: block;
}

/* --- Scrollbar -------------------------------------------- */
#tab-panels::-webkit-scrollbar { width: 5px; }
#tab-panels::-webkit-scrollbar-track { background: transparent; }
#tab-panels::-webkit-scrollbar-thumb { background: var(--surface-border); border-radius: 3px; }
#tab-panels::-webkit-scrollbar-thumb:hover { background: #555d6b; }

/* --- Paper Container -------------------------------------- */
.paper {
  --paper-ratio: 210 / 297;
  aspect-ratio: var(--paper-ratio);
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: none;
  object-fit: contain;
  border-radius: 2px;
  transition: box-shadow 0.3s ease;
}

.paper:hover { box-shadow: 0 30px 60px -15px rgba(0, 0, 0, 0.6); }

.paper.letter-portrait { --paper-ratio: 215.9 / 279.4; }
.paper.a4-landscape  { --paper-ratio: 297 / 210; }
.paper.letter-landscape { --paper-ratio: 279.4 / 215.9; }

/* --- Preview Panel (right column) -------------------------- */
/* Centers the paper and lets it fill the available panel.     */
#preview-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: none;
  box-sizing: border-box;
}

/* --- Target Canvas ---------------------------------------- */
#target-canvas { pointer-events: none; }
#target-canvas svg { display: block; width: 100%; height: 100%; }

/* --- Draggable Overlay Elements --------------------------- */
.draggable {
  cursor: grab;
  pointer-events: auto;
}

.draggable:active {
  cursor: grabbing;
}

#paper {
  pointer-events: auto;
  overflow: visible;
  /* Prevent clipping of drag targets at paper edges */
  clip-path: none;
}

/* Ensure the entire paper surface receives mouse events.
   The absolute-positioned #target-canvas must not block
   drag interactions at the bottom edge. */
#target-canvas {
  pointer-events: none;
  overflow: visible;
}

/* Draggable elements must extend their hit area to the
   full paper bounds — no dead zones at edges. */
.draggable {
  cursor: grab;
  pointer-events: auto;
  /* Ensure SVG groups inside paper are reachable */
  touch-action: none;
}

/* --- Responsive ------------------------------------------- */
@media (max-width: 1023px) {
  aside { max-height: 55vh; }
}

@media (max-width: 640px) {
  aside { max-height: 50vh; }
  .tab-btn { font-size: 10px; padding: 8px 3px; }
}

/* Desktop: dynamic contain-fill of the preview panel.
   The paper scales to fit within BOTH the panel width and
   height (~90-95%) while preserving its aspect ratio. */
@media (min-width: 1024px) {
  main {
    height: 100vh;
    height: 100svh;
    overflow: hidden;
  }

  #preview-container {
    position: relative;
    height: 100%;
    padding: 2rem 2rem 4rem;
    overflow: hidden;
  }

  #paper-label {
    position: absolute;
    bottom: 1rem;
    left: 0;
    right: 0;
    margin-top: 0;
  }

  .paper {
    width: min(100%, calc((100vh - 10rem) * var(--paper-ratio)));
    width: min(100%, calc((100svh - 10rem) * var(--paper-ratio)));
    height: auto;
    max-height: calc(100vh - 10rem);
    max-height: calc(100svh - 10rem);
  }
}

/* --- Toast Notification ----------------------------------- */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  z-index: 9999;
  max-width: 320px;
  padding: 0.75rem 1rem;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--amber);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ============================================================
   Print Styles
   ============================================================ */
@media print {
  aside, header, nav, footer, #paper-label, #preview-container > p,
  button, .no-print, .tab-btn, #tab-panels, form, #pdf-btn {
    display: none !important;
  }

  html, body {
    margin: 0 !important; padding: 0 !important;
    width: 100% !important; height: 100% !important;
    background: white !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body > div { display: block !important; margin: 0 !important; padding: 0 !important; width: 100% !important; height: 100% !important; }
  main { display: block !important; margin: 0 !important; padding: 0 !important; width: 100% !important; height: 100% !important; background: white !important; }
  #preview-container { max-width: none !important; width: 100% !important; height: 100% !important; margin: 0 !important; padding: 0 !important; }

  #paper {
    position: fixed; left: 0; top: 0;
    margin: 0 !important; padding: 0 !important;
    width: 210mm; height: 297mm; max-width: 210mm;
    aspect-ratio: auto; box-shadow: none !important;
    border-radius: 0 !important; overflow: hidden;
    page-break-after: avoid;
  }

  #paper.letter-portrait { width: 215.9mm; height: 279.4mm; max-width: 215.9mm; }
  #paper.a4-landscape { width: 297mm; height: 210mm; max-width: 297mm; }
  #paper.letter-landscape { width: 279.4mm; height: 215.9mm; max-width: 279.4mm; }
  #paper svg { width: 100% !important; height: 100% !important; }

  @page { size: A4 portrait; margin: 0; }
}