:root{
  /* Epopsio Brand */
  --primary: #E31E2F;
  --primary-dark: #7A0B13;
  --primary-soft: rgba(227, 30, 47, 0.18);
  --primary-soft-2: rgba(122, 11, 19, 0.18);

  /* Legacy variable mapping (UI only) */
  --aurora-blue: var(--primary);
  --aurora-purple: var(--primary-dark);
  --aurora-purple-dark: #7A0B13;

  /* Neutrals (black + dark gray) */
  --text-black: #0B0E14;
  --text-dark: #1B1F2A;
  --text-muted: #5C6475;
  --border: #E6E8EF;

  /* Surfaces */
  --bg: #F6F7FB;
  --card: #FFFFFF;
  --sidebar: #12141B;
  --sidebar-2: #181C26;

  --radius: 14px;
  --shadow: 0 10px 24px rgba(11, 14, 20, 0.08);
  --shadow-soft: 0 6px 16px rgba(11, 14, 20, 0.06);
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
/* Prevent sidebar/menu flash before RBAC permissions are applied. */
html:not(.perms-ready) [data-perm]{ visibility:hidden; }
body{
  margin:0;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--text-dark);
}

.toast{
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(10px);
  opacity: 0;
  z-index: 120;
  max-width: min(90vw, 560px);
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #111827;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 10px 24px rgba(0,0,0,0.22);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show{
  opacity: .98;
  transform: translateX(-50%) translateY(0);
}

a{ color:inherit; text-decoration:none; }
button, input{ font:inherit; }

/* ===== Layout ===== */
.app{
  display:flex;
  min-height:100vh;
}

.sidebar{
  width:270px;
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color:#fff;
  padding:22px 16px;
  border-right: 1px solid rgba(255,255,255,0.06);
}

.brand{
  display:flex;
  align-items:center;
  gap:12px;
  padding:10px 10px 18px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom:14px;
}

.brand img{
  height:34px;
  width:auto;
  display:block;
}

.brand .brand-title{
  display:flex;
  flex-direction:column;
  line-height:1.1;
}
.brand .brand-title strong{
  font-size:14px;
  letter-spacing:0.5px;
}
.brand .brand-title span{
  font-size:12px;
  color: rgba(255,255,255,0.7);
}

.nav{
  margin-top:14px;
  display:flex;
  flex-direction:column;
  gap:6px;
}

.nav a{
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 12px;
  border-radius: 12px;
  color: rgba(255,255,255,0.78);
  border: 1px solid transparent;
}

.nav a i{ width:18px; text-align:center; }

.nav a:hover{
  background: rgba(255,255,255,0.06);
  color:#fff;
}

.nav a.active{
  background: linear-gradient(90deg, var(--primary-soft), var(--primary-soft-2));
  border-color: rgba(255,255,255,0.10);
  color:#fff;
}

.main{
  flex:1;
  padding:26px;
}

/* ===== Topbar ===== */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  margin-bottom:18px;
}

.page-title h1{
  margin:0;
  font-size:22px;
  letter-spacing:0.2px;
  color: var(--text-black);
}
.page-title p{
  margin:6px 0 0 0;
  color: var(--text-muted);
  font-size:13px;
}

.badge-online{
  display:inline-flex;
  align-items:center;
  gap:8px;
  font-weight:600;
  color:#0D7A3A;
}
.badge-online .dot{
  width:10px; height:10px; border-radius:99px;
  background:#19C37D;
  box-shadow: 0 0 0 4px rgba(25,195,125,0.15);
}

