/* Ärendesystem — rapportknappen i appskalet (Task 11).
   Tokens (--bg, --surface, --hairline, --text, --fc-accent, …) come from
   /v2/styles.css, loaded render-blocking before this file in index.html.
   Lives in the shell (both V2Layout and the mobile shell), not on a page —
   so, unlike a page stylesheet, this one has no useV2Stylesheets guard and
   must always be present, hence the render-blocking <link> in index.html.

   Fixed positioning throughout: this component is mounted as a shell-level
   sibling, not inside a page's layout flow, on both desktop and mobile. */

.ar-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 400;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px 10px 13px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease), background 120ms;
}
.ar-fab:hover { background: var(--bg-elevated); }
.ar-fab:active { transform: scale(0.96); }

/* On phones the bottom tab bar (.m-tabbar) occupies the lowest ~90px of the
   screen — lift the fab clear of it. MOBILE_BREAKPOINT matches the one used
   in client/src/main.tsx. */
@media (max-width: 767px) {
  .ar-fab {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 92px);
    right: 14px;
  }
}

.ar-sheet {
  position: fixed;
  right: 16px;
  bottom: 20px;
  z-index: 401;
  width: 340px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-dialog);
  font-family: var(--font-sans);
  color: var(--text);
  animation: ar-sheet-in 180ms var(--ease);
}
@keyframes ar-sheet-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Full-width bottom sheet on phones, clear of the tab bar, same breakpoint
   as the fab above. */
@media (max-width: 767px) {
  .ar-sheet {
    left: 12px;
    right: 12px;
    width: auto;
    max-width: none;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 92px);
  }
}

.ar-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
}

.ar-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-quiet);
  margin-top: 2px;
}

.ar-textarea {
  width: 100%;
  resize: vertical;
  min-height: 84px;
  padding: 9px 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--hairline);
  background: var(--bg-sunken);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.4;
}
.ar-textarea:focus {
  outline: none;
  border-color: var(--fc-accent);
}
.ar-textarea::placeholder { color: var(--text-faint); }

.ar-select {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--hairline);
  background: var(--bg-sunken);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
}

.ar-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.ar-check input { width: 15px; height: 15px; accent-color: var(--fc-accent); }

.ar-attach {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.ar-btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border-radius: var(--r-md);
  border: 1px solid var(--hairline);
  background: var(--bg-elevated);
  color: var(--text-quiet);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}
.ar-btn-ghost:hover { color: var(--text); border-color: var(--hairline-strong); }
.ar-btn-ghost:disabled { opacity: 0.55; cursor: not-allowed; }

.ar-attach-ok {
  font-size: 12px;
  color: var(--h-strong);
}

.ar-error {
  font-size: 12.5px;
  color: var(--h-critical);
  margin: 0;
}

.ar-btn {
  width: 100%;
  padding: 10px;
  border-radius: var(--r-md);
  border: none;
  background: var(--fc-accent);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 120ms;
}
.ar-btn:hover { opacity: 0.92; }
.ar-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.ar-done {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
  font-size: 13.5px;
  color: var(--text);
}
.ar-done p { margin: 0; }
.ar-done .ar-btn { width: auto; padding: 8px 16px; }

/* ---------------------------------------------------------------------
   Listan, /arenden (Task 12).
   Not fixed-positioned like the fab/sheet above — this is a normal page,
   laid out in the V2 page-content flow, using the same --bg/--surface/
   --hairline/--text tokens from /v2/styles.css.
   --------------------------------------------------------------------- */

.ar-page {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px clamp(16px, 3vw, 32px) 48px;
  max-width: 920px;
  margin: 0 auto;
  font-family: var(--font-sans);
  color: var(--text);
}

.ar-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ar-title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.ar-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.ar-filter-btn {
  padding: 7px 13px;
  border-radius: var(--r-md);
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--text-quiet);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.ar-filter-btn:hover { border-color: var(--hairline-strong); color: var(--text); }
.ar-filter-btn.is-on {
  background: var(--fc-accent);
  border-color: var(--fc-accent);
  color: #fff;
}

.ar-select {
  padding: 7px 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--hairline);
  background: var(--bg-sunken);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 12.5px;
}

.ar-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ar-section-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-quiet);
}

