/**
 * HIB Frontlight Editor - Frontend Styles
 * Lightweight, modern, glassmorphic UI layer.
 */

:root {
  --hib-lock-color: #0f172a;
  --hib-lock-accent: #3b82f6;
  --hib-bg-card: rgba(255, 255, 255, 0.96);
  --hib-text-main: #0f172a;
  --hib-text-muted: #64748b;
  --hib-border: #e2e8f0;
  --hib-primary: #2563eb;
  --hib-primary-hover: #1d4ed8;
  --hib-success: #10b981;
  --hib-error: #ef4444;
  --hib-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --hib-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --hib-shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --hib-radius: 12px;
}

/* 1. Root & Base Isolation */
.hib-frontlight-root {
  font-family: var(--hib-font-family);
  font-size: 14px;
  line-height: 1.5;
  color: var(--hib-text-main);
  box-sizing: border-box;
  z-index: 999990;
}

.hib-frontlight-root *,
.hib-frontlight-root *::before,
.hib-frontlight-root *::after {
  box-sizing: border-box;
}

/* 2. Floating Padlock Button */
.hib-lock-btn {
  position: fixed;
  z-index: 999991;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--hib-lock-color);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 9999px;
  cursor: pointer;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
  padding: 0;
  margin: 0;
}

.hib-lock-btn:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 14px 20px -3px rgba(0, 0, 0, 0.3);
}

.hib-lock-btn:focus-visible {
  ring: 3px solid var(--hib-lock-accent);
  box-shadow: 0 0 0 3px var(--hib-lock-accent);
}

/* Posisjoner */
.hib-pos-bottom-right .hib-lock-btn { bottom: 24px; right: 24px; }
.hib-pos-bottom-left .hib-lock-btn  { bottom: 24px; left: 24px; }
.hib-pos-top-right .hib-lock-btn    { top: 24px; right: 24px; }
.hib-pos-top-left .hib-lock-btn     { top: 24px; left: 24px; }

/* Størrelser */
.hib-size-small .hib-lock-btn  { width: 38px; height: 38px; }
.hib-size-medium .hib-lock-btn { width: 46px; height: 46px; }
.hib-size-large .hib-lock-btn  { width: 54px; height: 54px; }

/* Synlighet */
.hib-vis-discrete .hib-lock-btn {
  opacity: 0.35;
}
.hib-vis-discrete .hib-lock-btn:hover,
.hib-vis-discrete .hib-lock-btn:focus,
.hib-frontlight-root.hib-active .hib-lock-btn {
  opacity: 1;
}

.hib-vis-hidden .hib-lock-btn {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}
.hib-vis-hidden.hib-revealed .hib-lock-btn,
.hib-vis-hidden.hib-active .hib-lock-btn {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

/* Hengelås ikoner og status */
.hib-lock-icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
}

.hib-icon-unlocked {
  display: none;
}

.hib-frontlight-root.hib-active .hib-icon-locked {
  display: none;
}

.hib-frontlight-root.hib-active .hib-icon-unlocked {
  display: block;
  color: var(--hib-lock-accent);
}

.hib-lock-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  background: var(--hib-success);
  border-radius: 9999px;
  border: 2px solid var(--hib-lock-color);
  display: none;
}

.hib-frontlight-root.hib-active .hib-lock-badge {
  display: block;
  animation: hib-pulse 2s infinite;
}

@keyframes hib-pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* 3. Brukermeny Popover */
.hib-popover {
  position: fixed;
  background: var(--hib-bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--hib-border);
  border-radius: var(--hib-radius);
  box-shadow: var(--hib-shadow);
  padding: 16px;
  width: 250px;
  z-index: 999992;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.hib-pos-bottom-right .hib-popover { bottom: 80px; right: 24px; }
.hib-pos-bottom-left .hib-popover  { bottom: 80px; left: 24px; }
.hib-pos-top-right .hib-popover    { top: 80px; right: 24px; }
.hib-pos-top-left .hib-popover     { top: 80px; left: 24px; }

.hib-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--hib-border);
}

.hib-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
}

.hib-user-dot {
  width: 8px;
  height: 8px;
  background: var(--hib-success);
  border-radius: 9999px;
}

.hib-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 500;
}

