/* © IKlett. Alle rettigheter forbeholdt. Proprietær programvare – kopiering og videredistribusjon er forbudt uten skriftlig avtale. */
/* IKlett - Ergonomisk Styling for Kjøkken, Bakeri og Mattilsyn
   Optimalisert for miltuote hender, arbeidshansker (Glove-mode) og varierende belysning */

:root {
  --bg: #f5f8f8;
  --card-bg: #ffffff;
  --card-border: #d0dbde;
  --fg: #15252b;
  --fg-muted: #536b73;
  --primary: #0f5268;
  --primary-hover: #0a3d4e;
  --primary-text: #ffffff;
  --accent: #197693;
  --link: #0a5aa8;
  --ok-bg: #e6f6ee;
  --ok-fg: #0d6838;
  --ok-border: #a3e0bf;
  --bad-bg: #fde8e8;
  --bad-fg: #b71c1c;
  --bad-border: #f8a5a5;
  --warn-bg: #fff5e5;
  --warn-fg: #b45309;
  --warn-border: #fcd34d;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --btn-h: 54px;
  --btn-font: 16px;
  --btn-pad: 12px 20px;
  --key-h: 60px;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(15, 82, 104, 0.08);
}

/* Vanlige tekstlenker (vilkår, personvern ...): lyse nok på mørk bakgrunn, aldri nettleserens standard mørkeblå */
a:not(.btn):not(.icon-btn), a:not(.btn):not(.icon-btn):visited { color: var(--link, #0a5aa8); text-decoration: underline; text-underline-offset: 2px; }
a:not(.btn):not(.icon-btn):hover { filter: brightness(1.15); }

/* Mørk modus */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1417;
    --card-bg: #152227;
    --card-border: #26383f;
    --fg: #e5f0f3;
    --fg-muted: #8ca4ad;
    --primary: #4fa1ba;
    --primary-hover: #6eb4ca;
    --primary-text: #091316;
    --accent: #37859c;
    --link: #9ad0ff;
    --ok-bg: #0f2c1c;
    --ok-fg: #6be39f;
    --ok-border: #1a5634;
    --bad-bg: #381212;
    --bad-fg: #ff8e8e;
    --bad-border: #6d2020;
    --warn-bg: #38240a;
    --warn-fg: #fbbf24;
    --warn-border: #78490a;
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #0c1417;
  --card-bg: #152227;
  --card-border: #26383f;
  --fg: #e5f0f3;
  --fg-muted: #8ca4ad;
  --primary: #4fa1ba;
  --primary-hover: #6eb4ca;
  --primary-text: #091316;
  --accent: #37859c;
  --link: #9ad0ff;
  --ok-bg: #0f2c1c;
  --ok-fg: #6be39f;
  --ok-border: #1a5634;
  --bad-bg: #381212;
  --bad-fg: #ff8e8e;
  --bad-border: #6d2020;
  --warn-bg: #38240a;
  --warn-fg: #fbbf24;
  --warn-border: #78490a;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

/* HANSKE-MODUS (Glove Mode): Spesialtilpasset for arbeidshansker og melstøv */
body.glove-mode {
  --btn-h: 70px;
  --btn-font: 20px;
  --btn-pad: 16px 26px;
  --key-h: 78px;
  --radius: 16px;
  font-size: 19px;
}

body.glove-mode .btn,
body.glove-mode .chip {
  min-height: var(--btn-h);
  font-size: var(--btn-font);
  font-weight: 700;
  border-width: 3px;
  margin: 6px 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

body.glove-mode .tab { min-height: 74px; font-size: 13px; }
body.glove-mode .tab .ic { width: 30px; height: 30px; }
body.glove-mode .tile { min-height: 110px; font-size: 15px; }
body.glove-mode .hbtn { min-height: 52px; min-width: 52px; }

body.glove-mode input,
body.glove-mode select,
body.glove-mode textarea {
  min-height: 64px;
  font-size: 20px;
  border-width: 2px;
  padding: 14px 18px;
}

body.glove-mode .keypad-btn {
  min-height: var(--key-h);
  font-size: 28px;
  font-weight: 800;
}

/* Høy kontrast modus */
body.high-contrast {
  --bg: #000000;
  --card-bg: #000000;
  --card-border: #ffffff;
  --fg: #ffffff;
  --fg-muted: #e2e8f0;
  --primary: #ffd700;
  --link: #ffe14d;
  --primary-text: #000000;
  --ok-bg: #000000;
  --ok-fg: #00ff66;
  --ok-border: #00ff66;
  --bad-bg: #000000;
  --bad-fg: #ff3333;
  --bad-border: #ff3333;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--font-family);
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom, 24px);
}

/* Topplinje / Header – slank, kun det viktigste */
:root {
  --header-h: 56px;
  --side-w: 232px;
}

header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  height: var(--header-h);
  padding: 0 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 130;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: var(--primary);
  color: var(--primary-text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.brand-mark .ic { width: 22px; height: 22px; }

.brand-name {
  display: none;
  font-size: 19px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.4px;
}
@media (min-width: 640px) { .brand-name { display: block; } }

.site-select {
  flex: 1;
  min-width: 0;
  max-width: 340px;
  min-height: 42px;
  font-weight: 700;
  font-size: 15px;
  padding: 6px 12px;
}

.sync-dot {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 17px;
  font-size: 12px;
  font-weight: 800;
  flex: none;
}
.sync-dot::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.sync-dot.ok { background: var(--ok-bg); color: var(--ok-fg); }
.sync-dot.warn { background: var(--warn-bg); color: var(--warn-fg); }
.sync-dot.bad { background: var(--bad-bg); color: var(--bad-fg); }

.hbtn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: transparent;
  color: var(--primary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  flex: none;
  touch-action: manipulation;
}
.hbtn.push { margin-left: auto; }
.hbtn .lbl { display: none; }
@media (min-width: 640px) { .hbtn .lbl { display: inline; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } }
.hbtn.glove-on { background: var(--warn-fg); border-color: var(--warn-fg); color: #fff; }

/* Taktile knapper */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--btn-h);
  padding: var(--btn-pad);
  font-size: var(--btn-font);
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius);
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease, border-color 0.15s ease;
  user-select: none;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--card-border);
}

