/* =========================================
   Realkompetencer - app.css (FULL)
   Light, modern UI + color scale 0-5
   ========================================= */

* { box-sizing: border-box; }
html, body { height: 100%; }

body{
  margin:0;
  font-family: "Helvetica Neue", Helvetica, Arial, ui-sans-serif, system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
}

button, input, select, textarea { font-family: inherit; }
h1, h2, h3, h4, h5, h6, .sectionTitle, .section-title, .modal-title {
  font-family: "Avenir Next", Avenir, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

/* --- Theme --- */
:root{
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e5e7eb;
  --shadow: 0 18px 50px rgba(2,6,23,.10);
  --shadow-soft: 0 10px 30px rgba(2,6,23,.08);

  --radius: 18px;

  --btn: #ffffff;
  --btn-text: #0f172a;
  --btn-border: #e5e7eb;
  --btn-hover: #f8fafc;

  --primary: #0f172a;
  --primary-text: #ffffff;
}

/* --- Helpers --- */
.muted{ color: var(--muted); }
hr{
  border:0;
  border-top:1px solid var(--border);
  margin:14px 0;
}
a{ color: inherit; }
a:hover{ opacity: .92; }

/* --- Layout --- */
.container{
  max-width: none;
  margin: 20px 0;
  padding: 0 20px;
}

.grid2{
  display:grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
}
@media (max-width: 980px){
  .grid2{ grid-template-columns: 1fr; }
}

/* --- Topbar --- */
.topbar{
  display:flex;
  align-items:center;
  gap:14px;
  padding: 14px 20px;
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(10px);
}
.topbar img{
  height: 34px;
  width: auto;
  object-fit: contain;
}

/* --- Cards --- */
.card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 16px;
}

/* --- Buttons --- */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  padding: 9px 14px;
  border-radius: 14px;
  border:1px solid var(--btn-border);
  background: var(--btn);
  color: var(--btn-text);
  font-weight: 850;
  font-size: 14px;
  cursor: pointer;
  text-decoration:none;
  user-select:none;
  white-space:nowrap;
}
.btn:hover{ background: var(--btn-hover); }
.btn:active{ transform: translateY(1px); }

.btn.primary{
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}
.btn.primary:hover{ filter: brightness(1.05); }

.smallbtn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding: 7px 10px;
  border-radius: 12px;
  border:1px solid var(--border);
  background: #fff;
  font-weight: 850;
  font-size: 12px;
  cursor:pointer;
  user-select:none;
  white-space:nowrap;
}
.smallbtn:hover{ background: #f8fafc; }

.iconbtn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border:1px solid var(--border);
  background:#fff;
  cursor:pointer;
}
.iconbtn:hover{ background:#f8fafc; }

/* --- Pills --- */
.pill{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding: 6px 10px;
  border-radius: 999px;
  border:1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 850;
  color: var(--muted);
}

/* --- Inputs --- */
.input, .select, select, input[type="text"], input[type="email"], input[type="password"]{
  width:100%;
  border:1px solid var(--border);
  background: #fff;
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}
.input:focus, .select:focus, select:focus, input:focus{
  border-color: #cbd5e1;
  box-shadow: 0 0 0 4px rgba(148,163,184,.18);
}
label{ display:block; margin-bottom: 6px; }

/* Normering input (N) */
.norm-input{
  width: 96px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 8px 10px;
  font-weight: 900;
  font-size: 14px;
  outline: none;
  background:#fff;
}
.norm-input:focus{
  border-color: #cbd5e1;
  box-shadow: 0 0 0 4px rgba(148,163,184,.18);
}

/* --- Table --- */
.table{
  width:100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow:hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
}
.table thead th{
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  text-align:left;
  font-size: 15px;
  font-weight: 900;
  padding: 12px 14px;
  vertical-align: bottom;
}
.table tbody td{
  border-bottom: 1px solid var(--border);
  padding: 14px;
  vertical-align: middle;
  font-size: 14px;
}
.table tbody tr:last-child td{ border-bottom: none; }

/* subtle zebra */
.table tbody tr:nth-child(even) td{
  background: rgba(248,250,252,.35);
}

/* Category header cell */
.cat-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}

