/* ============================================================
   Bemanningsappen – modern light theme
   Behåller alla befintliga klassnamn så JS fungerar oförändrad.
   ============================================================ */

:root {
  /* surfaces */
  --bg:           #f5f7fb;
  --bg-2:         #eef2f8;
  --surface:      #ffffff;
  --surface-2:    #fafbfd;
  --border:       #e4e8ef;
  --border-2:     #d6dde7;

  /* text */
  --text:         #0f172a;
  --text-muted:   #64748b;
  --text-soft:    #94a3b8;

  /* accent */
  --accent:       #4f46e5;        /* indigo-600 */
  --accent-soft:  #eef0ff;
  --accent-hover: #4338ca;

  /* status */
  --success:      #16a34a;
  --warning:      #d97706;
  --danger:       #dc2626;
  --info:         #0ea5e9;

  /* legacy variables behålls för bakåtkompatibilitet */
  --black:        #0f172a;
  --green:        #4f46e5;        /* mappas till indigo nu */
  --grid:         #e4e8ef;
  --header:       #f8fafc;
  --white:        #ffffff;
  --yellow:       #fde68a;
  --purple:       #ddd6fe;
  --orange:       #fed7aa;
  --blue:         #bfdbfe;

  /* radii + shadows */
  --r-sm: 6px;
  --r:    10px;
  --r-lg: 14px;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 1px rgba(15, 23, 42, .03);
  --shadow-2: 0 6px 18px -8px rgba(15, 23, 42, .12), 0 2px 6px rgba(15, 23, 42, .04);
  --shadow-3: 0 20px 40px -16px rgba(15, 23, 42, .18);

  --sidebar-w: 220px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font-family: inherit; color: inherit; }


/* ============================================================
   Layout: sidebar + main
   ============================================================ */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.app { transition: grid-template-columns 0.55s cubic-bezier(.22, 1, .36, 1); }
.app.sidebar-collapsed {
  grid-template-columns: 64px 1fr;
}

.sidebar {
  position: sticky;
  top: 28px;
  height: calc(100vh - 28px);
  margin-top: 28px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  border-top-right-radius: 14px;
  padding: 8px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 10;
  overflow: hidden;
  transition: padding 0.55s cubic-bezier(.22, 1, .36, 1), gap 0.55s cubic-bezier(.22, 1, .36, 1);
}

/* ===== Sidebar toggle (hamburger) ===== */
.sidebar-toggle {
  background: transparent;
  border: 0;
  padding: 8px;
  cursor: pointer;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  align-self: flex-start;
  transition: background 0.12s, color 0.12s;
}
.sidebar-toggle:hover { background: var(--bg-2); color: var(--text); }
.sidebar-toggle svg {
  transition: transform 0.55s cubic-bezier(.22, 1, .36, 1);
  transform-origin: 50% 50%;
}

