:root {
  color-scheme: light;
  --background: #f6f3f7;
  --surface: #fff;
  --text: #251b27;
  --muted: #625967;
  --border: #e7e0e9;
  --primary: #602147;
  --primary-hover: #441932;
  --primary-shadow: #60214726;
  --accent: #913662;
  --accent-soft: #f5eaf2;
  --control-border: #cbc1ce;
  --focus: #a84b86;
  --masthead: linear-gradient(140deg, #3a1a33, #5d224a);
  --brand-subtitle: #efdbe8;
  --page-wash: #f0e4ed;
  --timeline-track: #e7dbe7;
  --timeline-pending: #a491a2;
  --shadow: 0 8px 28px #35203909;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 100%;
  line-height: 1.5;
  color: var(--text);
  background: var(--background);
}

:root.admin-theme {
  --background: #edf4fc;
  --text: #112849;
  --muted: #4b607b;
  --border: #d8e5f3;
  --primary: #1257b6;
  --primary-hover: #0a418d;
  --primary-shadow: #1257b62b;
  --accent: #155daa;
  --accent-soft: #e9f3ff;
  --control-border: #aebfd7;
  --focus: #1974cc;
  --masthead: linear-gradient(155deg, #091e43 0%, #0b2c58 68%, #104781 100%);
  --brand-subtitle: #c6ddfb;
  --page-wash: #d7e9ff;
  --timeline-track: #cddff3;
  --timeline-pending: #647b97;
  --shadow: 0 5px 22px #143d7010;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
h1, h2, h3, p, ol, ul { margin: 0; }
h1, h2, h3 { line-height: 1.12; letter-spacing: -.035em; }
h1 { font-size: clamp(2rem, 5.9vw, 3.3rem); font-weight: 800; }
h2 { font-size: 1.28rem; font-weight: 760; }
h3 { font-size: 1rem; font-weight: 760; }
a { color: inherit; }
button, input, textarea, select { font: inherit; }
button, select { cursor: pointer; }
img { display: block; max-width: 100%; }
label { display: block; font-size: .9rem; font-weight: 680; }
input, textarea, select {
  width: 100%;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: .75rem;
  padding: .7rem .85rem;
  min-height: 2.85rem;
}
textarea { resize: vertical; }
select {
  appearance: none;
  padding-inline-end: 2.1rem;
  background-image: linear-gradient(45deg, transparent 48%, var(--muted) 51%), linear-gradient(135deg, var(--muted) 49%, transparent 52%);
  background-position: right 1rem center, right .7rem center;
  background-size: .3rem .3rem;
  background-repeat: no-repeat;
}
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
::selection { background: var(--page-wash); color: var(--text); }

.skip-link { position: absolute; top: .5rem; left: .5rem; padding: .7rem 1rem; background: white; transform: translateY(-150%); z-index: 9; }
.skip-link:focus { transform: none; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.85rem;
  border: 1px solid transparent;
  border-radius: .75rem;
  padding: .65rem 1rem;
  text-align: center;
  font-weight: 700;
  text-decoration: none;
  transition: background .18s, border .18s, box-shadow .18s;
}
.primary { background: var(--primary); color: white; box-shadow: 0 3px 8px var(--primary-shadow); }
.primary:hover { background: var(--primary-hover); }
.secondary { background: white; border-color: var(--control-border); color: var(--primary); }
.secondary:hover { background: var(--accent-soft); }
.text-link { color: var(--primary); text-underline-offset: .18em; font-weight: 700; }
.section-label { color: var(--accent); font-size: .88rem; font-weight: 760; margin-bottom: .35rem; }
.muted { color: var(--muted); font-size: .9rem; }
.multiline { white-space: pre-wrap; overflow-wrap: anywhere; }
.card { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 1.25rem; box-shadow: var(--shadow); }
.section-heading { display: flex; justify-content: space-between; gap: .6rem 1rem; flex-wrap: wrap; align-items: start; }
.section-heading .muted { margin-top: .3rem; }

.brand { display: inline-flex; align-items: center; gap: .68rem; text-decoration: none; line-height: 1.22; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: .98rem; letter-spacing: -.022em; font-weight: 780; }
.brand small { color: var(--brand-subtitle); font-size: .81rem; margin-top: .15rem; }
.brand-icon { width: 2.6rem; height: 2.6rem; flex: 0 0 auto; border-radius: .85rem; background: #ffffff1a; border: 1px solid #ffffff36; display: grid; place-items: center; }
.brand-icon i { width: .95rem; height: 1.3rem; border-inline: 2px solid currentColor; border-radius: .17rem; transform: skew(-19deg); background: repeating-linear-gradient(to bottom, currentColor 0 .22rem, transparent .22rem .42rem) center / 2px 100% no-repeat; }
.sidebar, .public-header { color: #fff; background: var(--masthead); }
.admin-theme .brand-icon { background: linear-gradient(145deg, #257dd2, #154785); border-color: #66bbff78; }
.sidebar { display: grid; grid-template-columns: 1fr auto; gap: .75rem .5rem; padding: .95rem 1rem .6rem; }
.sidebar .brand { grid-column: 1; }
.sidebar :focus-visible, .admin-theme .public-header :focus-visible { outline-color: #92d6ff; }
.admin-nav { grid-area: 2 / 1 / 3 / 3; display: flex; gap: .45rem; }
.admin-nav a, .public-link, .sign-out { font-size: .88rem; }
.admin-nav a { display: flex; gap: .6rem; align-items: center; min-height: 2.75rem; padding: .55rem .8rem; color: #dbeaff; text-decoration: none; border-radius: .65rem; font-weight: 650; }
.admin-nav a:hover { background: #ffffff20; color: white; }
.admin-nav a[aria-current] { background: #1b589e; box-shadow: inset 3px 0 #65baff; color: white; }
.nav-icon { position: relative; flex: 0 0 auto; width: .94rem; height: .88rem; opacity: .95; }
.nav-grid { background: linear-gradient(currentColor 0 0) 0 0, linear-gradient(currentColor 0 0) 100% 0, linear-gradient(currentColor 0 0) 0 100%, linear-gradient(currentColor 0 0) 100% 100%; background-size: .35rem .35rem; background-repeat: no-repeat; }
.nav-chat { border: 1.5px solid currentColor; border-radius: .25rem; }
.nav-chat::after { content: ""; position: absolute; bottom: -.2rem; left: .15rem; width: .25rem; height: .3rem; border-inline-start: 1.5px solid currentColor; transform: skewY(-30deg); }
.sidebar-footer { display: flex; align-items: center; gap: .65rem; }
.public-link { display: none; }
.sign-out { padding-inline: .55rem; color: #fff; background: transparent; min-height: 2.7rem; }
.sign-out:hover { background: #ffffff1a; }

.workspace { max-width: 98rem; margin-inline: auto; padding: 1.4rem 1rem 2.6rem; width: 100%; min-width: 0; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: .75rem 1rem; margin-bottom: 1.2rem; }
.report-heading {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: clamp(1rem, 3vw, 2rem);
  border-radius: 1.25rem;
  color: #fff;
  background: radial-gradient(ellipse at 100% 0%, #2486e6, transparent 68%),
    linear-gradient(115deg, #09234b, #0a478e 70%, #145cab);
  box-shadow: 0 9px 24px #133f7030;
}
.report-heading::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset-block: -2.5rem;
  inset-inline-end: clamp(-2rem, 4vw, 5rem);
  width: clamp(4rem, 13vw, 9rem);
  border-inline: 2px solid #b9e4ff5c;
  background: repeating-linear-gradient(#def1ff88 0 .85rem, transparent .85rem 1.65rem) center / 3px 100% no-repeat, #bbdefa1e;
  opacity: .68;
  transform: skewX(-26deg);
}
.report-heading .section-label { display: flex; align-items: center; gap: .45rem; color: #e8f5ff; font-style: italic; }
.report-heading .section-label::before { content: ""; width: 1.15rem; height: .24rem; border-radius: .2rem; background: #f667b4; transform: skewX(-23deg); }
.report-heading h1 { font-weight: 840; }
.connection { display: inline-flex; gap: .45rem; align-items: center; border: 1px solid #bcd4ef; border-radius: 1.5rem; color: #163f71; background: #eaf4ff; padding: .36rem .68rem; font-size: .84rem; font-weight: 700; }
.connection.online { border-color: #c0d9cd; color: #1e5945; background: #edf8f1; }
.connection::before { content: ""; width: .42rem; height: .42rem; border-radius: 50%; background: currentColor; }
.filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; align-items: end; margin-bottom: 1.15rem; padding: .75rem; border: 1px solid var(--border); border-radius: 1rem; background: #f7fbff; }
.filters label { margin-bottom: .24rem; }
.filters select { padding-inline: .7rem 1.65rem; }
.filters .button { grid-column: 1 / -1; width: 100%; }
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .66rem; }
.metric { display: grid; align-content: center; gap: .35rem; min-height: 6.35rem; padding: .85rem; text-decoration: none; border-top: 4px solid var(--mark, var(--primary)); transition: background .18s, border-color .18s, box-shadow .18s; }
.metric:hover, .metric[aria-current] { background: #f7fbff; box-shadow: 0 0 0 1px var(--mark, var(--primary)) inset, var(--shadow); }
.metric span { font-size: .89rem; font-weight: 680; color: var(--muted); }
.metric strong { font-size: clamp(1.75rem, 5vw, 2.4rem); line-height: 1.08; font-variant-numeric: tabular-nums; color: var(--ink, var(--primary)); }
.new { --mark: #bd3656; --ink: #962440; --tint: #fae8ee; }
.active { --mark: #bd740f; --ink: #824602; --tint: #fdf1d8; }
.done { --mark: #258164; --ink: #175c45; --tint: #e1f4eb; }
.status { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: .36rem; padding: .32rem .58rem; color: var(--ink); background: var(--tint); border-radius: 1rem; font-size: .82rem; font-weight: 740; line-height: 1.25; white-space: nowrap; }
.status::before { content: ""; width: .42rem; height: .42rem; background: var(--mark); border-radius: 50%; }

.overview-grid { display: grid; gap: .85rem; margin-block: 1rem; }
.map-card, .activity-card, .reports-card, .detail-card, .tracking-result { padding: 1rem; }
.map-frame {
  position: relative;
  margin-top: .85rem;
  border: 1px solid var(--border);
  border-radius: .9rem;
  min-height: 15rem;
  isolation: isolate;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #f5faff 20%, transparent 75%),
    linear-gradient(#c9dff280 1px, transparent 1px) 0 0 / 1.4rem 1.4rem,
    linear-gradient(90deg, #c9dff280 1px, transparent 1px) 0 0 / 1.4rem 1.4rem,
    #e8f3ff;
}
.map-placeholder { position: absolute; inset: 0; display: grid; gap: .75rem; place-content: center; justify-items: center; text-align: center; padding: 1rem 1.4rem; color: var(--muted); font-size: .9rem; font-weight: 600; }
.map-placeholder::before { content: ""; width: 1.5rem; height: 1.5rem; border: 2px solid var(--primary); border-radius: 50% 50% 50% 14%; background: radial-gradient(circle, var(--primary) 20%, #fff 23%); transform: rotate(-45deg); }
.map-legend { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .75rem; }
.map-pin { display: grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50% 50% 50% 7%; transform: rotate(-45deg); color: white; background: var(--ink); border: 2px solid white; box-shadow: 0 2px 7px #20132155; font: 750 .9rem system-ui; }
.map-popup { display: grid; gap: .45rem; width: 11rem; font-size: .86rem; }
.map-popup .status { justify-self: start; }
.map-popup img { width: 100%; height: 6.8rem; object-fit: cover; border-radius: .5rem; background: var(--accent-soft); }
.map-popup a { overflow-wrap: anywhere; }
.activity-chart { display: grid; grid-template-columns: repeat(var(--bar-count), minmax(0, 1fr)); gap: clamp(.15rem, .7vw, .43rem); height: 9.2rem; margin-top: 1rem; }
.chart-column { display: grid; grid-template-rows: 1fr 1.4rem; justify-items: center; min-width: 0; }
.chart-track { display: flex; align-items: flex-end; width: 100%; background: #e8f2ff; border-radius: .37rem .37rem .18rem .18rem; }
.chart-bar { width: 100%; height: var(--bar-height); background: linear-gradient(#328ee5, #1257b6); border-radius: .35rem .35rem .18rem .18rem; transform-origin: bottom; animation: bar-rise .6s ease-out var(--bar-delay) both; }
.chart-bar.zero { height: .18rem; background: #a8c2e5; }
.chart-day { font-size: .76rem; margin-top: .15rem; color: var(--muted); font-variant-numeric: tabular-nums; }
@keyframes bar-rise { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.distribution { display: grid; gap: .52rem; margin-top: 1rem; padding-top: .85rem; border-top: 1px solid var(--border); }
.distribution-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .24rem; font-size: .86rem; }
.progress-track { grid-column: 1 / -1; height: .35rem; border-radius: .4rem; background: var(--accent-soft); overflow: hidden; }
.progress-fill { display: block; width: var(--proportion); height: 100%; border-radius: inherit; background: var(--mark); transform-origin: left; animation: progress .65s ease-out both; }
@keyframes progress { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.empty-state { padding: 1rem; margin-top: .85rem; color: var(--muted); background: #f7fbff; border: 1px dashed var(--control-border); border-radius: .8rem; }
.report-list { list-style: none; padding: 0; margin-top: .7rem; }
.report-list li + li { border-top: 1px solid var(--border); }
.report-row { display: grid; grid-template-columns: 3.1rem minmax(0, 1fr); gap: .35rem .7rem; padding: .7rem .25rem; align-items: center; text-decoration: none; border-radius: .45rem; }
.report-row:hover { background: #f1f7ff; }
.report-row-main { display: grid; gap: .12rem; min-width: 0; }
.report-thumb { grid-row: span 2; aspect-ratio: 1; object-fit: cover; border-radius: .65rem; background: var(--accent-soft); }
.folio { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.report-row .folio { font-size: .87rem; }
.report-row time, .timeline time { color: var(--muted); font-size: .85rem; }
.report-row > .status { justify-self: start; grid-column: 2; }
.row-action { display: none; }
.pagination { display: flex; flex-wrap: wrap; justify-content: end; align-items: center; gap: .6rem; font-size: .88rem; margin-top: 1rem; }

.return-link { display: inline-block; margin-bottom: 1rem; }
.detail-heading h1 { font-size: clamp(1.45rem, 4vw, 2.1rem); }
.detail-grid, .detail-stack { display: grid; align-items: start; gap: .9rem; }
.detail-card > h2 { margin-bottom: .45rem; }
.form-stack { display: grid; gap: .62rem; }
.form-stack label:not(:first-child) { margin-top: .25rem; }
.form-actions { display: flex; flex-direction: column; gap: .6rem; margin-top: .3rem; }
.report-photo { width: 100%; max-height: 34rem; object-fit: contain; background: var(--accent-soft); border-radius: .8rem; margin-top: .85rem; }
.location { display: flex; justify-content: space-between; align-items: center; gap: .65rem; flex-wrap: wrap; margin-top: .85rem; font-size: .9rem; }
.timeline { list-style: none; margin-top: .65rem; padding: .3rem 0 0 .6rem; }
.timeline li { position: relative; display: grid; gap: .2rem; border-left: 2px solid var(--timeline-track); padding: 0 .1rem 1.15rem 1.05rem; }
.timeline li:last-child { padding-bottom: .1rem; border-color: transparent; }
.timeline li::before { content: ""; position: absolute; left: -.47rem; top: .14rem; width: .76rem; height: .76rem; border-radius: 50%; background: var(--mark, var(--timeline-pending)); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--mark, var(--timeline-pending)); }
.timeline li.pending::before { background: white; }
.timeline li p { color: var(--muted); font-size: .93rem; }
.notice, .error-message, .success-message { padding: .65rem .78rem; border-radius: .65rem; font-size: .9rem; font-weight: 600; }
.notice { background: var(--accent-soft); color: var(--primary); }
.error-message { background: #fbebee; color: #92213c; }
.success-message { background: #e4f4eb; color: #18563f; margin-bottom: .75rem; }
.chat-preview { display: grid; gap: .7rem; padding: .85rem; margin-top: .9rem; background: var(--accent-soft); border-radius: .85rem; }
.chat-preview p { max-width: 92%; padding: .62rem .75rem; border-radius: .78rem; font-size: .92rem; }
.chat-user { justify-self: end; background: var(--page-wash); }
.chat-assistant { background: #fff; }

.public-body { min-height: 100svh; background: radial-gradient(ellipse at 15% 17%, var(--page-wash), transparent 40rem), var(--background); }
.public-header { padding-block: .85rem; }
.public-shell { width: min(calc(100% - 2rem), 67rem); margin-inline: auto; }
.public-content { padding-block: clamp(1.9rem, 6.5vw, 4.5rem) 2.1rem; }
.tracking-intro { display: grid; gap: 1.3rem; align-items: center; }
.tracking-intro h1 { max-width: 16ch; font-size: clamp(2.25rem, 7.9vw, 4.05rem); }
.lede { margin-top: .75rem; max-width: 42ch; color: var(--muted); }
.public-form, .login-form { display: grid; gap: .6rem; padding: 1rem; }
.public-form input { font-variant-numeric: tabular-nums; }
.tracking-result { margin-top: 1.2rem; }
.tracking-result .section-heading { margin-bottom: 1rem; }
.tracking-result .folio { margin-top: .3rem; }
.public-footer { color: var(--muted); padding-block: .85rem 1.8rem; border-top: 1px solid #e4dbe5; font-size: .9rem; }
.login-shell { max-width: 27rem; display: grid; gap: 1.2rem; padding-block: clamp(2rem, 8vw, 5rem); }

@media (max-width: 23rem) {
  .filters { grid-template-columns: minmax(0, 1fr); }
}
@media (min-width: 40rem) {
  .workspace { padding: 1.8rem 1.6rem 3rem; }
  .public-link { display: inline-block; color: #fff; text-underline-offset: .18em; }
  .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .8rem; }
  .metric { padding: 1rem; }
  .filters { width: fit-content; grid-template-columns: repeat(2, minmax(10rem, 13rem)) auto; }
  .filters .button { grid-column: auto; }
  .report-row { grid-template-columns: 3.5rem minmax(0, 1fr) auto; padding: .72rem .35rem; }
  .report-thumb { grid-row: auto; }
  .report-row > .status { grid-column: auto; }
  .tracking-intro { grid-template-columns: 1.1fr 1fr; gap: 1.6rem; }
  .tracking-result { margin-top: 2rem; }
}
@media (min-width: 64rem) {
  .admin-body { display: grid; grid-template-columns: 13.5rem minmax(0, 1fr); }
  .sidebar { position: sticky; top: 0; min-height: 100svh; max-height: 100svh; display: flex; flex-direction: column; padding: 1.45rem .85rem 1rem; overflow: auto; }
  .sidebar .brand { margin-inline: .35rem; }
  .admin-nav { flex-direction: column; margin-top: 1.25rem; }
  .admin-nav a { padding-inline: .85rem; }
  .sidebar-footer { margin-top: auto; flex-direction: column; align-items: stretch; gap: .52rem; }
  .public-link { padding-inline: .55rem; }
  .sign-out { justify-content: start; width: 100%; }
  .workspace { padding: 2.05rem clamp(1.35rem, 3vw, 3.15rem) 3rem; }
  .page-heading { align-items: center; }
  .overview-grid { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 1rem; }
  .map-card { display: flex; flex-direction: column; }
  .map-frame { flex: 1; min-height: 15rem; }
  .overview-grid, .metrics, .detail-grid { gap: 1rem; }
  .detail-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
  .map-card, .activity-card, .reports-card, .detail-card, .tracking-result, .public-form, .login-form { padding: 1.2rem; }
  .report-row { grid-template-columns: 3.5rem minmax(0, 1fr) auto 6rem; }
  .row-action { display: inline; text-align: end; color: var(--primary); font-size: .86rem; font-weight: 700; }
  .form-actions { flex-direction: row; flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::after, *::before { animation: none !important; transition: none !important; }
}
