/* RISE — defect reporting styles. Mobile-first. */
:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1b1f2a;
  --muted: #6b7280;
  --primary: #c0392b;      /* default RISE red; overridden per-BU by theme.js */
  --primary-dark: #97271c;
  --accent: #1e8e5a;
  --ok: #1e8e5a;
  --border: #e6e8ec;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(16,24,40,0.04), 0 1px 3px rgba(16,24,40,0.06);
  --shadow-lg: 0 12px 32px rgba(16,24,40,0.12);
  --ring: color-mix(in srgb, var(--primary) 20%, transparent);
}

* { box-sizing: border-box; }
button { font-family: inherit; }

/* The `hidden` attribute must always win, even over rules that set display
   (e.g. .overlay sets display:flex). Without this the loading overlay shows
   on page load. */
[hidden] { display: none !important; }

html, body { max-width: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Page scrolls vertically only; wide tables scroll inside their own frame. */
  overflow-x: hidden;
}
/* Layout containers must be allowed to shrink so a wide child (a table) scrolls
   inside its frame instead of widening the page on narrow screens. */
.app, .admin-layout, .admin-main, .sec, .settings-grid, .config-stack { min-width: 0; }

.app {
  max-width: 1160px;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 30px) clamp(16px, 4vw, 40px) calc(36px + env(safe-area-inset-bottom));
}

/* Header behaves as a top bar: brand/title left, nav right, on wide screens. */
.app__header {
  margin-bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 18px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}
.app__header h1 { font-size: 1.5rem; margin: 0; flex: 0 0 auto; }
.app__subtitle { margin: 0; color: var(--muted); flex: 1 1 100%; order: 3; }
.app__header h1 + .app__subtitle { flex-basis: 100%; }
.brandbar { flex: 0 0 auto; order: -1; flex-basis: 100%; }
.brand-logo { height: 44px; width: auto; display: block; }

/* Forms read best at a comfortable width, centered within the wide page. */
main.app > form.card,
main.app > .card--success,
main.app > .state { max-width: 680px; margin-inline: auto; }
.app__header .nav { margin-left: auto; margin-top: 0; }
.app__link {
  display: inline-block;
  margin-top: 10px;
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}
.app__link:active { color: var(--primary-dark); }
.app__link--btn {
  background: none; border: none; padding: 0; cursor: pointer;
  font: inherit; font-weight: 600;
}

/* ---- Header user menu (name → Settings / Sign out) ---- */
.usermenu { position: relative; display: inline-flex; align-items: center; margin-top: 10px; vertical-align: middle; }
.usermenu__btn { display: inline-flex; align-items: center; gap: 8px; background: none; border: none; cursor: pointer; font: inherit; color: var(--ink); padding: 3px 8px 3px 3px; border-radius: 999px; }
.usermenu__btn:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.usermenu__av { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 800; font-size: 0.82rem; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.usermenu__name { font-weight: 600; font-size: 0.92rem; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usermenu__caret { color: var(--muted); font-size: 0.7rem; }
.usermenu__pop { position: absolute; top: calc(100% + 8px); right: 0; min-width: 184px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); z-index: 200; padding: 6px; display: flex; flex-direction: column; }
.usermenu__item { display: block; text-align: left; background: none; border: none; cursor: pointer; font: inherit; font-size: 0.9rem; color: var(--ink); text-decoration: none; padding: 9px 12px; border-radius: 8px; }
.usermenu__item:hover { background: color-mix(in srgb, var(--primary) 6%, transparent); }
.usermenu__signout { color: var(--primary); font-weight: 600; }

/* ---- Notifications (bell + floating panel) ---- */
.notif { position: relative; display: inline-flex; align-items: center; margin-top: 10px; margin-right: 14px; vertical-align: middle; }
.notif__bell { position: relative; background: none; border: none; cursor: pointer; padding: 2px; line-height: 1; font-size: 1.15rem; color: var(--ink); border-radius: 8px; }
.notif__bell:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.notif__bell.has-unread .notif__ic { animation: notif-wiggle 1.2s ease 1; }
@keyframes notif-wiggle { 0%,100% { transform: rotate(0); } 20% { transform: rotate(-12deg); } 40% { transform: rotate(10deg); } 60% { transform: rotate(-6deg); } 80% { transform: rotate(4deg); } }
.notif__badge { position: absolute; top: -3px; right: -4px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 0.62rem; font-weight: 800; line-height: 16px; text-align: center; box-shadow: 0 0 0 2px var(--bg); }
.notif__panel { position: absolute; top: calc(100% + 10px); right: 0; width: min(340px, 92vw); max-height: min(70vh, 460px); overflow: auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 200; }
.notif__head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 0.9rem; position: sticky; top: 0; background: var(--card); }
.notif__readall { background: none; border: none; cursor: pointer; color: var(--primary); font: inherit; font-size: 0.78rem; font-weight: 600; }
.notif__list { display: flex; flex-direction: column; }
.notif__item { display: flex; gap: 10px; align-items: flex-start; text-align: left; width: 100%; background: none; border: none; border-bottom: 1px solid var(--border); padding: 11px 14px; cursor: pointer; font: inherit; }
.notif__item:hover { background: color-mix(in srgb, var(--primary) 4%, transparent); }
.notif__item.is-unread { background: color-mix(in srgb, var(--primary) 6%, transparent); }
.notif__dot { flex: 0 0 auto; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: transparent; }
.notif__item.is-unread .notif__dot { background: var(--primary); }
.notif__body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.notif__title { font-weight: 700; font-size: 0.85rem; color: var(--ink); }
.notif__text { font-size: 0.82rem; color: var(--muted); }
.notif__time { font-size: 0.7rem; color: var(--muted); margin-top: 2px; }
.notif__empty { padding: 26px 14px; text-align: center; color: var(--muted); font-size: 0.85rem; }

