/* AT-347: Garagets listläge (Renderer/modules/archive-table.js). Samma färgvariabler, rullistor och chip som Garagets
   filter; inga nya färger. Tabellen fyller den stora ytan där hjälprutan annars står; korten står kvar till vänster. */

#view-archive .template-editor-container { position: relative; }

.archive-view-toggle.is-active { opacity: 1; }

/* Fler filter: sju val i två rader. "Anteckning innehåller" ser ut som pillren bredvid i alla teman: archive-table.js
   (syncNoteFieldStyle) läser grannpillrets beräknade stil in i variablerna nedan (ledarens granskning 11-27, punkt 3). */
#view-archive :is(#archive-wide-header, #archive-table-filter-host) .archive-advanced-filter-panel .archive-note-text {
  min-width: 0;
  width: auto;
  box-sizing: border-box;
  height: var(--atlas-pill-height, 32px);
  padding: 0 10px;
  border-style: solid;
  border-width: var(--atlas-pill-bw, 1px);
  border-color: var(--atlas-pill-border, var(--border-color));
  border-radius: var(--atlas-pill-radius, 8px);
  background: var(--atlas-pill-bg, transparent) !important;
  color: var(--atlas-pill-color, var(--text-primary)) !important;
  font-size: var(--atlas-pill-font, 13px);
  font-weight: var(--atlas-pill-weight, 500);
  box-shadow: var(--atlas-pill-shadow, none);
  backdrop-filter: none;
  transition: none; /* följer pillret direkt, ingen egen övergång mot temats filter-input */
}
#view-archive :is(#archive-wide-header, #archive-table-filter-host) .archive-advanced-filter-panel .archive-note-text::placeholder { color: inherit; opacity: 0.75; }
/* Ifyllt fält = samma markering som en vald rullista (archive-filters.css). */
:root body #view-archive :is(#archive-wide-header, #archive-table-filter-host) .archive-advanced-filter-panel .archive-note-text.has-value {
  background: color-mix(in srgb, var(--accent-primary) 26%, transparent) !important;
  box-shadow: inset 0 0 0 1px var(--accent-primary);
  border-color: var(--accent-primary) !important;
  font-weight: 600;
}

/* Listläget (punkt 1 och 2): tabellen tar hela bredden och kortspalten döljs, så att skärmen visar ETT antal för urvalet
   och alla kolumner ryms. Korten finns kvar i DOM (läsvyn öppnas via kortet) och kommer tillbaka när listläget stängs. */
#view-archive.archive-table-mode .templates-container > .template-list-container { display: none !important; }
#view-archive.archive-table-mode .templates-container > .template-editor-container { flex: 1 1 auto !important; max-width: none !important; width: auto !important; }

.archive-table-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 14px 16px 0;
  gap: 8px;
  box-sizing: border-box;
}
.archive-table-panel[hidden] { display: none !important; }

.archive-table-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}
.archive-table-toolbar > .atlas-filter-dd,
.archive-table-toolbar > select { flex: 0 0 180px; }

.archive-table-search {
  position: relative;
  flex: 1 1 320px;
  min-width: 220px;
}
.archive-table-search .filter-input {
  width: 100%;
  padding-left: 32px !important;
  box-sizing: border-box;
}
.archive-table-spark {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent-primary);
  display: flex;
  pointer-events: none;
  opacity: 0.85;
}

.archive-table-modes { display: inline-flex; gap: 4px; flex-shrink: 0; }
.archive-table-scope { padding-inline-end: 6px; border-inline-end: 1px solid var(--border-color); }
/* Pågående rader: tunn markering i vänsterkanten och ordet "pågår" i kanalkolumnen. */
.archive-table tbody tr.is-open td:first-child { box-shadow: inset 3px 0 0 var(--accent-primary); }
.archive-table-open { font-size: 11px; color: var(--accent-primary); }
.archive-table-channel-label { display: inline-block; width: 46px; }

.archive-table-toolbar-second { justify-content: space-between; min-height: 32px; }
.archive-table-interpretation {
  flex: 1 1 100%;
  order: -1;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-primary);
}
.archive-table-interpretation[hidden] { display: none; }
.archive-table-muted { color: var(--text-secondary); font-size: 12px; }
.archive-table-link {
  border: 0;
  background: none;
  padding: 0 0 0 6px;
  color: var(--accent-primary);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}