/* ===== Collapsed state ===== */
.sidebar.collapsed {
  padding: 8px 12px 16px;
  gap: 12px;
}
.sidebar.collapsed .brand {
  padding: 4px 6px 10px;
  gap: 0;
}
.sidebar.collapsed .brand > div:not(.brand-dot) {
  max-width: 0;
  opacity: 0;
  pointer-events: none;
}
.sidebar.collapsed nav a {
  gap: 0;
  padding: 9px 11px;
}
.sidebar.collapsed nav a > span:not(.icon) {
  max-width: 0;
  opacity: 0;
  pointer-events: none;
}
.sidebar.collapsed .sidebar-bottom {
  gap: 0;
  padding-left: 4px;
}
.sidebar.collapsed .sidebar-bottom > div:not(.avatar) {
  max-width: 0;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.brand {
  padding: 4px 10px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  transition: padding 0.55s cubic-bezier(.22, 1, .36, 1), gap 0.55s cubic-bezier(.22, 1, .36, 1);
}
.brand > div:not(.brand-dot) {
  max-width: 150px;
  overflow: hidden;
  opacity: 1;
  white-space: nowrap;
  transition: max-width 0.55s cubic-bezier(.22, 1, .36, 1), opacity 0.55s cubic-bezier(.22, 1, .36, 1);
}
.brand-dot {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, #7c6df0 100%);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px;
  box-shadow: 0 4px 12px -4px rgba(79, 70, 229, .5);
  flex: 0 0 28px;
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; color: var(--text); }
.brand-sub  { font-size: 11px; color: var(--text-soft); margin-top: 1px; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13px;
  text-decoration: none;
  overflow: hidden;
  white-space: nowrap;
  transition: background .12s, color .12s, gap 0.55s cubic-bezier(.22, 1, .36, 1), padding 0.55s cubic-bezier(.22, 1, .36, 1);
}
.sidebar nav a:hover { background: var(--bg-2); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar nav a .icon { font-size: 16px; line-height: 1; width: 18px; flex: 0 0 18px; text-align: center; }
.sidebar nav a > span:not(.icon) {
  max-width: 150px;
  overflow: hidden;
  opacity: 1;
  transition: max-width 0.55s cubic-bezier(.22, 1, .36, 1), opacity 0.55s cubic-bezier(.22, 1, .36, 1);
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--text-muted);
  overflow: hidden;
  transition: gap 0.55s cubic-bezier(.22, 1, .36, 1), padding-left 0.55s cubic-bezier(.22, 1, .36, 1);
}
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  flex: 0 0 32px;
}
.sidebar-bottom > div:not(.avatar) {
  max-width: 140px;
  overflow: hidden;
  opacity: 1;
  white-space: nowrap;
  transition: max-width 0.55s cubic-bezier(.22, 1, .36, 1), opacity 0.55s cubic-bezier(.22, 1, .36, 1);
}
.sidebar-bottom .who { font-weight: 600; color: var(--text); font-size: 13px; line-height: 1.3; }
.sidebar-bottom .logout {
  color: var(--text-muted);
  font-size: 11px;
  text-decoration: none;
  margin-top: 1px;
  display: inline-block;
}
.sidebar-bottom .logout:hover { color: var(--danger); text-decoration: underline; }

.app > main {
  padding: 28px 28px 60px;
  min-width: 0;
}
.app > main main {
  padding: 0;
}


/* Den gamla topbar-strukturen behålls för bakåtkompatibilitet men göms.
   Ny rendering sker via .sidebar. */
.topbar { display: none; }


/* ============================================================
   Page header
   ============================================================ */

.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  flex-wrap: wrap; gap: 14px;
  margin-bottom: 18px;
}
.page-title { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.015em; }
.page-sub   { margin: 4px 0 0; color: var(--text-muted); font-size: 13px; }


/* ============================================================
   Section title (behålls för bakåtkompatibilitet)
   ============================================================ */

.section-title {
  background: transparent;
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  padding: 0 0 10px;
  margin: 4px 0 12px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.005em;
}
.section-title-with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.section-title-with-action .table-checkbox-label {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}


/* ============================================================
   Controls / toolbar
   ============================================================ */

.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px 14px;
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center;
  box-shadow: var(--shadow-1);
  margin-bottom: 14px;
}

.controls label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.controls .controls-checkbox {
  margin-left: auto;
  text-transform: none;
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.date-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.date-nav-btn {
  padding: 4px 10px;
  font-size: 16px;
  line-height: 1;
  font-weight: 700;
  color: var(--text-muted);
}
.date-nav-btn:hover { color: var(--text); }

button.icon-btn {
  padding: 6px 10px;
  font-size: 18px;
  line-height: 1;
  font-weight: 700;
  color: var(--text-muted);
}
button.icon-btn:hover:not(:disabled) { color: var(--text); }
button.icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.controls #undoBtn { margin-left: auto; }
.date-display-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  padding: 6px 12px;
  background: var(--surface);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  min-width: 110px;
  justify-content: center;
}
.date-display-wrap:hover { background: var(--bg-2); }
.date-display-text {
  pointer-events: none;
  font-weight: 600;
  color: var(--text);
}
.date-display-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  color: transparent;
}
.date-display-overlay::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  opacity: 0;
}

/* Today / current-hour highlight ------------------------------------ */
table.matrix th.now-hour {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}
table.matrix td.now-hour {
  box-shadow: inset 2px 0 0 var(--accent), inset -2px 0 0 var(--accent);
}
table.overview th.today-col {
  background: var(--accent-soft);
  box-shadow: inset 0 -2px 0 var(--accent);
}
table.overview td.today-col {
  background: rgba(79, 70, 229, 0.04);
}


/* ============================================================
   Inputs & buttons
   ============================================================ */

