:root{
  --room-col-w: 110px;
  --slot-w: 20px;
  --row-h: 18px;
  --font-size: 9px;
}

html, body{
  margin:0;
  font-family: Arial, sans-serif;
  font-weight: normal;
  overflow: hidden;
}

.day-row td.day-time{ position: relative; }
/* se om bakgrunnsfarge eller lignende trengs */
.turnus-right{
  position: absolute;
  color: #ff0000;
  right: 2px;
  top: 1px;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
}
.turnus-on-ruler{
  position: absolute;
  color: #ff0000;
  left: 10px;
  top: 9px;
  font-size: 8px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 4;
}
.turnus-on-booking-row{
  position: absolute;
  left: 10px;
  top: 1px;
  font-size: 10px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 4;
  color: #7e7e7e;
}
.shift-invalid{
  border: 2px solid #c62828 !important;
  background: #ffe5e5;
  color: #000;
}
.toolbar{
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;

  display:flex;
  gap:8px;
  justify-content: center;

  padding: 8px 10px;
  border-top: 1px solid #bbb;
  background:#fff;

  width: 100%;
  box-sizing: border-box;
  z-index: 1000;
}

.toolbar button{
  flex: 0 0 auto;
}
.turnus-panel{
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 60px;
  max-height: 70vh;
  overflow: auto;
  background: #fff;
  border: 1px solid #000;
  padding: 10px;
  z-index: 3000;
}

.turnus-block{
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #ccc;
}

.turnus-name{
  width: 220px;
  margin-bottom: 8px;
}

.turnus-grid{
  border-collapse: collapse;
}

.turnus-grid th,
.turnus-grid td{
  border: 1px solid #999;
  padding: 4px;
  text-align: center;
}

.turnus-grid input{
  width: 42px;
  box-sizing: border-box;
  text-align: center;
}

