/* ==================== */
/* Bilder: stil, gestaltningar, arkiv, tekniskt och bildkort i chatten */
/* ==================== */

.light-theme {
  --img-thumb-bg: #ece8df;
  --img-select: #6b5b4f;
  --img-drop-bg: #f4f1ea;
  --img-badge-bg: rgba(255, 255, 255, 0.92);
  --img-badge-text: #4a3f36;
  --img-lightbox-bg: rgba(24, 20, 16, 0.86);
  --img-approved-bg: #e3f1e1;
  --img-approved-text: #2f6a36;
  --img-sheet-bg: #f7f5f0;
}

.dark-theme {
  --img-thumb-bg: #232323;
  --img-select: #c4a77d;
  --img-drop-bg: #1c1c1c;
  --img-badge-bg: rgba(18, 18, 18, 0.88);
  --img-badge-text: #e8e4df;
  --img-lightbox-bg: rgba(0, 0, 0, 0.9);
  --img-approved-bg: #22382a;
  --img-approved-text: #a5d8a9;
  --img-sheet-bg: #1e1e1e;
}

.img-section {
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border-color);
}

.img-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-bottom: 12px;
}

.img-section-head h3 {
  font-size: 17px;
  font-weight: 500;
}

.img-section-head .seg { margin-bottom: 0; }

.img-sub {
  margin: -4px 0 12px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--save-status-color);
}

.img-empty {
  font-size: 14px;
  font-style: italic;
  color: var(--save-status-color);
  line-height: 1.5;
}

/* ---- Rutnät ---- */

.img-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}

.img-grid .img-empty { grid-column: 1 / -1; }

.img-thumb {
  position: relative;
  display: block;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
  background: var(--img-thumb-bg);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.img-thumb:hover { border-color: var(--accent-color); }

.img-thumb.selected {
  border-color: var(--img-select);
  box-shadow: 0 0 0 2px var(--img-select);
}

.img-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.img-badge.approved {
  background: var(--img-approved-bg);
  color: var(--img-approved-text);
  font-weight: 600;
}

.img-badge.inline {
  position: static;
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 12px;
  font-size: 12px;
}

.img-thumb.approved { border-color: var(--fb-good); }

.img-thumb.small .img-badge { font-size: 9px; left: 3px; bottom: 3px; padding: 0 5px; }

.img-badge {
  position: absolute;
  left: 4px;
  bottom: 4px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--img-badge-bg);
  color: var(--img-badge-text);
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  line-height: 1.5;
}

/* ---- Förhandsvisning ---- */

.img-detail {
  margin-bottom: 14px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--card-bg);
  overflow: hidden;
}

.img-detail[hidden] { display: none; }

.img-detail-pic {
  background: var(--img-thumb-bg);
  max-height: 360px;
  aspect-ratio: 4 / 3;
  display: flex;
  justify-content: center;
}

.img-detail-pic img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 360px;
  object-fit: contain;
  cursor: zoom-in;
}

.img-detail-body { padding: 12px 14px 14px; }

.img-detail-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.img-detail-label {
  font-size: 17px;
  font-weight: 500;
  line-height: 1.35;
  min-width: 0;
  overflow-wrap: anywhere;
}

.img-close {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--save-status-color);
  cursor: pointer;
}

.img-close:hover { background: var(--header-bg); color: var(--text-color); }

.img-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 14px;
  margin: 10px 0 0;
}

.img-meta div { min-width: 0; }

.img-meta dt {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--placeholder-color);
}

.img-meta dd {
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.img-prompt {
  margin-top: 10px;
  font-size: 14px;
}

.img-prompt summary {
  cursor: pointer;
  color: var(--accent-color);
  font-size: 13px;
}

.img-prompt p {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--header-bg);
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 220px;
  overflow-y: auto;
}

.img-detail-btns { align-items: center; }
.img-detail-btns[hidden], .img-refform[hidden] { display: none; }

.img-delete-wrap { margin-left: auto; }

.img-confirm {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--problem-color);
}

.link-btn.danger { color: var(--problem-color); font-weight: 600; }

.img-refform {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}

.img-refform .seg { margin-bottom: 0; }

/* ---- Stil och inspiration ---- */

.img-section-head h3 .img-saved { vertical-align: middle; }

.img-style .fb-field + .fb-field { margin-top: 10px; }