.hib-toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}
.hib-toggle-switch input { opacity: 0; width: 0; height: 0; }
.hib-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #cbd5e1;
  transition: .3s;
  border-radius: 34px;
}
.hib-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}
.hib-toggle-switch input:checked + .hib-slider { background-color: var(--hib-primary); }
.hib-toggle-switch input:checked + .hib-slider:before { transform: translateX(16px); }

/* 4. Modal Backdrops and Cards */
.hib-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.hib-modal-backdrop.hib-hidden,
.hib-popover.hib-hidden,
.hib-format-toolbar.hib-hidden,
.hib-hidden {
  display: none !important;
}

.hib-modal-card {
  background: #ffffff;
  color: var(--hib-text-main);
  border-radius: var(--hib-radius);
  box-shadow: var(--hib-shadow);
  width: 100%;
  max-width: 440px;
  padding: 24px;
  position: relative;
  border: 1px solid var(--hib-border);
  animation: hib-modal-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.hib-modal-wide {
  max-width: 680px;
}

@keyframes hib-modal-in {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.hib-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}

.hib-modal-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hib-brand-icon {
  width: 40px;
  height: 40px;
  background: #eff6ff;
  color: var(--hib-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}

.hib-modal-header h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  color: var(--hib-text-main);
}

.hib-modal-subtitle {
  font-size: 13px;
  color: var(--hib-text-muted);
  margin: 2px 0 0 0;
}

.hib-modal-close,
.hib-close-btn {
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--hib-text-muted);
  padding: 4px;
  border-radius: 6px;
  transition: all 0.2s;
}

.hib-modal-close:hover,
.hib-close-btn:hover {
  color: var(--hib-text-main);
  background: #f1f5f9;
}

/* 5. Skjemaelementer i modaler */
.hib-form-group {
  margin-bottom: 16px;
  text-align: left;
}

.hib-form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #334155;
}

.hib-form-group input[type="text"],
.hib-form-group input[type="password"],
.hib-form-group input[type="email"],
.hib-form-group input[type="search"],
.hib-form-group textarea,
.hib-form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--hib-border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--hib-text-main);
  background: #ffffff;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.hib-form-group input:focus,
.hib-form-group textarea:focus {
  border-color: var(--hib-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.hib-checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.hib-url-input-wrap {
  position: relative;
}

.hib-link-type-badge {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: #f1f5f9;
  color: #64748b;
}

.hib-link-type-badge.external {
  background: #fef3c7;
  color: #b45309;
}

.hib-alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}

.hib-alert-error {
  background: #fef2f2;
  color: var(--hib-error);
  border: 1px solid #fecaca;
}

.hib-modal-footer,
.hib-form-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* 6. Knapper */
.hib-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.hib-btn-primary {
  background: var(--hib-primary);
  color: #ffffff;
}

.hib-btn-primary:hover {
  background: var(--hib-primary-hover);
}

.hib-btn-secondary {
  background: #f1f5f9;
  color: #334155;
  border-color: #e2e8f0;
}

.hib-btn-secondary:hover {
  background: #e2e8f0;
}

.hib-btn-subtle {
  background: transparent;
  color: #64748b;
  padding: 6px 10px;
  font-size: 13px;
}

.hib-btn-subtle:hover {
  background: #f1f5f9;
  color: var(--hib-text-main);
}

/* 7. Redigerbare elementer på siden */
.hib-edit-active [data-hib-edit] {
  position: relative !important;
  transition: outline 0.15s ease, box-shadow 0.15s ease;
  cursor: pointer;
}

.hib-edit-active [data-hib-edit]:hover {
  outline: 2px dashed var(--hib-lock-accent) !important;
  outline-offset: 3px;
}

.hib-edit-active [data-hib-edit].hib-is-editing {
  outline: 2px solid var(--hib-primary) !important;
  outline-offset: 3px;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15) !important;
  background-color: rgba(37, 99, 235, 0.03);
}

.hib-edit-active [data-hib-edit][data-hib-readonly="1"]:hover {
  outline: 2px dashed #94a3b8 !important;
  cursor: not-allowed !important;
}

/* Svevende "Rediger"-knapp ved hover (både flytende og element-trigger) */
.hib-hover-trigger,
#hib-floating-trigger {
  position: absolute;
  z-index: 999988;
  background: var(--hib-lock-color);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 9999px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(2px) scale(0.96);
  transition: opacity 0.15s cubic-bezier(0.16, 1, 0.3, 1), transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.15s;
  white-space: nowrap;
  line-height: 1;
}

