:root {
  --bg: #f3f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fbfe;
  --ink: #102033;
  --muted: #64748b;
  --line: #d8e3ee;
  --green: #0f7a68;
  --green-dark: #0b5f52;
  --blue: #2377ad;
  --cyan: #0e8aa6;
  --rose: #b8465b;
  --amber: #b7791f;
  --shadow: 0 16px 42px rgba(37, 66, 94, 0.10);
  --soft-shadow: 0 8px 24px rgba(37, 66, 94, 0.08);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: linear-gradient(180deg, #eef6fb 0, #f7fafc 260px, var(--bg) 100%);
  font-family: Aptos, "Segoe UI Variable", "Segoe UI", Inter, Roboto, Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 70px;
  border-bottom: 1px solid rgba(221, 231, 223, 0.95);
  padding: 14px 28px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 30px rgba(15, 78, 115, 0.12);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  flex: 0 1 270px;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  place-items: center;
  border: 1px solid rgba(23, 111, 92, 0.22);
  border-radius: 10px;
  background: #ffffff;
  color: var(--green-dark);
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(9, 45, 70, 0.10);
}

.brand-text {
  min-width: 0;
}

.brand-text strong,
.brand-text small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-text strong {
  font-size: 17px;
  font-weight: 900;
}

.brand-text small {
  color: var(--muted);
  font-size: 13px;
}

.nav-list {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}

.nav-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
  white-space: nowrap;
}

.nav-button:hover,
.nav-button:focus {
  border-color: rgba(23, 111, 92, 0.14);
  color: var(--green-dark);
  background: #eef7f2;
  outline: 0;
}

.nav-button.active {
  border-color: rgba(23, 111, 92, 0.2);
  color: #ffffff;
  background: var(--green-dark);
}

.profile-button,
.mobile-menu-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: #f8fbf8;
  font-weight: 900;
}

.mobile-menu-button {
  display: none;
  position: relative;
}

.menu-icon {
  grid-area: 1 / 1;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.menu-close-icon {
  opacity: 0;
  transform: rotate(-45deg) scale(0.82);
}

.mobile-menu-open .menu-open-icon {
  opacity: 0;
  transform: rotate(45deg) scale(0.82);
}

.mobile-menu-open .menu-close-icon {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.main {
  min-width: 0;
  padding: 28px;
}

.page-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid rgba(216, 227, 238, 0.9);
  border-radius: var(--radius);
  margin-bottom: 22px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--soft-shadow);
}

.page-heading h1 {
  margin: 0;
  font-size: clamp(28px, 3vw, 42px);
  font-weight: 900;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.lead,
.panel p,
.panel-header p {
  max-width: 720px;
  margin: 6px 0 0;
  color: var(--muted);
}

.toolbar,
.dialog-actions,
.row-actions,
.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-header.standalone {
  border: 1px solid rgba(216, 227, 238, 0.92);
  border-radius: var(--radius);
  padding: 18px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--soft-shadow);
}

.panel-header h2 {
  margin: 0;
  font-size: 21px;
}

.primary-button,
.ghost-button,
.icon-button,
.danger-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 9px 14px;
  font-weight: 800;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.primary-button {
  color: #ffffff;
  background: linear-gradient(180deg, #21816d, var(--green-dark));
  box-shadow: 0 12px 24px rgba(23, 111, 92, 0.18);
}

.primary-button:hover {
  background: linear-gradient(180deg, var(--green), #0b493d);
  transform: translateY(-1px);
}

.ghost-button,
.icon-button {
  border-color: var(--line);
  color: var(--ink);
  background: #f9fbf8;
}

.ghost-button:hover,
.icon-button:hover {
  border-color: rgba(23, 111, 92, 0.26);
  background: #eef7f2;
}

.danger-button {
  color: #ffffff;
  background: var(--rose);
}

.icon-button {
  width: 40px;
  padding: 0;
}

.role-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #d5e2d8;
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fbfdfb;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(23, 111, 92, 0.12);
  outline: 0;
}

.role-switch select,
.toolbar select {
  width: auto;
  min-width: 180px;
}

.view {
  display: grid;
  gap: 18px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 18px;
}

.metric-grid,
.user-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 14px;
}

.queue-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.metric,
.panel,
.table-panel,
.customer-card,
.request-card,
.queue-column,
.settings-hub {
  border: 1px solid rgba(216, 227, 238, 0.92);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--soft-shadow);
}

.metric {
  position: relative;
  overflow: hidden;
  padding: 18px;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: linear-gradient(180deg, var(--green), var(--cyan), var(--amber));
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(28px, 2.4vw, 38px);
  font-weight: 900;
}

.panel,
.table-panel,
.queue-column,
.customer-card {
  padding: clamp(16px, 2vw, 24px);
}

.service-health,
.activity-list {
  display: grid;
  gap: 10px;
}

.health-item,
.activity-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-soft);
}

.health-item strong,
.activity-item strong {
  display: block;
}