.btn-outline:hover {
  border-color: var(--primary);
  background: rgba(15, 82, 104, 0.05);
}

.btn-ok {
  background: var(--ok-fg);
  color: #ffffff;
  border-color: var(--ok-fg);
}

.btn-bad {
  background: var(--bad-fg);
  color: #ffffff;
  border-color: var(--bad-fg);
}

.btn-glove-toggle {
  background: var(--warn-bg);
  color: var(--warn-fg);
  border: 2px solid var(--warn-border);
  font-weight: 700;
}

.btn-glove-toggle.active {
  background: var(--warn-fg);
  color: #ffffff;
  border-color: var(--warn-fg);
}

/* Navigasjon: bunnlinje (mobil/nettbrett) – sidepanel (stor skjerm) */
.ic {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

#nav {
  position: fixed;
  z-index: 120;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  background: var(--card-bg);
  border-top: 1px solid var(--card-border);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
}

.tab {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 62px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--fg-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.1;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tab .ic { width: 26px; height: 26px; }
.tab-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab:active { transform: scale(0.96); }
.tab.active { color: var(--primary); background: rgba(15, 118, 147, 0.13); }
.tab .badge-count { position: absolute; top: 3px; left: calc(50% + 6px); }
.tab-sec { display: none; }

.badge-count {
  background: var(--bad-fg);
  color: #ffffff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 700;
}

@media (min-width: 1024px) {
  #nav {
    top: var(--header-h);
    bottom: 0;
    left: 0;
    right: auto;
    width: var(--side-w);
    flex-direction: column;
    gap: 4px;
    padding: 12px;
    overflow-y: auto;
    border-top: 0;
    border-right: 1px solid var(--card-border);
    box-shadow: none;
  }
  .tab {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: 14px;
    min-height: 52px;
    padding: 10px 14px;
    font-size: 15px;
  }
  .tab .ic { width: 24px; height: 24px; }
  .tab .badge-count { position: static; margin-left: auto; }
  .tab-sec { display: flex; }
  .tab-more { display: none; }
}

/* Bunnark (meny / innstillinger) */
#sheet {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(10, 20, 25, 0.5);
  backdrop-filter: blur(3px);
}
#sheet.open { display: flex; }

.sheet-panel {
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  background: var(--card-bg);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.25);
  animation: sheetUp 0.18s ease-out;
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-grip { width: 44px; height: 5px; margin: 6px auto 12px; border-radius: 3px; background: var(--card-border); }
.sheet-title { margin: 0 0 12px; font-size: 18px; font-weight: 800; display: flex; align-items: center; justify-content: space-between; }
.sheet-sec { margin: 16px 0 8px; font-size: 12px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--fg-muted); }
@media (min-width: 700px) {
  #sheet { align-items: center; }
  .sheet-panel { border-radius: 24px; padding-bottom: 20px; }
}