.turnus-actions{
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.note-rule-row{
  display: flex;
  gap: 3px;
  margin: 1px 0;
  align-items: center;
}

.note-rule-btn{
  font-size: 9px;
  padding: 0px 3px;
}

.note-rule-btn.active{
  background: #000;
  color: #fff;
}
.note-rule-space{
  min-height: 18px;
  box-sizing: border-box;
}
.note-repeat-input{
  width: 38px;
  font-size: 9px;
  height: 14px;
  box-sizing: border-box;
}
.page-scroll{
  width: 100vw;
  height: calc(100vh - 45px);
  overflow: auto;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}
.cal-wrap{
  flex: 0 0 auto;
  scroll-snap-align: start;
}

.calendar-layout{
  display: flex;
  align-items: flex-start;
  width: max-content;
  min-width: 100vw;
}
.cal-wrap{
  height: 100vh;
  overflow: auto;
  background:#f7f7f7;
  padding-bottom: 56px; /* plass til toolbar */
  box-sizing: border-box;
}
.note-panel{
  flex: 1 1 auto;
  min-width: 247px;
  max-width: 560px;
  padding: 4px 8px;
  box-sizing: border-box;
  background: transparent;
  border: none;
  font-size: 11px;
  overflow: visible;
  scroll-snap-align: end;
}

@media (max-width: 700px){
  .calendar-layout{
    min-width: calc(100vw + 320px);
  }

  .note-panel{
    width: 320px;
    min-width: 320px;
    max-width: 320px;
  }
}
.cal-inner{
  position: relative; /* now-line posisjoneres mot dette */
  width: max-content;
}

.cal{
  border-collapse: collapse;
  table-layout: fixed;          /* VIKTIG: jevn kolonnebredde */
  /* settes ogsa eksplisitt i JS til eksakt sum-bredde */
  width: max-content;
  background:#fff;
}

.cal th, .cal td{
  border-bottom: 1px solid #666; /* kun horisontale linjer */
  border-left: none;
  border-right: none;
  border-top: none;

  height: var(--row-h);
  padding: 0 2px;
  font-size: var(--font-size);
  white-space: nowrap;
  font-weight: normal;
  box-sizing: border-box;
}


/* Tykke skillelinjer mellom dager i flerukersvisning.
   Bruker inset box-shadow slik at linjen synes selv om .busy har egen border. */
tr.day-sep th,
tr.day-sep td{
  box-shadow: inset 0 -2px 0 #808080;
}
.room-day-label{
  display: inline-flex;
  align-items: baseline;
}

.room-day-weekday{
  display: inline-block;
  width: 35px;   /* juster denne */
}

.room-day-date{
  display: inline-block;
  font-variant-numeric: tabular-nums;
}
/* Romkolonne (sticky) */
.room{
  position: sticky;
  left: 0;
  z-index: 6;

  width: var(--room-col-w);
  min-width: var(--room-col-w);
  max-width: var(--room-col-w);

  background: transparent;
  text-align: left;
  vertical-align: top;

  padding-top: 0px;
  padding-bottom: 0;
  padding-left: 0;              /* helt til venstre */
  padding-right: 6px;
  border-right: 2px solid #000; /* skille rom/kalender */
}

/* Dag-rad */

/* Topp-rad klokkeslett */
.cal th.time{
  text-align: center;
  width: var(--slot-w);
  min-width: var(--slot-w);
  max-width: var(--slot-w);
  padding: 0 2px;
}
/* Etasjeskille i booking-delen */
tr.floor-sep > td { border-top: 2px solid #8b8b8b; }


.note-list-item{
  margin-bottom: 6px;
  line-height: 1.25;
  cursor: pointer;
}

.note-list-meta{
  font-weight: 700;
}

.note-list-text{
  white-space: pre-wrap;
}
.note-search-row{
  margin-bottom: 6px;
}

#noteSearchInput{
  width: 100%;
  box-sizing: border-box;
  font-size: 11px;
  padding: 2px 4px;
}
.note-list-edit{
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #cfcfcf;
  border-radius: 2px;
  background: transparent;
  outline: none;
  resize: none;
  overflow: hidden;
  font: inherit;
  line-height: 1.25;
  padding: 0;
  margin: 0;
  white-space: pre-wrap;
} 

.slot-note{
  cursor: pointer;
}

.slot-note.long-note{
  text-decoration: underline;
}

/* Notater over bookinger (hvis slot-note bruker absolute) */
td { position: relative; }
.slot-note { position: absolute; top: 1px; z-index: 5; pointer-events: auto; white-space: nowrap; color: #666; font-style: italic; }

.day-time{
  background: #ffffff;
  color: #6b6b6b;
  height: var(--row-h);
}

.day-left{
  position: sticky;
  left: 0;
  z-index: 8;
  border-right: 2px solid #000;
  background: transparent; /* kun label skal ha svart bakgrunn */
  padding-left: 0;
}

.cal th.day-left{
  padding-left: 0 !important;
  padding-right: 0;
}

.day-label{
  display: inline-flex;
  align-items: baseline;
  background: #ffffff;
  color: #000000;
  padding: 2px 0px;
}

.day-weekday{
  display: inline-block;
  width: 56px;   /* juster litt hvis nødvendig */
}

.day-date{
  display: inline-block;
  font-variant-numeric: tabular-nums;
}

.day-time{
  text-align: center;
  width: var(--slot-w);
  min-width: var(--slot-w);
  max-width: var(--slot-w);

  border-right: 1px solid rgba(255,255,255,0.18); /* kolonnestreker kun i dag-raden */
  padding: 0 2px;
}

.day-row td.day-time:last-child{
  border-right: none;
}

/* Selve cella */
td.busy{
  position: relative;
  background: var(--act-bg, #e4fff5);
  padding: 0;                 /* viktig */
  border: 1px solid #000;     /* hvis du vil ha ramme */
}

/* Innholdet skal fylle hele cella */
td.busy .busy-inner{
  display:flex;
  flex-direction:column;
  justify-content:flex-end;
  align-items:flex-start;
  height:100%;
  width:100%;
  padding:0 2px;
  box-sizing:border-box;
}



.busy .busy-label{
  position: sticky;
  left: 4px;
  top: 0px;
  z-index: 2;
  display: inline-block;
  white-space: nowrap;
  transform: translateY(1px); /* skyv teksten ned */
}

.busy .busy-label-text{
  position: relative;
  top: 2px;
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th.room{
  border-left: none;
}

/* romkolonne ma ligge over resten */
.cal th.room{
  position: sticky;
  left: 0;
  z-index: 10;
  background: transparent; /* som du vil */
  transform: translateY(-1px); /* juster px etter smak */
}


/* etasje-"vegg" som alltid synes (inni cella) */
.cal th.room.floor3{ box-shadow: inset 4px 0 0 #2587ff; }
.cal th.room.floor2{ box-shadow: inset 4px 0 0 #000bda; }
.cal th.room.floor1{ box-shadow: inset 4px 0 0 #000000; }



/* Ledige-rom-rad */
.free-fill{
  background: transparent;
}

/* Rod "na"-strek */
.now-line{
  position:absolute;
  width: 2px;
  background: #b00000;
  pointer-events: auto;
  z-index: 20;
  top: 0;
  height: 100px; /* fallback */
}
.cal th.free-text{
  white-space: normal !important;
  overflow-wrap: normal;
  word-break: normal;
  line-height: 1.25;
}

/* bookinger som er ferdig */
.cal td.busy.past{
  opacity: 0.35;
}

.free-room{
  display: inline-block;
  white-space: nowrap;
}

/* Valgte rom */
.room.selected{
  outline: 1px solid #000;
  outline-offset: -1px;
}

/* Mandag (multi-visning) */
.day-row.monday td.day-time{ background: #555; }
.day-row.monday .day-label{ background: #555; }

/* Tykk skillelinje mellom dager (brukes i flerukesvisning) */
.day-end th, .day-end td{ border-bottom: 2px solid #6f6f6f !important; }
.day-row.monday .day-label{ background: #555; }

/* 2px gap between floor groups (3->2 and 2->1) */
tr.floor-break > th,
tr.floor-break > td {
  border-top: 2px solid #616161; /* samme farge som bakgrunn */
}

/* --- LINJAL for tidsrad (test: nederste raden) --- */
tr.time-ruler .day-time{
  position: relative;
  height: 17px;

  border-right: none !important;
  text-align: left !important;
  padding: 0 !important;

  color: transparent !important; /* skjul original tekst */
}

/* hel time: strek */
tr.time-ruler .day-time[data-time$=":00"]{
  border-left: 2px solid #ffffff00;
}

/* hel time: tekst over streken */
tr.time-ruler .day-time[data-time$=":00"]::after{
  content: attr(data-time);
  position: absolute;
  left: 0;
  top: -4px;
  transform: translateX(-50%);
  color: #3d3d3d;
  font-size: 9px;
  line-height: 22px;
  white-space: nowrap;
  pointer-events: none;

  background: #ffffff00;     /* match din time-rad */
  padding: 0 2px;
}

tr.time-ruler .day-time[data-time$=":30"]::after{
  content: "";
  position: absolute;
  left: 0;
  top: 95%;
  transform: translate(-50%, -50%);
  width: 1px;
  height: 4px;
  background: #878787;
  pointer-events: none;
}
tr.time-ruler .day-time[data-time$=":00"]::before{
  content: "";
  position: absolute;
  left: 0;
  top: 89%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 6px;
  background: #767676;           /* eller #8a8a8a hvis du vil svakere */
  pointer-events: none;
}

/* Inline notater (localStorage) */
.room .room-name{
  display: block;
}
.room-name.free-all-day{
  color: #2e7d32;
}

.room .room-note{ display:none; }

.room .room-note:focus{
  outline: 1px dashed #333;
  background: rgba(255,255,255,0.5);
}
.cal td { overflow: visible; position: relative; }

/* *! markering for manglende faste aktiviteter */
td.missing-slot{
  position: relative;
}

.marker{
  position: absolute;
  top: 6px;
  left: 1px;
  font-size: 1.5em;
  line-height: 11px;
  padding: 0 2px;
  background: rgba(255, 255, 255, 0);
  border-radius: 2px;
  z-index: 5;
  pointer-events: auto;
}

.busy-inner{ overflow:hidden; display:block; }
.busy-label{ display:block; max-width:100%; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

/* time-cell notes overlay (top of row). can extend visually to the right without changing layout */
td{ position: relative; }
.slot-note{
  position:absolute;
  top:1px;
  left:2px;
  white-space:nowrap;
  pointer-events:none;
  font-size: var(--font-size);
  font-style: italic;
  color: #454545;
  line-height: var(--font-size);
  z-index: 2;
}
.note-editor{
  position:absolute;
  top:0px;
  z-index:5;
  padding:0 2px;
  height: calc(var(--font-size) + 2px);
  font-size: var(--font-size);
  font-style: italic;
  line-height: var(--font-size);
  border:1px solid #000;
  background:#fff;
  box-sizing:border-box;
}
@media (max-width: 700px){
  :root{
    --row-h: 18px;
  }
}
/* mindre font-size på mobil overstyrer original font size */
@media (max-width: 700px){
  tr.time-ruler .day-time[data-time$=":00"]::after{
    font-size: 7px;
  }
}

/* Tooltip for *! marker (works both on empty slots and on bookings) */
.marker[data-tooltip]:hover::after{
  content: attr(data-tooltip);
  position: absolute;
  right: 0;
  top: 1.6em;
  white-space: nowrap;
  background: #fff;
  border: 1px solid #000;
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.2;
  z-index: 2000;
}

.slot-note{
  pointer-events: auto;
  cursor: pointer;
}

.cal th.day-left{
  text-align: left !important;
  padding: 0 !important;
}

.cal th.day-left .day-label{
  display: inline-block;
  margin: 0 !important;
  padding: 2px 0 !important;
} 
/* Mobile: fix calendar scrolling and bottom clipping */
@media (max-width: 700px) {

  .page-scroll {
    height: calc(100dvh - 45px);
    overflow-x: auto;
    overflow-y: hidden;
  }

  .calendar-layout {
    height: 100%;
  }

  .cal-wrap {
    height: 100%;
    min-height: 0;
    padding-bottom: 12px;
    overflow-x: auto;
    overflow-y: auto;
  }

  .note-panel {
    height: 100%;
    overflow-y: auto;
  }

}
/* Sign-in and accounts */
[hidden] { display: none !important; }
.account-card {
  box-sizing: border-box;
  max-width: 26rem;
  margin: 8vh auto 1rem;
  padding: 1.5rem;
  border: 1px solid #b9c4cc;
  border-radius: .7rem;
  background: #fff;
  color: #1d292f;
}
.account-card h1, .account-card h2 { margin-top: 0; }
.account-form { display: grid; gap: .85rem; }
.account-form label, #accountList label { display: grid; gap: .35rem; }
.account-form input, #accountList input { padding: .55rem; font: inherit; }
.account-form .remember-choice { display: flex; align-items: center; gap: .5rem; }
.account-form button, .account-bar button, #accountDialog button, .note-scope button, .note-save {
  padding: .45rem .7rem;
  font: inherit;
  cursor: pointer;
}
.account-form button { justify-self: start; }
.account-bar { display: flex; justify-content: flex-end; align-items: center; gap: .5rem; padding: .3rem .65rem; }
.account-bar p { margin: 0; }
.account-bar p:empty { display: none; }
#accountDialog {
  box-sizing: border-box;
  width: min(37rem, calc(100vw - 1rem));
  max-height: 85vh;
  border: 1px solid #b9c4cc;
  border-radius: .7rem;
  padding: 1.25rem;
  color: #1d292f;
}
#accountDialog::backdrop { background: rgb(0 0 0 / .4); }
.account-dialog-close { float: right; }
#accountList fieldset { margin: .75rem 0; }
#accountList button { margin: .4rem .35rem 0 0; }
.note-scope { display: flex; gap: .3rem; margin-bottom: .45rem; }
.note-scope [aria-pressed="true"] { background: #234660; color: #fff; border-color: #234660; }
.note-status { margin: .3rem 0; }
.note-status:empty { display: none; }
.note-save { display: block; margin: .35rem 0 0 auto; }
@media (max-width: 560px) {
  .account-card { margin-left: .75rem; margin-right: .75rem; }
}

#calendarShell {
  height: calc(100dvh - 45px);
  display: flex;
  flex-direction: column;
}
#calendarShell .page-scroll { width: 100%; flex: 1 1 auto; min-height: 0; height: auto; }
#calendarShell .cal-wrap { height: 100%; }
#calendarShell .calendar-layout { min-height: 100%; }
body:has(.account-card:not([hidden])) { overflow-y: auto; }
