/* Filvelger (Design 2026-10) – brukes av static/fileinput.js.
   Kun eksisterende fargetokens (lys og mørk modus via :root[data-theme="dark"]).
   Det opprinnelige feltet ligger visuelt skjult inni omslaget og holder filene som sendes med skjemaet. */

/* ---------- Omslag ---------- */
.fip { position: relative; display: flex; flex-direction: column; gap: 6px; box-sizing: border-box; min-width: 0; max-width: 100%;
  vertical-align: middle; text-align: left; font-weight: 400; }
.fip *, .fip *::before, .fip *::after { box-sizing: border-box; }
.fip.fip-block { width: 100%; }
.fip.fip-inline { flex: 0 1 auto; }
.fip.fip-col { align-self: stretch; }

/* Det opprinnelige feltet: i DOM-en, fokuserbart, men usynlig. */
.fip > input.fip-native {
  position: absolute !important; top: 0 !important; left: 0 !important; z-index: -1;
  width: 1px !important; height: 1px !important; min-width: 0 !important; min-height: 0 !important; max-width: none !important;
  margin: 0 !important; padding: 0 !important; border: 0 !important; opacity: 0 !important; overflow: hidden !important;
  clip: rect(0 0 0 0) !important; clip-path: inset(50%) !important; white-space: nowrap !important; flex: none !important;
  box-shadow: none !important; pointer-events: none; }

/* ---------- Feltet (samme høyde og radius som andre felt) ---------- */
.fip-box { position: relative; display: flex; align-items: center; min-width: 0; min-height: 40px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm, 10px);
  background: var(--input-bg, var(--surface)); color: var(--text);
  transition: border-color .14s, box-shadow .14s, background-color .14s;
  scroll-margin-top: calc(var(--topbar-h, 56px) + env(safe-area-inset-top, 0px) + 16px); scroll-margin-bottom: 24px; }