.archive-table-count { font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.archive-table-count.is-loading { opacity: 0.6; }

.archive-table-lists { display: inline-flex; align-items: center; gap: 4px; margin-inline-start: auto; }
.archive-table-lists > .atlas-filter-dd, .archive-table-lists > select { width: 230px; }
.archive-table-lists .archive-more-filters[hidden] { display: none; }

.archive-table-export-wrap { position: relative; display: inline-flex; }
.archive-table-export-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  width: 260px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-dark-secondary, var(--bg-dark-primary, Canvas));
  box-shadow: 0 8px 18px rgb(0 0 0 / 16%);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.archive-table-export-pop[hidden] { display: none; }
.archive-table-export-title { font-weight: 600; font-size: 13px; color: var(--text-primary); }
.archive-table-export-pop p { margin: 0; line-height: 1.4; }
.archive-table-check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-primary); cursor: pointer; }

/* AT-363 (14): pilen, mätaren och räknaren över tabellens nederkant (list-position.css). */
#archive-table.archive-table-panel { position: relative; }
#archive-table .archive-table-hint { position: absolute; left: 0; right: 0; bottom: 0; }
#archive-table .archive-table-hint.hidden { display: flex; }

.archive-table-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border-top: 1px solid var(--border-color);
}

.archive-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 12.5px;
  color: var(--text-primary);
}
.archive-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-dark-secondary, var(--bg-dark-primary, Canvas));
  border-bottom: 1px solid var(--border-color);
  text-align: left;
  font-weight: 600;
  padding: 0;
}
.archive-table thead th button {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 8px 8px;
  border: 0;
  background: none;
  color: var(--text-secondary);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.archive-table thead th[aria-sort="ascending"] button,
.archive-table thead th[aria-sort="descending"] button { color: var(--accent-primary); }
.archive-table thead th button:hover { color: var(--text-primary); }
.archive-table-arrow { font-size: 9px; }

.archive-table tbody td {
  padding: 7px 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--border-color) 60%, transparent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.archive-table tbody tr { cursor: pointer; }
.archive-table.is-customer tbody tr { cursor: default; }
.archive-table tbody tr:hover td,
.archive-table tbody tr:focus-visible td { background: color-mix(in srgb, var(--accent-primary) 8%, transparent); }
.archive-table tbody tr:focus-visible { outline: none; }

.archive-table .c-date { width: 118px; font-variant-numeric: tabular-nums; }
.archive-table .c-customer { width: 15%; }
.archive-table .c-title { width: 20%; }
.archive-table .c-topic { width: 10%; }
.archive-table .c-office { width: 11%; }
.archive-table .c-vehicle { width: 8%; }
.archive-table .c-agent { width: 12%; }
.archive-table .c-channel { width: 112px; }
.archive-table .c-priority { width: 72px; }
.archive-table .c-rating { width: 58px; }
.archive-table .c-note { width: 14%; color: var(--text-secondary); }
.archive-table .c-num { width: 80px; font-variant-numeric: tabular-nums; }
/* Kundläget har fem kolumner: kontor och fordon/kategori får platsen (flera värden per kund). Hela texten finns som tooltip. */
.archive-table.is-customer .c-customer { width: 22%; }
.archive-table.is-customer .c-office, .archive-table.is-customer .c-vehicle { width: 26%; }
.archive-table.has-customer-details .c-customer { width: 16%; }
.archive-table.has-customer-details .c-office { width: 13%; }
.archive-table.has-customer-details .c-vehicle { width: 10%; }
.archive-table .c-email { width: 20%; }
.archive-table .c-phone { width: 112px; }
.archive-table .c-customer-note { width: 15%; color: var(--text-secondary); }
.archive-table-customer-query { flex: 1 1 auto; min-width: 130px; max-width: 320px; }
.archive-table-customer-query[hidden], .archive-table-check[hidden] { display: none; }
.archive-table .archive-rating-counter { display: inline-flex; }

.archive-table-priority {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-inline-start: 4px;
  border-radius: 50%;
  background: var(--prio-color);
  box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--prio-color) 65%, #000),
    0 0 8px color-mix(in srgb, var(--prio-color) 38%, transparent);
}
.archive-table-customer-link {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
.archive-table-customer-tickets { padding: 0; margin: 0; list-style: none; }
.archive-table-customer-tickets li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-block: 8px;
  border-bottom: 1px solid var(--border-color);
}
.archive-table-customer-tickets button { text-align: left; overflow-wrap: anywhere; }
.archive-table-customer-tickets time { flex-shrink: 0; color: var(--text-secondary); font-size: 12px; }
.archive-table-more[hidden] { display: none; }

.archive-table-more { margin: 4px 0 8px; }

/* Över läsvyns sidhuvud, mitt på (rubriken står till vänster och knapparna till höger). */
.archive-table-back {
  position: absolute;
  z-index: 6;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px 4px 6px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-dark-secondary, var(--bg-dark-primary, Canvas));
  color: var(--accent-primary);
  font-size: 12px;
  cursor: pointer;
}
.archive-table-back[hidden] { display: none; }