/* Assignee status control */
.status-control {
  display: flex; align-items: center; gap: 10px;
  margin-top: 14px; padding-top: 14px;
  border-top: 1px solid var(--border);
}
.status-control__label { font-weight: 600; font-size: 0.9rem; }
.status-control__select { width: auto; min-width: 150px; padding: 8px 32px 8px 12px; }
.status-control__note { font-size: 0.82rem; color: var(--muted); }

.field__optional { font-weight: 400; color: var(--muted); }

.nav { display: flex; gap: 16px; align-items: center; margin-top: 10px; flex-wrap: wrap; }

/* ---- Home landing: primary action buttons ---- */
.home-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  max-width: 760px;
}
.home-btn {
  display: flex; flex-direction: column; gap: 6px;
  text-decoration: none; color: var(--ink);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 22px;
  min-height: 150px;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.home-btn:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
}
.home-btn__icon {
  width: 50px; height: 50px; border-radius: 14px;
  display: grid; place-items: center;
  font-size: 1.5rem; margin-bottom: 8px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
}
.home-btn__label { font-size: 1.2rem; font-weight: 700; }
.home-btn__sub { color: var(--muted); font-size: 0.9rem; }

/* Defect/Improvement segmented toggle */
.segmented { display: inline-flex; background: #eef0f3; border-radius: 12px; padding: 4px; gap: 4px; }
.segmented__opt {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border-radius: 9px; cursor: pointer;
  font-weight: 600; color: var(--muted); transition: all 0.15s ease;
}
.segmented__opt input { display: none; }
.segmented__opt:has(input:checked) { background: #fff; color: var(--primary); box-shadow: var(--shadow); }

/* Type pill + badges column */
.badges { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.pill { font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; padding: 2px 8px; border-radius: 999px; }
.pill--defect { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); }
.pill--improvement { background: rgba(30,142,90,0.12); color: var(--ok); }
/* Priority pills (fixed colours, independent of brand, so severity reads clearly) */
.pri--low { background: #eef0f3; color: #59616e; }
.pri--medium { background: rgba(37,99,235,0.12); color: #2563eb; }
.pri--high { background: rgba(217,119,6,0.15); color: #b45309; }
.pri--urgent { background: rgba(220,38,38,0.14); color: #dc2626; }

/* Reporter satisfaction rating */
.rating { display: flex; gap: 8px; flex-wrap: wrap; }
.rating__btn {
  width: 44px; height: 44px; border-radius: 12px;
  border: 1px solid var(--border); background: #fff; cursor: pointer;
  font-size: 1.1rem; color: #c7ccd4; transition: all 0.12s ease;
}
.rating__btn:hover, .rating__btn.is-on { border-color: var(--primary); color: #f6b73c; background: color-mix(in srgb, var(--primary) 6%, #fff); }
.needs-rating { color: var(--muted); font-weight: 600; }

/* Half-star hover/click rating (fills like a progress bar; colour by value) */
.starrate { display: inline-flex; align-items: center; gap: 14px; }
.starrate__track { position: relative; display: inline-block; cursor: pointer; font-size: 2.1rem; line-height: 1; letter-spacing: 8px; user-select: none; }
.starrate__base { color: #d8dce2; }
.starrate__fill { position: absolute; top: 0; left: 0; width: 0; overflow: hidden; white-space: nowrap; pointer-events: none; transition: width 0.04s linear; }
.starrate__label { font-weight: 700; color: var(--muted); min-width: 68px; }

/* Description + mic */
.desc-wrap { position: relative; }
.mic-btn {
  position: absolute; right: 8px; bottom: 8px;
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: 1rem;
}
.mic-btn.is-on { background: var(--primary); border-color: var(--primary); }

/* Documents list */
.docs-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.docs-list:empty { display: none; }
.docs-list__item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  text-decoration: none; color: var(--ink); font-size: 0.9rem;
}
.docs-list__remove { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 0.9rem; }
.defect__desc--empty { color: var(--muted); font-style: italic; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.field { display: block; margin-bottom: 14px; }
.field__label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.92rem; }
.req { color: var(--primary); }

.field__input {
  width: 100%;
  font: inherit;
  color: inherit;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  resize: vertical;
}
.field__input::placeholder { color: #9aa1ad; }
.field__input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}
/* Native <select> is replaced by the custom themed dropdown (ui.js). When
   enhanced it's hidden; if JS is off it still works as a normal select. */
select.cs__native {
  position: absolute; opacity: 0; width: 0; height: 0;
  padding: 0; margin: 0; border: 0; pointer-events: none;
}

/* ---- Custom themed dropdown ---- */
.cs { position: relative; }
.cs__trigger {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font: inherit; color: inherit; text-align: left;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.cs__trigger:hover { border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); }
.cs--open .cs__trigger, .cs__trigger:focus-visible {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring);
}
.cs__trigger.is-placeholder .cs__label { color: #9aa1ad; }
.cs__trigger:disabled { background: #f3f4f6; color: var(--muted); cursor: default; }
.cs__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs__caret {
  flex: 0 0 auto; width: 9px; height: 9px; margin-right: 2px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translateY(-2px); transition: transform 0.18s ease;
}
.cs--open .cs__caret { transform: rotate(-135deg) translateY(-2px); }
.cs__menu {
  position: absolute; z-index: 1000; top: calc(100% + 6px); left: 0; right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 6px; max-height: 300px; overflow: auto;
  animation: cs-pop 0.12s ease;
}
@keyframes cs-pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.cs__group { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); padding: 9px 10px 4px; }
.cs__opt {
  padding: 10px 12px; border-radius: 9px; cursor: pointer; font-size: 0.95rem;
  transition: background 0.1s ease;
}
.cs__opt:hover { background: color-mix(in srgb, var(--primary) 10%, transparent); }
.cs__opt.is-selected { color: var(--primary); font-weight: 650; background: color-mix(in srgb, var(--primary) 8%, transparent); }
.cs__empty { padding: 12px; color: var(--muted); font-size: 0.9rem; }
.field__hint { display: block; text-align: right; color: var(--muted); font-size: 0.8rem; margin-top: 4px; }

/* ---- SLA progress bar (24h to closure) ---- */
.sla { margin: 10px 0 4px; }
.sla__head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 0.78rem; margin-bottom: 5px; }
.sla__label { color: var(--muted); font-weight: 600; }
.sla__status { font-weight: 700; }
.sla__track { height: 8px; background: #eef0f3; border-radius: 999px; overflow: hidden; }
.sla__fill { height: 100%; border-radius: 999px; min-width: 2px; transition: width 0.4s ease; }

.photo { display: flex; flex-direction: column; gap: 12px; }

/* Selected-photo thumbnail grid on the report form */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}
.photo-grid:empty { display: none; }
.photo-grid__cell { position: relative; aspect-ratio: 1 / 1; }
.photo-grid__cell img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}
.photo-grid__remove {
  position: absolute; top: 4px; right: 4px;
  width: 26px; height: 26px; border-radius: 50%;
  border: none; background: rgba(0,0,0,0.6); color: #fff;
  font-size: 0.85rem; line-height: 1; cursor: pointer;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%;
  font: inherit; font-weight: 650;
  padding: 13px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 28%, transparent); }
.btn--primary:hover { background: var(--primary-dark); }
.btn--primary:disabled { opacity: 0.55; cursor: default; box-shadow: none; }
.btn--ghost { background: #fff; border-color: var(--border); color: var(--ink); }
.btn--ghost:hover { border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); }
.btn--danger { background: #fff; border-color: rgba(192,57,43,0.4); color: var(--primary); }
.btn--danger:active { background: rgba(192,57,43,0.08); }
.btn--sm { width: auto; padding: 8px 12px; font-size: 0.82rem; }

.form-error {
  margin: 12px 0 0;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 9%, transparent);
  padding: 10px 12px;
  border-radius: 9px;
}
.form-msg { margin: 12px 0 0; padding: 10px 12px; border-radius: 9px; }
.form-msg--ok { color: #166534; background: rgba(22,163,74,0.12); }

/* Settings: name + password side by side (stack on narrow screens) */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }

/* Settings → background sync indicator (deliberately quiet) */
.sync-status { margin: 18px 2px 0; color: var(--muted); font-size: 0.78rem; }

/* Settings → Configuration links */
.config-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.config-link { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); text-decoration: none; color: var(--ink); font-weight: 600; background: #fff; transition: border-color 0.12s ease, transform 0.1s ease, box-shadow 0.15s ease; }
.config-link:hover { border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); transform: translateY(-1px); box-shadow: var(--shadow); }

.card--success { text-align: center; }
.success__check {
  width: 56px; height: 56px; margin: 4px auto 12px;
  border-radius: 50%; background: var(--ok); color: #fff;
  font-size: 1.8rem; line-height: 56px;
}
.success__ref { color: var(--muted); }
.success__ref strong { color: var(--ink); letter-spacing: 0.5px; }

.overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.8);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; color: var(--muted);
}
.spinner {
  width: 36px; height: 36px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Defect list / view screen ---- */
.state { color: var(--muted); padding: 24px 4px; }

/* Lists tile into columns on wider screens (uses the full width meaningfully,
   without stretching any single card). On mobile this collapses to 1 column. */
.list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
  align-items: start;
}
/* Admin panels keep their rows full-width in a single column. */
.panel .list { grid-template-columns: 1fr; }

/* Ticket page: comfortable reading width; two columns on wide screens. */
#ticket-grid { max-width: 860px; margin-inline: auto; }
@media (min-width: 960px) {
  #ticket-grid {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 28px;
    align-items: start;
    max-width: none;
  }
  #ticket-grid > * { min-width: 0; }
}
.ticket-col { display: flex; flex-direction: column; gap: 16px; }
.ticket-col .section-title { margin: 4px 0 0; }