input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  padding: 7px 10px;
  font-size: 13px;
  transition: border-color .12s, box-shadow .12s;
  color: var(--text);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="checkbox"] {
  width: auto; padding: 0; box-shadow: none;
  accent-color: var(--accent);
}
input[type="color"] {
  padding: 2px; height: 32px; cursor: pointer;
}

button {
  background: var(--surface);
  border: 1px solid var(--border-2);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .04s;
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover { background: var(--bg-2); border-color: #c4ccd9; }
button:active { transform: translateY(1px); }

button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

button.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border-2);
}
button.danger:hover { background: #fef2f2; border-color: #fecaca; }


/* ============================================================
   Tabeller (data – personer, ställen)
   ============================================================ */

.table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
  /* Göm scrollbar visuellt – scrollning fungerar fortfarande via mushjul/touch/tangentbord */
  scrollbar-width: none;          /* Firefox */
  -ms-overflow-style: none;       /* legacy Edge */
}
.table-wrap::-webkit-scrollbar { display: none; }  /* Chrome/Edge/Safari */

.matrix-wrap, .overview-wrap {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.matrix-wrap::-webkit-scrollbar,
.overview-wrap::-webkit-scrollbar { display: none; }

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  background: var(--surface);
}

th, td {
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  font-size: 13px;
  text-align: left;
}

thead th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

tbody tr:hover td { background: #fafbfd; }
tbody tr:last-child td { border-bottom: none; }

/* Åtgärdskolumn (sista td) – knappar på en rad utan radbryt */
table.data td:last-child,
table.data th:last-child {
  white-space: nowrap;
  text-align: right;
  width: 1%;
}
table.data td:last-child > button {
  margin-left: 6px;
  padding: 5px 10px;
  font-size: 12px;
}
table.data td:last-child > button:first-child { margin-left: 0; }

/* Personer-tabellen: smalare Aktiv + Sortering så åtgärdskolumnen får mer plats */
table#persons-table th:nth-child(4),
table#persons-table td:nth-child(4),
table#persons-table th:nth-child(5),
table#persons-table td:nth-child(5) {
  width: 90px;
}

/* Inline-redigerbara celler */
table.data td.editable {
  cursor: pointer;
  position: relative;
}
table.data td.editable:hover {
  box-shadow: inset 0 0 0 2px var(--accent);
}
table.data td.editing {
  padding: 4px 8px;
  box-shadow: inset 0 0 0 2px var(--accent);
}
table.data td .inline-input {
  width: 100%;
  border: 0;
  background: var(--surface);
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 4px;
  outline: none;
}
table.data td .inline-input:focus {
  box-shadow: 0 0 0 2px var(--accent-soft);
}


/* ============================================================
   Bemanningsmatris
   ============================================================ */

table.matrix {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 12px;
}

table.matrix th, table.matrix td {
  padding: 0;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  height: 32px;
  text-align: center;
  white-space: nowrap;
  min-width: 60px;
  background: var(--surface);
  position: relative;
}

table.matrix th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 8px 6px;
  text-transform: uppercase;
}

table.matrix th.name, table.matrix td.name {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--surface-2);
  color: var(--text);
  min-width: 180px;
  text-align: left;
  padding-left: 12px;
  font-weight: 600;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
}
table.matrix td.name { background: var(--surface); font-size: 12px; }
table.matrix tr:hover td.name { background: #fafbfd; }

table.matrix th.base, table.matrix td.base {
  position: sticky;
  left: 180px;
  z-index: 3;
  background: var(--surface-2);
  color: var(--text-muted);
  min-width: 130px;
  text-align: left;
  padding-left: 12px;
  font-size: 12px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}
table.matrix td.base { background: var(--surface); }
table.matrix tr:hover td.base { background: #fafbfd; }

table.matrix td select {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  appearance: none;
  padding: 0 3px;
  background-color: transparent;
  cursor: pointer;
}

body.read-only-mode select:disabled {
  opacity: 1;
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  cursor: default;
}

/* Display-label – visas ovanpå dropdown så implicit standardschema renderas
   med rätt aktivitetstext utan att förlita sig på <select> textrendering */
table.matrix td.with-display-label {
  position: relative;
}
table.matrix td.with-display-label > .cell-display-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  padding: 0 4px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
}
table.matrix td.with-display-label > select.cell-select {
  color: transparent;
  text-shadow: none;
}
table.matrix td.with-display-label > select.cell-select option {
  color: var(--text);
}

.hour-segment.with-display-label { position: relative; }
.hour-segment.with-display-label > .hour-segment-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-size: 9px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  padding: 0 2px;
}
.hour-segment.with-display-label > select.half-select {
  color: transparent;
  text-shadow: none;
}
.hour-segment.with-display-label > select.half-select option {
  color: var(--text);
}
table.matrix td.with-display-label select,
.hour-segment.with-display-label select {
  color: transparent;
}
.cell-display-label,
.hour-segment-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-display-label {
  padding: 0 3px;
  font-size: 11px;
}
.hour-segment-label {
  padding: 0 2px;
  font-size: 9px;
}

