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

:root {
  --primary:   #10b981;
  --primary-d: #059669;
  --primary-l: #d1fae5;
  --bg:        #f0f4f8;
  --card:      #ffffff;
  --text:      #1e293b;
  --muted:     #64748b;
  --border:    #e2e8f0;
  --radius:    12px;

  --ok:        #22c55e;
  --warn:      #f59e0b;
  --danger:    #ef4444;
  --blue:      #3b82f6;
  --purple:    #8b5cf6;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  max-width: 430px;
  margin: 0 auto;
}

/* ── SCREEN SWITCHER ── */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100vh; }

/* ── TOP BAR ── */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-back {
  width: 36px; height: 36px;
  border: none; background: var(--bg);
  border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--muted); flex-shrink: 0;
}
.topbar h1 { font-size: 17px; font-weight: 700; flex: 1; }
.topbar-badge {
  background: var(--danger); color: white;
  font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: 20px;
}
.topbar-icon {
  width: 36px; height: 36px;
  border: none; background: var(--primary);
  border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: white; flex-shrink: 0;
}

/* ── BOTTOM NAV ── */
.bottomnav {
  position: sticky;
  bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px 8px;
  gap: 3px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}
.nav-item .nav-icon { font-size: 22px; line-height: 1; }
.nav-item.active { color: var(--primary); }

/* ── CONTENT AREA ── */
.content { flex: 1; padding-bottom: 8px; }

/* ── STATS ── */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 12px 16px;
}
.stat-card {
  background: var(--card);
  border-radius: 10px;
  padding: 14px 12px;
  border: 1px solid var(--border);
}
.stat-card .num { font-size: 28px; font-weight: 800; line-height: 1; }
.stat-card .lbl { font-size: 11px; color: var(--muted); margin-top: 3px; }
.stat-card.avvikelse .num { color: var(--danger); }
.stat-card.pagaende  .num { color: var(--warn); }
.stat-card.klar      .num { color: var(--ok); }
.stat-card.mallar    .num { color: var(--blue); }

/* ── SECTION HEADER ── */
.section-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
}
.section-hdr h2 { font-size: 14px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.section-hdr a  { font-size: 13px; color: var(--primary); font-weight: 600; cursor: pointer; text-decoration: none; }

/* ── KONTROLL LIST ── */
.list { padding: 0 16px; display: flex; flex-direction: column; gap: 10px; }

.kontroll-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px;
  cursor: pointer;
}
.kontroll-card:active { box-shadow: 0 0 0 2px var(--primary); }