.defect { padding: 16px; }
.defect__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 4px;
}
.defect__reflabel {
  display: block;
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--muted);
  margin-bottom: 1px;
}
.defect__ref { font-weight: 700; letter-spacing: 0.5px; font-size: 0.7rem; color: var(--muted); }
.defect__outlet { margin: 6px 0 2px; font-weight: 700; font-size: 1.05rem; }
.defect__meta { margin: 0 0 10px; color: var(--muted); font-size: 0.85rem; }
.defect__desc { margin: 0 0 12px; white-space: pre-wrap; }
.defect__nophoto { margin: 0; color: var(--muted); font-size: 0.85rem; }

.badge {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 3px 9px; border-radius: 999px;
  background: #eef0f3; color: var(--muted);
}
.badge--open { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); }
.badge--in_progress { background: rgba(201,138,0,0.14); color: #9a6a00; }
.badge--resolved { background: rgba(30,142,90,0.14); color: var(--ok); }
.badge--closed { background: #e7e9ec; color: #59616e; }

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}
.thumbs__img {
  width: 100%; aspect-ratio: 1 / 1;
  object-fit: cover; border-radius: 8px;
  cursor: pointer; display: block;
  background: #eef0f3;
}

/* ---- Admin: tabs ---- */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab {
  background: none; border: none; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--muted);
  padding: 11px 16px; border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }
.panel { margin-bottom: 8px; }
.panel .card:first-child { margin-bottom: 14px; }

/* Admin/assignee workspace use the full screen with small margins. */
.app--admin { max-width: none; padding: clamp(10px, 1.4vw, 18px) clamp(12px, 1.8vw, 24px) clamp(16px, 2vw, 24px); }

/* Clickable dashboard cards (open a trend popup). */
.kpi--click, .metric-card--click { cursor: pointer; transition: transform 0.1s ease, box-shadow 0.15s ease, border-color 0.15s ease; }
.kpi--click:hover, .metric-card--click:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--primary) 30%, var(--border)); }
.kpi--click:focus-visible, .metric-card--click:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

/* Chart card header with enlarge button. */
.dash-card__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.dash-card__head .dash-card__title { margin: 0; }
.dash-card__enlarge { border: 1px solid var(--border); background: #fff; border-radius: 8px; width: 28px; height: 28px; cursor: pointer; color: var(--muted); font-size: 0.9rem; line-height: 1; flex: 0 0 auto; }
.dash-card__enlarge:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); color: var(--primary); }
.dash-enlarge .bars { gap: 16px; }
.dash-enlarge .bar-row__track { height: 22px; }
.dash-enlarge .col-chart { height: 320px; }

/* Trend popup / detail. */
.trend-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.trend-now__val { font-size: 1.6rem; font-weight: 800; }
.trend-now__lbl { display: block; color: var(--muted); font-size: 0.82rem; }
svg.trend { width: 100%; height: auto; display: block; }
.trend__grid { stroke: var(--border); stroke-width: 1; }
.trend__xlbl { font-size: 10px; fill: var(--muted); text-anchor: middle; }
.trend__ylbl { font-size: 10px; fill: var(--muted); }

