/* =============================================
   CARD BUILDER — Sidebar Layout (Print Friendly)
   ============================================= */

:root {
  --bg: #f4f4f4;
  --fg: #111111;
  --card-bg: #ffffff;
  --sidebar-bg: #f0f2f5;
  --sidebar-border: #dcdcdc;
  --accent: #2c7be5;
  --card-border: #cccccc;
  --btn-bg: #e2e6ea;
  --btn-border: #dae0e5;
  --success: #28a745;
  --danger: #dc3545;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.4;
}

/* ---- UI ELEMENTS (Hidden in Print) ---- */
.header { padding: 20px; background: #fff; border-bottom: 1px solid #ccc; }
.header h1 { margin: 0; font-size: 24px; }
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }
.toolbar { display: flex; gap: 16px; flex-wrap: wrap; background: #fff; padding: 16px; margin-bottom: 20px; border-radius: 8px; border: 1px solid #ccc; }
.btn { padding: 8px 14px; background: var(--btn-bg); border: 1px solid var(--btn-border); border-radius: 6px; cursor: pointer; }
.btn:hover { background: #d0d7de; }
.btn-success { background: var(--success); color: #fff; border: none; }
.btn-warning { background: var(--danger); color: #fff; border: none; }

/* ---- GRID ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

/* =============================================
   CARD STYLES (Sidebar Layout)
   ============================================= */

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  position: relative; /* Anchor for absolute sidebar */
  padding-left: 90px; /* Reserve space for sidebar */
  min-height: 400px; 
}

/* --- LEFT SIDEBAR (Icons) --- */
.stat-icons {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 90px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  padding: 10px 0;
  z-index: 2;
}

.stat-icons img {
  width: 65px;
  height: 65px;
  object-fit: contain;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.1));
}

/* --- RIGHT CONTENT --- */
.card-image {
  width: 100%;
  aspect-ratio: 1 / 1; 
  object-fit: contain;
  background: #fff;
  border-bottom: 1px solid #eee;
  display: block;
}

.card-pad {
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.card-header {
  border-bottom: 2px solid #333;
  margin-bottom: 5px;
  padding-bottom: 5px;
}

.card-title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  text-transform: uppercase;
  color: #000;
  letter-spacing: -0.5px;
}

.badge {
  font-size: 10px;
  text-transform: uppercase;
  color: #666;
  background: #eee;
  padding: 2px 6px;
  border-radius: 4px;
  float: right;
  margin-top: 4px;
}

/* --- TEXT STATS --- */
.stat-block { display: flex; flex-direction: column; gap: 8px; }

.stat-line {
  font-size: 14px;
  color: #111;
  text-align: left;
  line-height: 1.3;
}

.stat-line strong {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  color: #555;
  margin-bottom: 2px;
}

.card-controls {
  padding: 10px;
  border-top: 1px solid #eee;
  display: flex; gap: 5px; flex-wrap: wrap;
  margin-left: -90px;
  width: calc(100% + 90px);
  background: #fff;
  z-index: 5;
}

/* =============================================
   PRINT STYLES — FIXED FOR FIREFOX/PDF
   ============================================= */

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

  /* 1. Hide UI */
  .header, .toolbar, .footer, .card-controls, .btn, .modal-overlay, .busy-overlay {
    display: none !important;
  }

  body {
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .container { max-width: none; padding: 0; margin: 0; }
  
  .grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.2in;
  }

  .card {
    break-inside: avoid;
    height: 46vh;
    border: 2px solid #000;
    box-shadow: none;
    border-radius: 0;
    
    /* CRITICAL FIXES FOR SIDEBAR VISIBILITY */
    overflow: visible !important; /* Allow absolute children to be seen */
    position: relative !important; /* Ensure absolute context */
    display: block !important;    /* Reset flex/grid contexts */
    padding-left: 95px !important;
    background-color: #fff !important;
  }

  /* SIDEBAR RE-ENFORCEMENT */
  .stat-icons {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    height: 100% !important; /* Force full height */
    width: 95px !important;
    z-index: 100 !important; /* Bring to front */
    
    /* Ensure Background Prints */
    background-color: #f0f0f0 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    border-right: 2px solid #000;
    
    padding: 20px 0;
    justify-content: space-around;
  }

  /* BIGGER ICONS */
  .stat-icons img {
    width: 70px !important; 
    height: 70px !important;
    display: block;
  }

  /* IMAGE LAYOUT */
  .card-image {
    width: 100%;
    height: 60%; 
    border-bottom: 2px solid #000;
    object-fit: contain; 
    object-position: center bottom;
  }

  /* TEXT LAYOUT */
  .card-pad {
    height: 40%;
    padding: 12px 15px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  
  .card-header {
    border-bottom: 2px solid #000;
    margin-bottom: 8px;
    padding-bottom: 5px;
  }

  .card-title { font-size: 16pt; }
  
  .stat-line {
    font-size: 11pt;
    margin-bottom: 6px;
  }

  .stat-line strong {
    display: inline-block;
    width: 90px;
    font-weight: 800;
    color: #000;
  }
}