.ar-empty {
  margin: 0;
  padding: 16px;
  border-radius: var(--r-lg);
  border: 1px dashed var(--hairline);
  color: var(--text-faint);
  font-size: 13px;
}

.ar-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-radius: var(--r-lg);
  overflow: hidden;
  border: 1px solid var(--hairline);
  background: var(--hairline);
}

.ar-row { background: var(--surface); }

.ar-row-link {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 14px;
  color: inherit;
  text-decoration: none;
  transition: background 120ms;
}
.ar-row-link:hover { background: var(--bg-elevated); }

.ar-ref {
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
  font-size: 12.5px;
  font-weight: 600;
  min-width: 34px;
}

.ar-row-title {
  flex: 1 1 220px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ar-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--bg-elevated);
  color: var(--text-quiet);
}

/* Status chips — new needs attention, in_progress is the neutral working
   state, resolved is the "good" health colour, rejected is deliberately
   muted rather than red: it was looked at and dismissed, not a failure. */
.ar-chip.is-new { background: var(--h-low-bg); color: var(--h-low); }
.ar-chip.is-in_progress { background: var(--h-strong-bg); color: var(--fc-accent); }
.ar-chip.is-resolved { background: var(--h-strong-bg); color: var(--h-strong); }
.ar-chip.is-rejected { background: var(--bg-elevated); color: var(--text-faint); }

.ar-chip.is-cat {
  background: transparent;
  color: var(--text-quiet);
  box-shadow: inset 0 0 0 1px var(--hairline-strong);
}

.ar-chip.is-auto {
  background: var(--h-low-bg);
  color: var(--h-low);
  font-weight: 500;
}

@media (max-width: 640px) {
  .ar-row-link { padding: 10px 12px; }
  .ar-row-title { flex-basis: 140px; }
}

/* ---------------------------------------------------------------------
   Ärendesidan, /arenden/:ref (Task 13). Shares .ar-page/.ar-head/.ar-title/
   .ar-select/.ar-label/.ar-btn/.ar-btn-ghost/.ar-chip(+status variants)
   with the list above.
   --------------------------------------------------------------------- */

.ar-body {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-quiet);
  white-space: pre-wrap;
}

.ar-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 18px;
  border-radius: var(--r-lg);
  border: 1px solid var(--hairline);
  background: var(--surface);
}

.ar-card-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-quiet);
}

/* Route breakdown on an auto-created ticket. */
.ar-routes {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ar-routes li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}
.ar-routes code {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ar-routes li span {
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* error_logs has no UI of its own — this is a plain id list, not a link. */
.ar-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-faint);
}

.ar-attachments {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ar-attachments a {
  font-size: 13px;
  color: var(--fc-accent);
  text-decoration: none;
}
.ar-attachments a:hover { text-decoration: underline; }

/* Admin triage — status buttons, then a small form for mottagare/prioritet/deadline. */
.ar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ar-triage {
  display: grid;
  grid-template-columns: max-content 1fr;
  align-items: center;
  column-gap: 12px;
  row-gap: 8px;
}
.ar-triage .ar-label { margin-top: 0; }
.ar-triage .ar-select,
.ar-triage .ar-input { width: 100%; }

.ar-input {
  padding: 7px 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--hairline);
  background: var(--bg-sunken);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 12.5px;
}

/* Deadline readout — tone mirrors /integritet's (client/src/v2/lib/deadline.ts):
   critical is overdue, attention is due soon, neutral is comfortably ahead,
   none has no live deadline. */
.ar-deadline {
  margin: 0;
  font-size: 12.5px;
  font-weight: 600;
}
.ar-deadline.is-neutral { color: var(--text-quiet); }
.ar-deadline.is-attention { color: var(--h-low); }
.ar-deadline.is-critical { color: var(--h-critical); }
.ar-deadline.is-none { color: var(--text-faint); }

/* Timeline — status changes and comments interleaved chronologically. */
.ar-timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ar-tl {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-left: 14px;
  border-left: 2px solid var(--hairline);
  font-size: 13px;
}
.ar-tl time {
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.ar-tl-comment { border-left-color: var(--fc-accent); }

.ar-tl-body {
  margin: 0;
  color: var(--text);
  white-space: pre-wrap;
}