/* --- Legend --- */
.legend{
  display:grid;
  grid-template-columns: 60px 1fr;
  gap:10px 12px;
  align-items:center;
}
.legend strong{ font-weight: 900; }

/* --- Base colored cell style --- */
.cell{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:44px;
  height:38px;
  border-radius: 12px;
  font-weight: 950;
  border: 1px solid rgba(15,23,42,.08);
  user-select:none;
}

/* --- Clickable value pill (default) --- */
.valpill{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:44px;
  height:38px;
  border-radius:12px;
  border:1px solid var(--border);
  background:#fff;               /* default background */
  font-weight:950;
  cursor:pointer;
  user-select:none;
}
.valpill:hover{ filter: brightness(0.98); }

.valpill.empty{
  border-style:dashed;
  color: var(--muted);
  background:#fff;
}

/* --- IMPORTANT: Color states MUST beat .valpill background --- */
.valpill.v0, .cell.v0{ background:#ff2d2d; color:#fff; }
.valpill.v1, .cell.v1{ background:#ff8a2a; color:#0f172a; }
.valpill.v2, .cell.v2{ background:#ffc107; color:#0f172a; }
.valpill.v3, .cell.v3{ background:#7cb342; color:#0f172a; }
.valpill.v4, .cell.v4{ background:#90caf9; color:#0f172a; }
.valpill.v5, .cell.v5{ background:#2f6fd6; color:#fff; }

/* --- Tooltip --- */
.help{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:18px;
  height:18px;
  border-radius:999px;
  border:1px solid var(--border);
  background:#fff;
  color:var(--muted);
  font-size:12px;
  font-weight:950;
  cursor:help;
  position:relative;
  user-select:none;
  margin-left:6px;
}
.help::after{
  content: attr(data-tip);
  position:absolute;
  left:0;
  top: 24px;
  min-width: 260px;
  max-width: 360px;
  padding:10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background:#fff;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size:12px;
  font-weight: 750;
  line-height: 1.35;
  opacity:0;
  transform: translateY(-4px);
  pointer-events:none;
  transition: .15s ease;
  z-index: 999;
  white-space: normal;
}
.help:hover::after{
  opacity: 1;
  transform: translateY(0);
}

/* --- Picker popup --- */
.picker{
  position:absolute;
  background:#fff;
  border:1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px;
  display:none;
  gap: 8px;
  z-index: 9999;
}
.picker.open{ display:flex; }
.pickbtn{
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background:#fff;
  font-weight: 950;
  cursor:pointer;
}
.pickbtn:hover{ background:#f8fafc; }

/* --- Modals --- */
.modal-backdrop{
  display:none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.35);
  z-index: 200;
  align-items:center;
  justify-content:center;
  padding: 16px;
}
.modal{
  width: min(640px, 96vw);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow:hidden;
}
.modal-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.modal-title{
  font-weight: 950;
  font-size: 16px;
}
.modal-body{ padding: 16px; }
.modal-actions{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: #fff;
}

@media (max-width: 720px){
  .topbar{ padding: 12px 12px; }
  .container{ padding: 0 12px; }
  .card{ padding: 14px; }
  .table thead th, .table tbody td{ padding: 12px; }
}

/* --- Index flow cards --- */
.flow{
  display:grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap:12px;
  margin-top:12px;
  margin-bottom:14px;
}

.flow-card{
  border:1px solid var(--border);
  background:#fff;
  border-radius:16px;
  padding:14px 14px;
  display:flex;
  gap:12px;
  align-items:flex-start;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}

.flow-icon{
  width:40px;
  height:40px;
  border-radius:14px;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:20px;
  background:#f8fafc;
  border:1px solid var(--border);
  flex: 0 0 auto;
}

.flow-title{
  font-weight:950;
  font-size:14px;
  margin-bottom:4px;
}

.flow-text{
  font-size:12.5px;
  line-height:1.35;
  color:#64748b;
}

/* Responsive */
@media (max-width: 1100px){
  .flow{ grid-template-columns: repeat(2, minmax(220px, 1fr)); }
}
@media (max-width: 640px){
  .flow{ grid-template-columns: 1fr; }
}

/* =========================
   Process Flow (Index)
========================= */

.process-flow{
  display:flex;
  gap:16px;
  margin:18px 0 22px 0;
}

.process-box{
  flex:1;
  background:#ffffff;
  border:1px solid var(--border);
  border-radius:18px;
  padding:18px;
  display:flex;
  flex-direction:column;
  gap:8px;
  transition: all 0.2s ease;
}

.process-box:hover{
  box-shadow: 0 4px 14px rgba(15,23,42,0.06);
  transform: translateY(-2px);
}

.process-icon{
  font-size:26px;
  width:46px;
  height:46px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-radius:14px;
  background:#f8fafc;
  border:1px solid var(--border);
}

.process-title{
  font-weight:900;
  font-size:15px;
}

.process-text{
  font-size:13px;
  line-height:1.45;
  color:#64748b;
}

/* Responsive fallback */
@media (max-width: 1000px){
  .process-flow{
    flex-wrap:wrap;
  }
  .process-box{
    min-width:45%;
  }
}

@media (max-width: 600px){
  .process-box{
    min-width:100%;
  }
}

/* =========================
   Step status links (1-4)
========================= */
.steps{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

.stepbtn{
  width:34px;
  height:34px;
  border-radius:12px;
  border:1px solid var(--border);
  background:#fff;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-weight:950;
  font-size:13px;
  user-select:none;
  text-decoration:none;
  color:#0f172a;
}

.stepbtn:hover{
  background:#f8fafc;
}

.stepbtn.done{
  background:#16a34a;
  border-color:#16a34a;
  color:#fff;
}

.stepbtn.done:hover{
  filter: brightness(0.95);
}

.stepbtn[data-tip]{ position:relative; }
.stepbtn[data-tip]:hover::after{
  content: attr(data-tip);
  position:absolute;
  left:0;
  top:42px;
  white-space:nowrap;
  background:#0f172a;
  color:#fff;
  padding:8px 10px;
  border-radius:10px;
  font-size:12px;
  font-weight:700;
  z-index:50;
}

/* =========================
   Step 2 mode (only tasks/categories/quality/min)
========================= */

body.mode-step2 .col-emp{ display:none !important; }
body.mode-step2 .col-norm{ display:none !important; }
body.mode-step2 .step3-only{ display:none !important; }

/* Overlay */
.step2-overlay{
  position:fixed;
  inset:0;
  background: rgba(15,23,42,.55);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
  z-index:2000;
}
.step2-dialog{
  width:min(980px, 100%);
  background:#fff;
  border:1px solid var(--border);
  border-radius:18px;
  box-shadow: 0 24px 70px rgba(15,23,42,0.22);
  overflow:hidden;
}
.step2-head{
  padding:16px 18px;
  display:flex;
  justify-content:space-between;
  gap:12px;
  border-bottom:1px solid var(--border);
}
.step2-title{ font-weight:950; font-size:18px; }
.step2-sub{ color:#64748b; font-size:13px; margin-top:2px; }

.step2-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:12px;
  padding:14px 18px 18px;
}
.step2-card{
  border:1px solid var(--border);
  border-radius:16px;
  padding:14px;
  background:#fff;
}
.step2-card-title{ font-weight:950; margin-bottom:8px; }
.step2-foot{
  border-top:1px solid var(--border);
  padding:12px 18px;
}
@media (max-width: 860px){
  .step2-grid{ grid-template-columns: 1fr; }
}