/* Smala fönster (under Patriks 1366): de minst viktiga kolumnerna faller bort först; datum, kund, rubrik, ämne, kontor,
   handläggare och betyg står kvar. Ovanför syns alla tio (mätt i skärmbilderna 1366 och 1920). */
@media (max-width: 1279px) {
  .archive-table .c-note, .archive-table .c-channel, .archive-table .c-phone, .archive-table .c-customer-note { display: none; }
}
@media (max-width: 1023px) {
  .archive-table .c-vehicle { display: none; }
}

/* Listläget hör hemma på datorn; mobilen behåller korten. */
@media (max-width: 768px) {
  #archive-table-btn, .archive-table-panel, .archive-table-back { display: none !important; }
}

/* AT-363 (22): länken under korten när fritextsökningen kapas vid 500. Länkstil, ingen ruta (L-247). */
#view-archive .archive-truncated-link {
  display: block;
  margin: 10px auto 14px;
  padding: 0 !important;
  border: 0 !important;
  background: none !important;
  box-shadow: none !important;
  color: var(--accent-primary) !important;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}
#view-archive .archive-truncated-link[hidden] { display: none !important; }

/* Kund- och ärendeikoner: valt läge följer samma tema som statuspillren. */
#archive-table .archive-table-modes .archive-table-icon-chip {
  padding: 4px !important; min-width: 0; color: var(--text-secondary);
  display: inline-flex; align-items: center; justify-content: center;
}
#archive-table .archive-table-modes .archive-table-icon-chip:not(.is-active) {
  background: none !important; border-color: transparent !important; box-shadow: none !important;
}
#archive-table .archive-table-modes .archive-table-icon-chip:hover { color: var(--text-primary); }
#archive-table .archive-table-modes .archive-table-icon-chip[aria-pressed="true"] { color: var(--accent-primary); }
#archive-table .archive-table-modes .archive-table-icon-chip svg { width: 18px; height: 18px; display: block; }
#archive-table .atlas-filter-dd.archive-table-icon-trigger.is-icon {
  width: auto !important; min-width: 0 !important; padding: 4px !important; flex: 0 0 auto !important;
  background: none !important; border-color: transparent !important; box-shadow: none !important;
  color: var(--text-secondary);
}
#archive-table .atlas-filter-dd.archive-table-icon-trigger.is-icon:hover { color: var(--text-primary); }
#archive-table .atlas-filter-dd.archive-table-icon-trigger.is-icon > :is(.atlas-filter-dd-label, .atlas-filter-dd-chevron) { display: none !important; }
#archive-table .atlas-filter-dd.archive-table-icon-trigger.is-icon::before {
  content: ''; display: block; width: 18px; height: 18px; background: currentColor;
  -webkit-mask: var(--archive-table-icon) no-repeat center / contain; mask: var(--archive-table-icon) no-repeat center / contain;
}
#archive-table .atlas-filter-dd.is-calendar { --archive-table-icon: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Crect%20x%3D%223%22%20y%3D%224%22%20width%3D%2218%22%20height%3D%2218%22%20rx%3D%222%22%2F%3E%3Cline%20x1%3D%2216%22%20y1%3D%222%22%20x2%3D%2216%22%20y2%3D%226%22%2F%3E%3Cline%20x1%3D%228%22%20y1%3D%222%22%20x2%3D%228%22%20y2%3D%226%22%2F%3E%3Cline%20x1%3D%223%22%20y1%3D%2210%22%20x2%3D%2221%22%20y2%3D%2210%22%2F%3E%3C%2Fsvg%3E"); }
#archive-table .atlas-filter-dd.is-list-plus { --archive-table-icon: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M11%2012H3%22%2F%3E%3Cpath%20d%3D%22M16%206H3%22%2F%3E%3Cpath%20d%3D%22M16%2018H3%22%2F%3E%3Cpath%20d%3D%22M18%209v6%22%2F%3E%3Cpath%20d%3D%22M21%2012h-6%22%2F%3E%3C%2Fsvg%3E"); }
#archive-table .archive-table-lists > .atlas-filter-dd.is-icon { width: auto; }

/* AT-363 (17): knappen i läsfönstret för ett pågående ärende ur listvyn. Ikon utan ram (husregel 3), hovertext. */
#atlas-reader-modal .archive-table-open-home {
  background: none !important; border: 0 !important; box-shadow: none !important; padding: 4px; margin-right: 2px;
  color: var(--text-secondary); cursor: pointer; display: inline-flex; align-items: center;
}
#atlas-reader-modal .archive-table-open-home:hover { color: var(--accent-primary); }
