:root {
  --blue: #173b66;
  --blue-2: #235484;
  --gold: #d7a531;
  --gold-2: #fff6dc;
  --ink: #152237;
  --muted: #637083;
  --line: #dfe6ee;
  --bg: #f5f7fa;
  --white: #fff;
  --green: #23815b;
  --red: #b5473f;
  --orange: #c86b22;
  --shadow: 0 14px 42px rgba(23, 59, 102, .08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  background: var(--blue);
  color: white;
  padding: 10px 14px;
  font-weight: 750;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
button:hover { background: var(--blue-2); box-shadow: 0 8px 18px rgba(23, 59, 102, .16); transform: translateY(-1px); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(215, 165, 49, .38);
  outline-offset: 2px;
}
button.secondary { background: #e8eef5; color: var(--blue); }
button.secondary:hover { background: #dce6f0; }
button.ghost { background: transparent; color: var(--blue); border: 1px solid var(--line); }
button.gold { background: var(--gold); color: #2e2302; }
button.gold:hover { background: #c8992c; }
button:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
button[aria-busy="true"] { position: relative; }
button[aria-busy="true"]::after { content: ""; width: 12px; height: 12px; margin-left: 8px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; vertical-align: -2px; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
select:disabled { opacity: .62; color: var(--muted); background: #f4f7fa; cursor: not-allowed; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 11px;
  background: white;
  color: var(--ink);
}
textarea { min-height: 92px; resize: vertical; line-height: 1.45; }
label { display: grid; gap: 7px; font-size: 13px; font-weight: 750; color: #344255; }
a { color: var(--blue-2); font-weight: 700; }
h3 { margin: 0 0 12px; color: var(--blue); font-size: 17px; line-height: 1.25; }
p { margin: 0; line-height: 1.5; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 80% 10%, rgba(215, 165, 49, .24), transparent 30%),
    linear-gradient(145deg, var(--blue), #326795 58%, #f2d990);
}
.login-card {
  width: min(460px, 100%);
  background: var(--white);
  border: 1px solid rgba(255,255,255,.72);
  border-radius: var(--radius);
  padding: 30px;
  box-shadow: 0 28px 90px rgba(9, 31, 54, .30);
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; min-width: 0; }
.brand-logo { width: 148px; max-width: 44vw; height: auto; display: block; padding: 8px; border-radius: var(--radius); background: var(--blue); }
.brand h1 { font-size: 23px; line-height: 1.12; margin: 0; color: var(--blue); letter-spacing: 0; }
.helper { color: var(--muted); font-size: 13px; line-height: 1.45; }
.demo-logins { margin-top: 18px; padding: 14px; background: #f7f9fb; border-radius: var(--radius); border: 1px solid var(--line); }
.error { color: var(--red); font-weight: 750; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 276px minmax(0, 1fr); }
.side {
  min-width: 0;
  background: linear-gradient(180deg, var(--blue), #14375e);
  color: white;
  padding: 22px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,.08);
}
.side .brand { display: grid; gap: 12px; margin-bottom: 24px; }
.side .brand h1 { color: white; font-size: 17px; max-width: 210px; }
.side .brand-logo { width: 178px; max-width: 100%; padding: 0; background: transparent; }
.nav { display: grid; gap: 7px; min-width: 0; max-width: 100%; }
.nav button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  color: rgba(255,255,255,.9);
}
.nav button .nav-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,.11);
  color: white;
}
.nav button .nav-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav button .nav-label { min-width: 0; overflow-wrap: anywhere; }
.nav button.active, .nav button:hover { background: rgba(255,255,255,.13); border-color: rgba(255,255,255,.18); box-shadow: none; }
.nav button.active .nav-icon { background: var(--gold); color: #2e2302; }
.main { min-width: 0; }
.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 3;
}
.topbar > div:first-child { display: grid; gap: 7px; min-width: 0; }
.topbar strong { color: var(--blue); font-size: 15px; }
.userbox { display: flex; align-items: center; gap: 10px; }
.userbox select { min-width: 126px; }
.role-pill {
  width: fit-content;
  max-width: 100%;
  padding: 5px 9px;
  background: var(--gold-2);
  border: 1px solid #f0d888;
  color: #664d04;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: normal;
}
.content { width: min(1480px, 100%); padding: 28px; display: grid; gap: 22px; }
.section-head { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.section-head h2 { margin: 0; color: var(--blue); font-size: 28px; line-height: 1.1; letter-spacing: 0; }
.grid { display: grid; gap: 16px; }
.cards { grid-template-columns: repeat(5, minmax(150px, 1fr)); }
.two { grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr); align-items: start; }
.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card, .item {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 18px; }
.stat { min-height: 118px; display: grid; align-content: space-between; border-top: 4px solid var(--gold); }
.stat strong { font-size: 34px; line-height: 1; color: var(--blue); letter-spacing: 0; }
.stat span { color: var(--muted); font-weight: 850; line-height: 1.25; }
.toolbar { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.full { grid-column: 1 / -1; }
.list { display: grid; gap: 14px; }
.item { padding: 16px; display: grid; gap: 12px; }
.item-head { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.item h3 { margin: 0; font-size: 18px; }
.item > p { color: #344255; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 13px; align-items: center; }
.badge { border-radius: 999px; padding: 5px 9px; font-size: 12px; line-height: 1; font-weight: 850; background: #edf2f7; color: #344255; white-space: nowrap; }
.badge.Open, .badge.Received { background: #e5f3ff; color: #134f7c; }
.badge.Claimed, .badge.Accepted { background: var(--gold-2); color: #735404; }
.badge.In, .badge.Under { background: #e8f4ed; color: var(--green); }
.badge.Completed, .badge.Served, .badge.Passed { background: #e6f5ed; color: var(--green); }
.badge.Emergency, .badge.Rejected, .badge.Cancelled, .badge.Failed { background: #ffe8e5; color: var(--red); }
.badge.High { background: #fff0df; color: var(--orange); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions select, .actions input { width: auto; min-width: 160px; }
.activity { margin: 0; padding: 0; list-style: none; display: grid; gap: 0; }
.activity li { padding: 12px 0; border-bottom: 1px solid var(--line); color: #344255; }
.activity li:first-child { padding-top: 0; }
.activity li:last-child { border-bottom: 0; padding-bottom: 0; }
.activity small { display: block; color: var(--muted); margin-top: 4px; }
.table { width: 100%; border-collapse: collapse; min-width: 680px; }
.table th, .table td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--blue); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table tr:last-child td { border-bottom: 0; }
.card:has(.table) { overflow-x: auto; }
.chart-row { display: grid; grid-template-columns: minmax(110px, 150px) 1fr 38px; gap: 10px; align-items: center; margin: 10px 0; }
.bar { height: 12px; background: #e8eef5; border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--gold); }
.message { border-left: 4px solid var(--gold); }
.unread { border-color: var(--gold); background: #fffdf6; }
.small { font-size: 12px; color: var(--muted); }
.mobile-menu { display: none; }

@media (max-width: 1240px) {
  .cards { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
  .three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: static;
    height: auto;
    padding: 16px;
    overflow: visible;
  }
  .side .brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
  }
  .side .brand h1 { max-width: none; font-size: 16px; }
  .side .brand-logo { width: 150px; }
  .nav {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    min-width: 0;
    max-width: 100%;
    gap: 8px;
    overflow: visible;
    padding-bottom: 0;
  }
  .nav button {
    width: 100%;
    min-width: 0;
    grid-template-columns: 28px auto;
    padding: 8px 11px;
  }
  .nav button .nav-icon { width: 28px; height: 28px; }
  .topbar { position: static; padding: 14px 18px; }
  .content { padding: 22px 18px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two, .three { grid-template-columns: 1fr; }
  .toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .login-card { padding: 22px; }
  .login-card .brand { display: grid; }
  .brand-logo { width: 168px; max-width: 100%; }
  .topbar { display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; justify-items: stretch; }
  .topbar > * { width: 100%; }
  .userbox { width: 100%; justify-self: stretch; display: grid; grid-template-columns: 1fr auto; }
  .userbox select, .userbox button { width: 100%; }
  .content { gap: 16px; }
  .section-head { display: grid; }
  .section-head h2 { font-size: 24px; }
  .cards, .toolbar, .form-grid { grid-template-columns: 1fr; }
  .stat { min-height: 96px; }
  .item-head { display: grid; }
  .actions { display: grid; grid-template-columns: 1fr; }
  .actions button, .actions select, .actions input { width: 100%; min-width: 0; }
  .chart-row { grid-template-columns: minmax(84px, 110px) 1fr 30px; }
}

@media (max-width: 430px) {
  .login-page { padding: 14px; }
  .side { padding: 14px; }
  .side .brand { display: grid; }
  .side .brand-logo { width: 164px; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav button { font-size: 13px; gap: 8px; padding: 8px; }
  .topbar { padding: 13px 14px; }
  .content { padding: 16px 14px; }
  .card, .item { padding: 14px; }
  .userbox { grid-template-columns: 1fr; }
  .role-pill { width: 100%; }
}

.legal-links { margin-top: 16px; display: flex; justify-content: center; gap: 10px; color: var(--muted); font-size: 13px; }
.legal-page { min-height: 100vh; padding: 32px 18px; background: var(--bg); display: grid; place-items: start center; }
.legal-card { width: min(860px, 100%); background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; display: grid; gap: 16px; }
.legal-card .brand-logo { width: 210px; max-width: 100%; background: var(--blue); }
.legal-card h1 { margin: 8px 0 0; color: var(--blue); font-size: 32px; line-height: 1.1; }
.legal-card h2 { margin: 10px 0 0; color: var(--blue); font-size: 18px; }
.legal-card p { color: #344255; }
button.danger { color: var(--red); border-color: #f0cbc7; background: #fff7f6; }
button.danger:hover { background: #ffe8e5; color: var(--red); }
button.inline { min-height: 30px; padding: 5px 8px; font-size: 12px; }

.user-section { display: grid; gap: 12px; }
.user-section-head { display: grid; gap: 3px; margin-bottom: 4px; }
.user-section-head h3 { margin-bottom: 0; }
.user-table select { min-width: 170px; }
.empty-cell { color: var(--muted); font-size: 13px; padding: 18px 10px; }
@media (max-width: 700px) {
  .user-table select { min-width: 0; }
}

.version-banner {
  margin: 16px 28px 0;
  padding: 12px 14px;
  border: 1px solid #f0d888;
  border-radius: var(--radius);
  background: var(--gold-2);
  color: #664d04;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  font-weight: 750;
}
.version-banner[hidden], .nav-badge[hidden] { display: none; }
.refresh-meta { color: var(--muted); font-size: 12px; font-weight: 750; white-space: nowrap; }
.nav-badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 6px; padding: 0 6px; border-radius: 999px; background: var(--gold); color: #2e2302; font-size: 11px; font-weight: 900; }
.message-layout { grid-template-columns: minmax(240px, 320px) minmax(0, 1fr); align-items: start; }
.conversation-list { display: grid; gap: 8px; }
.conversation-button { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; background: #f7f9fb; color: var(--blue); border: 1px solid var(--line); box-shadow: none; }
.conversation-button.active, .conversation-button:hover { background: var(--blue); color: white; box-shadow: none; transform: none; }
.conversation-button span { flex: 0 0 auto; min-width: 24px; height: 24px; border-radius: 999px; display: grid; place-items: center; background: rgba(23, 59, 102, .1); font-size: 12px; }
.conversation-button.active span, .conversation-button:hover span { background: rgba(255,255,255,.18); }
.thread-panel { display: grid; gap: 14px; }
.thread-messages { display: grid; gap: 10px; }
.message-compose { border-top: 1px solid var(--line); padding-top: 14px; }
@media (max-width: 980px) {
  .message-layout { grid-template-columns: 1fr; }
  .version-banner { margin: 14px 18px 0; }
}
@media (max-width: 700px) {
  .version-banner { display: grid; margin: 12px 14px 0; }
}

.empty-state { display: grid; gap: 12px; align-content: start; }
.empty-state h3 { margin-bottom: 0; }