/* Header filter (integrerad input i namnkolumn) */
.header-filter-cell {
  padding: 4px 6px !important;
  white-space: normal !important;
  vertical-align: middle;
  text-transform: none !important;
  letter-spacing: 0 !important;
}
.header-filter {
  display: grid;
  grid-template-columns: auto minmax(96px, 30%);
  gap: 8px;
  align-items: center;
  justify-content: start;
}
.header-filter-label {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.header-filter-input {
  width: 100%;
  min-width: 0;
  font-size: 12px;
  font-weight: 400;
  padding: 5px 8px;
  line-height: 1.2;
  height: 28px;
}

table.matrix th[data-sort] { cursor: pointer; user-select: none; }
table.matrix th[data-sort]:hover { background: #f1f4fa; }
table.matrix .sort-ind { font-size: 10px; opacity: 0.7; margin-left: 4px; }

table.matrix td.split-hour { padding: 0; }
.hour-split { display: flex; flex-direction: row; height: 100%; }
.hour-segment {
  flex: 1 1 50%;
  min-height: 0;
  min-width: 0;
  position: relative;
}
.hour-segment + .hour-segment {
  border-left: 1px solid var(--border);
}
.hour-segment select {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  font-size: 9px;
  font-weight: 600;
  text-align: center;
  appearance: none;
  padding: 0 2px;
  background-color: transparent;
}
.hour-segment.scheduled-empty-half {
  background: repeating-linear-gradient(45deg, #fef9e7, #fef9e7 4px, var(--surface) 4px, var(--surface) 8px);
}

table.matrix td {
  position: relative;
  transition: background .08s, outline .08s;
}
table.matrix td.cell:hover, table.matrix td[data-hour]:hover {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
  z-index: 1;
}
table.matrix td.drag-target {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.hour-segment.drag-target-segment {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 1;
}
table.matrix td.drag-source-cell {
  outline: 2px dashed var(--text);
  outline-offset: -2px;
}
table.matrix td.focused {
  outline: 2px solid #f97316;
  outline-offset: -2px;
  z-index: 2;
}

table.matrix td.locked-cell,
.hour-segment.locked-cell {
  cursor: not-allowed;
  filter: saturate(0.72);
}

table.matrix td.locked-cell::after,
.hour-segment.locked-cell::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.45);
  pointer-events: none;
}

table.matrix td.pending-save,
table.overview td.day.pending-save {
  opacity: 0.72;
}
table.matrix td.pending-save::after,
table.overview td.day.pending-save::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    -45deg,
    rgba(15, 23, 42, 0.06),
    rgba(15, 23, 42, 0.06) 6px,
    rgba(255, 255, 255, 0.06) 6px,
    rgba(255, 255, 255, 0.06) 12px
  );
}

body.dragging { user-select: none; cursor: crosshair; }
body.dragging select { pointer-events: none; }

table.matrix td.scheduled-empty {
  background: repeating-linear-gradient(45deg, #fef9e7, #fef9e7 5px, var(--surface) 5px, var(--surface) 10px);
}
table.matrix td.scheduled-empty select { background-color: transparent; }

table.matrix td.base-value {
  opacity: 0.6;
  font-style: italic;
}
table.matrix td.base-value select { font-style: italic; opacity: 0.85; }

.drag-handle {
  position: absolute;
  bottom: 0; right: 0;
  width: 9px; height: 9px;
  background: var(--accent);
  border-radius: 2px 0 0 0;
  opacity: 0.55;
  transition: opacity .1s, transform .1s;
  cursor: crosshair;
  z-index: 1;
}
.drag-handle:hover { opacity: 1; transform: scale(1.2); transform-origin: bottom right; }

.clipboard-flash { animation: clipFlash 0.5s ease; }
@keyframes clipFlash {
  0%   { box-shadow: inset 0 0 0 3px var(--accent); }
  100% { box-shadow: inset 0 0 0 0 transparent; }
}


/* ============================================================
   Översiktstabell
   ============================================================ */

table.overview {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 12px;
  background: var(--surface);
}
table.overview th, table.overview td {
  padding: 8px 10px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: center;
  vertical-align: top;
  min-width: 110px;
}
table.overview th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2);
  font-weight: 600;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
