:root {
  --blue: #003660;
  --blue-2: #07517f;
  --blue-3: #eaf3f8;
  --ink: #172531;
  --muted: #617482;
  --line: #d9e3e9;
  --surface: #ffffff;
  --bg: #f4f7f9;
  --danger: #a32d2d;
  --shadow: 0 10px 30px rgba(14, 41, 61, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-header {
  background: linear-gradient(135deg, #002d51, var(--blue-2));
  color: #fff;
  padding: 22px clamp(18px, 4vw, 48px);
  box-shadow: 0 8px 24px rgba(0, 54, 96, .18);
}
.header-inner { max-width: 1420px; margin: 0 auto; }
.brand-wrap { display: flex; gap: 18px; align-items: center; }
.app-icon { width: 78px; height: 78px; object-fit: contain; flex: 0 0 auto; }
h1 { margin: 0; font-size: clamp(1.8rem, 3vw, 2.5rem); line-height: 1.08; }
.app-header p { margin: 8px 0 0; color: rgba(255,255,255,.88); }
.header-version { white-space: nowrap; font-weight: 700; }
.header-disclaimer {
  margin-top: 16px;
  padding: 11px 14px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 10px;
  background: rgba(255,255,255,.10);
  color: rgba(255,255,255,.94);
  font-size: .88rem;
  line-height: 1.45;
}
.header-disclaimer strong { color: #fff; }
.header-disclaimer a {
  color: #fff;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.header-disclaimer a:hover { color: #d9efff; }

.app-shell {
  width: min(1420px, calc(100% - 28px));
  margin: 28px auto 42px;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(340px, .9fr);
  gap: 22px;
  align-items: start;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px;
}
.library-panel { grid-row: span 2; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-heading h2 { margin: 0; color: var(--blue); font-size: 1.35rem; }
.panel-heading p { margin: 4px 0 0; color: var(--muted); font-size: .93rem; }
.result-count { background: var(--blue-3); color: var(--blue); padding: 7px 10px; border-radius: 999px; font-weight: 700; font-size: .84rem; white-space: nowrap; }

.filters { display: grid; grid-template-columns: 1fr 1fr 1.25fr; gap: 12px; margin-bottom: 18px; }
label { display: grid; gap: 6px; }
label > span:first-child { color: var(--muted); font-weight: 700; font-size: .82rem; }
input[type="search"], input[type="number"], select {
  width: 100%; border: 1px solid #cbd8e0; border-radius: 10px; background: #fff; color: var(--ink); padding: 10px 11px; outline: none;
}
input:focus, select:focus { border-color: var(--blue-2); box-shadow: 0 0 0 3px rgba(7,81,127,.12); }

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.badge-tile {
  border: 1px solid var(--line); border-radius: 14px; background: #fff; overflow: hidden; padding: 0; text-align: left; transition: .16s ease; color: inherit;
}
.badge-tile:hover { transform: translateY(-2px); border-color: #afc8d6; box-shadow: 0 8px 18px rgba(15,53,80,.08); }
.badge-tile.is-selected { border-color: var(--blue-2); box-shadow: 0 0 0 3px rgba(7,81,127,.12); }
.badge-tile-image { height: 155px; display: grid; place-items: center; padding: 14px; background: #fff; }
.badge-tile-image img { max-width: 100%; max-height: 100%; object-fit: contain; }
.badge-tile-body { padding: 18px 12px 12px; }
.badge-tile-title { font-weight: 800; color: var(--blue); margin-bottom: 6px; }
.badge-tile-meta { color: var(--muted); font-size: .78rem; line-height: 1.4; }

.empty-state { border: 1px dashed #bfd0da; background: #f8fbfc; color: var(--muted); border-radius: 12px; padding: 24px; text-align: center; }
.empty-state.compact { padding: 16px; }
.is-hidden { display: none !important; }
.selected-badge-head { display: flex; align-items: center; gap: 14px; padding: 12px; background: #f7fafc; border: 1px solid var(--line); border-radius: 12px; }
.selected-badge-head img { width: 72px; height: 72px; object-fit: contain; }
.selected-title { font-size: 1.1rem; font-weight: 850; color: var(--blue); }
.selected-meta { margin-top: 4px; color: var(--muted); font-size: .84rem; }
.control-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 16px 0; }
.toggle-label { align-content: end; }
.toggle-row { height: 42px; display: flex; align-items: center; gap: 9px; padding: 0 10px; border: 1px solid #cbd8e0; border-radius: 10px; color: var(--ink); }
.toggle-row input { width: 18px; height: 18px; accent-color: var(--blue-2); }
.preview-heading { display: flex; justify-content: space-between; align-items: center; margin: 16px 0 10px; }
.preview-heading h3 { margin: 0; font-size: 1rem; color: var(--blue); }
.preview-heading span { color: var(--muted); font-size: .8rem; font-weight: 700; }
.preview-stage { min-height: 380px; padding: 18px; display: grid; place-items: center; overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: linear-gradient(45deg, #f0f4f6 25%, transparent 25%), linear-gradient(-45deg, #f0f4f6 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #f0f4f6 75%), linear-gradient(-45deg, transparent 75%, #f0f4f6 75%); background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0px; }

.badge-card {
  width: 100mm;
  height: 150mm;
  background: #fff;
  color: #111;
  border: 1px solid #c8c8c8;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  page-break-inside: avoid;
  break-inside: avoid;
}
.preview-card { transform-origin: center center; box-shadow: 0 8px 20px rgba(0,0,0,.14); }
.badge-card-top {
  flex: 0 0 auto;
  min-height: 0;
  padding: 6mm 5mm 2mm;
  display: grid;
  grid-template-rows:
    var(--title-slot, 10mm)
    var(--badge-image-size, 55mm)
    var(--text-slot, 34mm);
  row-gap: var(--card-gap, 2.5mm);
  align-items: stretch;
  overflow: hidden;
}
.card-title {
  text-align: center;
  color: #111;
  font-weight: 800;
  font-size: 6.4mm;
  line-height: 1.05;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-wrap: anywhere;
  overflow: hidden;
}
.card-image-wrap {
  width: 100%;
  height: var(--badge-image-size, 55mm);
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.card-image {
  display: block;
  width: var(--badge-image-size, 55mm);
  height: var(--badge-image-size, 55mm);
  max-width: var(--badge-image-size, 55mm);
  max-height: var(--badge-image-size, 55mm);
  object-fit: contain;
  object-position: center;
}
.card-description {
  width: 100%;
  height: var(--text-slot, 34mm);
  min-width: 0;
  min-height: 0;
  position: static;
  z-index: auto;
  background: #fff;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 3.25mm;
  line-height: 1.3;
  text-align: left;
  overflow: hidden;
}
.card-description.is-hidden { visibility: hidden; }
.badge-card-pocket { flex: 1 1 auto; min-height: 38%; }

.primary-button, .secondary-button, .danger-button {
  border: 0; border-radius: 10px; padding: 11px 15px; font-weight: 800;
}
.primary-button { background: var(--blue); color: #fff; }
.primary-button:hover:not(:disabled) { background: var(--blue-2); }
.secondary-button { background: #edf3f6; color: var(--blue); }
.secondary-button:hover:not(:disabled) { background: #e1ebf0; }
.danger-button { background: #f8eded; color: var(--danger); }
button:disabled { opacity: .45; cursor: not-allowed; }
#addToQueueButton { width: 100%; margin-top: 14px; }

.queue-heading { align-items: flex-start; }
.queue-actions { display: flex; gap: 8px; }
.queue-list { display: grid; gap: 10px; }
.queue-item { display: grid; grid-template-columns: 54px minmax(0,1fr) auto; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.queue-item img { width: 54px; height: 54px; object-fit: contain; }
.queue-item-title { font-weight: 800; color: var(--blue); }
.queue-item-meta { margin-top: 3px; color: var(--muted); font-size: .79rem; }
.queue-item-actions { display: flex; gap: 6px; }
.queue-item-actions button { padding: 8px 10px; font-size: .8rem; }

.app-footer { text-align: center; color: var(--muted); font-size: .84rem; padding: 8px 16px 28px; }
#printArea { display: none; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 1fr; }
  .library-panel { grid-row: auto; }
}
@media (max-width: 690px) {
  .app-header { padding: 18px; }
  .brand-wrap { align-items: flex-start; }
  .app-icon { width: 58px; height: 58px; }
  .header-disclaimer { margin-top: 14px; padding: 10px 12px; font-size: .82rem; }
  .app-shell { width: min(100% - 16px, 1420px); margin-top: 16px; }
  .panel { padding: 15px; border-radius: 14px; }
  .filters, .control-grid { grid-template-columns: 1fr; }
  .badge-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .badge-tile-image { height: 125px; }
  .queue-heading { display: grid; }
  .queue-actions { width: 100%; }
  .queue-actions button { flex: 1; }
  .queue-item { grid-template-columns: 46px 1fr; }
  .queue-item img { width: 46px; height: 46px; }
  .queue-item-actions { grid-column: 1 / -1; }
  .queue-item-actions button { flex: 1; }
}

@media print {
  @page { size: A4 portrait; margin: 5mm; }
  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  body > *:not(#printArea) { display: none !important; }
  #printArea {
    display: flex !important;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 0;
    width: 200mm;
    margin: 0 auto;
    padding: 0;
  }
  #printArea .badge-card { flex: 0 0 auto; box-shadow: none; }
}



.badge-tile-image.is-empty { background: #fff; }
.queue-image-empty {
  width: 54px;
  height: 54px;
  display: block;
}
@media (max-width: 690px) {
  .queue-image-empty { width: 46px; height: 46px; }
}

@media print { .header-disclaimer { display: none !important; } }


/* Gemensam topprad för Lysfisken-program */
.global-links {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 22px;
  background: #f7fafc;
  border-bottom: 1px solid #d9e3ea;
  font-size: 0.84rem;
  font-weight: 800;
}

.global-links a {
  color: #0b5f92;
  text-decoration: none;
}

.global-links a:hover {
  text-decoration: underline;
}

.global-links-separator {
  color: #8ba0af;
  font-weight: 700;
}

@media (max-width: 900px) {
  .global-links {
    padding: 7px 14px;
    font-size: 0.8rem;
    flex-wrap: wrap;
  }
}

@media print {
  .global-links {
    display: none !important;
  }
}

.mode-tabs {
  display:flex;
  gap:8px;
  margin:0 0 16px;
  padding:4px;
  background:#eef4f7;
  border:1px solid var(--line);
  border-radius:12px;
}
.mode-tab {
  flex:1;
  border:0;
  border-radius:9px;
  padding:10px 14px;
  background:transparent;
  color:var(--muted);
  font-weight:800;
  cursor:pointer;
}
.mode-tab.is-active {
  background:#fff;
  color:var(--blue);
  box-shadow:0 2px 8px rgba(0,54,96,.10);
}
.custom-badge-area { margin-top:4px; }
.custom-badge-form { display:grid; gap:14px; }
.custom-badge-form label { display:grid; gap:6px; font-weight:700; color:#385066; }
.custom-badge-form input[type="text"],
.custom-badge-form input[type="file"],
.custom-badge-form textarea {
  width:100%;
  border:1px solid var(--line);
  border-radius:10px;
  padding:11px 12px;
  background:#fff;
  font:inherit;
  color:var(--text);
}
.custom-badge-form textarea { resize:vertical; min-height:130px; }
.custom-upload-preview {
  min-height:150px;
  display:grid;
  place-items:center;
  border:1px dashed #b8cbd7;
  border-radius:12px;
  background:#f7fafc;
}
.custom-upload-preview img {
  max-width:100%;
  max-height:220px;
  object-fit:contain;
  padding:12px;
}
.custom-actions { display:flex; gap:10px; }
.custom-actions .primary-button,
.custom-actions .secondary-button { flex:1; }
.custom-help { margin:12px 0 0; color:var(--muted); font-size:.9rem; line-height:1.45; }