.img-note { margin: 8px 0 0; font-size: 13px; }

.img-template {
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--img-drop-bg);
  margin: 0 0 12px;
}

.img-template[hidden] { display: none; }
.img-template strong { font-weight: 600; }

.img-insp { margin-top: 18px; }

.img-h4 {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--save-status-color);
  margin-bottom: 6px;
}

.img-insp > .img-sub { margin: 0 0 10px; }

.img-insp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}

.img-insp-grid .img-empty { grid-column: 1 / -1; }

.img-drop {
  padding: 10px 12px;
  border: 1px dashed var(--border-color);
  border-radius: 8px;
  background: var(--img-drop-bg);
  transition: border-color var(--transition), background-color var(--transition);
}

.img-drop .seg { margin-bottom: 0; }

.img-insp.dragover .img-drop {
  border-color: var(--accent-color);
  border-style: solid;
}

.img-drop-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 10px;
}

.img-drop-hint {
  font-size: 14px;
  font-style: italic;
  color: var(--save-status-color);
}

.img-upload-status {
  margin-top: 8px;
  font-size: 13px;
  color: var(--accent-color);
}

.img-upload-status[hidden] { display: none; }

/* ---- Gestaltningar ---- */

.img-gestalt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(124px, 1fr));
  gap: 10px;
}

.img-gestalt {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0 0 8px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-bg);
  color: var(--text-color);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.img-gestalt:hover { border-color: var(--accent-color); }
.img-gestalt.selected { border-color: var(--img-select); box-shadow: 0 0 0 2px var(--img-select); }

.img-gestalt-pic {
  display: block;
  aspect-ratio: 3 / 2;
  background: var(--img-sheet-bg);
}

.img-gestalt-pic img { display: block; width: 100%; height: 100%; object-fit: cover; }

.img-gestalt-name {
  padding: 6px 9px 0;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.img-gestalt-kind {
  padding: 0 9px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--save-status-color);
}

.img-lacking { margin: 10px 0 0; }

.img-view .fb-field input,
.img-view .fb-field textarea,
.img-view .fb-field select {
  min-width: 0;
  padding: 6px 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--text-color);
  font-family: var(--font-family);
  font-size: 15px;
}

.img-view .fb-field input:focus,
.img-view .fb-field textarea:focus,
.img-view .fb-field select:focus {
  outline: none;
  border-color: var(--accent-color);
  background: var(--card-bg);
}

.img-view .fb-field select { width: 100%; cursor: pointer; }
.img-view .fb-field select option { background: var(--panel-bg); color: var(--text-color); }

.img-view .fb-field input,
.img-view .fb-field textarea,
.img-view .fb-field select {
  width: 100%;
  border-color: var(--border-color);
  background: var(--card-bg);
}

.img-view .fb-field textarea {
  resize: none;
  overflow: hidden;
  line-height: 1.5;
}

.img-view .fb-field textarea::placeholder,
.img-view .fb-field input::placeholder {
  color: var(--placeholder-color);
  font-style: italic;
}

/* ---- Inställningar ---- */

.img-saved {
  margin-left: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--fb-good);
  opacity: 0;
  transition: opacity var(--transition);
}

.img-saved.visible { opacity: 1; }

.img-set-label {
  margin-top: 12px;
  font-size: 12px;
  color: var(--save-status-color);
}

.img-models {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.img-model {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color var(--transition), background-color var(--transition);
}

.img-model:hover { border-color: var(--accent-color); }

.img-model.active {
  border-color: var(--accent-color);
  background: var(--header-bg);
}

.img-model input {
  margin-top: 4px;
  accent-color: var(--accent-color);
}

.img-model-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.35;
}

.img-model-text strong { font-weight: 500; font-size: 15px; }
.img-model-default {
  margin-left: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-style: normal;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--save-status-color);
}

.img-model-text span { font-size: 13px; color: var(--save-status-color); }

/* ---- Bildkort i chatten ---- */

.img-card-pic {
  display: block;
  width: 100%;
  max-height: 320px;
  padding: 0;
  border: none;
  border-radius: 6px;
  overflow: hidden;
  background: var(--img-thumb-bg);
  cursor: zoom-in;
}

.img-card-pic img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 320px;
  object-fit: cover;
}

.img-card-label {
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.4;
}

/* Godkänn-knappen och märket i kortet */
.img-card-state { display: contents; }