table.overview th.name, table.overview td.name {
  width: 190px;
  min-width: 190px;
  max-width: 190px;
  position: sticky; left: 0;
  background: var(--surface);
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 13px;
  z-index: 3;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}
table.overview th.name {
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}
table.overview tr:hover td.name { background: #fafbfd; }

table.overview td.day {
  position: relative;
  cursor: pointer;
  transition: background .1s;
}
table.overview td.day:hover { background: #f9fafd; }
table.overview td.day select {
  width: 100%;
  border: 0;
  background-color: inherit;
  font-weight: 600;
  padding: 4px;
  font-size: 12px;
  cursor: pointer;
  appearance: none;
  text-align: center;
}
table.overview td.day.mixed {
  background: repeating-linear-gradient(135deg, var(--surface), var(--surface) 6px, var(--bg-2) 6px, var(--bg-2) 12px) !important;
}
table.overview td.day.is-off {
  background: #f3f5f9 !important;
  color: var(--text-soft);
  font-style: italic;
}
table.overview td.day.scheduled-empty {
  background: repeating-linear-gradient(45deg, #fef9e7, #fef9e7 6px, var(--surface) 6px, var(--surface) 12px) !important;
}
table.overview td.day.drag-target {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
table.overview td.day.focused {
  outline: 2px solid #f97316;
  outline-offset: -2px;
  z-index: 2;
}
table.overview th[data-sort] { cursor: pointer; user-select: none; }
table.overview th[data-sort]:hover { background: #f1f4fa; }
table.overview .sort-ind { font-size: 10px; opacity: 0.7; margin-left: 4px; }

.hour-info { font-size: 10px; color: var(--text-muted); margin-top: 3px; font-weight: 500; }

body.dragging-ov { cursor: crosshair; user-select: none; }
body.dragging-ov select { pointer-events: none; }


/* ============================================================
   Cards (summary, calc, tips)
   ============================================================ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 18px;
  box-shadow: var(--shadow-1);
}
.card h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.005em;
}

.summary-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.analytics-split {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.stat-value {
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.log-detail {
  min-width: 280px;
  color: var(--text-muted);
}

.muted-cell {
  color: var(--text-muted);
}

.summary-card, .calc-card { min-width: 0; }
.summary-card { position: relative; }
.summary-card.loading table {
  opacity: 0.72;
  transition: opacity 0.14s ease;
}
.summary-card.loading::after {
  content: "Uppdaterar";
  position: absolute;
  top: 16px;
  right: 18px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.summary-card table { font-size: 12px; }
.summary-card table th {
  background: var(--surface-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 10px;
}
.summary-card table td { padding: 8px 10px; font-size: 12px; }

.calc-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.calc-card-header h3 { margin: 0; }
.calc-area-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 0;
  margin-left: auto;
}
.calc-area-picker select { min-width: 180px; }

.calc-panels { display: grid; gap: 12px; }
.calc-panel { background: transparent; }
.calc-panel + .calc-panel {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.calc-panel-title {
  display: block;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
  padding: 0;
  margin: 0 0 8px;
  border: 0;
}

.calc-table { width: 100%; margin: 0; }
.calc-table th, .calc-table td {
  text-align: center;
  white-space: nowrap;
  padding: 6px 8px;
}
.calc-table thead th {
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.calc-table input {
  width: 100%;
  min-width: 0;
  text-align: center;
  font-weight: 600;
  padding: 5px 8px;
  font-size: 12px;
}
.calc-output { font-weight: 700; font-size: 13px; }
.calc-output.positive { color: var(--success); }
.calc-output.negative { color: var(--danger); }

.note {
  color: var(--text-muted);
  font-size: 12px;
  margin: 6px 0 0;
  line-height: 1.55;
}


/* ============================================================
   Tips FAB (floating action button)
   ============================================================ */

.tips-fab {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 20;
}
.tips-fab summary {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  list-style: none;
  border-radius: 999px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px -6px rgba(79, 70, 229, .5);
  transition: transform .12s, box-shadow .12s;
}
.tips-fab summary:hover { transform: scale(1.05); box-shadow: 0 12px 28px -6px rgba(79, 70, 229, .6); }
.tips-fab summary::-webkit-details-marker { display: none; }
.tips-fab[open] summary { background: var(--accent-hover); }

.tips-popover {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  width: min(340px, calc(100vw - 40px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-3);
  animation: pop .16s ease-out;
}
.tips-popover h3 { margin: 0 0 8px; font-size: 14px; font-weight: 700; }
.tips-popover .note { color: var(--text-muted); font-size: 13px; line-height: 1.55; }


/* ============================================================
   Sort/filter rows (personer, ställen)
   ============================================================ */

tr.sort-row th {
  cursor: pointer;
  user-select: none;
  background: var(--surface-2);
  transition: background .12s;
}
tr.sort-row th:hover { background: #f1f4fa; }
tr.sort-row .sort-ind {
  font-size: 10px;
  opacity: 0.6;
  margin-left: 4px;
  color: var(--text-soft);
}

tr.filter-row th {
  background: var(--surface);
  padding: 8px 12px;
}
tr.filter-row input {
  width: 100%;
  font-size: 12px;
  padding: 5px 8px;
  background: var(--surface);
}

.table-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.users-active-filter-cell {
  white-space: nowrap;
}


/* ============================================================
   Modal
   ============================================================ */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .35);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  z-index: 90;
  animation: fadeIn .14s ease-out;
}
.modal {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  max-width: 92vw;
  min-width: 420px;
  padding: 22px 24px;
  animation: pop .16s ease-out;
}
.modal.wide { min-width: min(760px, 92vw); }
.modal h2 { margin: 0 0 14px; font-size: 17px; font-weight: 700; }
.modal label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 12px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.modal input, .modal textarea, .modal select { width: 100%; }
.modal label.modal-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
  margin: 16px 0 4px;
}
.modal label.modal-checkbox input[type="checkbox"] { width: auto; }
.modal-table-scroll {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.modal-table-scroll table { box-shadow: none; border: 0; }
.modal .actions {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }


/* ============================================================
   Toast
   ============================================================ */

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  padding: 11px 16px;
  background: var(--text);
  color: #fff;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-2);
  z-index: 100;
  max-width: 360px;
  animation: slideUp .18s ease-out;
}
.toast.error { background: var(--danger); }
.toast.warn  { background: var(--warning); }
.toast.success { background: var(--success); }
@keyframes slideUp { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }


/* ============================================================
   Login
   ============================================================ */

.login-box {
  max-width: 380px;
  margin: 100px auto;
  background: var(--surface);
  padding: 28px 32px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
}
.login-box h2 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.015em;
}
.login-box .subtitle {
  margin: 0 0 22px;
  color: var(--text-muted);
  font-size: 13px;
}
.login-box label {
  display: block;
  margin: 12px 0 4px;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.login-box input { width: 100%; }
.login-box button {
  width: 100%;
  margin-top: 18px;
  padding: 10px;
  font-size: 14px;
}
.login-box .err {
  color: var(--danger);
  margin-top: 12px;
  font-size: 13px;
  background: #fef2f2;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  border: 1px solid #fecaca;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}
.login-brand .brand-dot { width: 32px; height: 32px; border-radius: 9px; font-size: 16px; }


/* ============================================================
   Helpers
   ============================================================ */

.small-table { width: 100%; margin: 0; }


/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 960px) {
  :root { --sidebar-w: 60px; }
  .sidebar { padding: 8px 8px 16px; }
  .brand-name, .brand-sub { display: none; }
  .sidebar nav a span:not(.icon) { display: none; }
  .sidebar nav a { justify-content: center; padding: 9px 0; }
  .sidebar-bottom .who, .sidebar-bottom .logout { display: none; }
  .summary-grid { grid-template-columns: 1fr; }
  .analytics-grid { grid-template-columns: 1fr; }
  .analytics-split { grid-template-columns: 1fr; }
  .calc-card-header { align-items: stretch; flex-direction: column; }
  .calc-area-picker { margin-left: 0; }
}

@media (max-width: 640px) {
  .modal { min-width: 320px; padding: 18px 20px; }
  main { padding: 18px 16px 50px; }
}
