/* l0ftet-tema: mørk lilla, lilla aksent, gul for nøkkelverdier */
:root {
  --bg: #16121f;
  --bg-card: #1e1830;
  --bg-card-inner: #241d3a;
  --border: #322a4d;
  --text: #e5e1f0;
  --text-dim: #a49bc0;
  --accent: #a78bfa;
  --accent-strong: #8b5cf6;
  --amber: #fbbf24;
  --green: #34d399;
  --green-bg: rgba(52, 211, 153, 0.12);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.12);
  --amber-bg: rgba(251, 191, 36, 0.12);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: radial-gradient(1200px 600px at 50% -100px, #221a38 0%, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

/* --- Toppbar --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(22, 18, 31, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-size: 1.25rem; font-weight: 800; color: var(--accent); }
.brand span { color: var(--text-dim); font-weight: 400; font-size: 1rem; margin-left: 8px; }
.topbar .spacer { flex: 1; }
.topbar .user-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.9rem;
}
.topbar .user-btn:hover { border-color: var(--accent); }

.container { max-width: 1080px; margin: 0 auto; padding: 28px 20px 80px; }

/* --- Seksjoner / kort --- */
.section-title {
  color: var(--accent);
  font-weight: 800;
  font-size: 1.15rem;
  margin: 26px 0 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-sub { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 14px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* --- Skjemaer --- */
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
input[type="text"], input[type="password"], select {
  background: var(--bg-card-inner);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 0.95rem;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
input[type="text"], input[type="password"] { flex: 1; min-width: 180px; }
select { cursor: pointer; }

.btn {
  background: var(--accent-strong);
  border: none;
  color: #fff;
  font-weight: 600;
  padding: 11px 22px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: filter 0.15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn.small { padding: 6px 14px; font-size: 0.83rem; border-radius: 8px; }
.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--accent);
}
.btn.ghost:hover { border-color: var(--accent); }

.checkbox-label {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-dim); font-size: 0.9rem; cursor: pointer;
  user-select: none;
}
.checkbox-label input { accent-color: var(--accent-strong); width: 16px; height: 16px; }

/* --- Resultatgrid --- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  position: relative;
}
.tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.tile img, .tile .noimg {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: var(--bg-card-inner);
}
.tile .noimg {
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 2rem;
}
.tile .meta { padding: 10px 12px 12px; }
.tile .title { font-weight: 600; font-size: 0.9rem; line-height: 1.3; }
.tile .sub { color: var(--text-dim); font-size: 0.8rem; margin-top: 3px; }
.tile .year { color: var(--amber); font-weight: 700; font-size: 0.8rem; }
.tile .dl {
  position: absolute; top: 8px; right: 8px;
  background: rgba(22, 18, 31, 0.85);
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 0.9rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.tile:hover .dl { opacity: 1; }
.tile .dl:hover { border-color: var(--accent); }

/* --- Artist/album-detalj --- */
.detail-head { display: flex; gap: 20px; align-items: center; margin: 18px 0; }
.detail-head img {
  width: 140px; height: 140px; border-radius: var(--radius);
  object-fit: cover; border: 1px solid var(--border);
}
.detail-head h2 { font-size: 1.7rem; }
.detail-head .dim { color: var(--text-dim); margin-top: 4px; }
.detail-head .amber { color: var(--amber); font-weight: 700; }

.tracklist { margin-top: 10px; }
.trackrow {
  display: flex; align-items: center; gap: 14px;
  padding: 9px 14px;
  border-radius: 10px;
}
.trackrow:hover { background: var(--bg-card-inner); }
.trackrow .n { color: var(--amber); font-weight: 700; width: 26px; text-align: right; }
.trackrow img { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; }
.trackrow .t { flex: 1; min-width: 0; }
.trackrow .t .name { font-weight: 500; }
.trackrow .t .sub { color: var(--text-dim); font-size: 0.82rem; }
.trackrow .dur { color: var(--text-dim); font-size: 0.85rem; }

.back-link { color: var(--accent); cursor: pointer; font-size: 0.9rem; margin-top: 14px; display: inline-block; }

/* --- Nedlastingskø --- */
.job {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.job:last-child { border-bottom: none; }
.job .label { flex: 1; min-width: 0; word-break: break-all; font-size: 0.9rem; }
.job .log { color: var(--text-dim); font-size: 0.78rem; margin-top: 4px; font-family: ui-monospace, monospace; white-space: pre-wrap; }

.pill {
  padding: 4px 12px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.done { color: var(--green); background: var(--green-bg); }
.pill.running, .pill.queued { color: var(--amber); background: var(--amber-bg); }
.pill.failed { color: var(--red); background: var(--red-bg); }

/* --- Innlogging --- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 34px 30px;
}
.login-card h1 { color: var(--accent); font-size: 1.6rem; text-align: center; }
.login-card .sub { color: var(--text-dim); text-align: center; margin: 6px 0 24px; font-size: 0.9rem; }
.login-card input { width: 100%; margin-bottom: 12px; }
.login-card .btn { width: 100%; margin-top: 6px; }

.error-msg { color: var(--red); font-size: 0.88rem; margin: 8px 0; min-height: 1.2em; }
.ok-msg { color: var(--green); font-size: 0.88rem; margin: 8px 0; }

/* --- Modal (konto) --- */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(10, 8, 16, 0.7);
  display: none;
  align-items: center; justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-bg.open { display: flex; }
.modal {
  width: 100%; max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
}
.modal h3 { color: var(--accent); margin-bottom: 16px; }
.modal input { width: 100%; margin-bottom: 10px; }
.modal .row { justify-content: flex-end; margin-top: 12px; }

.hidden { display: none !important; }
.spinner {
  color: var(--text-dim); font-size: 0.9rem; padding: 20px 0;
}

@media (max-width: 600px) {
  .detail-head img { width: 96px; height: 96px; }
  .detail-head h2 { font-size: 1.25rem; }
}

/* --- v2: fremdrift, Navidrome, innstillinger --- */
.job-progress { margin-top: 8px; }
.job-count { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 6px; }
.progressbar {
  height: 7px; border-radius: 999px;
  background: var(--bg-card-inner);
  overflow: hidden;
  margin-bottom: 8px;
}
.progressbar div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  border-radius: 999px;
  transition: width 0.6s ease;
}
.file-list { max-height: 180px; overflow-y: auto; }
.file-done {
  color: var(--green);
  font-size: 0.8rem;
  font-family: ui-monospace, monospace;
  padding: 1px 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.job-errors {
  margin-top: 8px;
  color: var(--red);
  font-size: 0.8rem;
  font-family: ui-monospace, monospace;
}
.job-errors div { padding: 1px 0; }

.nav-status { color: var(--text-dim); font-size: 0.82rem; font-weight: 400; }
.nav-status.scanning { color: var(--amber); }

.dim-note { color: var(--text-dim); font-weight: 400; font-size: 0.85rem; }

#rip-config {
  width: 100%;
  min-height: 420px;
  background: var(--bg-card-inner);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  resize: vertical;
  outline: none;
}
#rip-config:focus { border-color: var(--accent); }

/* --- v3: faner, bibliotek, sletting --- */
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab {
  background: transparent; border: none; color: var(--text-dim);
  padding: 8px 14px; border-radius: 10px; cursor: pointer;
  font-size: 0.92rem; font-weight: 600;
}
.tab:hover { color: var(--text); background: var(--bg-card); }
.tab.active { color: var(--text); background: var(--bg-card); border: 1px solid var(--border); }

.tile-actions {
  position: absolute; top: 8px; right: 8px;
  display: flex; gap: 6px;
  opacity: 0; transition: opacity 0.15s;
}
.tile:hover .tile-actions { opacity: 1; }
.tile-btn {
  background: rgba(22, 18, 31, 0.9);
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 8px; padding: 5px 9px;
  font-size: 0.9rem; cursor: pointer;
}
.tile-btn:hover { border-color: var(--accent); }
.tile-btn.danger { color: var(--red); }
.tile-btn.danger:hover { border-color: var(--red); }

.btn.danger { background: var(--red); color: #2a0f0f; }
.btn.danger:hover { filter: brightness(1.1); }
.btn.ghost.danger { background: transparent; color: var(--red); border-color: var(--border); }
.btn.ghost.danger:hover { border-color: var(--red); }

.noimg.head {
  width: 140px; height: 140px; border-radius: var(--radius);
  border: 1px solid var(--border); flex: none;
}

.confirm-note {
  color: var(--text-dim); font-size: 0.85rem;
  margin-top: 10px; line-height: 1.5;
}
#confirm-body p { line-height: 1.5; }
#confirm-input { width: 100%; }

#trash-path, #music-root { color: var(--accent); }

/* --- v4: mobilmeny og slettedialog --- */
.icon-btn {
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.1rem;
  padding: 7px 12px;
  border-radius: 10px;
  cursor: pointer;
  line-height: 1;
}
.icon-btn:hover { border-color: var(--accent); }

.nav-scrim {
  position: fixed; inset: 0;
  background: rgba(10, 8, 16, 0.6);
  /* Must stay BELOW .topbar (z-index 10). The drawer lives inside .topbar,
     which is a stacking context of its own (position:sticky + z-index), so
     the drawer's own z-index can't lift it above a sibling of .topbar --
     a higher scrim would cover the menu and swallow its clicks. */
  z-index: 5;
  display: none;
}
.nav-scrim.open { display: block; }

.confirm-actions { margin-top: 16px; flex-wrap: nowrap; }
.confirm-actions .spacer { flex: 1; }
.btn.hidden { display: none !important; }

@media (max-width: 780px) {
  /* backdrop-filter lager en containing block for fixed-elementer -- da blir
     uttrekksmenyen låst inne i topbaren i stedet for å dekke skjermen. */
  .topbar { gap: 12px; padding: 12px 16px; backdrop-filter: none; }
  .icon-btn { display: block; }

  /* Fanene blir en uttrekkbar meny */
  .tabs {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 250px;
    height: 100dvh;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    margin: 0;
    padding: 18px 14px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    overflow-y: auto;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .tabs.open { transform: translateX(0); }
  .tab {
    text-align: left;
    padding: 13px 14px;
    font-size: 1rem;
  }

  .container { padding: 18px 14px 60px; }
  .brand { font-size: 1.05rem; }
  .brand span { display: none; }

  /* Skjemaer stables i stedet for å klemmes sammen */
  .row { gap: 8px; }
  .card .row > select,
  .card .row > input[type="text"],
  .card .row > .btn { flex: 1 1 100%; min-width: 0; }
  #search-source, #search-type { flex: 1 1 calc(50% - 4px) !important; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  /* Uten hover på touch: vis handlingsknappene permanent */
  .tile-actions { opacity: 1; }

  .detail-head { flex-direction: column; align-items: flex-start; }

  .confirm-actions { flex-wrap: wrap; }
  .confirm-actions .spacer { display: none; }
  .confirm-actions .btn { flex: 1 1 100%; }
  .confirm-actions #confirm-cancel { order: 3; }

  .job { flex-direction: column; align-items: flex-start; gap: 8px; }

  /* Filnavn er lange og i monospace -- la dem brytes i stedet for å
     sprenge skjermbredden. */
  .job .label { font-size: 0.85rem; }
  .job-count { font-size: 0.8rem; }
  .file-list { max-height: 220px; }
  .file-done {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    word-break: break-word;
    font-size: 0.72rem;
    line-height: 1.45;
    padding: 2px 0;
  }
  .job-errors { font-size: 0.72rem; word-break: break-word; }
  .job-errors div { white-space: pre-wrap; }
}
