:root {
  --bg: #0e0b1a;
  --bg-2: #14101f;
  --surface: #1b1630;
  --surface-2: #221b3a;
  --surface-3: #2a2247;
  --line: #312a4d;
  --text: #ece9f5;
  --muted: #9b94b8;
  --muted-2: #6f6890;
  --coral: #ff6b5e;
  --magenta: #ff5fa2;
  --violet: #c44fe0;
  --indigo: #7c5cff;
  --blue: #4f6bff;
  --grad: linear-gradient(120deg, #ff6b5e, #ff5fa2 40%, #c44fe0 70%, #7c5cff);
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1d1636 0%, transparent 60%), var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* Riktig Staffler-orb (SVG) */
.orb-img { display: block; object-fit: contain; }
.orb-lg { width: 92px; height: 92px; filter: drop-shadow(0 10px 28px rgba(196,79,224,.45)); }
.orb-sm { width: 38px; height: 38px; filter: drop-shadow(0 4px 12px rgba(196,79,224,.4)); }
/* Interaktiv orb (canvas) på login */
.login-orb { display: block; filter: drop-shadow(0 12px 34px rgba(196,79,224,.5)); cursor: default; }

/* Orb-logga (gammal gradient, fallback) */
.brand-orb {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--grad);
  box-shadow: 0 0 0 4px rgba(124,92,255,.12), 0 8px 24px rgba(196,79,224,.4);
  position: relative; overflow: hidden;
}
.brand-orb::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(60% 40% at 30% 25%, rgba(255,255,255,.5), transparent 60%);
}
.brand-orb.small { width: 34px; height: 34px; box-shadow: 0 4px 14px rgba(196,79,224,.4); }

/* Login */
.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(800px 500px at 50% -10%, #251a45, transparent 70%), var(--bg);
}
.login-card {
  width: min(360px, 90vw); background: var(--surface);
  border: 1px solid var(--line); border-radius: 20px; padding: 36px 28px;
  display: grid; gap: 12px; justify-items: center; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 34px; letter-spacing: 2px; margin-top: 8px; }