.top-actions{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.manifest-summary-grid{
  display:grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap:8px;
  margin-top:10px;
  max-width:820px;
}
.manifest-summary-grid > div{
  border:1px solid var(--border);
  border-radius:8px;
  background:#fff;
  padding:8px 10px;
  min-width:0;
}
.manifest-summary-grid span{
  display:block;
  color:var(--text-muted);
  font-size:11px;
  font-weight:700;
  text-transform:uppercase;
}
.manifest-summary-grid strong{
  display:block;
  margin-top:3px;
  color:var(--text-black);
  font-size:13px;
  font-weight:800;
  overflow-wrap:anywhere;
}
.manifest-lifecycle-panel{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
  border:1px solid var(--border);
  border-radius:8px;
  background:#fff;
  padding:12px;
  margin:-6px 0 18px 0;
}
.manifest-lifecycle-title{
  font-size:13px;
  font-weight:800;
  color:var(--text-black);
}
.manifest-lifecycle-actions{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:8px;
  flex-wrap:wrap;
}

.page-head-actions-host{
  margin-left: auto;
  display:flex;
  align-items:center;
  justify-content:flex-end;
  flex: 1 1 auto;
}

.page-head > .top-actions{
  justify-content:flex-end;
}

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

.page-head .toolbar-actions,
.page-head .top-actions{
  margin-left:auto;
}

/* Users page header/toolbars */
.users-page-head{
  align-items:center;
  flex-wrap: nowrap;
}
.users-toolbar{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap: nowrap;
}
.users-toolbar > .input{
  flex: 1 1 420px;
  min-width: 260px;
}
.users-toolbar-actions{
  display:flex;
  align-items:center;
  gap:10px;
  margin-left:auto;
  flex-wrap: nowrap;
}
@media (max-width: 980px){
  .users-page-head{
    flex-wrap: wrap;
    align-items:flex-start;
  }
  .users-toolbar{
    flex-wrap: wrap;
  }
  .users-toolbar-actions{
    width:100%;
    margin-left:0;
    flex-wrap: wrap;
  }
}

.form-actions{
  display:flex;
  gap:10px;
  justify-content:flex-end;
  margin-top:16px;
}
.form-actions.sticky{
  position: sticky;
  bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 12px 0;
  margin-top: 18px;
  z-index: 5;
}

.btn{
  border: 1px solid var(--border);
  background: #fff;
  padding:10px 12px;
  border-radius: 12px;
  cursor:pointer;
  box-shadow: var(--shadow-soft);
}
.btn:hover{ transform: translateY(-1px); }

.draw-toolbar{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
  justify-content:flex-end;
}
.draw-toggle{
  display:inline-flex;
  align-items:center;
  gap:8px;
  border: 1px solid var(--border);
  background: #fff;
  padding:9px 12px;
  border-radius:10px;
  cursor:pointer;
  font-weight:600;
}
.draw-toggle input{
  margin:0 6px 0 0;
}
.draw-toggle.active{
  background: rgba(227,30,47,0.10);
  border-color: rgba(227,30,47,0.55);
  color: var(--primary);
}
.draw-status{
  display:flex;
  align-items:center;
  gap:8px;
}
.draw-mode{
  cursor: crosshair;
}
.route-point-pin{
  color: var(--primary);
  font-size:16px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

.btn-primary{
  border: none;
  color:#fff;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
}
.btn-primary:hover{ filter: brightness(1.03); }
.btn-primary:focus-visible{
  outline: 3px solid rgba(227, 30, 47, 0.28);
  outline-offset: 2px;
}
.btn-primary:disabled{
  cursor: not-allowed;
  opacity: 0.62;
  transform: none;
}

/* Alias variants for mixed HTML usage */
.btn.primary{
  border: none;
  color:#fff;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
}
.btn.primary:hover{ filter: brightness(1.03); }
.btn.primary:focus-visible{
  outline: 3px solid rgba(227, 30, 47, 0.28);
  outline-offset: 2px;
}
.btn.primary:disabled{
  cursor: not-allowed;
  opacity: 0.62;
  transform: none;
}

.input.ep-validation-invalid,
input.ep-validation-invalid,
select.ep-validation-invalid,
textarea.ep-validation-invalid{
  border-color: var(--primary) !important;
  background: rgba(227, 30, 47, 0.06) !important;
  box-shadow: 0 0 0 3px rgba(227, 30, 47, 0.12) !important;
}
.ep-validation-message{
  display:none;
  margin-top:6px;
  color:#B42318;
  font-size:12px;
  font-weight:700;
  line-height:1.35;
}
.ep-validation-field-invalid > label:first-child{
  color:#B42318;
}

.btn.secondary{
  background: #f6f7fb;
  border: 1px solid var(--border);
  color: #2b2f36;
}
.btn.secondary:hover{ filter: brightness(0.98); }
.btn-secondary{
  background: #f6f7fb;
  border: 1px solid var(--border);
  color: #2b2f36;
}
.btn-secondary:hover{ filter: brightness(0.98); }

.btn.danger{
  border: none;
  color:#fff;
  background: linear-gradient(90deg, #d64545, #b61f1f);
}
.btn.danger:hover{ filter: brightness(1.03); }
.btn-danger{
  border: none;
  color:#fff;
  background: linear-gradient(90deg, #d64545, #b61f1f);
}
.btn-danger:hover{ filter: brightness(1.03); }

.avatar{
  width:38px; height:38px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(227,30,47,0.95), rgba(122,11,19,0.95));
  box-shadow: var(--shadow-soft);
  display: none;
}

.client-user-menu{
  position: relative;
  z-index: 30;
}
.client-user-trigger{
  display:flex;
  align-items:center;
  gap:10px;
  border:1px solid var(--border);
  background:#fff;
  border-radius:999px;
  padding:6px 12px 6px 8px;
  box-shadow: var(--shadow-soft);
  cursor:pointer;
}
.client-user-avatar{
  width:28px;
  height:28px;
  border-radius:999px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  color:#fff;
  font-size:12px;
  font-weight:700;
  background: linear-gradient(135deg, rgba(227,30,47,0.95), rgba(122,11,19,0.95));
}
.client-user-login{
  max-width:220px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  font-size:13px;
  color: var(--text-dark);
}
.client-user-panel{
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  margin-top:8px;
  min-width:210px;
  background:#fff;
  border:1px solid var(--border);
  border-radius:12px;
  box-shadow: var(--shadow);
  padding:6px;
}
.top-actions .client-user-menu{
  margin-left: auto;
}
.client-user-item{
  width:100%;
  display:flex;
  align-items:center;
  gap:8px;
  padding:9px 10px;
  border:none;
  background:transparent;
  border-radius:8px;
  cursor:pointer;
  color:var(--text-dark);
  text-align:left;
}
.client-user-item:hover{
  background:#f6f8fc;
}
.client-user-item.danger{
  color:#b42318;
}

.monitor-controls{
  margin-bottom: 14px;
}
.monitor-toolbar{
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  overflow-x: auto;
}
.monitor-filter{
  min-width: 220px;
}
.monitor-toggle{
  display:flex;
  align-items:center;
  gap:8px;
  font-size:13px;
  white-space:nowrap;
}
.monitor-route-status{
  margin-left: auto;
  white-space: nowrap;
}
.monitor-sim-controls{
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px dashed rgba(0,0,0,0.12);
  border-radius: 12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}
.monitor-sim-left{
  display:flex;
  align-items:center;
  gap:10px;
}
.monitor-sim-actions{
  display:flex;
  align-items:center;
  gap:8px;
}
.monitor-stage{
  position: relative;
  padding: 12px;
  overflow: hidden;
}
.monitor-map-head{
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 4;
  display:flex;
  align-items:center;
  justify-content:space-between;
  pointer-events: none;
}
.monitor-map{
  position: relative;
  z-index: 1;
  height: 620px;
  border-radius: 12px;
  overflow: hidden;
}
.monitor-map-popout{
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.95);
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 10px 24px rgba(0,0,0,0.15);
}
.monitor-map-popout:hover{
  transform: translateY(-1px);
}
.monitor-map-window .main{
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
}
html.monitor-map-window,
body.monitor-map-window{
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
}
.monitor-map-window.app{
  display:block;
}
.monitor-map-window .sidebar{
  display:none;
}
.monitor-map-window .monitor-stage{
  border-radius: 0;
  padding: 0;
  min-height: 100%;
  height: 100%;
  border: 0;
  box-shadow: none;
  background: transparent;
  margin: 0;
}
.monitor-map-window .monitor-map{
  height: 100%;
  border-radius: 0;
}
.monitor-map-meta{
  position: absolute;
  left: 16px;
  top: 16px;
  z-index: 6;
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(0,0,0,0.08);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
}
.monitor-map-window #clientUserMenu{
  display:none !important;
}
.monitor-map-layout{
  display:flex;
  gap:0;
  height: 100%;
  width: 100%;
  align-items: stretch;
}
.monitor-map-canvas{
  flex:1;
  position:relative;
  min-width: 0;
  height: 100%;
}
.monitor-map-sidebar{
  border-left: 1px solid rgba(0,0,0,0.08);
}
.monitor-map-sidebar{
  width: min(420px, 32vw);
  display:flex;
  flex-direction:column;
  height: 100%;
}
.monitor-map-panel{
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.12);
  display:flex;
  flex-direction:column;
  min-height: 0;
}
.monitor-map-panel-head{
  padding: 10px 12px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.monitor-map-panel-body{
  padding: 10px 12px;
  overflow:auto;
  flex:1;
}
.monitor-map-panel .table{
  margin-top: 0;
  background: transparent;
}
.map-pin{
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.map-pin-wrap{
  position: relative;
  width: 18px;
  height: 18px;
}
.map-pin-icon{
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 15px;
  color: inherit;
  text-shadow:
    -1px -1px 0 #fff,
    1px -1px 0 #fff,
    -1px 1px 0 #fff,
    1px 1px 0 #fff,
    0 2px 3px rgba(0,0,0,0.2);
}
.map-pin.green{ background:#16a34a; }
.map-pin.orange{ background:#f59e0b; }
.map-pin.red{ background:#dc2626; }
.map-pin.blue{ background:#2563eb; }
.map-pin-wrap.green{ color:#16a34a; }
.map-pin-wrap.orange{ color:#f59e0b; }
.map-pin-wrap.red{ color:#dc2626; }
.map-pin-wrap.blue{ color:#2563eb; }
@media (max-width: 1100px){
  .monitor-map-layout{
    flex-direction: column;
    height: auto;
  }
  .monitor-map-sidebar{
    width: 100%;
  }
  .monitor-map-window .monitor-map{
    height: 520px;
  }
}
.monitor-live-overlay{
  position: absolute;
  top: 56px;
  right: 24px;
  bottom: 24px;
  width: min(440px, 32vw);
  z-index: 1200;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(255,255,255,0.65);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
}
.monitor-live-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.monitor-live-body{
  overflow: auto;
  height: 100%;
}
.monitor-live-overlay .table{
  margin-top: 0;
  background: transparent;
}
.status-pill{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:3px 8px;
  border-radius:999px;
  font-size:11px;
  font-weight:700;
  letter-spacing:0.2px;
}
.status-pill.normal{ background:#e7f7ee; color:#0f7a3a; }
.status-pill.warning{ background:#fff4e6; color:#b45309; }
.status-pill.critical,
.status-pill.danger{ background:#fde8e8; color:#b91c1c; }
.status-pill.muted{ background:#f3f4f6; color:#4b5563; }
.status-pill.info{ background:#eff6ff; color:#1d4ed8; }
@media (max-width: 1100px){
  .monitor-live-overlay{
    position: static;
    width: 100%;
    margin-top: 10px;
    background: rgba(255,255,255,0.92);
    border-color: var(--border);
    backdrop-filter: none;
    box-shadow: none;
    max-height: 320px;
  }
  .monitor-map-head{
    position: static;
    margin-bottom: 8px;
    pointer-events: auto;
  }
  .monitor-map{
    height: 500px;
  }
}

.drawer{
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.25);
  display: flex;
  justify-content: flex-end;
  z-index: 20;
}
.drawer.hidden{ display:none; }
.drawer-panel{
  width: 420px;
  max-width: 92vw;
  height: 100%;
  background: #fff;
  box-shadow: -12px 0 30px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
}

.drawer.driver-modal{
  justify-content: center;
  align-items: center;
  padding: 20px;
}
.drawer.driver-modal .drawer-panel{
  width: min(960px, calc(100vw - 40px));
  max-width: 960px;
  height: min(88vh, 900px);
  max-height: 88vh;
  border-radius: 14px;
  box-shadow: 0 18px 44px rgba(0,0,0,0.22);
}
.drawer.driver-modal .drawer-body{
  max-height: none;
}
.drawer-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:16px;
  border-bottom:1px solid var(--border);
}
.drawer-title{ font-weight:700; font-size:16px; }
.drawer-sub{ font-size:12px; color: var(--muted); margin-top:4px; }
.drawer-body{
  padding:16px;
  overflow:auto;
  display:grid;
  gap:10px;
}
.detail-row{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
}
.detail-block{
  background:#f7f8fb;
  border:1px solid var(--border);
  padding:10px;
  border-radius:10px;
}

/* ===== Cards / Grid ===== */
.grid{
  display:grid;
  grid-template-columns: repeat(12, 1fr);
  gap:16px;
  margin-top:14px;
}
@media (max-width: 1100px){
  .grid.stack > *{ grid-column: span 12 !important; }
}

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

.kpi{
  grid-column: span 3;
  min-height: 110px;
}
@media (max-width: 1100px){
  .kpi{ grid-column: span 6; }
}
@media (max-width: 720px){
  .sidebar{ display:none; }
  .main{ padding:18px; }
  .kpi{ grid-column: span 12; }
}
@media (max-width: 980px){
  .topbar{
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .top-actions{
    width: 100%;
    justify-content: flex-end;
  }
  .manifest-summary-grid{
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width:100%;
  }
  .manifest-lifecycle-panel,
  .manifest-lifecycle-actions{
    align-items:stretch;
    width:100%;
  }
  .manifest-lifecycle-actions .btn{
    flex:1 1 auto;
  }
  .client-user-login{
    max-width: 140px;
  }
}
@media (max-width: 640px){
  .client-user-login{
    display: none;
  }
  .client-user-trigger{
    padding-right: 10px;
  }
}

.kpi-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  color: var(--text-muted);
  font-size:12px;
  text-transform: uppercase;
  letter-spacing:0.08em;
}

.kpi-value{
  margin-top:10px;
  font-size:34px;
  font-weight:800;
  color: var(--text-black);
}

.kpi-sub{
  margin-top:6px;
  color: var(--text-muted);
  font-size:12px;
}

.icon-pill{
  width:34px; height:34px;
  border-radius: 12px;
  display:flex;
  align-items:center;
  justify-content:center;
  color:#fff;
}
.icon-purple{ background: rgba(122,11,19,0.95); }
.icon-blue{ background: rgba(227,30,47,0.95); }
.icon-dark{ background: rgba(27,31,42,0.92); }
.icon-warn{ background: #F59E0B; }

.section{
  grid-column: span 12;
}

.table{
  width:100%;
  border-collapse: collapse;
  margin-top:10px;
}

.table th, .table td{
  border-top: 1px solid var(--border);
  padding:10px 8px;
  text-align:left;
  font-size:13px;
}

.table th{
  color: var(--text-muted);
  font-weight:700;
  font-size:12px;
  text-transform: uppercase;
  letter-spacing:0.06em;
}

.pill{
  display:inline-flex;
  align-items:center;
  padding:6px 10px;
  border-radius:999px;
  font-size:12px;
  font-weight:700;
  border: 1px solid var(--border);
  background: #fff;
}
.pill.ok{ color:#0D7A3A; border-color: rgba(25,195,125,0.25); background: rgba(25,195,125,0.10); }
.pill.note,
.pill.warn{ color:#92400E; border-color: rgba(245,158,11,0.35); background: rgba(245,158,11,0.12); }
.pill.danger{ color:#A61B1B; border-color: rgba(220,38,38,0.28); background: rgba(220,38,38,0.10); }
.pill.gray{ color:#4B5563; border-color: rgba(107,114,128,0.28); background: rgba(107,114,128,0.10); }
.pill.info{ color:#1D4ED8; border-color: rgba(59,130,246,0.28); background: rgba(59,130,246,0.10); }

/* ===== Dispatcher/operator cleanup ===== */
.btn.sm{
  padding:7px 10px;
  border-radius:10px;
  font-size:12px;
  box-shadow:none;
}

.dispatcher-surface{
  display:flex;
  flex-direction:column;
  gap:14px;
}

.dispatcher-filter-grid{
  display:grid;
  grid-template-columns: minmax(280px, 2fr) repeat(3, minmax(180px, 1fr)) auto;
  gap:12px;
  align-items:end;
}

.dispatcher-filter-main{
  min-width:0;
}

.dispatcher-row,
.dispatcher-action-row,
.dispatcher-pager,
.dispatcher-saved-views,
.dispatcher-quick-filters,
.dispatcher-button-group{
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
}

.dispatcher-row{
  justify-content:space-between;
}

.dispatcher-action-row{
  justify-content:space-between;
  padding-top:2px;
}

.dispatcher-actions-right,
.dispatcher-actions-left{
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
}

.dispatcher-pager{
  justify-content:flex-end;
}

.dispatcher-summary{
  color:var(--text-muted);
  font-size:12px;
  line-height:1.45;
}

.dispatcher-check{
  min-height:42px;
  display:flex;
  align-items:center;
  gap:8px;
  color:var(--text-muted);
  font-size:13px;
  white-space:nowrap;
  padding-bottom:2px;
}

.dispatcher-bulk-bar{
  display:none;
  padding:10px 12px;
  border:1px solid rgba(227,30,47,0.22);
  border-radius:8px;
  background:rgba(227,30,47,0.06);
}

.dispatcher-bulk-bar.is-active{
  display:block;
}

.dispatcher-bulk-content{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
}

.dispatcher-bulk-content .dispatcher-button-group{
  margin-left:auto;
  justify-content:flex-end;
}

.dispatcher-table-wrap{
  overflow:auto;
  -webkit-overflow-scrolling:touch;
  border:1px solid var(--border);
  border-radius:8px;
  background:#fff;
}

.dispatcher-table{
  min-width:980px;
  margin-top:0;
}

.dispatcher-table th,
.dispatcher-table td{
  white-space:normal;
  vertical-align:top;
}

.dispatcher-table .cell-primary{
  font-weight:700;
  color:var(--text-black);
}

.dispatcher-table .cell-secondary{
  color:var(--text-muted);
  font-size:12px;
  margin-top:3px;
}

.dispatcher-table .actions-cell{
  min-width:132px;
  text-align:right;
}

.dispatcher-table .action-stack{
  display:flex;
  justify-content:flex-end;
  gap:6px;
  flex-wrap:wrap;
}

.dispatcher-table .action-stack .btn{
  white-space:nowrap;
}

#shipmentsTable.dispatcher-table{
  min-width:1240px;
}

#shipmentsTable.dispatcher-table th:nth-child(2),
#shipmentsTable.dispatcher-table td:nth-child(2){
  width:150px;
  max-width:150px;
  overflow-wrap:anywhere;
}

#shipmentsTable.dispatcher-table th:nth-child(9),
#shipmentsTable.dispatcher-table td:nth-child(9){
  min-width:220px;
  max-width:300px;
}

.route-review-summary{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap:6px 12px;
  font-size:13px;
}

.route-review-summary .route-review-note{
  grid-column:1 / -1;
}

.operator-panel-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}

@media (max-width: 1180px){
  .dispatcher-filter-grid{
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .dispatcher-check{
    align-items:flex-start;
  }
}

@media (max-width: 760px){
  .dispatcher-filter-grid,
  .route-review-summary{
    grid-template-columns:1fr;
  }
  .dispatcher-row,
  .dispatcher-action-row,
  .dispatcher-pager{
    align-items:stretch;
  }
  .dispatcher-actions-right,
  .dispatcher-actions-left,
  .dispatcher-saved-views,
  .dispatcher-quick-filters,
  .dispatcher-button-group,
  .dispatcher-pager{
    width:100%;
  }
  .dispatcher-action-row .btn,
  .dispatcher-bulk-content .btn,
  .dispatcher-pager .btn{
    flex:1 1 auto;
  }
  .dispatcher-bulk-content .dispatcher-button-group{
    margin-left:0;
  }
}

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

.analytics-section-head{
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:flex-start;
  flex-wrap:wrap;
}

.analytics-mini-grid{
  display:grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap:12px;
  margin-top:16px;
}

.analytics-metric{
  border:1px solid var(--border);
  border-radius:12px;
  padding:14px;
  background: linear-gradient(180deg, #fff, #fafbff);
}

.analytics-metric-label{
  color: var(--text-muted);
  font-size:12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.analytics-metric-value{
  margin-top:10px;
  font-size:28px;
  font-weight:800;
  color: var(--text-black);
}

.analytics-split-grid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap:16px;
}

.muted{
  color: var(--text-muted);
}

@media (max-width: 1180px){
  .analytics-mini-grid{
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px){
  .analytics-mini-grid,
  .analytics-split-grid{
    grid-template-columns: 1fr;
  }
}

/* ===== Report Builder ===== */
.report-palette{
  display:flex;
  flex-direction:column;
  gap:8px;
  max-height:360px;
  overflow:auto;
  padding-right:4px;
}
.report-field{
  border:1px solid var(--border);
  border-radius:10px;
  padding:8px 10px;
  background:#fff;
  cursor:grab;
  user-select:none;
  font-size:13px;
}
.report-field:active{ cursor:grabbing; }
.report-dropzone{
  min-height:90px;
  margin-top:8px;
  border:2px dashed var(--border);
  border-radius:12px;
  padding:10px;
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:flex-start;
  background:#fafbff;
}
.report-dropzone.over{
  border-color: var(--primary);
  background:#fff4f5;
}
.report-pill{
  display:inline-flex;
  align-items:center;
  gap:8px;
  border:1px solid var(--border);
  border-radius:999px;
  padding:6px 10px;
  background:#fff;
  font-size:12px;
}
.report-pill button{
  border:none;
  background:transparent;
  color:#9b1c1c;
  cursor:pointer;
  padding:0;
  font-weight:700;
}
.criteria-row{
  display:grid;
  grid-template-columns: 1fr 120px 1fr auto;
  gap:8px;
  margin-bottom:8px;
}
@media (max-width: 900px){
  .criteria-row{ grid-template-columns: 1fr; }
}

/* ===== Roles page helpers ===== */
.split{
  display:grid;
  grid-template-columns: 340px 1fr;
  gap:16px;
}
@media (max-width: 980px){
  .split{ grid-template-columns: 1fr; }
}

.input{
  width:100%;
  padding:10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  outline:none;
  background:#fff;
}
.input:focus{
  border-color: rgba(227,30,47,0.55);
  box-shadow: 0 0 0 4px rgba(227,30,47,0.12);
}
.input.with-action{ padding-right:44px; }
.input-with-action{ position:relative; }
.input-action-btn{
  position:absolute;
  right:8px;
  top:8px;
  transform:none;
  width:28px;
  height:28px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border:0;
  background:transparent;
  box-shadow:none;
  padding:0;
  border-radius:8px;
  color: var(--text-muted);
  cursor:pointer;
}
.input-action-btn:hover{
  background: rgba(0,0,0,0.04);
  color: var(--text-dark);
}

.role-card{
  border: 1px solid var(--border);
  border-radius: 12px;
  padding:12px;
  margin-top:10px;
  cursor:pointer;
  background:#fff;
}
.role-card:hover{ transform: translateY(-1px); }
.role-card.active{
  border-color: rgba(122,11,19,0.45);
  box-shadow: 0 0 0 4px rgba(122,11,19,0.10);
}

.permission-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:10px 0;
  border-top: 1px solid var(--border);
  font-size:13px;
}
.permission-row:first-child{ border-top:none; }

/* ===== Form controls ===== */
.select{
  padding:10px 12px;
  border-radius:12px;
  border: 1px solid var(--border);
  background:#fff;
  color: var(--text-dark);
  outline:none;
}
.select:focus{
  border-color: rgba(227,30,47,0.55);
  box-shadow: 0 0 0 4px rgba(227,30,47,0.12);
}

/* ===== Modal (used by users.html) ===== */
/* Small helper text under inputs */
.help-text{
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.35;
  color: #7a8192;
  font-weight: 500;
}

.modal-backdrop{
  position:fixed;
  inset:0;
  background: rgba(11,14,20,0.55);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
  z-index: 3000;
  pointer-events: auto;
}
.modal{
  width:min(760px,100%);
  background:#fff;
  border:1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding:16px;
}
.modal-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding-bottom:12px;
  border-bottom:1px solid var(--border);
}
.modal-title{
  font-size:16px;
  font-weight:800;
  color:var(--text-black);
}
.modal-subtitle{
  margin-top:6px;
  font-size:12px;
  color:var(--text-muted);
}
.modal-body{
  padding-top:14px;
}
.modal-actions{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  padding-top:14px;
  border-top:1px solid var(--border);
  margin-top:14px;
}
.icon-btn{
  border:1px solid var(--border);
  background:#fff;
  border-radius:12px;
  width:38px;
  height:38px;
  cursor:pointer;
  box-shadow: var(--shadow-soft);
}
.icon-btn:hover{ transform: translateY(-1px); }

/* ===== Users page form layout ===== */
.form-row{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:12px;
}
.form-row.cols-3{
  grid-template-columns: repeat(3, 1fr);
}
.form-row.cols-1{
  grid-template-columns: 1fr;
}
@media (max-width: 1200px){
  .form-row.cols-3{ grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px){
  .form-row{ grid-template-columns: 1fr; }
  .form-row.cols-3{ grid-template-columns: 1fr; }
}
.field label{
  display:block;
  font-size:12px;
  color:var(--text-muted);
  margin:0 0 6px 0;
}
.geo-search-wrap{
  position:relative;
}
.geo-suggestions{
  position:absolute;
  left:0;
  right:0;
  top:calc(100% + 4px);
  z-index:50;
  display:none;
  max-height:300px;
  overflow:auto;
  background:#fff;
  border:1px solid var(--border);
  border-radius:8px;
  box-shadow:0 14px 34px rgba(11,14,20,.16);
}
.geo-suggestion{
  width:100%;
  border:0;
  border-bottom:1px solid var(--border);
  background:#fff;
  color:var(--text);
  text-align:left;
  padding:10px 12px;
  cursor:pointer;
  display:block;
}
.geo-suggestion:last-child{ border-bottom:0; }
.geo-suggestion:hover,
.geo-suggestion.active{
  background:#f7f8fb;
}
.geo-suggestion span{
  display:block;
  font-weight:650;
  line-height:1.3;
}
.geo-suggestion small{
  display:block;
  color:var(--text-muted);
  margin-top:3px;
  line-height:1.25;
}
.chips{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  padding:10px;
  border:1px dashed rgba(227,30,47,0.35);
  border-radius:12px;
  background: rgba(227,30,47,0.04);
}
.chip-btn{
  border:1px solid var(--border);
  background:#fff;
  padding:8px 10px;
  border-radius:999px;
  cursor:pointer;
  font-size:12px;
  font-weight:700;
  color: var(--text-dark);
}
.chip-btn.on{
  border-color: rgba(122,11,19,0.45);
  background: rgba(122,11,19,0.12);
  color: var(--primary-dark);
}

/* --- Epopsio Admin Polish --- */
.table td, .table th { vertical-align: middle; }
.actions a {
  margin-left: 10px;
  cursor: pointer;
  transition: color .16s ease;
}
.actions a:hover,
.actions a:focus-visible {
  color: var(--primary-dark) !important;
}
.pill { display:inline-flex; align-items:center; justify-content:center; min-width:70px; }

.table th.sortable{
  cursor:pointer;
  user-select:none;
}

.role-chip{
  display:inline-flex;
  align-items:center;
  height:24px;
  padding:0 8px;
  margin:0 6px 4px 0;
  border:1px solid rgba(122,11,19,0.25);
  border-radius:999px;
  background:rgba(122,11,19,0.10);
  color:var(--primary-dark);
  font-size:12px;
  font-weight:700;
}
.modal { max-width: 900px; }
.modal .input { height: 44px; }
.errorline { margin-top: 12px; }

/* === EPOPSIO SIDEBAR BRAND STACK FIX (AUTO) === */
.sidebar .brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding-top: 18px;
  padding-bottom: 18px;
  text-align: center;
}

.sidebar .brand img,
.sidebar .brand .logo,
.sidebar .brand .brand-logo {
  display: block;
  max-width: 170px;
  height: auto;
  margin: 0 auto;
}

.sidebar .brand-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  margin-top: 2px;
}

.sidebar .brand-title strong {
  display: block;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.sidebar .brand-title span {
  display: block;
  opacity: 0.85;
  font-weight: 500;
  margin-top: 4px;
}
/* === END EPOPSIO SIDEBAR BRAND STACK FIX (AUTO) === */


/* =========================================================
   EPOPSIO CLIENT PORTAL — SINGLE SOURCE OF TRUTH (Layout+Modal)
   ========================================================= */

:root{
  --sidebar-w: 270px;
  --page-pad: 26px;
}

html, body { height: 100%; }
body { margin: 0; overflow-x: hidden; }

/* App shell */
.app{ min-height: 100vh; display: flex; }

/* Sidebar fixed */
.sidebar{
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  position: fixed;
  left: 0; top: 0; bottom: 0;
  overflow-y: auto;
  z-index: 20;
}

/* Main reserves sidebar space */
.main{
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
  min-height: 100vh;
  padding: var(--page-pad);
  box-sizing: border-box;
}

/* ===== Modal: true viewport overlay, centered =====
   Sidebar remains visible by z-index order */
.modal-backdrop{
  position: fixed;
  inset: 0;                 /* cover full viewport */
  background: rgba(11,14,20,0.55);
  display: none;            /* JS toggles */
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 10000;           /* above page */
}
.modal-backdrop.show{ display: flex; }

/* Keep sidebar visible on top of backdrop (optional, as you requested) */
.sidebar{ z-index: 10001; }

/* Modal panel */
.modal{
  width: min(760px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  box-sizing: border-box;
}

/* Mobile */
@media (max-width: 900px){
  :root{ --sidebar-w: 0px; --page-pad: 16px; }
  .sidebar{ position: static; width: 100%; height: auto; }
  .main{ margin-left: 0; width: 100%; }
  .sidebar{ z-index: 20; } /* normal on mobile */
}

/* =========================================================
   EPOPSIO CLIENT PORTAL — SINGLE SOURCE OF TRUTH (Layout+Modal)
   ========================================================= */

:root{
  --sidebar-w: 270px;
  --page-pad: 26px;
}

html, body { height: 100%; }
body { margin: 0; overflow-x: hidden; }

/* App shell */
.app{ min-height: 100vh; display: flex; }

/* Sidebar fixed */
.sidebar{
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  position: fixed;
  left: 0; top: 0; bottom: 0;
  overflow-y: auto;
  z-index: 20;
}

/* Main reserves sidebar space */
.main{
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
  min-height: 100vh;
  padding: var(--page-pad);
  box-sizing: border-box;
}

/* ===== Modal: true viewport overlay, centered =====
   Sidebar remains visible by z-index order */
.modal-backdrop{
  position: fixed;
  inset: 0;                 /* cover full viewport */
  background: rgba(11,14,20,0.55);
  display: none;            /* JS toggles */
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 10000;           /* above page */
}
.modal-backdrop.show{ display: flex; }

/* Keep sidebar visible on top of backdrop (optional, as you requested) */
.sidebar{ z-index: 10001; }

/* Modal panel */
.modal{
  width: min(760px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  box-sizing: border-box;
}

/* Mobile */
@media (max-width: 900px){
  :root{ --sidebar-w: 0px; --page-pad: 16px; }
  .sidebar{ position: static; width: 100%; height: auto; }
  .main{ margin-left: 0; width: 100%; }
  .sidebar{ z-index: 20; } /* normal on mobile */
}


/* =========================================================
   MODAL UI POLISH
   ========================================================= */

.modal{
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 25px 70px rgba(0,0,0,.25);
  border: 1px solid rgba(0,0,0,.06);
  padding: 20px;
}

.modal h2,
.modal h3{
  margin: 0 0 14px;
  font-size: 18px;
  font-weight: 700;
}

.modal label{
  display:block;
  margin:12px 0 6px;
  font-weight:600;
}

.modal input,
.modal select{
  width:100%;
  margin-bottom:8px;
}

.modal-actions{
  display:flex;
  justify-content:flex-end;
  gap:12px;
  margin-top:16px;
  padding-top:14px;
  border-top:1px solid rgba(0,0,0,.06);
}

/* Remove any ghost floating white bar */
/* =========================================================
   FIX: remove stray empty modal container (#modalDialog)
   This element was rendering as a "bar" even when closed.
   ========================================================= */
#modalDialog{ display:none !important; }



/* ===== Modal Close Button Fix ===== */

.modal{
  position: relative;   /* allow absolute children */
}

/* Target the close button inside modal */
.modal .close-btn,
.modal button.close,
.modal .modal-close{
  position: absolute !important;
  top: 18px !important;
  right: 18px !important;
  left: auto !important;
  margin: 0 !important;
}

/* Optional: better visual style */
.modal .close-btn,
.modal button.close,
.modal .modal-close{
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Legacy modal overlays (shipments + trips) */
.modal.modal-overlay{
  position: fixed;
  inset: 0;
  display: none; /* JS toggles */
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(11,14,20,0.55);
  z-index: 10000;
}
.modal.modal-overlay .modal-content{
  width: min(900px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  box-sizing: border-box;
}
.modal.modal-overlay .modal-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding-bottom:12px;
  border-bottom:1px solid var(--border);
}
.modal.modal-overlay .modal-body{
  padding-top:12px;
}
.modal.modal-overlay .modal-footer{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  padding-top:14px;
  border-top:1px solid var(--border);
  margin-top:14px;
}


/* =========================================================
   FINAL CLEAN OVERRIDE — CLIENT PORTAL MODAL (SOURCE OF TRUTH)
   ========================================================= */

/* Backdrop: full viewport overlay */
.modal-backdrop{
  position: fixed !important;
  inset: 0 !important;
  background: rgba(11,14,20,0.55) !important;

  display: none !important;              /* JS toggles by adding .show or inline */
  align-items: center !important;
  justify-content: center !important;

  padding: 18px !important;
  z-index: 10000 !important;
}

.modal-backdrop.show{
  display: flex !important;
}

/* Keep sidebar above backdrop (if you want sidebar clickable/visible) */
.sidebar{
  z-index: 10001 !important;
}

/* Modal card */
.modal{
  position: relative !important;         /* anchor for close button */
  width: min(860px, 100%) !important;
  max-height: calc(100vh - 36px) !important;
  overflow: auto !important;

  background: #fff !important;
  border-radius: 18px !important;
  border: 1px solid rgba(0,0,0,.06) !important;
  box-shadow: 0 25px 70px rgba(0,0,0,.25) !important;

  padding: 22px !important;
  box-sizing: border-box !important;

  transform: none !important;
  left: auto !important;
  top: auto !important;
}

/* Modal header spacing so the X doesn't push layout */
.modal-head{
  padding-right: 56px !important;        /* space for the close button */
}

/* Close button: your HTML uses .icon-btn and id="modalClose" */
.modal .icon-btn,
.modal #modalClose{
  position: absolute !important;
  top: 18px !important;
  right: 18px !important;
  left: auto !important;
  margin: 0 !important;

  width: 40px !important;
  height: 40px !important;
  border-radius: 12px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Remove the ghost bar (the element you highlighted in DevTools) */
#modalDialog{
  display: none !important;
}


/* === Users modal close button: force top-right === */
.modal{ position: relative; }
#modalClose{
  position: absolute !important;
  top: 16px !important;
  right: 16px !important;
  left: auto !important;
  margin: 0 !important;
  z-index: 2 !important;
}



/* === LAYOUT FIX === */
.app {
  display: flex;
  width: 100%;
  min-height: 100vh;
}

.sidebar {
  width: 270px;
  flex: 0 0 270px;
  background: #FFFFFF;
  color: var(--text-black);
  border-right: 1px solid var(--border);
}

.main {
  flex: 1;
  overflow-x: hidden;
  padding: 24px;
  box-sizing: border-box;
}

/* === helpers === */
.hidden{ display:none !important; }

/* === RELEASE OVERRIDE: UNIFIED LIGHT SIDEBAR === */
.sidebar .brand{
  border-bottom: 1px solid var(--border);
}

.sidebar .brand-title strong{
  color: var(--text-black);
}

.sidebar .brand-title span{
  color: var(--text-muted);
  opacity: 1;
}

.nav a{
  color: var(--text-black);
}

.nav a:hover{
  background: rgba(122,11,19,0.10);
  border-color: rgba(122,11,19,0.25);
  color: var(--primary-dark);
}

.nav a.active{
  background: rgba(122,11,19,0.10);
  border-color: rgba(122,11,19,0.25);
  color: var(--primary-dark);
}
/* === END RELEASE OVERRIDE: UNIFIED LIGHT SIDEBAR === */