.health-item span,
.activity-item span,
.customer-card span,
.request-card span {
  color: var(--muted);
  font-size: 13px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--green-dark);
  background: #e7f2ec;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status.warning {
  color: #805311;
  background: #fff4db;
}

.status.danger {
  color: #943246;
  background: #fde8ed;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
  min-width: 820px;
}

th,
td {
  padding: 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

td {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

td:first-child {
  border-left: 1px solid var(--line);
  border-radius: 10px 0 0 10px;
}

td:last-child {
  border-right: 1px solid var(--line);
  border-radius: 0 10px 10px 0;
}

.service-name strong {
  display: block;
}

.service-name span {
  color: var(--muted);
  font-size: 13px;
}

.queue-column h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.request-list {
  display: grid;
  gap: 10px;
}

.request-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: #ffffff;
}

.request-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.request-card h3,
.customer-card h3 {
  margin: 0;
  font-size: 16px;
}

.request-card p {
  margin: 0;
  color: #324458;
}

.customer-card {
  display: grid;
  gap: 12px;
}

.customer-card dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.customer-card dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.customer-card dd {
  margin: 2px 0 0;
  font-weight: 900;
}

.settings-hub {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  padding: 10px;
}

.settings-hub button {
  display: grid;
  gap: 4px;
  min-width: 0;
  border: 0;
  border-radius: 10px;
  padding: 14px;
  color: var(--ink);
  text-align: left;
  background: transparent;
}

.settings-hub button:hover {
  color: var(--green-dark);
  background: #e7f2ec;
}

.settings-hub strong {
  font-size: 15px;
}

.settings-hub span {
  color: var(--muted);
  font-size: 13px;
}

.dialog {
  width: min(620px, calc(100vw - 24px));
  border: 0;
  border-radius: 16px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(16, 32, 51, 0.24);
}

.dialog::backdrop {
  background: rgba(16, 32, 51, 0.42);
}

.dialog-panel {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-header h2 {
  margin: 0;
}

.dialog label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 850;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 6px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(23, 111, 92, 0.18);
  outline-offset: 2px;
}

body.customer-mode .admin-only,
body.customer-mode #customers .primary-button {
  display: none !important;
}

body:not(.superadmin-mode) .superadmin-only {
  display: none !important;
}

.error-banner {
  border: 1px solid #f0b8c4;
  border-radius: 8px;
  margin: 0;
  padding: 12px 14px;
  color: #943246;
  background: #fde8ed;
  font-weight: 800;
}

@media (max-width: 980px) {
  .appbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 42px 42px;
    gap: 10px;
    min-height: 64px;
    padding: 9px 14px;
  }

  .mobile-menu-button {
    display: inline-grid;
  }

  .profile-menu {
    grid-column: 3;
  }

  .nav-list {
    position: fixed;
    top: 72px;
    right: 12px;
    z-index: 40;
    display: none;
    width: min(340px, calc(100vw - 24px));
    max-height: calc(100vh - 86px);
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 22px 54px rgba(28, 45, 38, 0.18);
  }

  .mobile-menu-open .nav-list {
    display: grid;
    gap: 6px;
  }

  .nav-button {
    justify-content: flex-start;
    width: 100%;
    min-height: 46px;
    color: var(--ink);
  }

  .nav-button.active {
    color: #ffffff;
  }

  .page-heading,
  .dashboard-grid,
  .queue-grid {
    grid-template-columns: 1fr;
  }

  .page-heading {
    display: grid;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 14px 10px 24px;
  }

  .page-heading,
  .panel,
  .table-panel,
  .queue-column,
  .customer-card,
  .metric {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .toolbar,
  .dialog-actions {
    width: 100%;
  }

  .toolbar > .primary-button,
  .toolbar > .ghost-button,
  .toolbar select,
  .role-switch,
  .dialog-actions .primary-button,
  .dialog-actions .ghost-button {
    flex: 1 1 160px;
    width: 100%;
    min-width: 0;
  }

  .customer-card dl {
    grid-template-columns: 1fr;
  }

  table {
    min-width: 760px;
  }
}

/* Enterprise portal layout */
body {
  background: #f4f6f8;
}

.app-shell {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  min-height: 100vh;
}

.appbar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 286px;
  height: 100vh;
  min-height: 0;
  border-right: 1px solid #d9e1e8;
  border-bottom: 0;
  padding: 18px 14px;
  background: #ffffff;
  box-shadow: 8px 0 28px rgba(21, 32, 43, 0.06);
  overflow: auto;
}