.login-card input {
  width: 100%; padding: 13px 16px; text-align: center; letter-spacing: 6px; font-size: 18px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; color: var(--text);
}
.login-card input:focus { outline: none; border-color: var(--indigo); }
.login-card button {
  width: 100%; padding: 13px; border: none; border-radius: 12px; color: white; font-weight: 700;
  background: var(--grad); font-size: 15px;
}
.login-error { color: var(--coral); font-size: 13px; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px; justify-content: space-between;
  padding: 12px 22px; background: rgba(20,16,31,.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.brand-title { font-weight: 800; letter-spacing: 2px; font-size: 18px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.tab {
  border: none; background: transparent; color: var(--muted); font-weight: 600; font-size: 14px;
  padding: 8px 16px; border-radius: 9px; transition: .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface-3); color: var(--text); }
.project-chip {
  margin-left: 6px; font-size: 12px; font-weight: 700; color: #c3b6ff;
  background: rgba(124,92,255,.14); border: 1px solid rgba(124,92,255,.35);
  padding: 6px 12px; border-radius: 999px; letter-spacing: .2px;
}
.project-chip::before { content: '●'; color: var(--indigo); margin-right: 6px; font-size: 9px; vertical-align: middle; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.pill {
  font-size: 12px; font-weight: 600; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px;
}
.ghost-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 7px 12px; border-radius: 9px; font-size: 13px; font-weight: 600;
}
.ghost-btn:hover { color: var(--text); border-color: var(--muted-2); }

/* Views */
.view { padding: 22px; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.view-head h2 { font-size: 20px; font-weight: 700; }
.view-head-actions { display: flex; align-items: center; gap: 14px; }
.primary-btn {
  background: var(--grad); color: white; border: none; font-weight: 700; font-size: 14px;
  padding: 9px 16px; border-radius: 10px; box-shadow: 0 6px 16px rgba(124,92,255,.3);
}
.primary-btn:hover { filter: brightness(1.08); }

/* Filterbar */
.filterbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.filter-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.filterbar select {
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  padding: 8px 12px; border-radius: 9px; font-size: 13px;
}
.filterbar select:focus { outline: none; border-color: var(--indigo); }
.chip-toggle {
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
}
.chip-toggle.active { background: rgba(255,95,162,.18); border-color: var(--magenta); color: #ffd0e4; }

/* Board */
.board { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 20px; align-items: flex-start; }
.column {
  flex: 0 0 290px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 200px);
}
.column-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px; font-weight: 700; font-size: 14px;
}
.column-head .count-wrap { display: inline-flex; gap: 5px; align-items: center; }
.column-head .count {
  background: var(--surface-3); color: var(--muted); font-size: 12px; font-weight: 600;
  padding: 2px 9px; border-radius: 999px;
}
.column-head .count.done { background: rgba(43,182,115,.2); color: #7ee0ad; }
.column-cards { padding: 4px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 30px; }
.column-cards.drag-over { background: rgba(124,92,255,.08); border-radius: 10px; }
.add-card {
  margin: 8px 12px 14px; background: transparent; border: 1px dashed var(--line); color: var(--muted);
  padding: 9px; border-radius: 10px; font-size: 13px; font-weight: 600;
}
.add-card:hover { color: var(--text); border-color: var(--indigo); }

/* Card */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px;
  padding: 12px 13px; cursor: grab; transition: border-color .15s, transform .05s;
}
.card:hover { border-color: var(--muted-2); }
.card:active { cursor: grabbing; }
.card.dragging { opacity: .4; }
.card-title { font-size: 14px; font-weight: 600; line-height: 1.35; margin-bottom: 9px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; letter-spacing: .2px; }
.tag.org-Monvir { background: rgba(255,95,162,.16); color: #ffb3d4; }
.tag.org-Staffler { background: rgba(124,92,255,.16); color: #c3b6ff; }
.tag.phase { background: var(--surface-3); color: var(--muted); border: 1px solid transparent; }
.tag.phase::before { content: '◆'; font-size: 8px; margin-right: 4px; vertical-align: middle; opacity: .9; }
.tag.phase-none { background: transparent; color: var(--muted-2); border: 1px dashed var(--line); }
.tag.due { background: rgba(79,107,255,.16); color: #b9c4ff; }
.tag.due.overdue { background: rgba(255,107,94,.18); color: #ffb3aa; }
.avatar {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: white; margin-left: auto;
}
.avatar.Mikael { background: linear-gradient(135deg,#ff6b5e,#ff5fa2); }
.avatar.Daniel { background: linear-gradient(135deg,#c44fe0,#7c5cff); }
.avatar.Dennis { background: linear-gradient(135deg,#4f6bff,#22d3ee); }

/* Kort: klarmarkering (grön ruta) */
.card-top { display: flex; align-items: flex-start; gap: 9px; }
.card-check {
  flex: 0 0 auto; width: 19px; height: 19px; margin-top: 1px; border-radius: 6px;
  border: 2px solid var(--muted-2); background: transparent; cursor: pointer; position: relative;
  transition: .15s;
}
.card-check:hover { border-color: var(--indigo); }
.card-check.done { background: #2bb673; border-color: #2bb673; }
.card-check.done::after {
  content: ''; position: absolute; left: 5px; top: 1px; width: 5px; height: 10px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.card.done { border-color: rgba(43,182,115,.5); background: linear-gradient(180deg, rgba(43,182,115,.10), var(--surface)); }
.card.done .card-title { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(155,148,184,.6); }
.card-comment-count { font-size: 11px; color: var(--muted-2); font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }

/* Kommentarer i modal */
.comments-block { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 14px; }
.comments-block h4 { font-size: 13px; color: var(--muted); margin-bottom: 10px; font-weight: 600; }
.comment {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; margin-bottom: 8px;
}
.comment-text { font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.comment-text a { color: var(--blue); text-decoration: underline; }
.comment-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 5px; }
.comment-author { font-size: 11px; color: var(--muted-2); }
.comment-add { display: flex; gap: 8px; align-items: flex-end; margin-top: 4px; }
.comment-add textarea { min-height: 44px; }
.comment-add button { white-space: nowrap; padding: 9px 14px; }
.linkified a { color: var(--blue); text-decoration: underline; }

/* Live länk-förhandsvisning av beskrivningen i kort-modalen */
.desc-preview {
  display: none; margin-top: 8px; font-size: 13px; line-height: 1.5; color: var(--text);
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; white-space: pre-wrap; word-break: break-word;
}
.desc-preview a { color: var(--blue); text-decoration: underline; }

/* Avstämning: klarmarkering grön */
.checkin.done { border-color: rgba(43,182,115,.55); background: linear-gradient(180deg, rgba(43,182,115,.12), var(--surface)); }
.checkin.done .checkin-date { background: rgba(43,182,115,.18); color: #7ee0ad; }
.checkin-check {
  display: inline-flex; align-items: center; gap: 6px; background: transparent; border: 1px solid var(--line);
  color: var(--muted); padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.checkin-check:hover { border-color: #2bb673; color: #7ee0ad; }
.checkin-check.done { background: #2bb673; border-color: #2bb673; color: #fff; }

/* Gantt: dragbara staplar */
.gantt-bar { user-select: none; }
.gantt-bar.draggable { cursor: grab; }
.gantt-bar.dragging { cursor: grabbing; opacity: .85; box-shadow: 0 6px 18px rgba(0,0,0,.45); }
.gantt-handle {
  position: absolute; top: 0; bottom: 0; width: 9px; cursor: ew-resize; z-index: 2;
}
.gantt-handle.left { left: 0; border-radius: 7px 0 0 7px; }
.gantt-handle.right { right: 0; border-radius: 0 7px 7px 0; }
.gantt-handle:hover { background: rgba(255,255,255,.25); }
.gantt-bar-label { pointer-events: none; }
.gantt-hint { font-size: 12px; color: var(--muted-2); margin-bottom: 10px; }

/* Gantt / tidslinje */
.gantt { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.gantt-months { display: grid; grid-template-columns: 180px 1fr; border-bottom: 1px solid var(--line); }
.gantt-months .corner { padding: 10px 14px; font-size: 12px; color: var(--muted); font-weight: 600; }
.gantt-month-cells { display: grid; position: relative; }
.gantt-month-cells .m { padding: 10px 4px; text-align: center; font-size: 11px; color: var(--muted); border-left: 1px solid var(--line); }
.gantt-row { display: grid; grid-template-columns: 180px 1fr; border-bottom: 1px solid var(--line); align-items: center; }
.gantt-row:last-child { border-bottom: none; }
.gantt-label { padding: 12px 14px; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.gantt-label .dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.gantt-track { position: relative; height: 46px; }
.gantt-track .grid-line { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); }
.gantt-bar {
  position: absolute; top: 11px; height: 24px; border-radius: 7px; cursor: pointer;
  display: flex; align-items: center; padding: 0 10px; font-size: 11px; font-weight: 700; color: white;
  white-space: nowrap; overflow: hidden; box-shadow: 0 3px 10px rgba(0,0,0,.3);
}
.gantt-today { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; opacity: .55; z-index: 5; }
.gantt-today::after {
  content: 'idag'; position: absolute; top: -2px; left: 4px; font-size: 10px; color: #fff;
  background: rgba(0,0,0,.4); padding: 1px 5px; border-radius: 4px;
}

/* Avstämningar */
.checkins { display: grid; gap: 12px; max-width: 760px; }
.checkin {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; display: grid; gap: 6px;
}
.checkin-head { display: flex; align-items: center; gap: 12px; }
.checkin-date {
  font-size: 12px; font-weight: 700; color: var(--indigo); background: rgba(124,92,255,.12);
  padding: 4px 10px; border-radius: 8px; white-space: nowrap;
}
.checkin-title { font-size: 15px; font-weight: 700; }
.checkin-summary { color: var(--muted); font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.checkin-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.checkin-author { font-size: 12px; color: var(--muted-2); }
.link-btn { background: none; border: none; color: var(--muted-2); font-size: 12px; font-weight: 600; padding: 2px 6px; }
.link-btn:hover { color: var(--coral); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(8,6,16,.6); backdrop-filter: blur(4px); padding: 20px;
}
.modal {
  width: min(520px, 96vw); max-height: 92vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 24px; box-shadow: var(--shadow);
}
.modal h3 { font-size: 18px; margin-bottom: 18px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 12px; border-radius: 10px; font-size: 14px; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--indigo); }
.field textarea { resize: vertical; min-height: 80px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 20px; }
.modal-actions .primary-btn { flex: 1; }
.danger-btn { background: transparent; border: 1px solid rgba(255,107,94,.4); color: var(--coral); padding: 9px 14px; border-radius: 10px; font-weight: 600; font-size: 14px; }
.danger-btn:hover { background: rgba(255,107,94,.1); }
.cancel-btn { background: var(--surface-3); border: none; color: var(--muted); padding: 9px 14px; border-radius: 10px; font-weight: 600; font-size: 14px; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 12px; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; }
  .gantt-months, .gantt-row { grid-template-columns: 120px 1fr; }
  .gantt-label { font-size: 12px; padding: 10px; }
  .field-row { grid-template-columns: 1fr; }
}