/* ---- Filter bar (open tickets / history) ---- */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; margin-bottom: 14px; }
.filters .filter { display: flex; flex-direction: column; gap: 4px; }
.filters .filter__lbl { font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); font-weight: 700; }
.filters select.field__input, .filters input.field__input { padding: 6px 10px; min-width: 130px; font-size: 0.8rem; }
.filters .filter--date input { min-width: 120px; }
/* Smaller, tighter custom dropdown inside the filter bar so labels fit. */
.filters .cs__trigger { padding: 6px 10px; font-size: 0.8rem; }
.filters .cs__menu { font-size: 0.8rem; padding: 4px; }
.filters .cs__opt { padding: 6px 10px; font-size: 0.8rem; white-space: nowrap; }
.filters .filter-reset { align-self: flex-end; }
.filters .filter-custom { display: flex; gap: 8px; align-items: flex-end; }
.filters .filter-custom .filter { flex: 1 1 0; min-width: 0; }
.filters .filter-custom input[type="date"] { min-width: 0; width: 100%; }
.filters input[type="date"].field__input { -webkit-appearance: none; appearance: none; }
@media (max-width: 640px) {
  .filters .filter, .filters select.field__input, .filters input.field__input { min-width: 0; flex: 1 1 140px; }
  /* Custom From/To take a full row together and split it evenly — never oversized. */
  .filters .filter-custom { flex: 1 1 100%; }
  .filters input[type="date"].field__input { font-size: 0.8rem; padding: 7px 8px; }
}

/* The admin ticket tables should fill the panel and not wrap awkwardly. */
#open-list .tbl-wrap, #history-list .tbl-wrap { width: 100%; }
#open-list .tbl td, #history-list .tbl td { white-space: nowrap; }

/* ---- Admin: sidebar layout ---- */
.admin-layout { display: grid; grid-template-columns: 220px 1fr; gap: 26px; align-items: start; }
.admin-side { display: flex; flex-direction: column; gap: 1px; position: sticky; top: 16px; }
.side-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: none; border: none; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--muted);
  padding: 7px 12px; border-radius: 10px; transition: background 0.12s ease, color 0.12s ease;
}
a.side-btn { text-decoration: none; }
.side-btn:hover { background: rgba(16,24,40,0.05); color: var(--ink); }
.side-btn.is-active { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); }
.side-btn__ic { width: 20px; text-align: center; }
.side-sep { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); padding: 10px 12px 3px; }
@media (max-width: 820px) {
  .admin-layout { grid-template-columns: 1fr; gap: 16px; }
  .admin-side { flex-direction: row; flex-wrap: wrap; position: static; gap: 6px; }
  .side-btn { width: auto; }
  .side-sep { flex-basis: 100%; padding: 6px 4px 0; }
}

/* ---- Section header (title + add button) ---- */
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sec-head .section-title { margin: 0; }