.kk-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.kk-ref  { font-size: 11px; color: var(--muted); font-weight: 600; }
.kk-name { font-size: 15px; font-weight: 700; margin-top: 1px; }
.kk-addr { font-size: 12px; color: var(--muted); margin-top: 2px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-pagaende  { background: #fef3c7; color: #b45309; }
.badge-klar      { background: #dcfce7; color: #15803d; }
.badge-underkand { background: #fee2e2; color: #b91c1c; }

.progress-wrap {
  margin: 10px 0 8px;
}
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--primary);
  transition: width .3s;
}
.progress-fill.warn { background: var(--warn); }
.progress-fill.done { background: var(--ok); }
.progress-lbl {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.kk-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.kk-bottom span { display: flex; align-items: center; gap: 4px; }
.avvik-dot {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
}

/* ── FILTER TABS ── */
.filter-tabs {
  display: flex;
  gap: 6px;
  padding: 0 16px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-tabs::-webkit-scrollbar { display: none; }
.tab {
  white-space: nowrap;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}
.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ── MALL LIST ── */
.mall-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
}
.mall-card:active { box-shadow: 0 0 0 2px var(--primary); }
.mall-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--primary-l);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.mall-info { flex: 1; min-width: 0; }
.mall-name { font-size: 15px; font-weight: 700; }
.mall-sub  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mall-chevron { color: var(--muted); font-size: 16px; }

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
}
.tag-aktiv   { background: #dcfce7; color: #15803d; }
.tag-inaktiv { background: #f1f5f9; color: #64748b; }

/* ── MALL REDIGERA ── */
.category-section {
  margin: 0 16px 12px;
}
.category-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 12px 0 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.punkt-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.drag-handle { color: #cbd5e1; font-size: 16px; cursor: grab; flex-shrink: 0; }
.punkt-text  { flex: 1; font-size: 14px; }
.punkt-icons { display: flex; gap: 6px; flex-shrink: 0; }
.punkt-icon  {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--bg);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  color: var(--muted);
}
.punkt-icon.on { background: var(--primary-l); color: var(--primary-d); }
.punkt-row.dragging { opacity: 0.35; }
.punkt-row.drag-over { border-top: 2px solid var(--primary); }
.category-section.dragging { opacity: 0.35; }
.category-section.drag-over { border-top: 2px solid var(--primary); padding-top: 4px; }
.cat-drag-handle { font-size: 14px; margin-right: 4px; cursor: grab; }

.add-punkt-btn {
  width: 100%;
  background: none;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.kat-name-input {
  background: none; border: none;
  border-bottom: 1.5px solid transparent;
  font-size: 12px; font-weight: 700;
  color: var(--muted); text-transform: uppercase;
  letter-spacing: .06em; flex: 1;
  outline: none; padding: 0; font-family: inherit;
}
.kat-name-input:focus { border-bottom-color: var(--primary); }
.add-inline-row { display: flex; gap: 6px; align-items: center; padding: 4px 0 8px; }
.add-inline-row .form-input { flex: 1; margin: 0; padding: 10px 12px; font-size: 14px; }
.btn-sm { display: inline-flex; align-items: center; justify-content: center; padding: 10px 14px; border-radius: 10px; font-size: 14px; font-weight: 700; cursor: pointer; border: none; font-family: inherit; white-space: nowrap; }

/* ── NY KONTROLL FORM ── */
.form-section { padding: 0 16px; }
.form-group { margin-bottom: 16px; }
.form-label { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; display: block; text-transform: uppercase; letter-spacing: .04em; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  font-family: inherit;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
}
.form-textarea { min-height: 80px; resize: vertical; }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

.mall-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mall-option {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
}
.mall-option.selected { border-color: var(--primary); background: var(--primary-l); color: var(--primary-d); }
.mall-option .mi { font-size: 18px; }

/* ── PORTAL / GENOMFÖR ── */
.portal-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-d) 100%);
  color: white;
  padding: 24px 16px 20px;
}
.portal-header .ref   { font-size: 12px; opacity: .8; font-weight: 600; }
.portal-header h2     { font-size: 20px; font-weight: 800; margin: 4px 0 2px; }
.portal-header .addr  { font-size: 13px; opacity: .85; }
.portal-progress-wrap { margin-top: 16px; }
.portal-progress-bar  { height: 8px; background: rgba(255,255,255,.3); border-radius: 99px; overflow: hidden; }
.portal-progress-fill { height: 100%; border-radius: 99px; background: white; }
.portal-progress-lbl  { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; opacity: .85; }

.check-category {
  padding: 12px 16px 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.check-item {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
}
.check-item:last-child { border-bottom: none; }

.checkbox-wrap {
  width: 26px; height: 26px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  color: transparent;
  margin-top: 1px;
  transition: all .15s;
}
.check-item.checked .checkbox-wrap {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.check-text { flex: 1; }
.check-desc { font-size: 14px; font-weight: 600; line-height: 1.3; }
.check-tags { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.check-tag  {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
}
.ct-obligatorisk { background: #fee2e2; color: #b91c1c; }
.ct-foto         { background: #dbeafe; color: #1d4ed8; }
.ct-done         { background: #dcfce7; color: #15803d; }

.foto-upload-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  margin-top: 8px;
  width: 100%;
}
.foto-thumb {
  width: 52px; height: 52px;
  border-radius: 8px;
  background: #dbeafe;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.add-avvik-btn {
  margin: 6px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff7ed;
  border: 1.5px solid #fed7aa;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #c2410c;
  cursor: pointer;
  width: calc(100% - 32px);
}

.portal-actions {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── AVVIKELSER ── */
.avvik-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px;
  cursor: pointer;
}
.avvik-card:active { box-shadow: 0 0 0 2px var(--danger); }
.avvik-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.avvik-cat { font-size: 11px; font-weight: 700; color: var(--muted); }
.avvik-desc { font-size: 14px; font-weight: 600; margin-top: 2px; line-height: 1.35; }
.avvik-ref  { font-size: 12px; color: var(--muted); margin-top: 4px; }

.prio-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.prio-hog    { background: #fee2e2; color: #b91c1c; }
.prio-medium { background: #fef3c7; color: #b45309; }
.prio-lag    { background: #dcfce7; color: #15803d; }

.avvik-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
.avvik-hint {
  font-size: 11px;
  color: var(--primary);
  margin-top: 6px;
  text-align: right;
}
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.sb-ny        { background: #f1f5f9; color: #334155; }
.sb-pagaende  { background: #fef3c7; color: #b45309; }
.sb-atgardad  { background: #dcfce7; color: #15803d; }

/* ── BUTTONS ── */
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  border: none;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:active { background: var(--primary-d); }
.btn-danger  { background: #ef4444; color: white; }
.btn-ghost   { background: var(--bg); color: var(--text); }
.btn-outline { background: white; color: var(--primary); border: 1.5px solid var(--primary); }

/* ── AVVIK DETALJ ── */
.info-block {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 0 16px 12px;
  overflow: hidden;
}
.info-row {
  display: flex;
  align-items: flex-start;
  padding: 12px 14px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}
.info-row:last-child { border-bottom: none; }
.info-key   { font-size: 12px; font-weight: 700; color: var(--muted); width: 90px; flex-shrink: 0; padding-top: 1px; }
.info-val   { font-size: 14px; flex: 1; font-weight: 500; }

.foto-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 0 16px 12px;
}
.foto-box {
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
}
.foto-box.f1 { background: #dbeafe; }
.foto-box.f2 { background: #dcfce7; }
.foto-box.f3 { background: #fef3c7; }

/* ── KLAR SUMMERING ── */
.klar-banner {
  background: linear-gradient(135deg, #059669 0%, #10b981 100%);
  color: white;
  margin: 0 16px 12px;
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}
.klar-banner .icon { font-size: 44px; margin-bottom: 8px; }
.klar-banner h3    { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.klar-banner p     { font-size: 13px; opacity: .85; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 16px 12px;
}
.result-card {
  background: var(--card);
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 12px 8px;
  text-align: center;
}
.result-card .num { font-size: 24px; font-weight: 800; }
.result-card .lbl { font-size: 10px; color: var(--muted); margin-top: 2px; }
.rc-ok   .num { color: var(--ok); }
.rc-miss .num { color: var(--danger); }
.rc-avv  .num { color: var(--warn); }

/* ── EMPTY STATE ── */
.empty { padding: 48px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.empty .icon { font-size: 40px; margin-bottom: 12px; }

/* ── AUTOCOMPLETE ── */
.ac-wrap { position: relative; }
.ac-dropdown {
  position: absolute; top: 100%; left: 0; right: 0;
  background: var(--card); border: 1.5px solid var(--primary);
  border-radius: 10px; z-index: 200; margin-top: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,.1); overflow: hidden; display: none;
}
.ac-dropdown.open { display: block; }
.ac-item {
  padding: 11px 14px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: var(--bg); }
.ac-main { font-size: 14px; font-weight: 600; }
.ac-sub  { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 80px; left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: #1e293b; color: white;
  padding: 12px 20px; border-radius: 10px;
  font-size: 14px; font-weight: 600;
  z-index: 9999; opacity: 0; pointer-events: none;
  max-width: 320px; text-align: center;
  transition: opacity .2s, transform .2s;
  white-space: pre-wrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: var(--danger); }
.toast.toast-ok    { background: var(--primary); }

/* ── MODAL ── */
#ao-modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 9990;
  align-items: flex-end; justify-content: center;
  padding-bottom: 24px; overflow-y: auto;
}
#ao-modal-overlay.active { display: flex; }
.ao-status-btn {
  flex: 1; padding: 10px; border-radius: 10px; font-size: 14px; font-weight: 600;
  border: 1.5px solid var(--border); background: var(--bg); color: var(--muted); cursor: pointer; font-family: inherit;
}
.ao-status-btn.active { background: var(--primary-l); color: var(--primary-d); border-color: var(--primary); }
#modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 9990;
  align-items: flex-end; justify-content: center;
  padding-bottom: 24px;
}
#modal-overlay.active { display: flex; }
.modal-box {
  background: var(--card); border-radius: 16px;
  padding: 20px 16px; width: 100%; max-width: 398px; margin: 0 16px;
}
.modal-box h3 { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.modal-box p  { font-size: 14px; color: var(--muted); margin-bottom: 20px; line-height: 1.5; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }

/* ── UTFÖRARE SUGGEST ── */
.kk-suggest-wrap { position: relative; }
.kk-suggest-list {
  display: none; position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  z-index: 50; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.1);
  max-height: 220px; overflow-y: auto;
}
.kk-suggest-list.open { display: block; }
.kk-suggest-item {
  width: 100%; border: none; border-bottom: 1px solid var(--border);
  background: none; color: var(--text); text-align: left;
  padding: 11px 14px; font-size: 14px; font-family: inherit; cursor: pointer;
}
.kk-suggest-item:last-child { border-bottom: none; }
.kk-suggest-item:hover, .kk-suggest-item:focus { background: var(--primary-l); outline: none; }