.brand {
  flex: 0 0 auto;
  padding: 4px 4px 14px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex-basis: 42px;
  border-radius: 8px;
  color: #ffffff;
  background: linear-gradient(180deg, #2377ad, #0b5f52);
  box-shadow: none;
}

.sidebar-context,
.sidebar-status,
.profile-menu {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.sidebar-context {
  display: grid;
  gap: 3px;
  margin-top: 16px;
  padding: 12px;
}

.sidebar-context span,
.sidebar-context small,
.sidebar-status p,
.profile-summary span {
  color: var(--muted);
  font-size: 12px;
}

.sidebar-context span {
  font-weight: 850;
  text-transform: uppercase;
}

.sidebar-context strong {
  font-size: 15px;
}

.nav-list {
  display: grid;
  flex: 0 0 auto;
  align-items: stretch;
  justify-content: stretch;
  gap: 4px;
  margin-top: 16px;
}

.nav-button {
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  border-radius: 8px;
  padding: 10px;
  color: #394b5c;
  font-weight: 780;
}

.nav-icon {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid #d6e0e8;
  border-radius: 6px;
  color: #476276;
  background: #ffffff;
  font-size: 12px;
  font-weight: 900;
}

.nav-button.active {
  border-color: #0b5f52;
  color: #ffffff;
  background: #0b5f52;
}

.nav-button.active .nav-icon {
  border-color: rgba(255, 255, 255, 0.28);
  color: #ffffff;
  background: rgba(255, 255, 255, 0.14);
}

.sidebar-status {
  display: grid;
  gap: 10px;
  margin-top: auto;
  padding: 12px;
}

.sidebar-status p {
  margin: 0;
  line-height: 1.45;
}

.profile-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px;
}

.profile-button {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 8px;
  background: #ffffff;
}

.profile-summary {
  display: grid;
  min-width: 0;
}

.profile-summary strong,
.profile-summary span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  position: relative;
  display: grid;
  align-content: start;
  gap: 18px;
  min-width: 0;
  padding: 24px 28px 36px;
}

.page-loader {
  position: sticky;
  top: 0;
  z-index: 4;
  height: 4px;
  margin: -24px -28px 0;
  overflow: hidden;
  background: #e5edf3;
}

.page-loader span {
  display: block;
  width: 34%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), var(--green));
  animation: page-load 0.8s ease-in-out infinite;
}

@keyframes page-load {
  from { transform: translateX(-120%); }
  to { transform: translateX(320%); }
}

.page-is-loading .view.active,
.page-is-loading .page-heading {
  opacity: 0.58;
  transition: opacity 0.12s ease;
}

.page-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 20px;
  margin: 0;
  border-radius: 8px;
  padding: 18px 20px;
  background: #ffffff;
  box-shadow: 0 8px 22px rgba(21, 32, 43, 0.05);
}

.page-heading h1 {
  font-size: clamp(26px, 2.2vw, 34px);
}

.lead {
  max-width: 860px;
}

.metric-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric,
.panel,
.table-panel,
.customer-card,
.request-card,
.queue-column,
.settings-hub,
.panel-header.standalone {
  border-color: #dce4eb;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 20px rgba(21, 32, 43, 0.045);
}

.metric {
  padding: 16px;
}

.metric strong {
  font-size: 30px;
}

.panel,
.table-panel,
.queue-column,
.customer-card {
  padding: 18px;
}

.dashboard-grid {
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
}

.panel-header {
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.panel-header h2 {
  font-size: 18px;
}

.primary-button,
.ghost-button,
.icon-button,
.danger-button,
input,
select,
textarea {
  border-radius: 8px;
}

.primary-button,
.ghost-button,
.danger-button {
  min-height: 38px;
  padding: 8px 12px;
}

th {
  padding: 10px 12px;
  background: #f7fafc;
}

td {
  padding: 10px 12px;
}

table {
  border-spacing: 0;
}

tbody tr + tr td {
  border-top: 0;
}

td:first-child,
td:last-child {
  border-radius: 0;
}

.queue-grid {
  align-items: start;
}

.request-card {
  border-radius: 8px;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 252px minmax(0, 1fr);
  }

  .appbar {
    width: 252px;
  }

  .metric-grid,
  .dashboard-grid,
  .queue-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
  }

  .appbar {
    position: sticky;
    top: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 42px 42px;
    width: 100%;
    height: auto;
    min-height: 64px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 9px 14px;
    overflow: visible;
  }

  .brand {
    padding: 0;
    border-bottom: 0;
  }

  .sidebar-context,
  .sidebar-status {
    display: none;
  }

  .profile-menu {
    grid-column: 3;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .profile-summary {
    display: none;
  }

  .mobile-menu-button {
    display: inline-grid;
  }

  .nav-list {
    position: fixed;
    top: 72px;
    right: 12px;
    left: auto;
    z-index: 40;
    display: none;
    width: min(340px, calc(100vw - 24px));
    max-height: calc(100vh - 86px);
    margin: 0;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 22px 54px rgba(28, 45, 38, 0.18);
  }

  .mobile-menu-open .nav-list {
    display: grid;
  }

  .main {
    padding: 18px 14px 28px;
  }

  .page-loader {
    margin: -18px -14px 0;
  }

  .page-heading,
  .metric-grid,
  .dashboard-grid,
  .queue-grid {
    grid-template-columns: 1fr;
  }
}