/* ---- Data tables ---- */
/* The frame is the scroll container: it scrolls horizontally on narrow screens
   (so the page never does) and vertically when rows overflow its max height. */
.tbl-wrap { overflow: auto; -webkit-overflow-scrolling: touch; max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.dt-wrap { max-height: 65vh; }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tbl th { text-align: left; font-size: 0.71rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); font-weight: 700; padding: 11px 14px; border-bottom: 1px solid var(--border); background: #fafbfc; white-space: nowrap; }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: color-mix(in srgb, var(--primary) 4%, transparent); }
.tbl__click { cursor: pointer; }

/* Frozen header row + frozen first column (used by DataTable and ticket tables).
   Cells need a solid background so scrolled content doesn't show through. */
.tbl--sticky { min-width: max-content; }
.tbl--sticky th, .tbl--sticky td { white-space: nowrap; }
.tbl--sticky thead th { position: sticky; top: 0; z-index: 3; }
.tbl--sticky tbody td:first-child,
.tbl--sticky tbody th:first-child { position: sticky; left: 0; z-index: 2; background: var(--card); box-shadow: 1px 0 0 var(--border); }
.tbl--sticky thead th:first-child { left: 0; z-index: 4; box-shadow: 1px 0 0 var(--border); }
.tbl--sticky tbody tr:hover td:first-child { background: color-mix(in srgb, var(--primary) 4%, var(--card)); }
.tbl--sticky .dt-empty-row td:first-child { position: static; box-shadow: none; }

/* DataTable chrome: search box + pagination footer */
.dt-search { margin-bottom: 10px; }
.dt-search__input { max-width: 320px; }
.dt-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.dt-foot__info { font-size: 0.82rem; color: var(--muted); }
.dt-foot__btns { display: flex; align-items: center; gap: 8px; }
.dt-foot__page { font-size: 0.82rem; color: var(--muted); min-width: 84px; text-align: center; }
.dt-empty { text-align: center; color: var(--muted); padding: 22px 14px; }

/* "Install app" floating button + iOS instructions sheet */
.install-fab { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 9000; display: inline-flex; align-items: center; gap: 8px; background: var(--ink); color: #fff; border: none; border-radius: 999px; padding: 10px 12px 10px 16px; font: inherit; font-weight: 700; font-size: 0.9rem; box-shadow: var(--shadow-lg); cursor: pointer; }
.install-fab__ic { font-size: 1.05rem; }
.install-fab__x { margin-left: 4px; opacity: 0.65; font-size: 0.78rem; padding: 2px 5px; border-radius: 6px; }
.install-fab__x:hover { opacity: 1; background: rgba(255,255,255,0.16); }
.install-sheet-back { position: fixed; inset: 0; background: rgba(16,24,40,0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 10000; padding: 16px; animation: fade 0.12s ease; }
.install-sheet { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 420px; padding: 20px; }
.install-sheet h3 { margin: 0 0 12px; font-size: 1.1rem; }
.install-steps { margin: 0 0 16px; padding-left: 20px; display: flex; flex-direction: column; gap: 9px; color: var(--ink); font-size: 0.92rem; line-height: 1.45; }
.install-share { display: inline-block; font-weight: 700; }

/* "+N more" chip + its floating popover (anchored to the chip, not the cursor) */
.more-chip { position: relative; display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 18px; padding: 0 6px; border-radius: 999px; background: color-mix(in srgb, var(--primary) 12%, #fff); color: var(--primary); font-size: 0.7rem; font-weight: 800; border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border)); vertical-align: middle; cursor: default; }
.more-pop { display: none; } /* data holder only; rendered via the floating tip */
.chip-pop-float { position: fixed; transform: translate(-50%, -100%); z-index: 9999; background: var(--ink); color: #fff; font-size: 0.78rem; line-height: 1.55; padding: 8px 11px; border-radius: 9px; box-shadow: var(--shadow-lg); max-width: 320px; pointer-events: none; display: none; }

/* Levels & assignment-rules editor — one compact row per level */
.lvl-rows { display: flex; flex-direction: column; gap: 8px; }
.lvl-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lvl-row__tag { font-weight: 800; color: var(--muted); min-width: 26px; font-size: 0.85rem; }
.lvl-row .lvl-name { flex: 0 1 240px; max-width: 240px; padding: 7px 10px; font-size: 0.88rem; }
.lvl-row .ms-roles { flex: 0 1 300px; min-width: 0; }
.ms-roles .ms-btn { width: 100%; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lvl-row__rule { display: flex; align-items: center; gap: 8px; }
.lvl-row__lbl { font-size: 0.78rem; color: var(--muted); }
.ms { position: relative; }
.ms-btn { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 10px; font: inherit; font-size: 0.85rem; cursor: pointer; min-width: 150px; text-align: left; }
.ms-btn::after { content: "▾"; color: var(--muted); margin-left: 8px; float: right; }
.ms-pop { position: absolute; top: calc(100% + 4px); left: 0; z-index: 60; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 6px; min-width: 220px; max-height: 260px; overflow: auto; }
.ms-opt { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px; font-size: 0.84rem; cursor: pointer; white-space: nowrap; }
.ms-opt:hover { background: color-mix(in srgb, var(--primary) 6%, transparent); }

/* Stacked configuration blocks on the Settings page */
.config-stack { display: flex; flex-direction: column; gap: 22px; margin-top: 6px; }
.config-block { }
.config-block .sec-head { margin-bottom: 12px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.ibtn { border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: 5px 11px; font: inherit; font-size: 0.82rem; font-weight: 600; color: var(--ink); cursor: pointer; transition: border-color 0.12s ease, color 0.12s ease; }
.ibtn:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); color: var(--primary); }

/* ---- Modal dialog ---- */
.modal-back { position: fixed; inset: 0; background: rgba(16,24,40,0.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 100; animation: fade 0.12s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; max-height: 88vh; overflow: auto; animation: cs-pop 0.14s ease; }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card); }
.modal__head h3 { margin: 0; font-size: 1.05rem; }
.modal__x { border: none; background: none; cursor: pointer; font-size: 1rem; color: var(--muted); }
.modal__body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal__body .field { margin: 0; }
.modal__foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--border); }
.modal__foot .btn { width: auto; }
.modal .form-error { margin: 0 18px; }

/* Ticket detail popup */
.modal--wide { max-width: 640px; }
.tkt-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.tkt-tl-title { margin: 18px 0 10px; font-size: 0.95rem; }
.tkt-thumb { display: block; }
.tkt-thumb img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 8px; display: block; background: #eef0f3; }

/* Themed confirm/alert dialog (replaces window.confirm / alert) */
.modal--dialog { max-width: 420px; align-self: center; }
.modal-back:has(.modal--dialog) { align-items: center; }
.dialog__msg { margin: 0; font-size: 0.98rem; line-height: 1.5; }
.btn--danger-solid { background: #dc2626; border-color: #dc2626; box-shadow: 0 2px 8px rgba(220,38,38,0.28); }
.btn--danger-solid:hover { background: #b91c1c; border-color: #b91c1c; }

/* ---- Dashboard ---- */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.dash-grid .dash-card { margin-bottom: 0; }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi__label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.kpi__val { font-size: 1.9rem; font-weight: 800; margin-top: 8px; }
.dash-card { margin-bottom: 16px; }
.dash-card__title { margin: 0 0 14px; font-size: 1rem; }
.dash-h { font-size: 1.05rem; margin: 24px 0 12px; }
/* ---- Issues-over-time column chart ---- */
.ts-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.ts-head .dash-card__title { margin: 0; }
.ts-toggle { display: inline-flex; background: #eef0f3; border-radius: 10px; padding: 3px; gap: 3px; }
.ts-toggle button { border: none; background: none; cursor: pointer; font: inherit; font-weight: 600; font-size: 0.82rem; color: var(--muted); padding: 6px 12px; border-radius: 8px; }
.ts-toggle button.is-on { background: #fff; color: var(--primary); box-shadow: var(--shadow); }
.col-chart { display: flex; align-items: flex-end; gap: 6px; height: 168px; padding-top: 8px; overflow-x: auto; }
.col { flex: 1 1 0; min-width: 22px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 5px; height: 100%; }
.col__bar { width: 62%; min-width: 12px; min-height: 2px; background: var(--primary); border-radius: 6px 6px 0 0; transition: height 0.4s ease; }
.col__val { font-size: 0.7rem; font-weight: 700; }
.col__lbl { font-size: 0.64rem; color: var(--muted); white-space: nowrap; }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 38px; align-items: center; gap: 10px; }
.bar-row__label { font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row__track { background: #eef0f3; border-radius: 999px; height: 14px; overflow: hidden; }
.bar-row__fill { height: 100%; border-radius: 999px; transition: width 0.5s ease; min-width: 3px; }
.bar-row__val { text-align: right; font-weight: 700; font-size: 0.9rem; }
.metric-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.metric-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.metric-card__val { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.metric-card__label { font-weight: 600; margin-top: 4px; }
.metric-card__sub { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.muted { color: var(--muted); }
.muted-count { color: var(--muted); font-weight: 400; font-size: 0.9rem; }
@media (max-width: 520px) { .bar-row { grid-template-columns: 96px 1fr 32px; } }

/* ---- Admin: rows ---- */
.admin-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 14px 16px; flex-wrap: wrap;
}
.admin-row--stack { flex-direction: column; align-items: stretch; }
.admin-row__top { display: flex; align-items: center; justify-content: space-between; }
.admin-row__name { font-weight: 600; }
.admin-row__name.is-inactive { color: var(--muted); text-decoration: line-through; }
.admin-row__right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-row__edit { flex: 1; min-width: 160px; }
.admin-row__panel {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
}
.admin-row__panel .field__input { width: auto; min-width: 150px; }

/* ---- Clickable ticket cards ---- */
a.ticket-link { text-decoration: none; color: inherit; display: block; transition: transform 0.1s ease, box-shadow 0.15s ease, border-color 0.15s ease; }
a.ticket-link:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); border-color: color-mix(in srgb, var(--primary) 25%, var(--border)); }

/* ---- BU filter bar ---- */
.bu-filter { display: flex; align-items: center; margin-bottom: 14px; }

/* ---- Assigned-tickets groups ---- */
.tkt-group { margin-bottom: 22px; }
.tkt-group__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.tkt-group__title { font-size: 1.02rem; margin: 0; }
.tkt-group__head .btn { flex: 0 0 auto; }

/* ---- Section title ---- */
.section-title { font-size: 1.05rem; margin: 22px 0 12px; }

/* ---- Checkboxes (outlet coverage) ---- */
.checks { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }

/* ---- Ticket actions ---- */
.action-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.action-row .field__input { flex: 1; min-width: 160px; }
.action-close { margin-top: 6px; }
.action-close .btn--primary { margin-top: 10px; }

/* ---- Timeline ---- */
.timeline { position: relative; margin-left: 6px; }
.timeline__item { position: relative; padding: 0 0 18px 22px; border-left: 2px solid var(--border); }
.timeline__item:last-child { border-left-color: transparent; }
.timeline__dot {
  position: absolute; left: -7px; top: 2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--primary); border: 2px solid #fff;
}
.timeline__item--closed .timeline__dot { background: var(--ok); }
.timeline__item--created .timeline__dot { background: var(--muted); }
.timeline__body { font-size: 0.95rem; }
.timeline__when { display: block; color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.timeline__body .thumbs { margin-top: 8px; }

/* ---- Sign-in screen ---- */
.auth-body {
  min-height: 100vh;
  margin: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
  padding: 32px 20px calc(32px + env(safe-area-inset-bottom));
  background:
    radial-gradient(1100px 520px at 50% -8%, color-mix(in srgb, var(--primary) 13%, var(--bg)), transparent 70%),
    var(--bg);
}
.auth__card {
  width: 100%; max-width: 408px;
  background: var(--card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--primary);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: clamp(26px, 5vw, 40px);
  animation: cs-pop 0.18s ease;
}
.auth__logo { height: 42px; width: auto; display: block; margin-bottom: 22px; }
.auth__title { margin: 0; font-size: 1.55rem; font-weight: 800; letter-spacing: -0.01em; }
.auth__sub { margin: 6px 0 26px; color: var(--muted); font-size: 0.95rem; line-height: 1.4; }
.auth__card .field:last-of-type { margin-bottom: 20px; }
.auth__card .btn { margin-top: 2px; }
.auth__foot { margin: 0; color: var(--muted); font-size: 0.8rem; text-align: center; }

/* ---- Lightbox ---- */
.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.lightbox img {
  max-width: 100%; max-height: 100%;
  border-radius: 8px;
}
.lightbox__close {
  position: absolute; top: 16px; right: 16px;
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: rgba(255,255,255,0.15); color: #fff;
  font-size: 1.1rem; cursor: pointer;
}