.img-card-text {
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 180px;
  overflow-y: auto;
  overflow-wrap: anywhere;
}

.img-card-approved {
  display: flex;
  align-items: center;
  gap: 12px;
}

.img-card-thumb {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
  background: var(--img-thumb-bg);
  cursor: zoom-in;
}

.img-card-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }

.img-card-approved-text { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.img-card-approved .act-card-title { margin-bottom: 0; overflow-wrap: anywhere; }

/* ---- Förstoring ---- */

.img-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--img-lightbox-bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  cursor: zoom-out;
}

.img-lightbox.visible { opacity: 1; pointer-events: auto; }

.img-lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.img-lightbox-close {
  position: absolute;
  top: 14px;
  right: 16px;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  background: none;
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  cursor: pointer;
}

@media (max-width: 600px) {
  .img-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .img-insp-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .img-gestalt-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .img-detail-pic, .img-detail-pic img { max-height: 280px; }
}

/* ---- Flikar ---- */

.img-tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 18px;
  border-bottom: 1px solid var(--border-color);
  font-family: 'Inter', sans-serif;
}

.img-tabs button {
  margin-bottom: -1px;
  padding: 8px 12px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--save-status-color);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}

.img-tabs button:hover { color: var(--text-color); }
.img-tabs button.active { color: var(--text-color); border-bottom-color: var(--accent-color); font-weight: 500; }
.img-pane[hidden] { display: none; }

/* ---- Ensemble ---- */

.img-ensemble:empty { display: none; }
.img-ensemble { margin-bottom: 18px; }

.img-ens-pic {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
  background: var(--img-sheet-bg);
  cursor: pointer;
  transition: border-color var(--transition);
}

.img-ens-pic:hover { border-color: var(--accent-color); }
.img-ens-pic img { display: block; width: 100%; height: 100%; object-fit: cover; }

.img-ens-busy {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  padding: 6px;
  border-radius: 50%;
  background: var(--img-badge-bg);
}

.img-ens-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  aspect-ratio: 16 / 9;
  border: 1px dashed var(--border-color);
  border-radius: 10px;
  background: var(--img-drop-bg);
  font-size: 14px;
  color: var(--save-status-color);
}

.img-ens-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 8px;
}

.img-ens-title {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--save-status-color);
}

.img-ens-title .link-btn { font-size: inherit; }
.img-ens-status { margin: 6px 0 0; }
.img-ens-status.error { color: var(--danger-color, #b3261e); }
.img-ens-hint { margin: 0 0 12px; }

/* ---- Karaktärens vy ---- */

.img-ent-modal {
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px;
  overflow-y: auto;
  background: var(--img-lightbox-bg);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.img-ent-modal[hidden] { display: none; }
.img-ent-modal.visible { opacity: 1; }

.img-ent-sheet {
  width: 100%;
  max-width: 760px;
  padding: 18px 20px 22px;
  border-radius: 12px;
  background: var(--bg-color);
  color: var(--text-color);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

.img-ent-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.img-ent-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.img-ent-title h3 { font-size: 20px; font-weight: 500; overflow-wrap: anywhere; }
.img-ent-title .img-gestalt-kind { padding: 0; }

.img-ent-hero { margin-bottom: 18px; }

.img-ent-pic {
  display: block;
  width: 100%;
  max-height: 62vh;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  background: var(--img-sheet-bg);
  cursor: zoom-in;
}

.img-ent-pic img { display: block; width: 100%; height: 100%; max-height: 62vh; object-fit: contain; }

.img-ent-hero-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin-top: 10px;
}

.img-ent-hero-bar .img-badge { position: static; }

.img-ent-date {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--save-status-color);
}

.img-ent-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }

.img-ent-grid { margin-top: 4px; }

@media (max-width: 600px) {
  .img-ent-modal { padding: 0; }
  .img-ent-sheet { min-height: 100%; border-radius: 0; padding: 14px 16px 20px; }
  .img-ent-acts { margin-left: 0; width: 100%; }
}

/* ---- Roman: posterna bilden visas vid ---- */

.img-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
}

.img-links-label { color: var(--save-status-color); }

.img-link-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 9px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
}

.img-link-chip button {
  border: none;
  background: none;
  color: var(--save-status-color);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.img-link-chip button:hover { color: var(--text-color); }
.img-linkform[hidden] { display: none; }