.fip-box:hover { border-color: var(--primary); }
.fip.fip-has:not(.fip-multi) .fip-box { border-style: solid; }
.fip-zone { flex: 1 1 auto; align-self: stretch; display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: 5px 12px 5px 5px; border-radius: inherit; cursor: pointer; outline: none;
  font-family: inherit; font-size: var(--fs-sm, 0.875rem); line-height: 1.3; white-space: nowrap;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
.fip-zone:focus { outline: none; }
.fip.fip-focus .fip-box { border-color: var(--primary); border-style: solid; box-shadow: 0 0 0 3px var(--ring, rgba(54, 74, 181, 0.22)); }

/* Ikonflis / miniatyr */
.fip-ic { flex: none; display: inline-grid; place-items: center; width: 28px; height: 28px; overflow: hidden;
  border-radius: var(--radius-xs, 8px); background: var(--primary-soft); color: var(--primary);
  transition: background-color .14s, color .14s; }
.fip-zone:hover .fip-ic { background: var(--primary-soft-2, var(--primary-soft)); }
.fip-ic.fip-thumb { background: var(--surface-3, var(--bg)); box-shadow: inset 0 0 0 1px var(--border); }
.fip-ic img { display: block; width: 100%; height: 100%; object-fit: cover; }
.fip.fip-has.fip-multi .fip-box .fip-ic { background: var(--success-bg); color: var(--success); }

/* Tekst: tittel, hint (enkel linje med «…», men kan krympe helt ved svært liten plass) */
.fip-title { flex: none; font-weight: 600; color: var(--primary); }
.fip.fip-has .fip-title { color: var(--text); }
.fip-hint, .fip-name { flex: 0 1 auto; min-width: 0; overflow: hidden; white-space: normal; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; line-clamp: 1; }
.fip-hint { color: var(--text-muted); font-size: var(--fs-xs, 0.8125rem); }
.fip-name { font-weight: 600; color: var(--text); }
.fip-meta { flex: none; color: var(--text-muted); font-size: var(--fs-xs, 0.8125rem); font-variant-numeric: tabular-nums; }
.fip-dnd { display: none; flex: none; margin-left: auto; padding-left: 8px; color: var(--text-faint, var(--text-muted)); font-size: var(--fs-xs, 0.8125rem); }
@media (hover: hover) and (pointer: fine) {
  .fip.fip-wide:not(.fip-has):not(.fip-disabled) .fip-dnd { display: inline; }
}
.fip.fip-has:not(.fip-multi):not(.fip-disabled):not(.fip-drag).fip-wide .fip-dnd { display: inline; color: var(--primary); font-weight: 600; }
.fip-drop { display: none; font-weight: 600; color: var(--primary); }

/* Fjern-knapp (x) i feltet og på brikkene */
.fip-x { flex: none; display: inline-grid; place-items: center; width: 30px; height: 30px; margin-right: 5px;
  border-radius: var(--radius-xs, 8px); color: var(--text-muted); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.fip-x[hidden] { display: none; }
.fip-x:hover { background: var(--error-bg); color: var(--danger); }
.fip-x:focus { outline: none; }
.fip-x:focus-visible { outline: 2px solid var(--focus, var(--primary)); outline-offset: -2px; }

/* ---------- Flere filer: én brikke per fil ---------- */
.fip-list { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin: 0; padding: 0; }
.fip-list[hidden] { display: none; }
.fip-chip { display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 44px; padding: 5px 4px 5px 6px;
  border: 1px solid var(--border); border-radius: var(--radius-sm, 10px); background: var(--surface); color: var(--text);
  font-size: var(--fs-sm, 0.875rem); line-height: 1.3; animation: fip-in .16s var(--ease, ease-out); }
.fip-chip .fip-ic { width: 32px; height: 32px; }
.fip-cmeta { flex: 1 1 auto; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.fip-chip .fip-x { margin-right: 0; }
@keyframes fip-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

/* ---------- Melding (påkrevd, feil filtype) ---------- */
.fip-msg { display: block; font-size: var(--fs-xs, 0.8125rem); font-weight: 600; line-height: 1.3; color: var(--danger); white-space: normal; }
.fip-msg[hidden] { display: none; }
.fip-msg.is-info { color: var(--text-muted); font-weight: 500; }

/* ---------- Tilstander ---------- */
/* Dra og slipp */
html.fip-dragging .fip:not(.fip-disabled) .fip-box { border-color: var(--primary); }
.fip.fip-drag .fip-box { border-style: dashed; border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px var(--ring, rgba(54, 74, 181, 0.22)); }
.fip.fip-drag .fip-zone > :not(.fip-ic):not(.fip-drop) { display: none; }
.fip.fip-drag .fip-drop { display: inline; }
.fip-drop-on { border-color: var(--primary) !important; background-color: var(--primary-soft) !important; }

/* Påkrevd uten fil */
.fip.fip-invalid .fip-box { border-color: var(--danger); border-style: solid; }
.fip.fip-invalid.fip-focus .fip-box { box-shadow: 0 0 0 3px var(--error-bg, rgba(192, 57, 43, 0.15)); }
.fip.fip-invalid .fip-box .fip-ic:not(.fip-thumb) { background: var(--error-bg); color: var(--danger); }

/* Deaktivert */
.fip.fip-disabled .fip-box { border-style: solid; border-color: var(--border); background: var(--surface-2, var(--bg)); box-shadow: none; }
.fip.fip-disabled .fip-box:hover { border-color: var(--border); }
.fip.fip-disabled .fip-zone { cursor: not-allowed; }
.fip.fip-disabled .fip-title { color: var(--text-muted); }
.fip.fip-disabled .fip-ic:not(.fip-thumb) { background: var(--surface-3, var(--bg)); color: var(--text-faint, var(--text-muted)); }
.fip.fip-disabled .fip-dnd { display: none; }

/* Stor slippsone (input.lg-file, f.eks. lagerimport) */
.fip.fip-lg .fip-box { min-height: 76px; }
.fip.fip-lg:not(.fip-has) .fip-zone { justify-content: center; flex-wrap: wrap; row-gap: 2px; padding: 12px 16px; white-space: normal; text-align: center; }
.fip.fip-lg:not(.fip-has) .fip-dnd { display: none; }
@media (hover: hover) and (pointer: fine) {
  .fip.fip-lg:not(.fip-has):not(.fip-disabled):not(.fip-drag) .fip-dnd { display: inline; margin-left: 0; padding-left: 0; }
}

/* Små felt (input.small) */
.fip.fip-small .fip-box { min-height: 32px; }
.fip.fip-small .fip-zone { padding-top: 2px; padding-bottom: 2px; font-size: var(--fs-xs, 0.8125rem); gap: 8px; }
.fip.fip-small .fip-box .fip-ic { width: 24px; height: 24px; }

/* I eksisterende opplastingsflater (allerede stiplet ramme rundt): heltrukken kant, fyll bredden. */
.rs-file .fip-box, .tm-receipt-row .fip-box, .tm-upload .fip-box { border-style: solid; }
.tm-receipt-row .fip-box { min-height: 44px; }   /* samme høyde som «Ta bilde» ved siden av */
.rs-file > .fip { width: 100%; max-width: 460px; }
.tm-upload > .fip { flex: 1 1 240px; }
.rs-file.fip-drop-on, .tm-receipt-row.fip-drop-on, .tm-upload.fip-drop-on { transition: background-color .12s, border-color .12s; }

/* Berøringsskjerm: litt tydeligere trykk-respons (trykk åpner telefonens eget filvalg: kamera/bilder/filer). */
@media (pointer: coarse) {
  .fip-zone:active { background: var(--surface-2, var(--bg)); }
  .fip-x { width: 34px; height: 34px; margin-right: 3px; }
}

@media (prefers-reduced-motion: reduce) {
  .fip-box, .fip-ic { transition: none; }
  .fip-chip { animation: none; }
}
@media print {
  .fip-x { display: none !important; }
  .fip-box { border-style: solid; }
}
