/* ============ Tabeller-vyn ============ */

.tables-view { display: flex; flex-direction: column; gap: var(--s4); }

/* -- Tabellväljare (segmenterade tabbar) -- */
.tbl-tabs .tab { user-select: none; }
.tab-grades { cursor: pointer; }
.tab .tab-year {
  width: auto; min-width: 96px;
  padding: 3px 26px 3px 8px; font-size: 12.5px;
  border-radius: 7px; border-width: 1px;
  background-color: var(--card);
}
.tab .badge { margin-left: 2px; }

/* -- Verktygsrad -- */
.tbl-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tbl-search { width: 280px; flex: none; }
.tbl-count { font-size: 13px; margin-right: auto; white-space: nowrap; }

/* ============ Datagrid ============ */

.grid {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  outline: none;
}
.grid:focus-visible { box-shadow: 0 0 0 3px rgba(0, 189, 250, .18); }

/* Den ENDA scrollern - båda axlarna. Breda tabeller scrollar horisontellt här inne. */
.grid-scroll {
  overflow: auto;
  position: relative;
  height: calc(100vh - 320px);
  min-height: 320px;
  overscroll-behavior: contain;
}

/* -- Header (sticky top) -- */
.grid-head {
  position: sticky; top: 0; z-index: 4;
  display: flex;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  min-width: max-content;
}
.grid-hcell {
  flex: none;
  display: flex; align-items: center; gap: 5px;
  height: 36px; padding: 0 10px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: inherit;
  white-space: nowrap; overflow: hidden;
  cursor: pointer; user-select: none;
}
.grid-hcell .hlabel { overflow: hidden; text-overflow: ellipsis; }
.grid-hcell:hover { color: var(--cyan-deep); }
.grid-hcell.sorted { color: var(--cyan-deep); }
.grid-hcell .sort-ind { flex: none; }
.grid-hcell.grid-rowactions { cursor: default; }

/* -- Virtualisering -- */
.grid-spacer { position: relative; }
.grid-window { position: absolute; top: 0; left: 0; will-change: transform; min-width: 100%; }

/* -- Rader (36px, 13px text, randning via klass - inte nth-child) -- */
.grid-row {
  display: flex;
  height: 36px;
  font-size: 13px;
  background: var(--card);
}
.grid-row.stripe { background: #FAFCFE; }
.grid-row:hover { background: var(--cyan-050); }

.grid-cell {
  flex: none;
  padding: 0 10px;
  line-height: 35px; height: 36px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-bottom: 1px solid var(--line);
  background: inherit; /* sticky-celler ärver radens bakgrund (rand/hover) */
  cursor: default;
}
.grid-cell.noedit { cursor: not-allowed; color: var(--muted); }
.grid-cell.sticky { box-shadow: 1px 0 0 var(--line); }

/* Aktiv cell (tangentbordsnavigering) */
.grid-cell.cell-active {
  box-shadow: inset 0 0 0 2px var(--cyan);
  border-radius: 2px;
}
.grid-cell.sticky.cell-active {
  box-shadow: inset 0 0 0 2px var(--cyan), 1px 0 0 var(--line);
}

/* Sparstatus */
.grid-cell.cell-saving { animation: cellSaving 1s ease-in-out infinite; }
@keyframes cellSaving {
  0%, 100% { background-color: var(--cyan-050); }
  50%      { background-color: var(--cyan-100); }
}
.grid-cell.cell-saved { animation: cellSaved .8s ease forwards; }
@keyframes cellSaved {
  from { background-color: var(--cyan-100); }
  to   { background-color: transparent; }
}
.grid-cell.cell-error { animation: cellError .8s ease; }
@keyframes cellError {
  from { background-color: var(--bad-100); }
}

/* Cellredigerare */
.grid-cell.editing { padding: 2px 3px; line-height: normal; overflow: visible; }
.grid-cell .cell-editor {
  width: 100%; height: 30px;
  padding: 2px 8px; font-size: 13px;
  border-radius: 6px; margin: 0;
}
.grid-cell select.cell-editor { padding-right: 26px; background-position: right 6px center; }

/* Skelettrader (sidor som hämtas) */
.grid-row.skel-row { align-items: center; padding: 0 10px; border-bottom: 1px solid var(--line); }
.grid-row.skel-row .skel {
  display: block; height: 12px; width: 100%; max-width: 100%;
  position: sticky; left: 10px;
}

/* -- Radåtgärder (sticky höger, 44px) -- */
.grid-rowactions {
  flex: none; width: 44px;
  position: sticky; right: 0; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  background: inherit;
  border-bottom: 1px solid var(--line);
  box-shadow: -1px 0 0 var(--line);
}
.row-del {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--t-fast), background var(--t-fast), color var(--t-fast);
}
.grid-row:hover .row-del,
.row-del:focus-visible { opacity: 1; }
.row-del:hover { background: var(--bad-100); color: var(--bad); }

/* ============ Ny rad-modal ============ */

.modal-newrow { max-width: 640px; }
.newrow-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.newrow-subjhead { margin: 16px 0 8px; }
.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}
.subj-field { display: flex; flex-direction: column; gap: 3px; }
.subj-field > span {
  font-size: 11px; font-weight: 700; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.subj-field .select { padding: 5px 26px 5px 8px; font-size: 13px; border-radius: 8px; }
.form-err { min-height: 18px; margin-top: 10px; font-size: 13px; font-weight: 600; color: var(--bad); }

/* ============ Låsskärm ============ */

.lock-submit { width: 100%; }
.spin { animation: iconSpin 1s linear infinite; }
@keyframes iconSpin { to { transform: rotate(360deg); } }
