:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --btn: #2563eb; --btn-dark: #1d4ed8; --btn-soft: #dbeafe;
  --brand: #2563eb; --brand-soft: #dbeafe;
  --slate: #475569; --slate-2: #334155;
  --ink: #1a1a1a; --muted: #6b7280;
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f7f9fb; --hair: #e5e7eb;
  --ok: #16a34a; --ok-soft: #dcfce7;
  --danger: #d0342c;

  /* Mörk skena */
  --rail-bg: #0f172a; --rail-bg-2: #1e293b; --rail-ink: #cbd5e1;
  --rail-ink-dim: #94a3b8; --rail-active: #2563eb;
  --rail-w: 232px; --rail-w-narrow: 64px;

  --shadow: 0 1px 3px rgba(20,25,35,0.06), 0 10px 24px -18px rgba(20,25,35,0.18);
}

* { box-sizing: border-box; }
body { font-family: var(--font); margin: 0; background: var(--bg); color: var(--ink); line-height: 1.55; }
a { color: var(--btn); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { margin-top: 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { margin-top: 0.25rem; font-weight: 700; letter-spacing: -0.01em; font-size: 1.15rem; }
.muted { color: var(--muted); font-size: 0.92rem; }

/* ---------------- Skal (shell) ---------------- */
.shell { min-height: 100vh; }

/* Skenan är smal (bara ikoner) som standard, ligger fast och expanderar vid hover.
   "Fäst" (body.rail-pinned) låser den öppen. */
.rail {
  position: fixed; top: 0; left: 0; height: 100vh; z-index: 30;
  width: var(--rail-w-narrow);
  background: var(--rail-bg); color: var(--rail-ink);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width 0.16s ease;
}
.rail:hover,
body.rail-pinned .rail { width: var(--rail-w); box-shadow: 6px 0 24px -10px rgba(0,0,0,0.45); }
body.rail-pinned .rail { box-shadow: none; }

.rail-top { display: flex; align-items: center; padding: 0.9rem 0; height: 56px; flex: 0 0 auto; }
.rail-brand { display: flex; align-items: center; color: #fff; font-weight: 700; min-width: 0; flex: 1; }
.rail-brand:hover { text-decoration: none; }
.rail-logo { font-size: 1.4rem; line-height: 1; width: 24px; text-align: center; margin: 0 20px; flex: 0 0 auto; }
.rail-pin {
  background: var(--rail-bg-2); color: var(--rail-ink); border: none;
  width: 28px; height: 28px; border-radius: 7px; cursor: pointer; font-size: 0.9rem; flex: 0 0 auto; margin-right: 12px;
}
.rail-pin:hover { background: #334155; color: #fff; }

/* Projektväljare i skenan */
.rail-project { padding: 0 8px 6px; flex: 0 0 auto; position: relative; }
.rail-project-btn {
  display: flex; align-items: center; width: 100%; border: none; cursor: pointer;
  background: var(--rail-bg-2); color: var(--rail-ink); border-radius: 9px;
  padding: 0.5rem 0; overflow: hidden; white-space: nowrap; font: inherit; text-align: left;
}
.rail-project-btn:hover { background: #334155; color: #fff; }
.rail-project-name { flex: 1; overflow: hidden; text-overflow: ellipsis; font-size: 0.9rem; }
.rail-project-caret { margin: 0 10px 0 4px; font-size: 0.7rem; }
.rail-project-menu {
  position: absolute; left: 8px; right: 8px; top: 100%; z-index: 60;
  background: #fff; color: var(--ink); border-radius: 9px; box-shadow: 0 8px 24px -6px rgba(0,0,0,0.5);
  padding: 4px; max-height: 320px; overflow-y: auto;
}
.rail-project-menu.hidden { display: none; }
.rail-project-item {
  display: block; width: 100%; text-align: left; border: none; background: none; cursor: pointer;
  padding: 0.5rem 0.6rem; border-radius: 7px; font: inherit; font-size: 0.9rem; color: var(--ink);
}
.rail-project-item:hover { background: var(--surface-2); }
.rail-project-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.rail-project-empty { padding: 0.5rem 0.6rem; color: var(--muted); font-size: 0.85rem; }
/* Smal skena: dölj projektnamn + pil, bara mappikonen syns */
.rail:not(:hover):not(.rail-pinned) .rail-project-btn { justify-content: center; }

.rail-tools { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 0.5rem 8px; overflow-y: auto; overflow-x: hidden; }
.rail-bottom { padding: 0.5rem 8px 0.75rem; border-top: 1px solid rgba(255,255,255,0.07); display: flex; flex-direction: column; gap: 2px; flex: 0 0 auto; }

.rail-tool {
  display: flex; align-items: center;
  padding: 0.6rem 0; border-radius: 9px; color: var(--rail-ink);
  white-space: nowrap; overflow: hidden;
}
.rail-tool:hover { background: var(--rail-bg-2); color: #fff; text-decoration: none; }
.rail-tool.active { background: var(--rail-active); color: #fff; }
.rail-tool.disabled { opacity: 0.5; cursor: default; }
.rail-tool.disabled:hover { background: transparent; color: var(--rail-ink); }
.rail-tool-icon { font-size: 1.2rem; width: 24px; text-align: center; margin: 0 12px; flex: 0 0 auto; }

.rail-user { display: flex; align-items: center; padding: 0.45rem 0; border-radius: 9px; color: var(--rail-ink); }
.rail-user:hover { background: var(--rail-bg-2); text-decoration: none; }
.rail-avatar {
  flex: 0 0 auto; width: 32px; height: 32px; border-radius: 50%; margin: 0 8px;
  background: var(--rail-active); color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
}

/* Etiketter: syns bara när skenan är bred (hover/fäst). Klipps annars bort. */
.rail-label { white-space: nowrap; overflow: hidden; opacity: 0; transition: opacity 0.12s ease; }
.rail:hover .rail-label,
body.rail-pinned .rail-label { opacity: 1; }
.rail-user-meta { display: flex; flex-direction: column; min-width: 0; }
.rail-user-name { color: #e2e8f0; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; }
.rail-user-logout { color: var(--rail-ink-dim); font-size: 0.78rem; }

/* ---------------- Innehåll (röda zonen) ---------------- */
.content {
  position: relative;
  margin-left: var(--rail-w-narrow);
  min-height: 100vh;
  transition: margin-left 0.16s ease;
}
body.rail-pinned .content { margin-left: var(--rail-w); }

.homeview { max-width: 1000px; margin: 0 auto; padding: 1.75rem 1.5rem; }
.page-head { margin-bottom: 1.25rem; }
.page-head h1 { margin-bottom: 0.25rem; }

/* Verktyget bäddas in och fyller hela innehållsytan */
.tool-iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: none; display: none; background: #fff; }
.tool-iframe.show { display: block; }

.card { background: var(--surface); border: 1px solid var(--hair); border-radius: 12px; padding: 1.25rem 1.5rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }

/* Verktygskort på startsidan */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.tool-card {
  display: flex; align-items: flex-start; gap: 0.9rem;
  background: var(--surface); border: 1px solid var(--hair); border-radius: 12px;
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow); color: var(--ink);
  transition: transform 0.1s, box-shadow 0.15s, border-color 0.15s;
}
.tool-card:hover { text-decoration: none; transform: translateY(-2px); border-color: #cdd7e5; box-shadow: 0 6px 20px -12px rgba(20,25,35,0.28); }
.tool-card.disabled { opacity: 0.6; cursor: default; }
.tool-card.disabled:hover { transform: none; box-shadow: var(--shadow); border-color: var(--hair); }
.tool-card-icon { font-size: 2rem; line-height: 1; flex: 0 0 auto; }
.tool-card-body { display: flex; flex-direction: column; min-width: 0; }
.tool-card-name { font-weight: 700; font-size: 1.05rem; }
.tool-card-name .soon { font-style: normal; font-size: 0.72rem; font-weight: 600; background: var(--surface-2); color: var(--muted); padding: 0.05rem 0.4rem; border-radius: 20px; margin-left: 0.35rem; vertical-align: middle; }
.tool-card-desc { color: var(--muted); font-size: 0.9rem; margin-top: 0.2rem; }

/* Projektväljare */
.project-form { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.project-form select { padding: 0.5rem 0.65rem; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 1rem; font-family: inherit; background: var(--surface); min-width: 260px; }
.project-form select:focus { outline: none; border-color: var(--btn); box-shadow: 0 0 0 3px var(--btn-soft); }
.proj-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.55rem 0; border-top: 1px solid var(--hair); }
.proj-row:first-child { border-top: none; }
.proj-row.inactive { opacity: 0.55; }

/* Buggfix */
textarea { width: 100%; padding: 0.58rem 0.65rem; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 1rem; font-family: inherit; margin-top: 0.25rem; resize: vertical; }
textarea:focus { outline: none; border-color: var(--btn); box-shadow: 0 0 0 3px var(--btn-soft); }
.paste-zone { margin-top: 0.75rem; border: 2px dashed #cbd5e1; border-radius: 10px; padding: 1.25rem; text-align: center; background: var(--surface-2); cursor: text; }
.paste-zone:focus { outline: none; border-color: var(--btn); background: var(--btn-soft); }
.paste-hint { color: var(--muted); line-height: 1.5; }
.paste-preview { max-width: 100%; max-height: 320px; border-radius: 8px; border: 1px solid var(--hair); }

.bug-item { display: flex; gap: 1rem; align-items: flex-start; justify-content: space-between; padding: 0.9rem 0; border-top: 1px solid var(--hair); }
.bug-item:first-of-type { border-top: none; }
.bug-item.fixed { opacity: 0.6; }
.bug-main { min-width: 0; flex: 1; }
.bug-meta { font-size: 0.9rem; margin-bottom: 0.3rem; }
.bug-who { font-weight: 600; }
.bug-comment { white-space: pre-wrap; margin-bottom: 0.5rem; }
.bug-thumb { max-width: 220px; max-height: 160px; border-radius: 8px; border: 1px solid var(--hair); display: block; }
.bug-thumb-link:hover { text-decoration: none; }
.bug-actions { flex: 0 0 auto; }
.pill-open { font-size: 0.72rem; font-weight: 600; background: #fef3c7; color: #92400e; padding: 0.1rem 0.5rem; border-radius: 20px; margin-left: 0.4rem; }
.pill-fixed { font-size: 0.72rem; font-weight: 600; background: var(--ok-soft); color: #0c5c2c; padding: 0.1rem 0.5rem; border-radius: 20px; margin-left: 0.4rem; }

/* Formulär */
label { display: block; font-weight: 550; margin-top: 0.5rem; }
input[type=text], input[type=email], input[type=password] {
  width: 100%; padding: 0.58rem 0.65rem; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 1rem; background: var(--surface); margin-top: 0.25rem; color: var(--ink); font-family: inherit;
}
input:focus { outline: none; border-color: var(--btn); box-shadow: 0 0 0 3px var(--btn-soft); }
.check { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 500; margin-top: 0; cursor: pointer; }
.check input { width: auto; margin: 0; }

.btn { display: inline-block; background: var(--btn); color: #fff; padding: 0.58rem 1.15rem; border: none; border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer; text-decoration: none; transition: background 0.15s, transform 0.1s; }
.btn:hover { background: var(--btn-dark); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--slate); }
.btn.secondary:hover { background: var(--slate-2); }
.btn.small { padding: 0.32rem 0.72rem; font-size: 0.85rem; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b0241d; }

.error { background: #fdecec; color: #9a2820; padding: 0.75rem 0.9rem; border: 1px solid #f6cfcb; border-radius: 8px; margin-bottom: 1rem; }
.success { background: var(--ok-soft); color: #0c5c2c; padding: 0.75rem 0.9rem; border: 1px solid #bfe6cd; border-radius: 8px; margin-bottom: 1rem; }

/* Admin-rader */
.row-form { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; }
.row-form .grow { flex: 1; min-width: 180px; }
.row-form label { margin-top: 0; }

.user-row { display: grid; grid-template-columns: 1.3fr 1.5fr 0.8fr auto; gap: 1rem; align-items: center; padding: 0.9rem 0; border-top: 1px solid var(--hair); }
.user-row:first-of-type { border-top: none; }
.user-name { font-weight: 600; }
.user-email { color: var(--muted); font-size: 0.9rem; }
.user-flags { font-size: 0.8rem; margin-top: 0.2rem; }
.user-tools { display: flex; flex-direction: column; gap: 0.3rem; }
.user-switches { display: flex; flex-direction: column; gap: 0.3rem; }
.user-actions { display: flex; flex-direction: column; gap: 0.4rem; }

/* ---------------- Auth-sidor (login/glömt/återställ) ---------------- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #0f172a, #1e293b); padding: 1rem; }
.auth-card { background: var(--surface); border-radius: 16px; padding: 2.5rem 2rem; width: 100%; max-width: 26rem; text-align: center; box-shadow: 0 20px 50px -20px rgba(0,0,0,0.5); }
.auth-card h1 { font-size: 1.5rem; margin: 0.5rem 0 0.35rem; }
.auth-logo { font-size: 3rem; line-height: 1; }
.auth-card form { text-align: left; margin-top: 1rem; }
.auth-card .muted { margin-top: 1.1rem; }

/* ---------------- Mobil ---------------- */
@media (max-width: 720px) {
  .homeview { padding: 1.25rem 1rem; }
  .user-row { grid-template-columns: 1fr; gap: 0.5rem; }
}