.tile-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 560px) { .tile-grid { grid-template-columns: repeat(4, 1fr); } }
.tile {
  position: relative;
  min-height: 94px;
  padding: 14px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--card-border);
  border-radius: 16px;
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
}
.tile .ic { width: 28px; height: 28px; color: var(--primary); }
.tile:active { transform: scale(0.96); }
.tile .badge-count { position: absolute; top: 6px; right: 8px; }

.set-row {
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--card-border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}
.set-row .ic { color: var(--primary); }
.set-row .sw { margin-left: auto; width: 46px; height: 26px; border-radius: 13px; background: var(--card-border); position: relative; transition: background 0.15s; }
.set-row .sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.set-row.on .sw { background: var(--primary); }
.set-row.on .sw::after { transform: translateX(20px); }

.seg { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--card-border); border-radius: 14px; background: var(--bg); }
.seg button {
  flex: 1;
  min-height: 50px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.seg button.on { background: var(--primary); color: var(--primary-text); }

/* Hovedinnhold */
main {
  max-width: 1024px;
  margin: 0 auto;
  padding: 12px 12px calc(96px + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 1024px) {
  main {
    max-width: 1100px;
    margin-left: calc(var(--side-w) + 28px);
    margin-right: auto;
    padding: 24px 28px 60px;
  }
}

/* Kort / Cards */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 12px 0;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 768px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

/* Form elementer */
.form-group {
  margin-bottom: 14px;
}

label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-muted);
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: var(--bg);
  color: var(--fg);
  font-size: 16px;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Numpad & Taktilt tastatur */
.keypad-container {
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: 16px;
  padding: 16px;
  margin: 16px 0;
  box-shadow: var(--shadow);
}

.keypad-display {
  background: var(--bg);
  border: 2px solid var(--primary);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 32px;
  font-weight: 800;
  text-align: right;
  margin-bottom: 12px;
  color: var(--primary);
}

.presets-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 10px;
}

.preset-chip {
  min-height: 48px;
  padding: 8px 14px;
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: 24px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  white-space: nowrap;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.keypad-btn {
  min-height: var(--key-h);
  border-radius: 12px;
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  color: var(--fg);
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

.keypad-btn:active {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

/* Oppgaver & Status linjer */
.task-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px;
  border-bottom: 1px solid var(--card-border);
  gap: 12px;
}

.task-row:last-child {
  border-bottom: none;
}

.task-info {
  flex: 1;
}

.task-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 3px;
}

.task-sub {
  font-size: 13px;
  color: var(--fg-muted);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
}

.status-badge.ok {
  background: var(--ok-bg);
  color: var(--ok-fg);
  border: 1px solid var(--ok-border);
}

.status-badge.bad {
  background: var(--bad-bg);
  color: var(--bad-fg);
  border: 1px solid var(--bad-border);
}

.status-badge.warn {
  background: var(--warn-bg);
  color: var(--warn-fg);
  border: 1px solid var(--warn-border);
}

/* Avviks-boks */
.deviation-card {
  border-left: 6px solid var(--bad-fg);
  background: var(--bad-bg);
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 14px;
}

.deviation-card.closed {
  border-left-color: var(--ok-fg);
  background: var(--ok-bg);
}

/* AI Rådgiver Panel */
.ai-box {
  background: linear-gradient(135deg, rgba(15, 82, 104, 0.06), rgba(25, 118, 147, 0.12));
  border: 2px dashed var(--accent);
  border-radius: 14px;
  padding: 16px;
  margin: 14px 0;
}

.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 700;
  color: var(--primary);
}

/* Tilsynsvisning (Mattilsynet) */
.tilsyn-header {
  border: 3px solid var(--primary);
  background: #ffffff;
  color: #111827;
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 20px;
}

.qr-code-box {
  background: #f8fafc;
  border: 2px dashed #94a3b8;
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  margin: 16px 0;
}

.chain-badge {
  font-family: monospace;
  font-size: 12px;
  background: #e2e8f0;
  color: #0f172a;
  padding: 4px 8px;
  border-radius: 6px;
  word-break: break-all;
}

/* Tabeller for logger */
.table-responsive {
  overflow-x: auto;
  margin-top: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--card-border);
}

th {
  background: var(--bg);
  font-weight: 700;
  color: var(--fg-muted);
}

/* Utskrift / PDF (Print Style for Mattilsynet) */
@media print {
  header, #nav, #sheet, .btn, .noprint, .glove-toggle {
    display: none !important;
  }
  main {
    margin: 0 !important;
    max-width: none !important;
    padding: 0 !important;
  }
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 12pt;
  }
  .card {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }
  .tilsyn-header {
    border: 2px solid #000000 !important;
  }
}