.hib-hover-trigger:hover,
#hib-floating-trigger:hover {
  background: #1e293b;
  transform: translateY(0) scale(1.04);
}

.hib-hover-trigger.hib-readonly-trigger,
#hib-floating-trigger.hib-readonly-trigger {
  background: #475569;
  cursor: not-allowed;
  border-color: #64748b;
}

.hib-hover-trigger.hib-visible,
#hib-floating-trigger.hib-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.hib-hover-trigger.hib-hidden,
#hib-floating-trigger.hib-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(2px) scale(0.92);
}

/* 8. Rik tekst formateringsverktøylinje */
.hib-format-toolbar {
  position: absolute;
  z-index: 999985;
  background: #0f172a;
  color: #ffffff;
  padding: 4px;
  border-radius: 8px;
  box-shadow: var(--hib-shadow);
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  animation: hib-modal-in 0.15s ease;
}

.hib-format-toolbar button {
  background: transparent;
  color: #cbd5e1;
  border: none;
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}

.hib-format-toolbar button:hover {
  background: #1e293b;
  color: #ffffff;
}

.hib-format-toolbar .hib-toolbar-divider {
  width: 1px;
  height: 18px;
  background: #334155;
  margin: 0 4px;
}

.hib-format-toolbar .hib-tb-save {
  background: var(--hib-success);
  color: #ffffff;
  border-radius: 6px;
  padding: 4px 10px;
  font-weight: 700;
}

.hib-format-toolbar .hib-tb-save:hover {
  background: #059669;
}

.hib-format-toolbar .hib-tb-cancel {
  background: transparent;
  color: #94a3b8;
  padding: 4px 8px;
}

.hib-format-toolbar .hib-tb-cancel:hover {
  color: #f87171;
}

/* 9. Bildeopplasting og Galleri Grid */
.hib-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--hib-border);
  margin-bottom: 16px;
}

.hib-tab-btn {
  background: transparent;
  border: none;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--hib-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

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

.hib-tab-pane {
  display: none;
}

.hib-tab-pane.active {
  display: block;
}

.hib-dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  padding: 32px 16px;
  text-align: center;
  background: #f8fafc;
  cursor: pointer;
  transition: all 0.2s;
}

.hib-dropzone:hover,
.hib-dropzone.dragover {
  border-color: var(--hib-primary);
  background: #eff6ff;
}

.hib-dropzone-lead {
  font-size: 14px;
  font-weight: 600;
  margin: 10px 0 4px 0;
  color: var(--hib-text-main);
}

.hib-dropzone-help {
  font-size: 12px;
  color: var(--hib-text-muted);
  margin: 0;
}

.hib-hidden-input {
  display: none;
}

.hib-media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
  margin-top: 10px;
}

.hib-media-thumb {
  aspect-ratio: 1/1;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  transition: all 0.15s;
}

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

.hib-media-thumb:hover {
  transform: scale(1.03);
}

.hib-media-thumb.selected {
  border-color: var(--hib-primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4);
}

.hib-image-meta-section {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--hib-border);
}

.hib-image-preview-box {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  border: 1px solid var(--hib-border);
  overflow: hidden;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.hib-image-preview-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hib-preview-placeholder {
  font-size: 11px;
  color: var(--hib-text-muted);
  text-align: center;
  padding: 4px;
}

.hib-image-inputs {
  flex: 1;
}

/* 10. Toasts */
.hib-toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.hib-toast {
  background: #0f172a;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
  animation: hib-toast-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.25s, transform 0.25s;
}

.hib-toast.hib-toast-success {
  background: #065f46;
}

.hib-toast.hib-toast-error {
  background: #991b1b;
}

.hib-toast.hib-toast-pending {
  background: #1e3a8a;
}

@keyframes hib-toast-in {
  from { opacity: 0; transform: translateY(16px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Responsivitet for mobil */
@media (max-width: 640px) {
  .hib-modal-card {
    padding: 18px;
    max-width: 95vw;
  }
  .hib-image-meta-section {
    flex-direction: column;
    align-items: flex-start;
  }
  .hib-pos-bottom-right .hib-popover,
  .hib-pos-bottom-left .hib-popover {
    left: 16px;
    right: 16px;
    width: auto;
  }
}
